Skip to content

Commit

Permalink
Merge pull request #134 from zzq996/master
Browse files Browse the repository at this point in the history
Version 3.23.5
  • Loading branch information
zzq996 authored Aug 14, 2023
2 parents 2a31fb9 + 7553933 commit 1b8a70d
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README-Android.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 3.23.5
New features:
1. Allow you put Object in two Buckets by calling putObjectInTwoBucket
2. Allow you query statistics on the capacity of standard, warm and cold objects in bucket
-----------------------------------------------------------------------------------
Version 3.23.3
New features:
1. Allow you to query the progress of crr
Expand Down
5 changes: 5 additions & 0 deletions README-Java.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 3.23.5
New features:
1. Allow you put Object in two Buckets by calling putObjectInTwoBucket
2. Allow you query statistics on the capacity of standard, warm and cold objects in bucket
-----------------------------------------------------------------------------------
Version 3.23.3
New features:
1. Allow you to query the progress of crr
Expand Down
5 changes: 5 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 3.23.5
New features:
1. Allow you put Object in two Buckets by calling putObjectInTwoBucket
2. Allow you query statistics on the capacity of standard, warm and cold objects in bucket
-----------------------------------------------------------------------------------
Version 3.23.3
New features:
1. Allow you to query the progress of crr
Expand Down
5 changes: 5 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 3.23.5
New features:
1. 新增双写桶能力
2. 支持标准、归档、低频三种桶容量的统计
-----------------------------------------------------------------------------------
Version 3.23.3
New features:
1. 支持crr进度查询
Expand Down
52 changes: 52 additions & 0 deletions app/src/main/java/com/obs/services/AbstractObjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.obs.services.exception.ObsException;
import com.obs.services.internal.ServiceException;
import com.obs.services.internal.utils.ObjectUtils;
import com.obs.services.internal.utils.ServiceUtils;
import com.obs.services.model.AccessControlList;
import com.obs.services.model.AppendObjectRequest;
Expand All @@ -43,6 +44,8 @@
import com.obs.services.model.ObsObject;
import com.obs.services.model.OptionsInfoRequest;
import com.obs.services.model.OptionsInfoResult;
import com.obs.services.model.PutObjectInTwoBucketRequest;
import com.obs.services.model.PutObjectInTwoBucketResult;
import com.obs.services.model.PutObjectRequest;
import com.obs.services.model.PutObjectResult;
import com.obs.services.model.RestoreObjectRequest;
Expand Down Expand Up @@ -317,6 +320,55 @@ public PutObjectResult putObject(String bucketName, String objectKey, File file,
request.setMetadata(metadata);
return this.putObject(request);
}

@Override
public PutObjectInTwoBucketResult putObjectInTwoBucket(PutObjectInTwoBucketRequest request)
throws ObsException {
ServiceUtils.assertParameterNotNull(request, "PutObjectInTwoBucketRequest is null");
ServiceUtils.assertParameterNotNull(request.getMainBucketRequest(), "mainBucketRequest is null");
ServiceUtils.assertParameterNotNull(request.getBackupBucketRequest(), "backupBucketRequest is null");
ServiceUtils.assertParameterNotNull2(request.getBackupBucketRequest().getBucketName(), "backupBucketName is null");
ServiceUtils.assertParameterNotNull2(request.getMainBucketRequest().getBucketName(), "mainBucketName is null");
ServiceUtils.assertParameterNotNull2(request.getBackupBucketRequest().getObjectKey(), "backupObjectKey is null");
ServiceUtils.assertParameterNotNull2(request.getMainBucketRequest().getObjectKey(), "mainObjectKey is null");
String path = request.getFilePath();
if (ObjectUtils.isNotBlank(path)) {
File file = new File(path);
if (file.exists()) {
PutObjectRequest mainBucketRequest = request.getMainBucketRequest();
mainBucketRequest.setFile(file);
request.setMainBucketRequest(mainBucketRequest);
PutObjectRequest backupBucketRequest = request.getBackupBucketRequest();
backupBucketRequest.setFile(file);
request.setBackupBucketRequest(backupBucketRequest);
}
}
return this.doActionWithResult("putObjectInTwoBucket", "All Buckets",
new ActionCallbackWithResult<PutObjectInTwoBucketResult>() {
@Override
public PutObjectInTwoBucketResult action() throws ServiceException {
if (null != request.getMainBucketRequest().getInput()
&& null != request.getMainBucketRequest().getFile()) {
throw new ServiceException("Both input and file are set, only one is allowed in main bucket request.");
}
if (null != request.getBackupBucketRequest().getInput()
&& null != request.getBackupBucketRequest().getFile()) {
throw new ServiceException("Both input and file are set, only one is allowed in backup bucket request.");
}
return AbstractObjectClient.this.putObjectInTwoBucketImpl(request);
}

@Override
void authTypeNegotiate(String bucketName) throws ServiceException {
AuthTypeEnum authTypeEnum = AbstractObjectClient.this.getProviderCredentials()
.getLocalAuthType().get(bucketName);
if (authTypeEnum == null) {
authTypeEnum = AbstractObjectClient.this.getApiVersion("");
AbstractObjectClient.this.getProviderCredentials().setLocalAuthType(bucketName, authTypeEnum);
}
}
});
}

