Skip to content

Commit 94c49d6

Browse files
liyanzhang505huiguangjun
authored andcommitted
Support async fetch task.
1 parent ecb2e74 commit 94c49d6

17 files changed

+1089
-7
lines changed

src/main/java/com/aliyun/oss/OSS.java

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,7 +3197,7 @@ public String generateRtmpUri(GenerateRtmpUriRequest generatePushflowUrlRequest)
31973197
public BucketQosInfo getBucketQosInfo(GenericRequest genericRequest) throws OSSException, ClientException;
31983198

31993199
/**
3200-
* Deletes the bucket qos info
3200+
* Deletes the bucket qos info.
32013201
* @param bucketName
32023202
* The bucket name
32033203
* @throws OSSException
@@ -3208,7 +3208,7 @@ public String generateRtmpUri(GenerateRtmpUriRequest generatePushflowUrlRequest)
32083208
public void deleteBucketQosInfo(String bucketName) throws OSSException, ClientException;
32093209

32103210
/**
3211-
* Deletes the bucket qos info
3211+
* Deletes the bucket qos info.
32123212
* @param genericRequest
32133213
* A {@link GenericRequest} instance that has the bucket name
32143214
* @throws OSSException
@@ -3219,8 +3219,8 @@ public String generateRtmpUri(GenerateRtmpUriRequest generatePushflowUrlRequest)
32193219
public void deleteBucketQosInfo(GenericRequest genericRequest) throws OSSException, ClientException;
32203220

32213221
/**
3222-
* Gets the User qos info
3223-
*
3222+
* Gets the User qos info.
3223+
*
32243224
* @return A {@link UserQosInfo} instance.
32253225
* @throws OSSException
32263226
* OSS Server side exception.
@@ -3229,6 +3229,69 @@ public String generateRtmpUri(GenerateRtmpUriRequest generatePushflowUrlRequest)
32293229
*/
32303230
public UserQosInfo getUserQosInfo() throws OSSException, ClientException;
32313231

