Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replenish lifecycle,replication,website,image process,referer some fi… #461

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/com/aliyun/oss/OSS.java
Original file line number Diff line number Diff line change
Expand Up @@ -3248,6 +3248,23 @@ public BucketReplicationProgress getBucketReplicationProgress(
public List<String> getBucketReplicationLocation(GenericRequest genericRequest)
throws OSSException, ClientException;

/**
* @param bucketName
* @return
* @throws OSSException
* @throws ClientException
*/
public BucketReplicationLocationResult getBucketReplicationLocationV2(String bucketName) throws OSSException, ClientException;

/**
* @param genericRequest
* @return
* @throws OSSException
* @throws ClientException
*/
public BucketReplicationLocationResult getBucketReplicationLocationV2(GenericRequest genericRequest)
throws OSSException, ClientException;

/**
* Adds a Cname for the {@link Bucket} instance.
*
Expand Down Expand Up @@ -5101,4 +5118,12 @@ public UdfApplicationLog getUdfApplicationLog(GetUdfApplicationLogRequest getUdf
* If any errors occurred in OSS while processing the request.
*/
VoidResult closeMetaQuery(String bucketName) throws OSSException, ClientException;

/**
* Turn RTC on or off for an existing cross region replication rule
*
* @param putBucketRTCRequest
* @return VoidResult
*/
VoidResult putBucketRTC(PutBucketRTCRequest putBucketRTCRequest) throws OSSException, ClientException;
}
15 changes: 15 additions & 0 deletions src/main/java/com/aliyun/oss/OSSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,16 @@ public List<String> getBucketReplicationLocation(GenericRequest genericRequest)
return this.bucketOperation.getBucketReplicationLocation(genericRequest);
}

@Override
public BucketReplicationLocationResult getBucketReplicationLocationV2(String bucketName) throws OSSException, ClientException {
return this.bucketOperation.getBucketReplicationLocationV2(new GenericRequest(bucketName));
}

@Override
public BucketReplicationLocationResult getBucketReplicationLocationV2(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketReplicationLocationV2(genericRequest);
}

@Override
public AddBucketCnameResult addBucketCname(AddBucketCnameRequest addBucketCnameRequest) throws OSSException, ClientException {
return this.bucketOperation.addBucketCname(addBucketCnameRequest);
Expand Down Expand Up @@ -1957,6 +1967,11 @@ public VoidResult closeMetaQuery(String bucketName) throws OSSException, ClientE
return this.bucketOperation.closeMetaQuery(new GenericRequest(bucketName));
}

@Override
public VoidResult putBucketRTC(PutBucketRTCRequest putBucketRTCRequest) throws OSSException, ClientException {
return this.bucketOperation.putBucketRTC(putBucketRTCRequest);
}