/*
* (non-Javadoc)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/obs/services/IObsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import com.obs.services.model.ObsObject;
import com.obs.services.model.PostSignatureRequest;
import com.obs.services.model.PostSignatureResponse;
import com.obs.services.model.PutObjectInTwoBucketRequest;
import com.obs.services.model.PutObjectInTwoBucketResult;
import com.obs.services.model.PutObjectRequest;
import com.obs.services.model.PutObjectResult;
import com.obs.services.model.PutObjectsRequest;
Expand Down Expand Up @@ -1652,6 +1654,8 @@ PutObjectResult putObject(String bucketName, String objectKey, InputStream input
PutObjectResult putObject(String bucketName, String objectKey, File file, ObjectMetadata metadata)
throws ObsException;

PutObjectInTwoBucketResult putObjectInTwoBucket(final PutObjectInTwoBucketRequest request) throws ObsException;

/**
* Perform an appendable upload.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,34 @@ public void endElement(String name, String content) {
storageInfo.setSize(Long.parseLong(content));
} else if (name.equals("ObjectNumber")) {
storageInfo.setObjectNumber(Long.parseLong(content));
} else if (name.equals("StandardSize")) {
storageInfo.setStandardSize(Long.parseLong(content));
} else if (name.equals("StandardObjectNumber")) {
storageInfo.setStandardObjectNumber(Long.parseLong(content));
} else if (name.equals("WarmSize")) {
storageInfo.setWarmSize(Long.parseLong(content));
} else if (name.equals("WarmObjectNumber")) {
storageInfo.setWarmObjectNumber(Long.parseLong(content));
} else if (name.equals("ColdSize")) {
storageInfo.setColdSize(Long.parseLong(content));
} else if (name.equals("ColdObjectNumber")) {
storageInfo.setColdObjectNumber(Long.parseLong(content));
} else if (name.equals("DeepArchiveSize")) {
storageInfo.setDeepArchiveSize(Long.parseLong(content));
} else if (name.equals("DeepArchiveObjectNumber")) {
storageInfo.setDeepArchiveObjectNumber(Long.parseLong(content));
} else if (name.equals("HighPerformanceSize")) {
storageInfo.setHighPerformanceSize(Long.parseLong(content));
} else if (name.equals("HighPerformanceObjectNumber")) {
storageInfo.setHighPerformanceObjectNumber(Long.parseLong(content));
} else if (name.equals("Standard_IASize")) {
storageInfo.setStandard_IASize(Long.parseLong(content));
} else if (name.equals("Standard_IAObjectNumber")) {
storageInfo.setStandard_IAObjectNumber(Long.parseLong(content));
} else if (name.equals("GlacierSize")) {
storageInfo.setGlacierSize(Long.parseLong(content));
} else if (name.equals("GlacierObjectNumber")) {
storageInfo.setGlacierObjectNumber(Long.parseLong(content));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.obs.log.ILogger;
import com.obs.log.LoggerBuilder;
import com.obs.services.exception.ObsException;
import com.obs.services.internal.Constants;
import com.obs.services.internal.Constants.CommonHeaders;
import com.obs.services.internal.Constants.ObsRequestParams;
Expand Down Expand Up @@ -45,7 +46,10 @@
import com.obs.services.model.HttpMethodEnum;
import com.obs.services.model.ObjectMetadata;
import com.obs.services.model.ObsObject;
import com.obs.services.model.PutObjectInTwoBucketRequest;
import com.obs.services.model.PutObjectInTwoBucketResult;
import com.obs.services.model.PutObjectRequest;
import com.obs.services.model.PutObjectResult;
import com.obs.services.model.SetObjectAclRequest;
import com.obs.services.model.SetObjectMetadataRequest;
import com.obs.services.model.SpecialParamEnum;
Expand All @@ -68,6 +72,10 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public abstract class ObsObjectBaseService extends ObsBucketAdvanceService {
private static final ILogger log = LoggerBuilder.getLogger(ObsObjectBaseService.class);
Expand Down Expand Up @@ -137,6 +145,51 @@ protected ObsFSFile putObjectImpl(PutObjectRequest request) throws ServiceExcept
return ret;
}

protected PutObjectInTwoBucketResult putObjectInTwoBucketImpl(PutObjectInTwoBucketRequest request) throws ObsException {
ExecutorService executorService = Executors.newFixedThreadPool(2);
PutObjectInTwoBucketResult putObjectInTwoBucketResult;
try {
Future<PutObjectInTwoBucketResult> futureMainBucket = executorService.submit(() -> {
PutObjectInTwoBucketResult result = new PutObjectInTwoBucketResult();
try {
PutObjectResult putObjectResult = this.putObjectImpl(request.getMainBucketRequest());
result.setMainBucketResult(putObjectResult);
} catch (ServiceException e) {
result.setMainBucketException(ServiceUtils.changeFromServiceException(e));
} catch (Exception e) {
result.setMainBucketException(ServiceUtils.changeFromException(e));
}
return result;
});

Future<PutObjectInTwoBucketResult> futureBackupBucket = executorService.submit(() -> {
PutObjectInTwoBucketResult result = new PutObjectInTwoBucketResult();
try {
PutObjectResult putObjectResult = this.putObjectImpl(request.getBackupBucketRequest());
result.setBackupBucketResult(putObjectResult);
} catch (ServiceException e) {
result.setBackupBucketException(ServiceUtils.changeFromServiceException(e));
} catch (Exception e) {
result.setBackupBucketException(ServiceUtils.changeFromException(e));
}
return result;
});

executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);

putObjectInTwoBucketResult = futureMainBucket.get();
PutObjectInTwoBucketResult backupBucketResult = futureBackupBucket.get();
putObjectInTwoBucketResult.setBackupBucketResult(backupBucketResult.getBackupBucketResult());
putObjectInTwoBucketResult.setBackupBucketException(backupBucketResult.getBackupBucketException());
} catch (ServiceException e) {
throw ServiceUtils.changeFromServiceException(e);
} catch (Exception e) {
throw ServiceUtils.changeFromException(e);
}
return putObjectInTwoBucketResult;
}

protected ObsObject getObjectImpl(GetObjectRequest request) throws ServiceException {
return (ObsObject) this.getObjectImpl((GetObjectMetadataRequest) request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ public static boolean isEquals(Object obj1, Object obj2) {
return obj1.equals(obj2);
}
}

public static boolean isNotBlank(String str) {
return str != null && str.length() > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

public class V4Authentication {

public static final String CONTENT_SHA256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
public static final String CONTENT_SHA256 = PropertyManager.getInstance(Constants.PROPERTY_NAME_OBS)
.getFormattedString("content.sha256");

private String ak;

Expand Down
Loading

0 comments on commit 1b8a70d

Please sign in to comment.