3232+
/**
3233+
* Sets an async fetch task.
3234+
*
3235+
* @param bucketName
3236+
* The bucket name.
3237+
* @param asyncFetchTaskConfiguration
3238+
* The async fetch task configuration.
3239+
* @return A {@link SetAsyncFetchTaskResult} instance.
3240+
* @throws OSSException
3241+
* OSS Server side exception.
3242+
* @throws ClientException
3243+
* OSS Client side exception.
3244+
*/
3245+
public SetAsyncFetchTaskResult setAsyncFetchTask(String bucketName,
3246+
AsyncFetchTaskConfiguration asyncFetchTaskConfiguration) throws OSSException, ClientException;
3247+
3248+
/**
3249+
* Sets an async fetch task.
3250+
*
3251+
* @param setAsyncFetchTaskRequest
3252+
* A {@link SetAsyncFetchTaskRequest} instance that specified the bucket name
3253+
* and the task configuration.
3254+
* @return A {@link SetAsyncFetchTaskResult} instance.
3255+
* @throws OSSException
3256+
* OSS Server side exception.
3257+
* @throws ClientException
3258+
* OSS Client side exception.
3259+
*/
3260+
public SetAsyncFetchTaskResult setAsyncFetchTask(SetAsyncFetchTaskRequest setAsyncFetchTaskRequest)
3261+
throws OSSException, ClientException;
3262+
3263+
3264+
/**
3265+
* Gets the async fetch task information.
3266+
*
3267+
* @param bucketName
3268+
* The bucket name.
3269+
* @param taskId
3270+
* The id of the task which you want to get.
3271+
* @return A {@link GetAsyncFetchTaskResult} instance.
3272+
* @throws OSSException
3273+
* OSS Server side exception.
3274+
* @throws ClientException
3275+
* OSS Client side exception.
3276+
*/
3277+
public GetAsyncFetchTaskResult getAsyncFetchTask(String bucketName, String taskId) throws OSSException, ClientException;
3278+
3279+
3280+
/**
3281+
* Gets the async fetch task information.
3282+
*
3283+
* @param getAsyncFetchTaskRequest
3284+
* A {@link GetAsyncFetchTaskRequest} instance that specified the bucket name
3285+
* and the task id.
3286+
* @return A {@link GetAsyncFetchTaskResult} instance.
3287+
* @throws OSSException
3288+
* OSS Server side exception.
3289+
* @throws ClientException
3290+
* OSS Client side exception.
3291+
*/
3292+
public GetAsyncFetchTaskResult getAsyncFetchTask(GetAsyncFetchTaskRequest getAsyncFetchTaskRequest)
3293+
throws OSSException, ClientException;
3294+
32323295
/**
32333296
* Creates UDF
32343297
*

src/main/java/com/aliyun/oss/OSSClient.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,30 @@ public UserQosInfo getUserQosInfo() throws OSSException, ClientException {
14731473
return this.bucketOperation.getUserQosInfo();
14741474
}
14751475

1476+
@Override
1477+
public SetAsyncFetchTaskResult setAsyncFetchTask(String bucketName,
1478+
AsyncFetchTaskConfiguration asyncFetchTaskConfiguration) throws OSSException, ClientException {
1479+
return this.setAsyncFetchTask(new SetAsyncFetchTaskRequest(bucketName,asyncFetchTaskConfiguration));
1480+
}
1481+
1482+
@Override
1483+
public SetAsyncFetchTaskResult setAsyncFetchTask(SetAsyncFetchTaskRequest setAsyncFetchTaskRequest)
1484+
throws OSSException, ClientException {
1485+
return this.bucketOperation.setAsyncFetchTask(setAsyncFetchTaskRequest);
1486+
}
1487+
1488+
@Override
1489+
public GetAsyncFetchTaskResult getAsyncFetchTask(String bucketName, String taskId)
1490+
throws OSSException, ClientException {
1491+
return this.getAsyncFetchTask(new GetAsyncFetchTaskRequest(bucketName, taskId));
1492+
}
1493+
1494+
@Override
1495+
public GetAsyncFetchTaskResult getAsyncFetchTask(GetAsyncFetchTaskRequest getAsyncFetchTaskRequest)
1496+
throws OSSException, ClientException {
1497+
return this.bucketOperation.getAsyncFetchTask(getAsyncFetchTaskRequest);
1498+
}
1499+
14761500
@Override
14771501
public void createUdf(CreateUdfRequest createUdfRequest) throws OSSException, ClientException {
14781502
throw new ClientException("Not supported.");

src/main/java/com/aliyun/oss/OSSErrorCode.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,12 @@ public interface OSSErrorCode {
263263
static final String INVALID_POLICY_DOCUMENT = "InvalidPolicyDocument";
264264

265265
/**
266-
* The exsiting bucket without policy
266+
* The exsiting bucket without policy.
267267
*/
268268
static final String NO_SUCH_BUCKET_POLICY = "NoSuchBucketPolicy";
269+
270+
/**
271+
* The object has already exists.
272+
*/
273+
static final String OBJECT_ALREADY_EXISTS = "ObjectAlreadyExists";
269274
}

