use of com.aliyun.oss.model.UdfApplicationInfo in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetUdfApplicationInfo.
/**
* Unmarshall get udf info response body to udf application info.
*/
public static UdfApplicationInfo parseGetUdfApplicationInfo(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
String id = root.getChildText("ID");
String name = root.getChildText("Name");
String status = root.getChildText("Status");
String region = root.getChildText("Region");
Integer imageVersion = Integer.valueOf(root.getChildText("ImageVersion"));
Integer instanceNum = Integer.valueOf(root.getChildText("InstanceNum"));
Date date = DateUtil.parseIso8601Date(root.getChildText("CreationDate"));
String instanceType = root.getChild("Flavor").getChildText("InstanceType");
InstanceFlavor flavor = new InstanceFlavor(instanceType);
return new UdfApplicationInfo(name, id, region, status, imageVersion, instanceNum, date, flavor);
} 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.UdfApplicationInfo in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseListUdfApplicationInfo.
/**
* Unmarshall get udf info response body to udf image info list.
*/
@SuppressWarnings("unchecked")
public static List<UdfApplicationInfo> parseListUdfApplicationInfo(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
List<UdfApplicationInfo> udfApps = new ArrayList<UdfApplicationInfo>();
if (root.getChild("UDFApplicationInfo") != null) {
List<Element> udfImageElems = root.getChildren("UDFApplicationInfo");
for (Element elem : udfImageElems) {
String id = elem.getChildText("ID");
String name = elem.getChildText("Name");
String status = elem.getChildText("Status");
String region = elem.getChildText("Region");
Integer imageVersion = Integer.valueOf(elem.getChildText("ImageVersion"));
Integer instanceNum = Integer.valueOf(elem.getChildText("InstanceNum"));
Date date = DateUtil.parseIso8601Date(elem.getChildText("CreationDate"));
String instanceType = elem.getChild("Flavor").getChildText("InstanceType");
InstanceFlavor flavor = new InstanceFlavor(instanceType);
UdfApplicationInfo udfApp = new UdfApplicationInfo(name, id, region, status, imageVersion, instanceNum, date, flavor);
udfApps.add(udfApp);
}
}
return udfApps;
} 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.UdfApplicationInfo 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());
}
}
Aggregations