Create an Application
A DataCloud application needs at minimum three components:
1. A Destination describing where to run the job.
2. A Product describing what should be run.
3. A Provisioning corresponding to an instance of the product containing customer-specific data
Multiple products can use the same destination, and multiple provisionings can be created for each product.
Destination
Virtually all of the fields in a Destination object are required. Here we set some defaults, persist and return the destination.
private static Destination createDestination(String sessionId) throws CloudAPIException, InvalidSessionException {
Destination destination = new Destination();
destination.setSecurityGroup("default");
destination.setAmiId("ami-00729269");
destination.setQueueLowerThreshold(0);
destination.setQueueUpperThreshold(1);
destination.setInstanceType("m1.small");
destination.setKeyName("cloud-key");
destination.setMaxInstances(2);
destination.setAvailabilityzone("us-east-1a");
destination.setSqsQueuePrefix("myTestQueuePrefix");
destination.setUserDataTemplateName("userdata.sh");
destination.setMinInstances(0);
destination = port.createDestination(destination, sessionId);
return destination;
}
Product
//create a product
Product product = new Product();
//Unlike other entites, the ID must be set by the user for product
product.setId(UUID.randomUUID().toString());
product.setDestination(destination.getId());
product.setActive(Boolean.TRUE);
product.setConcurrent(Boolean.FALSE);
product.setName("My Test Product");
product.setDescription("A product for testing the API.");
product.setUserProduct(Boolean.TRUE);
final Parameters parameters = new Product.Parameters();
ProductParameter productParameter = new ProductParameter();
productParameter.setKey("foo");
productParameter.setValue("bar");
parameters.getParameter().add(productParameter);
productParameter = new ProductParameter();
productParameter.setKey("key2");
productParameter.setValue("value2");
parameters.getParameter().add(productParameter);
product.setParameters(parameters);
//TODO set process
product.setProcess("test.1.0.djar");
product = port.createProduct(product, sessionId);
// Upload the process file
//open the local file
File file = new File("C:\\ec2\\test.1.0.djar");
//create a javax.activation.DataHandler to wrap it
DataHandler dataHandler = new DataHandler(new FileDataSource(file));
//upload the file to datacloud. Note the integrationSpec folder specified
//processes are expected to be relative to the integrationSpec folder
port.putProductFile(product.getId(), "integrationSpec/test.1.0.djar", dataHandler, sessionId);
Provisioning
private static Provisioning createProvisioning(Product product, String sessionId) throws InvalidSessionException, CloudAPIException {
//create a provisioning for the product
Provisioning provisioning = new Provisioning();
//Set the product field to the corresponding product id
provisioning.setProduct(product.getId());
//Set the expiration
GregorianCalendar calendar = new GregorianCalendar();
calendar.add(Calendar.YEAR, 1);
XMLGregorianCalendar expirationDate = datatypeFactory.newXMLGregorianCalendar(calendar);
provisioning.setExpirationDate(expirationDate);
provisioning.setParameters(new Provisioning.Parameters());
ProvisioningParameter provisioningParameter = new ProvisioningParameter();
provisioningParameter.setKey("foo");
provisioningParameter.setValue("baz"); //overrides foo=bar in product
provisioning.getParameters().getParameter().add(provisioningParameter);
provisioning = port.createProvisioning(provisioning, sessionId);
return provisioning;
}
Last modified date: 12/17/2021