Search in sources :

Example 1 with UdfInfo

use of com.aliyun.oss.model.UdfInfo in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseGetUdfInfo.

/**
 * Unmarshall get udf info response body to udf info.
 */
public static UdfInfo parseGetUdfInfo(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        String name = root.getChildText("Name");
        String id = root.getChildText("ID");
        String owner = root.getChildText("Owner");
        String desc = root.getChildText("Description");
        Date date = DateUtil.parseIso8601Date(root.getChildText("CreationDate"));
        CannedUdfAcl acl = CannedUdfAcl.parse(root.getChildText("ACL"));
        return new UdfInfo(name, owner, id, desc, acl, date);
    } 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) UdfInfo(com.aliyun.oss.model.UdfInfo) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) Date(java.util.Date) CannedUdfAcl(com.aliyun.oss.model.CannedUdfAcl) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 2 with UdfInfo

use of com.aliyun.oss.model.UdfInfo in project aliyun-oss-java-sdk by aliyun.

the class UdfTest method testUdfImage.

@Test
public void testUdfImage() {
    String udf = "udf-go-pingpong-1";
    String desc = "udf-go-pingpong-1";
    try {
        // create udf
        CreateUdfRequest createUdfRequest = new CreateUdfRequest(udf, desc);
        ossClient.createUdf(createUdfRequest);
        UdfGenericRequest genericRequest = new UdfGenericRequest(udf);
        UdfInfo ui = ossClient.getUdfInfo(genericRequest);
        System.out.println(ui);
        // upload image
        InputStream in = new FileInputStream(UDF_IMG_V1);
        UploadUdfImageRequest uploadUdfImageRequest = new UploadUdfImageRequest(udf, desc, in);
        ossClient.uploadUdfImage(uploadUdfImageRequest);
        in = new FileInputStream(UDF_IMG_V2);
        uploadUdfImageRequest = new UploadUdfImageRequest(udf, desc, in);
        ossClient.uploadUdfImage(uploadUdfImageRequest);
        List<UdfImageInfo> udfImages = ossClient.getUdfImageInfo(genericRequest);
        for (UdfImageInfo image : udfImages) {
            System.out.println(image);
        }
        // wait build completed
        for (UdfImageInfo image : udfImages) {
            if (image.getStatus().equals("building")) {
                TestUtils.waitForCacheExpiration(60);
                udfImages = ossClient.getUdfImageInfo(genericRequest);
                continue;
            }
        }
        // delete udf image
        ossClient.deleteUdfImage(genericRequest);
        // wait images deleted
        udfImages = ossClient.getUdfImageInfo(genericRequest);
        for (; udfImages.size() > 0; ) {
            TestUtils.waitForCacheExpiration(60);
            udfImages = ossClient.getUdfImageInfo(genericRequest);
        }
        // delete image
        ossClient.deleteUdf(genericRequest);
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
}
Also used : UdfInfo(com.aliyun.oss.model.UdfInfo) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UdfImageInfo(com.aliyun.oss.model.UdfImageInfo) CreateUdfRequest(com.aliyun.oss.model.CreateUdfRequest) UdfGenericRequest(com.aliyun.oss.model.UdfGenericRequest) UploadUdfImageRequest(com.aliyun.oss.model.UploadUdfImageRequest) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with UdfInfo

use of com.aliyun.oss.model.UdfInfo in project aliyun-oss-java-sdk by aliyun.

the class UdfTest method testUdfApplication.

@Test
public void testUdfApplication() {
    String udf = "udf-go-pingpong-1";
    String desc = "udf-go-pingpong-1";
    try {
        // create udf
        CreateUdfRequest createUdfRequest = new CreateUdfRequest(udf, desc);
        ossClient.createUdf(createUdfRequest);
        UdfGenericRequest genericRequest = new UdfGenericRequest(udf);
        UdfInfo ui = ossClient.getUdfInfo(genericRequest);
        System.out.println(ui);
        // upload image
        InputStream in = new FileInputStream(UDF_IMG_V1);
        UploadUdfImageRequest uploadUdfImageRequest = new UploadUdfImageRequest(udf, desc, in);
        ossClient.uploadUdfImage(uploadUdfImageRequest);
        in = new FileInputStream(UDF_IMG_V2);
        uploadUdfImageRequest = new UploadUdfImageRequest(udf, desc, in);
        ossClient.uploadUdfImage(uploadUdfImageRequest);
        List<UdfImageInfo> udfImages = ossClient.getUdfImageInfo(genericRequest);
        for (UdfImageInfo image : udfImages) {
            System.out.println(image);
        }
        // wait build completed
        for (UdfImageInfo image : udfImages) {
            if (image.getStatus().equals("building")) {
                TestUtils.waitForCacheExpiration(60);
                udfImages = ossClient.getUdfImageInfo(genericRequest);
                continue;
            }
        }
        // list images
        udfImages = ossClient.getUdfImageInfo(genericRequest);
        for (UdfImageInfo image : udfImages) {
            System.out.println(image);
        }
        // list applications
        List<UdfApplicationInfo> appInfos = ossClient.listUdfApplications();
        for (UdfApplicationInfo app : appInfos) {
            System.out.println(app);
        }
        // create application
        UdfApplicationConfiguration configuration = new UdfApplicationConfiguration(1, 1);
        CreateUdfApplicationRequest createUdfApplicationRequest = new CreateUdfApplicationRequest(udf, configuration);
        ossClient.createUdfApplication(createUdfApplicationRequest);
        // wait application running
        UdfApplicationInfo appInfo = ossClient.getUdfApplicationInfo(genericRequest);
        System.out.println(appInfo);
        for (; appInfo.getStatus().equals("creating"); ) {
            TestUtils.waitForCacheExpiration(60);
            appInfo = ossClient.getUdfApplicationInfo(genericRequest);
        }
        System.out.println(appInfo);
        // upgrade application
        UpgradeUdfApplicationRequest UpgradeUdfApplicationRequest = new UpgradeUdfApplicationRequest(udf, 2);
        ossClient.upgradeUdfApplication(UpgradeUdfApplicationRequest);
        appInfo = ossClient.getUdfApplicationInfo(genericRequest);
        System.out.println(appInfo);
        for (; appInfo.getStatus().equals("upgrading"); ) {
            TestUtils.waitForCacheExpiration(60);
            appInfo = ossClient.getUdfApplicationInfo(genericRequest);
        }
        System.out.println(appInfo);
        // resize application
        ResizeUdfApplicationRequest resizeUdfApplicationRequest = new ResizeUdfApplicationRequest(udf, 2);
        ossClient.resizeUdfApplication(resizeUdfApplicationRequest);
        appInfo = ossClient.getUdfApplicationInfo(genericRequest);
        System.out.println(appInfo);
        for (; appInfo.getStatus().equals("resizing"); ) {
            TestUtils.waitForCacheExpiration(60);
            appInfo = ossClient.getUdfApplicationInfo(genericRequest);
        }
        System.out.println(appInfo);
        // get application log
        GetUdfApplicationLogRequest getUdfApplicationLogRequest = new GetUdfApplicationLogRequest(udf);
        getUdfApplicationLogRequest.setStartTime(DateUtil.parseRfc822Date("Wed, 15 Mar 2017 03:23:45 GMT"));
        getUdfApplicationLogRequest.setEndLines(100L);
        UdfApplicationLog udfApplicationLog = ossClient.getUdfApplicationLog(getUdfApplicationLogRequest);
        displayTextInputStream(udfApplicationLog.getLogContent());
    // // delete application
    // ossClient.deleteUdfApplication(genericRequest);
    // 
    // // wait application deleted
    // appInfos = ossClient.listUdfApplications();
    // for (; appInfos.size() > 0 ; ) {
    // TestUtils.waitForCacheExpiration(60);
    // appInfos = ossClient.listUdfApplications();
    // }
    // 
    // // delete udf image
    // ossClient.deleteUdfImage(genericRequest);
    // 
    // // wait images deleted
    // udfImages = ossClient.getUdfImageInfo(genericRequest);
    // for (; udfImages.size() > 0;) {
    // TestUtils.waitForCacheExpiration(60);
    // udfImages = ossClient.getUdfImageInfo(genericRequest);
    // }
    // 
    // // delete image
    // ossClient.deleteUdf(genericRequest);
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
}
Also used : GetUdfApplicationLogRequest(com.aliyun.oss.model.GetUdfApplicationLogRequest) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CreateUdfRequest(com.aliyun.oss.model.CreateUdfRequest) UploadUdfImageRequest(com.aliyun.oss.model.UploadUdfImageRequest) FileInputStream(java.io.FileInputStream) UpgradeUdfApplicationRequest(com.aliyun.oss.model.UpgradeUdfApplicationRequest) IOException(java.io.IOException) UdfApplicationLog(com.aliyun.oss.model.UdfApplicationLog) UdfInfo(com.aliyun.oss.model.UdfInfo) CreateUdfApplicationRequest(com.aliyun.oss.model.CreateUdfApplicationRequest) UdfApplicationConfiguration(com.aliyun.oss.model.UdfApplicationConfiguration) UdfImageInfo(com.aliyun.oss.model.UdfImageInfo) UdfApplicationInfo(com.aliyun.oss.model.UdfApplicationInfo) ResizeUdfApplicationRequest(com.aliyun.oss.model.ResizeUdfApplicationRequest) UdfGenericRequest(com.aliyun.oss.model.UdfGenericRequest) Test(org.junit.Test)

Example 4 with UdfInfo

use of com.aliyun.oss.model.UdfInfo in project aliyun-oss-java-sdk by aliyun.

the class UdfTest method testUdf.

@Test
public void testUdf() {
    String udf = "udf-go-pingpong-1";
    String desc = "udf-go-pingpong-1";
    try {
        // create udf
        CreateUdfRequest createUdfRequest = new CreateUdfRequest(udf, desc);
        ossClient.createUdf(createUdfRequest);
        UdfGenericRequest genericRequest = new UdfGenericRequest(udf);
        UdfInfo ui = ossClient.getUdfInfo(genericRequest);
        System.out.println(ui);
        // list image info
        List<UdfImageInfo> udfImages = ossClient.getUdfImageInfo(genericRequest);
        for (UdfImageInfo image : udfImages) {
            System.out.println(image);
        }
        List<UdfInfo> udfs = ossClient.listUdfs();
        for (UdfInfo u : udfs) {
            System.out.println(u);
        }
        // delete udf
        ossClient.deleteUdf(genericRequest);
        udfs = ossClient.listUdfs();
        System.out.println("After delete:");
        for (UdfInfo u : udfs) {
            System.out.println(u);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
}
Also used : UdfInfo(com.aliyun.oss.model.UdfInfo) UdfImageInfo(com.aliyun.oss.model.UdfImageInfo) CreateUdfRequest(com.aliyun.oss.model.CreateUdfRequest) UdfGenericRequest(com.aliyun.oss.model.UdfGenericRequest) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with UdfInfo

use of com.aliyun.oss.model.UdfInfo in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseListUdf.

/**
 * Unmarshall list udf response body to udf info list.
 */
@SuppressWarnings("unchecked")
public static List<UdfInfo> parseListUdf(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        List<UdfInfo> udfs = new ArrayList<UdfInfo>();
        if (root.getChild("UDFInfo") != null) {
            List<Element> udfElems = root.getChildren("UDFInfo");
            for (Element elem : udfElems) {
                String name = elem.getChildText("Name");
                String id = elem.getChildText("ID");
                String owner = elem.getChildText("Owner");
                String desc = elem.getChildText("Description");
                Date date = DateUtil.parseIso8601Date(elem.getChildText("CreationDate"));
                CannedUdfAcl acl = CannedUdfAcl.parse(elem.getChildText("ACL"));
                udfs.add(new UdfInfo(name, owner, id, desc, acl, date));
            }
        }
        return udfs;
    } 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) UdfInfo(com.aliyun.oss.model.UdfInfo) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ArrayList(java.util.ArrayList) Date(java.util.Date) CannedUdfAcl(com.aliyun.oss.model.CannedUdfAcl) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

UdfInfo (com.aliyun.oss.model.UdfInfo)5 CreateUdfRequest (com.aliyun.oss.model.CreateUdfRequest)3 UdfGenericRequest (com.aliyun.oss.model.UdfGenericRequest)3 UdfImageInfo (com.aliyun.oss.model.UdfImageInfo)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)2 CannedUdfAcl (com.aliyun.oss.model.CannedUdfAcl)2 UploadUdfImageRequest (com.aliyun.oss.model.UploadUdfImageRequest)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 Element (org.jdom.Element)2 JDOMParseException (org.jdom.input.JDOMParseException)2 CreateUdfApplicationRequest (com.aliyun.oss.model.CreateUdfApplicationRequest)1 GetUdfApplicationLogRequest (com.aliyun.oss.model.GetUdfApplicationLogRequest)1 ResizeUdfApplicationRequest (com.aliyun.oss.model.ResizeUdfApplicationRequest)1 UdfApplicationConfiguration (com.aliyun.oss.model.UdfApplicationConfiguration)1 UdfApplicationInfo (com.aliyun.oss.model.UdfApplicationInfo)1