use of com.aliyun.oss.model.UserQos in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetUserQos.
/**
* Unmarshall get user qos response body to user qos.
*/
public static UserQos parseGetUserQos(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
UserQos userQos = new UserQos();
if (root.getChild("StorageCapacity") != null) {
userQos.setStorageCapacity(Integer.parseInt(root.getChildText("StorageCapacity")));
}
return userQos;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
use of com.aliyun.oss.model.UserQos in project aliyun-oss-java-sdk by aliyun.
the class OSSBucketOperation method setBucketStorageCapacity.
public void setBucketStorageCapacity(SetBucketStorageCapacityRequest setBucketStorageCapacityRequest) throws OSSException, ClientException {
assertParameterNotNull(setBucketStorageCapacityRequest, "setBucketStorageCapacityRequest");
assertParameterNotNull(setBucketStorageCapacityRequest.getUserQos(), "setBucketStorageCapacityRequest.userQos");
String bucketName = setBucketStorageCapacityRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
UserQos userQos = setBucketStorageCapacityRequest.getUserQos();
assertParameterNotNull(userQos.getStorageCapacity(), "StorageCapacity");
Map<String, String> params = new HashMap<String, String>();
params.put(RequestParameters.SUBRESOURCE_QOS, null);
byte[] rawContent = setBucketQosRequestMarshaller.marshall(userQos);
Map<String, String> headers = new HashMap<String, String>();
addRequestRequiredHeaders(headers, rawContent);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setParameters(params).setHeaders(headers).setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent)).setOriginalRequest(setBucketStorageCapacityRequest).build();
doOperation(request, emptyResponseParser, bucketName, null);
}
use of com.aliyun.oss.model.UserQos in project aliyun-oss-java-sdk by aliyun.
the class BucketUserQosTest method testSetBucketStorageCapacityNegative.
@Test
public void testSetBucketStorageCapacityNegative() {
try {
UserQos userQos = new UserQos(-2);
ossClient.setBucketStorageCapacity(bucketName, userQos);
Assert.fail("Set bucket storage capacity should not be successful");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_ARGUMENT, e.getErrorCode());
}
try {
UserQos userQos = new UserQos(-3);
ossClient.setBucketStorageCapacity(new SetBucketStorageCapacityRequest(bucketName).withUserQos(userQos));
Assert.fail("Set bucket storage capacity should not be successful");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_ARGUMENT, e.getErrorCode());
}
}
use of com.aliyun.oss.model.UserQos in project aliyun-oss-java-sdk by aliyun.
the class BucketUserQosTest method testDefaultBucketStorageCapacity.
@Test
public void testDefaultBucketStorageCapacity() {
try {
UserQos userQos = new UserQos();
userQos = ossClient.getBucketStorageCapacity(bucketName);
Assert.assertEquals(userQos.getStorageCapacity(), -1);
Assert.assertEquals(userQos.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.UserQos in project aliyun-oss-java-sdk by aliyun.
the class BucketUserQosTest method testSetBucketStorageCapacity.
@Test
public void testSetBucketStorageCapacity() {
try {
UserQos userQos = new UserQos(-1);
ossClient.setBucketStorageCapacity(bucketName, userQos);
userQos = ossClient.getBucketStorageCapacity(bucketName);
Assert.assertEquals(userQos.getStorageCapacity(), -1);
Assert.assertEquals(userQos.getRequestId().length(), REQUEST_ID_LEN);
userQos.setStorageCapacity(10000);
ossClient.setBucketStorageCapacity(new SetBucketStorageCapacityRequest(bucketName).withUserQos(userQos));
userQos = ossClient.getBucketStorageCapacity(bucketName);
Assert.assertEquals(userQos.getStorageCapacity(), 10000);
Assert.assertEquals(userQos.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
Aggregations