Skip to content

Commit

Permalink
update bos and bvw services
Browse files Browse the repository at this point in the history
  • Loading branch information
friendshipbridge committed Sep 3, 2020
1 parent 71b730f commit cb6db6f
Show file tree
Hide file tree
Showing 39 changed files with 2,813 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Release Notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
【版本:vx.xx.xx】
涉及产品:SHC,新增广播接口,现有product接口增加asrKafka参数。

【版本:v0.10.126】
涉及产品:BVW(VideoWorks),支持视频快编合成和查询快编任务状态。

【版本:v0.10.125】
涉及产品:BOS(对象存储),新增支持软链接、多规则replication、取消重定向、归档状态显示等相关接口。

【版本:v0.10.124】
涉及产品:BVW(VideoWorks),支持上传素材和查询素材。

Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.baidubce</groupId>
<artifactId>bce-java-sdk</artifactId>
<version>0.10.124</version>
<version>0.10.126</version>
<name>bce-sdk-java</name>
<description>The BCE SDK for Java provides Java APIs for all of BCE services.</description>
<url>http://bce.baidu.com/sdk/index.html</url>
Expand Down Expand Up @@ -203,6 +203,12 @@
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/baidubce/BceClientConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ public class BceClientConfiguration {
*/
private BceCredentials credentials = null;

/**
* determines whether redirects should be handled automatically
* @return
*/
private boolean redirectsEnabled = true;

// Initialize DEFAULT_USER_AGENT
static {
String language = System.getProperty("user.language");
Expand Down Expand Up @@ -203,6 +209,7 @@ public BceClientConfiguration(BceClientConfiguration other) {
this.endpoint = other.endpoint;
this.region = other.region;
this.credentials = other.credentials;
this.redirectsEnabled = other.redirectsEnabled;
}

/**
Expand Down Expand Up @@ -232,6 +239,7 @@ public BceClientConfiguration(BceClientConfiguration other, String endpoint) {
this.socketBufferSizeInBytes = other.socketBufferSizeInBytes;
this.region = other.region;
this.credentials = other.credentials;
this.redirectsEnabled = other.redirectsEnabled;
}

/**
Expand Down Expand Up @@ -368,6 +376,32 @@ public BceClientConfiguration withLocalAddress(InetAddress localAddress) {
return this;
}


/**
* Gets the flag of http redirection
* @return
*/
public boolean isRedirectsEnabled() {
return redirectsEnabled;
}

/**
* Sets the flag of http redirection
* @param redirectsEnabled
*/
public void setRedirectsEnabled(boolean redirectsEnabled) {
this.redirectsEnabled = redirectsEnabled;
}

/**
* Sets the flag of http redirection
* @param redirectsEnabled
* @return the updated configuration instance.
*/
public BceClientConfiguration withRedirectsEnabled(boolean redirectsEnabled) {
this.setRedirectsEnabled(redirectsEnabled);
return this;
}
/**
* Returns the optional proxy host the client will connect through.
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/baidubce/BceResponseMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public class BceResponseMetadata implements Serializable {

private String location;

public String getSymlinkTarget() {
return symlinkTarget;
}

public void setSymlinkTarget(String symlinkTarget) {
this.symlinkTarget = symlinkTarget;
}

private String symlinkTarget;

public String getBceRequestId() {
return this.bceRequestId;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/baidubce/http/BceHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public BceHttpClient(BceClientConfiguration config, Signer signer) {
this.requestConfigBuilder = RequestConfig.custom();
this.requestConfigBuilder.setConnectTimeout(config.getConnectionTimeoutInMillis());
this.requestConfigBuilder.setStaleConnectionCheckEnabled(true);
this.requestConfigBuilder.setRedirectsEnabled(config.isRedirectsEnabled());
if (config.getLocalAddress() != null) {
this.requestConfigBuilder.setLocalAddress(config.getLocalAddress());
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/baidubce/http/Headers.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public interface Headers {

public static final String BCE_RESTORE_DAYS = "x-bce-restore-days";

public static final String BCE_SYMLINK_TARGET = "x-bce-symlink-target";

public static final String BCE_FORBID_OVERWRITE = "x-bce-forbid-overwrite";

public static final String BCE_RESTORE = "x-bce-restore";
/*
* CFC HTTP Headers
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public boolean handle(BceHttpResponse httpResponse, AbstractBceResponse response
metadata.setContentType(httpResponse.getHeader(Headers.CONTENT_TYPE));
metadata.setDate(httpResponse.getHeaderAsRfc822Date(Headers.DATE));
metadata.setTransferEncoding(httpResponse.getHeader(Headers.TRANSFER_ENCODING));
metadata.setSymlinkTarget(httpResponse.getHeader(Headers.BCE_SYMLINK_TARGET));
String eTag = httpResponse.getHeader(Headers.ETAG);
if (eTag != null) {
metadata.setETag(CharMatcher.is('"').trimFrom(eTag));
Expand Down
219 changes: 219 additions & 0 deletions src/main/java/com/baidubce/services/bos/BosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,137 @@ public void deleteBucketCors(DeleteBucketCorsRequest request) {
this.invokeHttpClient(internalRequest, BosResponse.class);
}

/**
* Sets the replication for the specified Bos bucket with specified replicationId.
* @param request
*/
public void setBucketReplication(SetBucketReplicationRequest request) {
checkNotNull(request.getId(), "the replication id should not be null.");
checkNotNull(request.getStatus(), "the replication status should not be null");
checkNotNull(request.getResource(), "the replication source should not be null");
checkNotNull(request.getDestination(), "the replication destination should not be null");
checkNotNull(request.getDestination().getBucket(), "the replication dest bucket shoule not be null");
checkNotNull(request.getReplicateDeletes(), "the replication deletes should not be null");
InternalRequest internalRequest = this.createRequest(request, HttpMethodName.PUT);
internalRequest.addParameter("replication", null);
internalRequest.addParameter("id", request.getId());
if (request.getJsonBucketReplication() != null) {
byte[] json = null;
try {
json = request.getJsonBucketReplication().getBytes(DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new BceClientException("Fail to get UTF-8 bytes", e);
}
internalRequest.addHeader(Headers.CONTENT_LENGTH, String.valueOf(json.length));
internalRequest.addHeader(Headers.CONTENT_TYPE, Constants.APPLICATION_JSON);
internalRequest.setContent(RestartableInputStream.wrap(json));
} else if (request.getId() != null) {
byte[] json = null;
StringWriter writer = new StringWriter();
try {
JsonGenerator jsonGenerator = JsonUtils.jsonGeneratorOf(writer);
jsonGenerator.writeStartObject();
// set status
jsonGenerator.writeStringField("status", request.getStatus());
// set resource
jsonGenerator.writeArrayFieldStart("resource");
for (String resource : request.getResource()) {
jsonGenerator.writeString(resource);
}
jsonGenerator.writeEndArray();
// set destination
jsonGenerator.writeObjectFieldStart("destination");
jsonGenerator.writeStringField("bucket", request.getDestination().getBucket());
if (request.getDestination().getStorageClass() != null) {
jsonGenerator.writeStringField("storageClass", request.getDestination().getStorageClass());
}
jsonGenerator.writeEndObject();
// set replicateHistory
if (request.getReplicateHistory() != null) {
jsonGenerator.writeObjectFieldStart("replicateHistory");
if (request.getReplicateHistory().getStorageClass() != null) {
jsonGenerator.writeObjectField("storageClass", request.getReplicateHistory().getStorageClass());
}
jsonGenerator.writeEndObject();
}

// set replicateDeletes
if (request.getReplicateDeletes() != null) {
jsonGenerator.writeStringField("replicateDeletes", request.getReplicateDeletes());
}
// set id
jsonGenerator.writeStringField("id", request.getId());
jsonGenerator.writeEndObject();
jsonGenerator.close();

} catch (IOException e) {
throw new BceClientException("Fail to generate json", e);
}
try {
json = writer.toString().getBytes(DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new BceClientException("Fail to get UTF-8 bytes", e);
}
internalRequest.addHeader(Headers.CONTENT_LENGTH, String.valueOf(json.length));
internalRequest.addHeader(Headers.CONTENT_TYPE, Constants.APPLICATION_JSON);
internalRequest.setContent(RestartableInputStream.wrap(json));
} else {
checkNotNull(request, "request should not be null.");
}
this.invokeHttpClient(internalRequest, BosResponse.class);
}

/**
* Gets the replication for the specified Bos bucket with specified replicationId.
*/
public GetBucketReplicationResponse getBucketReplication(GetBucketReplicationRequest request) {
checkNotNull(request, "request should not be null.");
InternalRequest internalRequest = this.createRequest(request, HttpMethodName.GET);
internalRequest.addParameter("replication", null);
internalRequest.addParameter("id", request.getId());
GetBucketReplicationResponse response = this.invokeHttpClient(internalRequest,
GetBucketReplicationResponse.class);
return response;
}

/**
* Deletes the replication for the specified Bos bucket with specified replicationId.
*/
public void deleteBucketReplication(DeleteBucketReplicationRequest request) {
checkNotNull(request, "request should not be null.");
checkNotNull(request.getId(), "replication id should not be null");

InternalRequest internalRequest = this.createRequest(request, HttpMethodName.DELETE);
internalRequest.addParameter("replication", null);
internalRequest.addParameter("id", request.getId());
this.invokeHttpClient(internalRequest, BosResponse.class);
}

/**
* Gets the bucket replication progress for the specified Bos bucket with specified replicationId
*/
public BucketReplicationProgress getBucketReplicationProgress(GetBucketReplicationProgressRequest request) {
checkNotNull(request, "request should not be null.");
InternalRequest internalRequest = this.createRequest(request, HttpMethodName.GET);
internalRequest.addParameter("replicationProgress", null);
internalRequest.addParameter("id", request.getId());
BucketReplicationProgress response = this.invokeHttpClient(internalRequest, BucketReplicationProgress.class);
return response;
}

/**
* List all bucket replication
*/
public ListBucketReplicationResponse listBucketReplication(ListBucketReplicationRequest request) {
checkNotNull(request, "request should not be null.");
InternalRequest internalRequest = this.createRequest(request, HttpMethodName.GET);
internalRequest.addParameter("replication", null);
internalRequest.addParameter("list", null);
ListBucketReplicationResponse response = this.invokeHttpClient(internalRequest,
ListBucketReplicationResponse.class);
return response;
}

/**
* Sets the Lifecycle for the specified Bos bucket.
*
Expand Down Expand Up @@ -1498,6 +1629,91 @@ public void deleteObject(DeleteObjectRequest request) {
this.invokeHttpClient(this.createRequest(request, HttpMethodName.DELETE), BosResponse.class);
}

/**
* Set the specified object symlink in the specified bucket.
* @param bucketName The name of the Bos bucket containing the object
* @param key The object's symlink name
* @param symlinkTarget The target object of the symlink
* @return
*/
public SetObjectSymlinkResponse setObjectSymlink(String bucketName, String key, String symlinkTarget) {
return this.setObjectSymlink(new SetObjectSymlinkRequest(bucketName, key, symlinkTarget));
}

/**
* Set the specified object symlink in the specified bucket.
* @param request The request object containing all options for setting a symlink of target object.
* @return
*/
public SetObjectSymlinkResponse setObjectSymlink(SetObjectSymlinkRequest request) {
checkNotNull(request, "request should not be null.");
assertStringNotNullOrEmpty(request.getSymlinkTarget(), "object key should not be null or empty");

InternalRequest internalRequest = this.createRequest(request, HttpMethodName.PUT);
internalRequest.addParameter("symlink", null);

internalRequest.addHeader(Headers.BCE_SYMLINK_TARGET, request.getSymlinkTarget());
if (request.isForbidOverwrite() == false) {
internalRequest.addHeader(Headers.BCE_FORBID_OVERWRITE, "false");
} else {
internalRequest.addHeader(Headers.BCE_FORBID_OVERWRITE, "true");
}
if (request.getStorageClass() != null) {
internalRequest.addHeader(Headers.BCE_STORAGE_CLASS, request.getStorageClass());
}
Map<String, String> userMetadata = request.getUserMetadata();
if (userMetadata != null) {
for (Entry<String, String> entry : userMetadata.entrySet()) {
String key = entry.getKey();
if (key == null) {
continue;
}
String value = entry.getValue();
if (value == null) {
value = "";
}
if (key.length() + value.length() > 1024 * 32) {
throw new BceClientException("MetadataTooLarge");
}
internalRequest.addHeader(Headers.BCE_USER_METADATA_PREFIX + HttpUtils.normalize(key.trim()),
HttpUtils.normalize(value));
}
}

this.setZeroContentLength(internalRequest);
BosResponse response = this.invokeHttpClient(internalRequest, BosResponse.class);
SetObjectSymlinkResponse result = new SetObjectSymlinkResponse();
result.setETag(response.getMetadata().getETag());
return result;
}

/**
* Gets the specified object symlink in the specified bucket
* @param bucketName The name of the Bos bucket containing the symlink object
* @param key The symlink name
* @return The symlink target Object
*/
public GetObjectSymlinkResponse getObjectSymlink(String bucketName, String key) {
return this.getObjectSymlink(new GetObjectSymlinkRequest(bucketName, key));
}

/**
* Gets the specified object symlink in the specified bucket
* @param request The request object containing all options for getting a symlink of target object.
* @return The symlink target Object
*/
public GetObjectSymlinkResponse getObjectSymlink(GetObjectSymlinkRequest request) {
checkNotNull(request, "request should not be null.");
assertStringNotNullOrEmpty(request.getBucketName(), "bucketName should not be null or empty");
assertStringNotNullOrEmpty(request.getKey(), "object key should not be null or empty");
InternalRequest internalRequest = this.createRequest(request, HttpMethodName.GET);
internalRequest.addParameter("symlink", null);

BosResponse response = this.invokeHttpClient(internalRequest, BosResponse.class);
GetObjectSymlinkResponse result = new GetObjectSymlinkResponse();
result.setSymlinkTarget(response.getMetadata().getSymlinkTarget());
return result;
}
/**
* Deletes the multiple specified objects in the specified bucket.
*
Expand Down Expand Up @@ -2067,6 +2283,9 @@ private static void populateRequestMetadata(InternalRequest request, ObjectMetad
if (metadata.getStorageClass() != null) {
request.addHeader(Headers.BCE_STORAGE_CLASS, metadata.getStorageClass());
}
if (metadata.getxBceAcl() != null) {
request.addHeader(Headers.BCE_ACL, String.valueOf(metadata.getxBceAcl()));
}

Map<String, String> userMetadata = metadata.getUserMetadata();
if (userMetadata != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public boolean handle(BceHttpResponse httpResponse, AbstractBceResponse response
objectMetadata.setContentDisposition(httpResponse.getHeader(Headers.CONTENT_DISPOSITION));
objectMetadata.setCacheControl(httpResponse.getHeader(Headers.CACHE_CONTROL));
objectMetadata.setxBceCrc(httpResponse.getHeader(Headers.BCE_CONTENT_CRC32));
objectMetadata.setRestore(httpResponse.getHeader(Headers.BCE_RESTORE));
// set whatever the BOS server returns if not null
String storageClass = httpResponse.getHeader(Headers.BCE_STORAGE_CLASS);
if (storageClass == null) {
Expand Down
Loading

0 comments on commit cb6db6f

Please sign in to comment.