Search in sources :

Example 1 with CreateStorageAccountTask

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;
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) VMNode(com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMNode) File(java.io.File) CreateStorageAccountTask(com.microsoft.azuretools.azureexplorer.helpers.CreateStorageAccountTask) FileInputStream(java.io.FileInputStream) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Aggregations

VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1 CreateStorageAccountTask (com.microsoft.azuretools.azureexplorer.helpers.CreateStorageAccountTask)1 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)1 VMNode (com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMNode)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1