@Override
public void shutdown() {
try {
Expand Down
70 changes: 67 additions & 3 deletions src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public final class RequestMarshallers {
public static final PutBucketTransferAccelerationRequestMarshaller putBucketTransferAccelerationRequestMarshaller = new PutBucketTransferAccelerationRequestMarshaller();
public static final PutBucketAccessMonitorRequestMarshaller putBucketAccessMonitorRequestMarshaller = new PutBucketAccessMonitorRequestMarshaller();
public static final DoMetaQueryRequestMarshaller doMetaQueryRequestMarshaller = new DoMetaQueryRequestMarshaller();
public static final PutBucketRTCRequestMarshaller putBucketRTCRequestMarshaller = new PutBucketRTCRequestMarshaller();

public interface RequestMarshaller<R> extends Marshaller<FixedLengthInputStream, R> {

Expand Down Expand Up @@ -156,6 +157,34 @@ public FixedLengthInputStream marshall(ImageProcess imageProcessConf) {
}
xmlBody.append("<SourceFileProtectSuffix>" + imageProcessConf.getSourceFileProtectSuffix()
+ "</SourceFileProtectSuffix>");

if (imageProcessConf.getBucketChannelConfig() != null ) {
List<BucketChannelConfig> bucketChannelConfigs = imageProcessConf.getBucketChannelConfig();
xmlBody.append("<BucketChannelConfig><RuleList>");
for (BucketChannelConfig item: bucketChannelConfigs) {
xmlBody.append("<Rule>");
xmlBody.append("<RuleName>" + item.getRuleName() + "</RuleName>");
xmlBody.append("<RuleRegex>" + item.getRuleRegex()+ "</RuleRegex>");
if (item.getFrontContent() != null) {
xmlBody.append("<FrontContent>" + item.getFrontContent()+ "</FrontContent>");
}

if (item.getCreateTime() != null) {
xmlBody.append("<CreateTime>" + item.getCreateTime() + "</CreateTime>");
}

if (item.getLastModifiedTime() != null) {
xmlBody.append("<LastModifiedTime>" + item.getLastModifiedTime() + "</LastModifiedTime>");
}
xmlBody.append("</Rule>");
}
xmlBody.append(" </RuleList></BucketChannelConfig>");
}

if (imageProcessConf.getDeleteAllBucketChannel()) {
xmlBody.append("<BucketChannelConfig></BucketChannelConfig>>");
}

xmlBody.append("<StyleDelimiters>" + imageProcessConf.getStyleDelimiters() + "</StyleDelimiters>");
if (imageProcessConf.isSupportAtStyle() != null && imageProcessConf.isSupportAtStyle().booleanValue()) {
xmlBody.append("<OssDomainSupportAtProcess>Enabled</OssDomainSupportAtProcess>");
Expand Down Expand Up @@ -216,7 +245,7 @@ public static final class CreateBucketRequestMarshaller implements RequestMarsha
public FixedLengthInputStream marshall(CreateBucketRequest request) {
StringBuffer xmlBody = new StringBuffer();
if (request.getLocationConstraint() != null
|| request.getStorageClass() != null
|| request.getStorageClass() != null
|| request.getDataRedundancyType() != null) {
xmlBody.append("<CreateBucketConfiguration>");
if (request.getLocationConstraint() != null) {
Expand Down Expand Up @@ -245,6 +274,7 @@ public FixedLengthInputStream marshall(BucketReferer br) {
StringBuffer xmlBody = new StringBuffer();
xmlBody.append("<RefererConfiguration>");
xmlBody.append("<AllowEmptyReferer>" + br.isAllowEmptyReferer() + "</AllowEmptyReferer>");
xmlBody.append("<AllowTruncateQueryString>" + br.isAllowTruncateQueryString() + "</AllowTruncateQueryString>");

if (!br.getRefererList().isEmpty()) {
xmlBody.append("<RefererList>");
Expand Down Expand Up @@ -306,6 +336,9 @@ public FixedLengthInputStream marshall(SetBucketWebsiteRequest request) {
if (request.getErrorDocument() != null) {
xmlBody.append("<ErrorDocument>");
xmlBody.append("<Key>" + request.getErrorDocument() + "</Key>");
if (request.getHttpStatus() != null) {
xmlBody.append("<HttpStatus>" + request.getHttpStatus() + "</HttpStatus>");
}
xmlBody.append("</ErrorDocument>");
}

Expand Down Expand Up @@ -597,7 +630,7 @@ public FixedLengthInputStream marshall(SetBucketLifecycleRequest request) {
if (storageTransition.hasIsAccessTime()) {
xmlBody.append("<IsAccessTime>" + storageTransition.getIsAccessTime() + "</IsAccessTime>");
}
if (storageTransition.hasReturnToStdWhenVisit()) {
if ("true".equals(storageTransition.getIsAccessTime()) && storageTransition.hasReturnToStdWhenVisit()) {
xmlBody.append("<ReturnToStdWhenVisit>" + storageTransition.getReturnToStdWhenVisit() + "</ReturnToStdWhenVisit>");
}

Expand Down Expand Up @@ -625,7 +658,7 @@ public FixedLengthInputStream marshall(SetBucketLifecycleRequest request) {
if (transition.hasIsAccessTime()) {
xmlBody.append("<IsAccessTime>" + transition.getIsAccessTime() + "</IsAccessTime>");
}
if (transition.hasReturnToStdWhenVisit()) {
if ("true".equals(transition.getIsAccessTime()) && transition.hasReturnToStdWhenVisit()) {
xmlBody.append("<ReturnToStdWhenVisit>" + transition.getReturnToStdWhenVisit() + "</ReturnToStdWhenVisit>");
}

Expand Down Expand Up @@ -949,6 +982,10 @@ public FixedLengthInputStream marshall(AddBucketReplicationRequest request) {
xmlBody.append("<CloudLocation>" + request.getTargetCloudLocation() + "</CloudLocation>");
}

if (request.getTransferType() != null) {
xmlBody.append("<TransferType>" + request.getTransferType() + "</TransferType>");
}

xmlBody.append("</Destination>");
if (request.isEnableHistoricalObjectReplication()) {
xmlBody.append("<HistoricalObjectReplication>" + "enabled" + "</HistoricalObjectReplication>");
Expand Down Expand Up @@ -988,6 +1025,12 @@ public FixedLengthInputStream marshall(AddBucketReplicationRequest request) {
xmlBody.append("</Source>");
}

if (request.getRtcStatus() != null) {
xmlBody.append("<RTC>");
xmlBody.append("<Status>" + request.getRtcStatus() + "</Status>");
xmlBody.append("</RTC>");
}

xmlBody.append("</Rule>");
xmlBody.append("</ReplicationConfiguration>");
return stringMarshaller.marshall(xmlBody.toString());
Expand Down Expand Up @@ -1863,6 +1906,27 @@ public byte[] marshall(DoMetaQueryRequest input) {
}
}

public static final class PutBucketRTCRequestMarshaller implements RequestMarshaller2<PutBucketRTCRequest> {
@Override
public byte[] marshall(PutBucketRTCRequest input) {
StringBuffer xmlBody = new StringBuffer();
xmlBody.append("<ReplicationRule>");
xmlBody.append("<RTC>");
xmlBody.append("<Status>"+ input.getStatus() +"</Status>");
xmlBody.append("</RTC>");
xmlBody.append("<ID>"+ input.getRuleID() +"</ID>");
xmlBody.append("</ReplicationRule>");

byte[] rawData = null;
try {
rawData = xmlBody.toString().getBytes(DEFAULT_CHARSET_NAME);
} catch (UnsupportedEncodingException e) {
throw new ClientException("Unsupported encoding " + e.getMessage(), e);
}
return rawData;
}
}

private static enum EscapedChar {
// "\r"
RETURN("&#x000D;"),
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,28 @@ public List<String> getBucketReplicationLocation(GenericRequest genericRequest)
return doOperation(request, getBucketReplicationLocationResponseParser, bucketName, null, true);
}

/***
* New Get Bucket Replication Location
* @param genericRequest
* @throws OSSException
* @throws ClientException
*/
public BucketReplicationLocationResult getBucketReplicationLocationV2(GenericRequest genericRequest)
throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");

String bucketName = genericRequest.getBucketName();

Map<String, String> params = new HashMap<String, String>();
params.put(RequestParameters.SUBRESOURCE_REPLICATION_LOCATION, null);

RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint())
.setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params)
.setOriginalRequest(genericRequest).build();

return doOperation(request, getBucketReplicationLocationV2ResponseParser, bucketName, null, true);
}

public AddBucketCnameResult addBucketCname(AddBucketCnameRequest addBucketCnameRequest) throws OSSException, ClientException {

assertParameterNotNull(addBucketCnameRequest, "addBucketCnameRequest");
Expand Down Expand Up @@ -2120,4 +2142,18 @@ public VoidResult closeMetaQuery(GenericRequest genericRequest) throws OSSExcept

return doOperation(request, requestIdResponseParser, bucketName, null, true);
}

public VoidResult putBucketRTC(PutBucketRTCRequest putBucketRTCRequest) throws OSSException, ClientException {
assertParameterNotNull(putBucketRTCRequest, "putBucketRTCRequest");
String bucketName = putBucketRTCRequest.getBucketName();
assertParameterNotNull(putBucketRTCRequest.getRuleID(), "ruleID");
assertParameterNotNull(putBucketRTCRequest.getStatus(), "status");
Map<String, String> params = new HashMap<String, String>();
params.put(RTC, null);
byte[] rawContent = putBucketRTCRequestMarshaller.marshall(putBucketRTCRequest);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint())
.setMethod(HttpMethod.PUT).setBucket(bucketName).setParameters(params)
.setOriginalRequest(putBucketRTCRequest).setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent)).build();
return doOperation(request, requestIdResponseParser, bucketName, null, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public final class RequestParameters {
public static final String PLAYLIST_NAME = "playlistName";
public static final String SINCE = "since";
public static final String TAIL = "tail";
public static final String RTC = "rtc";

/* V1 signature params */
public static final String SIGNATURE = "Signature";
Expand Down
Loading