src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public final class RequestMarshallers {
8282
public static final SetBucketPolicyRequestMarshaller setBucketPolicyRequestMarshaller = new SetBucketPolicyRequestMarshaller();
8383
public static final SetBucketRequestPaymentRequestMarshaller setBucketRequestPaymentRequestMarshaller = new SetBucketRequestPaymentRequestMarshaller();
8484
public static final SetBucketQosInfoRequestMarshaller setBucketQosInfoRequestMarshaller = new SetBucketQosInfoRequestMarshaller();
85+
public static final SetAsyncFetchTaskRequestMarshaller setAsyncFetchTaskRequestMarshaller = new SetAsyncFetchTaskRequestMarshaller();
8586

8687
public static final CreateSelectObjectMetadataRequestMarshaller createSelectObjectMetadataRequestMarshaller = new CreateSelectObjectMetadataRequestMarshaller();
8788
public static final SelectObjectRequestMarshaller selectObjectRequestMarshaller = new SelectObjectRequestMarshaller();
@@ -1065,6 +1066,50 @@ public byte[] marshall(BucketQosInfo bucketQosInfo) {
10651066

10661067
}
10671068

1069+
public static final class SetAsyncFetchTaskRequestMarshaller implements RequestMarshaller2<AsyncFetchTaskConfiguration> {
1070+
1071+
@Override
1072+
public byte[] marshall(AsyncFetchTaskConfiguration asyncFetchTaskConfiguration) {
1073+
StringBuffer xmlBody = new StringBuffer();
1074+
xmlBody.append("<AsyncFetchTaskConfiguration>");
1075+
1076+
if (asyncFetchTaskConfiguration.getUrl() != null) {
1077+
xmlBody.append("<Url>" + escapeKey(asyncFetchTaskConfiguration.getUrl()) + "</Url>");
1078+
}
1079+
1080+
if (asyncFetchTaskConfiguration.getObjectName() != null) {
1081+
xmlBody.append("<Object>" + asyncFetchTaskConfiguration.getObjectName() + "</Object>");
1082+
}
1083+
1084+
if (asyncFetchTaskConfiguration.getHost() != null) {
1085+
xmlBody.append("<Host>" + asyncFetchTaskConfiguration.getHost() + "</Host>");
1086+
}
1087+
1088+
if (asyncFetchTaskConfiguration.getContentMd5() != null) {
1089+
xmlBody.append("<ContentMD5>" + asyncFetchTaskConfiguration.getContentMd5() + "</ContentMD5>");
1090+
}
1091+
1092+
if (asyncFetchTaskConfiguration.getCallback() != null) {
1093+
xmlBody.append("<Callback>" + asyncFetchTaskConfiguration.getCallback() + "</Callback>");
1094+
}
1095+
1096+
if (asyncFetchTaskConfiguration.getIgnoreSameKey() != null) {
1097+
xmlBody.append("<IgnoreSameKey>" + asyncFetchTaskConfiguration.getIgnoreSameKey() + "</IgnoreSameKey>");
1098+
}
1099+
1100+
xmlBody.append("</AsyncFetchTaskConfiguration>");
1101+
1102+
byte[] rawData = null;
1103+
try {
1104+
rawData = xmlBody.toString().getBytes(DEFAULT_CHARSET_NAME);
1105+
} catch (UnsupportedEncodingException e) {
1106+
throw new ClientException("Unsupported encoding " + e.getMessage(), e);
1107+
}
1108+
return rawData;
1109+
}
1110+
1111+
}
1112+
10681113
public static final class CreateUdfRequestMarshaller implements RequestMarshaller2<CreateUdfRequest> {
10691114

10701115
@Override

src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketPolicyRequestMarshaller;
3939
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketRequestPaymentRequestMarshaller;
4040
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketQosInfoRequestMarshaller;
41+
import static com.aliyun.oss.common.parser.RequestMarshallers.setAsyncFetchTaskRequestMarshaller;
4142
import static com.aliyun.oss.common.utils.CodingUtils.assertParameterNotNull;
4243
import static com.aliyun.oss.internal.OSSUtils.OSS_RESOURCE_MANAGER;
4344
import static com.aliyun.oss.internal.OSSUtils.ensureBucketNameValid;
@@ -70,6 +71,8 @@
7071
import static com.aliyun.oss.internal.ResponseParsers.getBucketRequestPaymentResponseParser;
7172
import static com.aliyun.oss.internal.ResponseParsers.getUSerQosInfoResponseParser;
7273
import static com.aliyun.oss.internal.ResponseParsers.getBucketQosInfoResponseParser;
74+
import static com.aliyun.oss.internal.ResponseParsers.getAsyncFetchTaskResponseParser;
75+
import static com.aliyun.oss.internal.ResponseParsers.setAsyncFetchTaskResponseParser;
7376

7477
import java.io.ByteArrayInputStream;
7578
import java.util.ArrayList;
@@ -147,7 +150,11 @@
147150
import com.aliyun.oss.model.UserQosInfo;
148151
import com.aliyun.oss.model.VersionListing;
149152
import org.apache.http.HttpStatus;
150-
153+
import com.aliyun.oss.model.SetAsyncFetchTaskRequest;
154+
import com.aliyun.oss.model.SetAsyncFetchTaskResult;
155+
import com.aliyun.oss.model.GetAsyncFetchTaskRequest;
156+
import com.aliyun.oss.model.GetAsyncFetchTaskResult;
157+
import com.aliyun.oss.model.AsyncFetchTaskConfiguration;
151158
/**
152159
* Bucket operation.
153160
*/
@@ -1454,6 +1461,56 @@ public UserQosInfo getUserQosInfo() throws OSSException, ClientException {
14541461
return doOperation(request, getUSerQosInfoResponseParser, null, null, true);
14551462
}
14561463

1464+
public SetAsyncFetchTaskResult setAsyncFetchTask(SetAsyncFetchTaskRequest setAsyncFetchTaskRequest)
1465+
throws OSSException, ClientException {
1466+
assertParameterNotNull(setAsyncFetchTaskRequest, "setAsyncFetchTaskRequest");
1467+
1468+
String bucketName = setAsyncFetchTaskRequest.getBucketName();
1469+
assertParameterNotNull(bucketName, "bucketName");
1470+
ensureBucketNameValid(bucketName);
1471+
1472+
AsyncFetchTaskConfiguration taskConfiguration = setAsyncFetchTaskRequest.getAsyncFetchTaskConfiguration();
1473+
assertParameterNotNull(taskConfiguration, "taskConfiguration");
1474+
1475+
Map<String, String> params = new HashMap<String, String>();
1476+
params.put(SUBRESOURCE_ASYNC_FETCH, null);
1477+
1478+
byte[] rawContent = setAsyncFetchTaskRequestMarshaller.marshall(setAsyncFetchTaskRequest.getAsyncFetchTaskConfiguration());
1479+
Map<String, String> headers = new HashMap<String, String>();
1480+
addRequestRequiredHeaders(headers, rawContent);
1481+
1482+
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint())
1483+
.setMethod(HttpMethod.POST).setBucket(bucketName).setParameters(params).setHeaders(headers)
1484+
.setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent))
1485+
.setOriginalRequest(setAsyncFetchTaskRequest).build();
1486+
1487+
return doOperation(request, setAsyncFetchTaskResponseParser, bucketName, null, true);
1488+
}
1489+
1490+
public GetAsyncFetchTaskResult getAsyncFetchTask(GetAsyncFetchTaskRequest getAsyncFetchTaskRequest)
1491+
throws OSSException, ClientException {
1492+
assertParameterNotNull(getAsyncFetchTaskRequest, "getAsyncFetchTaskInfoRequest");
1493+
1494+
String bucketName = getAsyncFetchTaskRequest.getBucketName();
1495+
assertParameterNotNull(bucketName, "bucketName");
1496+
ensureBucketNameValid(bucketName);
1497+
1498+
String taskId = getAsyncFetchTaskRequest.getTaskId();
1499+
assertParameterNotNull(taskId, "taskId");
1500+
1501+
Map<String, String> params = new HashMap<String, String>();
1502+
params.put(RequestParameters.SUBRESOURCE_ASYNC_FETCH, null);
1503+
1504+
Map<String, String> headers = new HashMap<String, String>();
1505+
headers.put(OSSHeaders.OSS_HEADER_TASK_ID, taskId);
1506+
1507+
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint())
1508+
.setMethod(HttpMethod.GET).setBucket(bucketName).setHeaders(headers).setParameters(params)
1509+
.setOriginalRequest(getAsyncFetchTaskRequest).build();
1510+
1511+
return doOperation(request, getAsyncFetchTaskResponseParser, bucketName, null, true);
1512+
}
1513+
14571514
private static void populateListObjectsRequestParameters(ListObjectsRequest listObjectsRequest,
14581515
Map<String, String> params) {
14591516

src/main/java/com/aliyun/oss/internal/OSSHeaders.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@ public interface OSSHeaders extends HttpHeaders {
9696

9797
static final String OSS_HEADER_TRAFFIC_LIMIT = "x-oss-traffic-limit";
9898

99+
static final String OSS_HEADER_TASK_ID = "x-oss-task-id";
100+
99101
}

src/main/java/com/aliyun/oss/internal/RequestParameters.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public final class RequestParameters {
6464
public static final String SUBRESOURCE_POLICY = "policy";
6565
public static final String SUBRESOURCE_REQUEST_PAYMENT = "requestPayment";
6666
public static final String SUBRESOURCE_QOS_INFO = "qosInfo";
67+
public static final String SUBRESOURCE_ASYNC_FETCH = "asyncFetch";
6768

6869
public static final String SUBRESOURCE_UDF = "udf";
6970
public static final String SUBRESOURCE_UDF_NAME = "udfName";

0 commit comments

Comments
 (0)