@Override
public List<Resource> create(AzureProvisionContextObject po, int index, List<Resource> resources) throws Exception {
Stack stack = stackRepository.findById(po.getStackId());
String vmName = filterResourcesByType(resources, ResourceType.AZURE_CLOUD_SERVICE).get(0).getResourceName();
String internalIp = "172.16.0." + (index + VALID_IP_RANGE_START);
AzureTemplate azureTemplate = (AzureTemplate) stack.getTemplate();
AzureCredential azureCredential = (AzureCredential) stack.getCredential();
byte[] encoded = Base64.encodeBase64(vmName.getBytes());
String label = new String(encoded);
Map<String, Object> props = new HashMap<>();
List<Port> ports = new ArrayList<>();
ports.add(new Port("Ambari", "8080", "8080", "tcp"));
ports.add(new Port("NameNode", "50070", "50070", "tcp"));
ports.add(new Port("RM Web", "8088", "8088", "tcp"));
ports.add(new Port("RM Scheduler", "8030", "8030", "tcp"));
ports.add(new Port("RM IPC", "8050", "8050", "tcp"));
ports.add(new Port("Job History Server", "19888", "19888", "tcp"));
ports.add(new Port("HBase Master", "60010", "60010", "tcp"));
ports.add(new Port("Falcon", "15000", "15000", "tcp"));
ports.add(new Port("Storm", "8744", "8744", "tcp"));
ports.add(new Port("Oozie", "11000", "11000", "tcp"));
ports.add(new Port("HTTP", "80", "80", "tcp"));
props.put(NAME, vmName);
props.put(DEPLOYMENTSLOT, PRODUCTION);
props.put(LABEL, label);
props.put(IMAGENAME,
azureTemplate.getImageName().equals(AzureStackUtil.IMAGE_NAME) ? po.getOsImageName() : azureTemplate.getImageName());
props.put(IMAGESTOREURI, buildimageStoreUri(po.getCommonName(), vmName));
props.put(HOSTNAME, vmName);
props.put(USERNAME, DEFAULT_USER_NAME);
X509Certificate sshCert = null;
try {
sshCert = createX509Certificate(azureCredential, po.getEmailAsFolder());
} catch (FileNotFoundException e) {
throw new StackCreationFailureException(e);
} catch (CertificateException e) {
throw new StackCreationFailureException(e);
}
try {
props.put(SSHPUBLICKEYFINGERPRINT, sshCert.getSha1Fingerprint().toUpperCase());
} catch (CertificateEncodingException e) {
throw new StackCreationFailureException(e);
} catch (NoSuchAlgorithmException e) {
throw new StackCreationFailureException(e);
}
props.put(SSHPUBLICKEYPATH, String.format("/home/%s/.ssh/authorized_keys", DEFAULT_USER_NAME));
props.put(AFFINITYGROUP, po.getCommonName());
if (azureTemplate.getVolumeCount() > 0) {
List<Integer> disks = new ArrayList<>();
for (int i = 0; i < azureTemplate.getVolumeCount(); i++) {
disks.add(azureTemplate.getVolumeSize());
}
props.put(DISKS, disks);
}
props.put(SERVICENAME, vmName);
props.put(SUBNETNAME, po.filterResourcesByType(ResourceType.AZURE_NETWORK).get(0).getResourceName());
props.put(VIRTUAL_NETWORK_IP_ADDRESS, internalIp);
props.put(CUSTOMDATA, new String(Base64.encodeBase64(po.getUserData().getBytes())));
props.put(VIRTUALNETWORKNAME, po.filterResourcesByType(ResourceType.AZURE_NETWORK).get(0).getResourceName());
props.put(PORTS, ports);
props.put(VMTYPE, AzureVmType.valueOf(azureTemplate.getVmType()).vmType().replaceAll(" ", ""));
AzureClient azureClient = po.getNewAzureClient(azureCredential);
HttpResponseDecorator virtualMachineResponse = (HttpResponseDecorator) azureClient.createVirtualMachine(props);
String requestId = (String) azureClient.getRequestId(virtualMachineResponse);
waitUntilComplete(azureClient, requestId);
return Arrays.asList(new Resource(resourceType(), vmName, stack));