Search in sources :

Example 1 with UdfApplicationLog

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

the class UdfTest method testUdfApplicationLog.

@Test
public void testUdfApplicationLog() {
    String udf = "udf-go-pingpong-1";
    try {
        GetUdfApplicationLogRequest getUdfApplicationLogRequest = new GetUdfApplicationLogRequest(udf);
        getUdfApplicationLogRequest.setStartTime(DateUtil.parseRfc822Date("Wed, 15 Mar 2017 03:23:45 GMT"));
        getUdfApplicationLogRequest.setEndLines(10L);
        UdfApplicationLog udfApplicationLog = ossClient.getUdfApplicationLog(getUdfApplicationLogRequest);
        displayTextInputStream(udfApplicationLog.getLogContent());
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
}
Also used : UdfApplicationLog(com.aliyun.oss.model.UdfApplicationLog) GetUdfApplicationLogRequest(com.aliyun.oss.model.GetUdfApplicationLogRequest) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with UdfApplicationLog

use of com.aliyun.oss.model.UdfApplicationLog 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 3 with UdfApplicationLog

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

the class OSSUdfOperation method getUdfApplicationLog.

public UdfApplicationLog getUdfApplicationLog(GetUdfApplicationLogRequest getUdfApplicationLogRequest) throws OSSException, ClientException {
    assertParameterNotNull(getUdfApplicationLogRequest, "resizeUdfApplicationRequest");
    String udfName = getUdfApplicationLogRequest.getName();
    assertParameterNotNull(udfName, "udfName");
    ensureBucketNameValid(udfName);
    Map<String, String> params = new HashMap<String, String>();
    populateGetUdfApplicationLogParameters(params, getUdfApplicationLogRequest);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setParameters(params).setOriginalRequest(getUdfApplicationLogRequest).build();
    ProgressListener listener = getUdfApplicationLogRequest.getProgressListener();
    UdfApplicationLog udfApplicationLog = null;
    try {
        publishProgress(listener, ProgressEventType.TRANSFER_STARTED_EVENT);
        udfApplicationLog = doOperation(request, new GetUdfApplicationLogResponseParser(udfName), null, null, true);
        InputStream instream = udfApplicationLog.getLogContent();
        ProgressInputStream progressInputStream = new ProgressInputStream(instream, listener) {

            @Override
            protected void onEOF() {
                publishProgress(getListener(), ProgressEventType.TRANSFER_COMPLETED_EVENT);
            }
        };
        CRC64 crc = new CRC64();
        CheckedInputStream checkedInputstream = new CheckedInputStream(progressInputStream, crc);
        udfApplicationLog.setLogContent(checkedInputstream);
    } catch (RuntimeException e) {
        publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT);
        throw e;
    }
    return udfApplicationLog;
}
Also used : GetUdfApplicationLogResponseParser(com.aliyun.oss.internal.ResponseParsers.GetUdfApplicationLogResponseParser) CRC64(com.aliyun.oss.common.utils.CRC64) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProgressInputStream(com.aliyun.oss.event.ProgressInputStream) CheckedInputStream(java.util.zip.CheckedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ProgressInputStream(com.aliyun.oss.event.ProgressInputStream) IOUtils.newRepeatableInputStream(com.aliyun.oss.common.utils.IOUtils.newRepeatableInputStream) InputStream(java.io.InputStream) CheckedInputStream(java.util.zip.CheckedInputStream) UdfApplicationLog(com.aliyun.oss.model.UdfApplicationLog) ProgressListener(com.aliyun.oss.event.ProgressListener) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Aggregations

UdfApplicationLog (com.aliyun.oss.model.UdfApplicationLog)3 GetUdfApplicationLogRequest (com.aliyun.oss.model.GetUdfApplicationLogRequest)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 RequestMessage (com.aliyun.oss.common.comm.RequestMessage)1 CRC64 (com.aliyun.oss.common.utils.CRC64)1 IOUtils.newRepeatableInputStream (com.aliyun.oss.common.utils.IOUtils.newRepeatableInputStream)1 ProgressInputStream (com.aliyun.oss.event.ProgressInputStream)1 ProgressListener (com.aliyun.oss.event.ProgressListener)1 GetUdfApplicationLogResponseParser (com.aliyun.oss.internal.ResponseParsers.GetUdfApplicationLogResponseParser)1 CreateUdfApplicationRequest (com.aliyun.oss.model.CreateUdfApplicationRequest)1 CreateUdfRequest (com.aliyun.oss.model.CreateUdfRequest)1 ResizeUdfApplicationRequest (com.aliyun.oss.model.ResizeUdfApplicationRequest)1 UdfApplicationConfiguration (com.aliyun.oss.model.UdfApplicationConfiguration)1 UdfApplicationInfo (com.aliyun.oss.model.UdfApplicationInfo)1 UdfGenericRequest (com.aliyun.oss.model.UdfGenericRequest)1 UdfImageInfo (com.aliyun.oss.model.UdfImageInfo)1 UdfInfo (com.aliyun.oss.model.UdfInfo)1 UpgradeUdfApplicationRequest (com.aliyun.oss.model.UpgradeUdfApplicationRequest)1