use of com.microsoft.azuretools.azureexplorer.helpers.CreateStorageAccountTask in project azure-tools-for-java by Microsoft.
the class CreateVMWizard method performFinish.
@Override
public boolean performFinish() {
Operation operation = TelemetryManager.createOperation(VM, CREATE_VM);
AzureTaskManager.getInstance().runInBackground("Creating virtual machine " + name + "...", new Runnable() {
@Override
public void run() {
try {
operation.start();
byte[] certData = new byte[0];
if (!certificate.isEmpty()) {
File certFile = new File(certificate);
if (certFile.exists()) {
try (FileInputStream certStream = new FileInputStream(certFile)) {
certData = new byte[(int) certFile.length()];
if (certStream.read(certData) != certData.length) {
throw new Exception("Unable to process certificate: " + "stream longer than informed size.");
}
} finally {
}
}
}
// create storage account when use choose to create new one
if (Objects.nonNull(newStorageAccount)) {
storageAccount = new CreateStorageAccountTask(newStorageAccount).execute();
}
VirtualMachine vm = AzureSDKManager.createVirtualMachine(subscription.getId(), name, resourceGroupName, isNewResourceGroup, size.name(), region.getName(), virtualMachineImage, knownMachineImage, isKnownMachineImage, storageAccount, virtualNetwork, newNetwork, isNewNetwork, subnet, publicIpAddress, withNewPip, availabilitySet, withNewAvailabilitySet, userName, password, certData.length > 0 ? new String(certData) : null);
// update resource groups cache if new resource group was created when creating storage account
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
try {
node.addChildNode(new VMNode(node, subscription.getId(), vm));
} catch (AzureCmdException e) {
PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), Messages.err, "An error occurred while refreshing the list of virtual machines.", e);
}
}
});
} catch (Exception e) {
EventUtil.logError(operation, ErrorType.userError, e, null, null);
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
public void run() {
PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), "Error Creating Virtual Machine", "An error occurred while trying to create the specified virtual machine", e);
}
});
} finally {
operation.complete();
}
}
});
return true;
}
Aggregations