全部产品
阿里云办公

创建App

更新时间:2018-11-19 21:00:25

接口

createApp

参数

参数 类型 是否必需 说明
appDescription AppDescription 创建App的描述。

appDescription 的详细描述信息参考创建 APP 文档

返回值

创建成功后返回一个 CreateAppResponse 实例,可以通过 getAppName() 获取创建的App名称。创建失败后,抛出异常: ClientException

例子

Java 源码:

  1. import com.aliyuncs.batchcompute.main.v20151111.*;
  2. import com.aliyuncs.batchcompute.model.v20151111.*;
  3. import com.aliyuncs.batchcompute.pojo.v20151111.*;
  4. import com.aliyuncs.exceptions.ClientException;
  5. public class CreateApp {
  6. static String ACCESS_KEY_ID = "xxx"; //这里填写您的 AccessKeyId
  7. static String ACCESS_KEY_SECRET = "xxx"; //这里填写您的 AccessKeySecret
  8. static String REGION_ID = "cn-xxx"; //这里填写 region
  9. public static void main(String[] args) {
  10. BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
  11. try {
  12. AppDescription appDesc = GenAppDescription();
  13. CreateAppResponse response = client.createApp(appDesc);
  14. System.out.println("AppName: " + response.getAppName());
  15. System.out.println("RequestId: " + response.getRequestId());
  16. System.out.println("StatusCode: " + response.getStatusCode());
  17. //创建成功
  18. } catch (ClientException e) {
  19. e.printStackTrace();
  20. //创建失败
  21. }
  22. }
  23. private static AppDescription GenAppDescription(){
  24. AppDescription desc = new AppDescription();
  25. desc.setName("JavaSdkApp");
  26. desc.setDescription("JavaSdkApp");
  27. //设置APP输入参数
  28. AppDescription.InputParameterValue inputPara = new AppDescription.InputParameterValue();
  29. inputPara.setDescription("Input param 1");
  30. inputPara.setType("String");
  31. inputPara.setLocalPath("/home/input/infile1");
  32. desc.addInputParameters("inputFile", inputPara);
  33. //根据业务需要可以设置其他的输入参数,例如:
  34. //AppDescription.InputParameterValue inputPara = new AppDescription.InputParameterValue();
  35. //inputPara.setDefaultValue("255");
  36. //inputPara.setDescription("the length of picture");
  37. //inputPara.setType("String");
  38. //inputPara.setLocalPath("");
  39. //desc.addInputParameters("length", inputPara);
  40. //设置APP输出参数
  41. AppDescription.OutputParameterValue outputParameterValue = new AppDescription.OutputParameterValue();
  42. outputParameterValue.setDescription("Output param");
  43. outputParameterValue.setType("String");
  44. outputParameterValue.setLocalPath("/home/test/outfile/");
  45. desc.addOutputParameters("outputFile", outputParameterValue);
  46. //环境变量设置
  47. desc.addEnvVars("env-k1", "env-v1");
  48. desc.addEnvVars("env-k2", "env-v2");
  49. //设置config参数
  50. AppDescription.Config config = new AppDescription.Config();
  51. //设置磁盘类型
  52. AppDescription.ConfigValue configValue = new AppDescription.ConfigValue();
  53. configValue.setDefaultValue("cloud_efficiency");
  54. configValue.setDescription("diskType");
  55. configValue.setOverwritable(true);
  56. config.setDiskType(configValue);
  57. //设置实例个数
  58. AppDescription.ConfigValueInteger configValueInt = new AppDescription.ConfigValueInteger();
  59. configValueInt.setDefaultValue(1);
  60. configValueInt.setDescription("Instance count");
  61. configValueInt.setOverwritable(true);
  62. config.setInstanceCount(configValueInt);
  63. //设置资源类型
  64. AppDescription.ConfigValue resourceConfig = new AppDescription.ConfigValue();
  65. resourceConfig.setDefaultValue("OnDemand");
  66. resourceConfig.setDescription("Resource type");
  67. resourceConfig.setOverwritable(true);
  68. config.setResourceType(resourceConfig);
  69. //设置实例类型
  70. AppDescription.ConfigValue InstanceConfig = new AppDescription.ConfigValue();
  71. InstanceConfig.setDefaultValue("ecs.sn2ne.large");
  72. InstanceConfig.setDescription("Instance type");
  73. InstanceConfig.setOverwritable(true);
  74. config.setInstanceType(InstanceConfig);
  75. //设置最小盘大小
  76. AppDescription.ConfigValueInteger minDiskConfig = new AppDescription.ConfigValueInteger();
  77. minDiskConfig.setDefaultValue(40);//GB
  78. minDiskConfig.setDescription("Min Disk size");
  79. minDiskConfig.setOverwritable(true);
  80. config.setMinDiskSize(minDiskConfig);
  81. //设置最大重试次数
  82. AppDescription.ConfigValueInteger retryConfig = new AppDescription.ConfigValueInteger();
  83. retryConfig.setDefaultValue(3);
  84. retryConfig.setDescription("Max retry count");
  85. retryConfig.setOverwritable(true);
  86. config.setMaxRetryCount(retryConfig);
  87. //设置超时时间
  88. AppDescription.ConfigValueLong configValueLong = new AppDescription.ConfigValueLong();
  89. configValueLong.setDefaultValue(6000);//单位:秒
  90. configValueLong.setOverwritable(true);
  91. configValueLong.setDescription("Time out");
  92. config.setTimeout(configValueLong);
  93. desc.setConfig(config);
  94. //VM和docker 是互斥的只能设置其中一项参数
  95. AppDescription.VM vm = new AppDescription.VM();
  96. vm.setECSImageId("img-ubuntu");
  97. desc.setVm(vm);
  98. desc.setCommandLine("cp ${inputFile} ${outputFile}");
  99. desc.setDaemonize(false);
  100. return desc;
  101. }
  102. }

执行结果:

  1. {
  2. AppName: JavaSdkApp
  3. RequestId: null
  4. StatusCode: 201
  5. }