Search in sources :

Example 1 with UserQos

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) UserQos(com.aliyun.oss.model.UserQos) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 2 with UserQos

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) UserQos(com.aliyun.oss.model.UserQos)

Example 3 with UserQos

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());
    }
}
Also used : SetBucketStorageCapacityRequest(com.aliyun.oss.model.SetBucketStorageCapacityRequest) UserQos(com.aliyun.oss.model.UserQos) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 4 with UserQos

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());
    }
}
Also used : UserQos(com.aliyun.oss.model.UserQos) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 5 with UserQos

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());
    }
}
Also used : SetBucketStorageCapacityRequest(com.aliyun.oss.model.SetBucketStorageCapacityRequest) UserQos(com.aliyun.oss.model.UserQos) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Aggregations

UserQos (com.aliyun.oss.model.UserQos)5 OSSException (com.aliyun.oss.OSSException)3 Test (org.junit.Test)3 SetBucketStorageCapacityRequest (com.aliyun.oss.model.SetBucketStorageCapacityRequest)2 RequestMessage (com.aliyun.oss.common.comm.RequestMessage)1 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1