Search in sources :

Example 6 with AzureString

use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.

the class SelectImageStep method fillOffers.

private void fillOffers() {
    disableNext();
    final VirtualMachinePublisher publisher = (VirtualMachinePublisher) publisherComboBox.getSelectedItem();
    final AzureString title = AzureOperationBundle.title("vm|offer.list", publisher.name());
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setIndeterminate(true);
        RxJavaUtils.unsubscribeSubscription(fillOfferSubscription);
        clearSelection(offerComboBox, skuComboBox, imageLabelList);
        fillOfferSubscription = Observable.fromCallable(() -> publisher.offers().list()).subscribeOn(Schedulers.io()).subscribe(offerList -> DefaultLoader.getIdeHelper().invokeLater(() -> {
            offerComboBox.setModel(new DefaultComboBoxModel(offerList.toArray()));
            fillSkus();
        }), error -> {
            final String msg = String.format(ERROR_MESSAGE_FILL_SKUS, String.format(message("webappExpMsg"), error.getMessage()));
            handleError(msg, error);
        });
    }));
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualMachinePublisher(com.microsoft.azure.management.compute.VirtualMachinePublisher) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 7 with AzureString

use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.

the class SettingsStep method retrieveNetworkSecurityGroups.

private void retrieveNetworkSecurityGroups() {
    final AzureString title = AzureOperationBundle.title("vm.list_security_groups");
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setIndeterminate(true);
        if (networkSecurityGroups == null) {
            networkSecurityGroups = azure.networkSecurityGroups().list();
        }
        AzureTaskManager.getInstance().runLater(() -> nsgCombo.setModel(getNsgModel(model.getNetworkSecurityGroup())));
    }));
    if (networkSecurityGroups == null) {
        AzureTaskManager.getInstance().runAndWait(new Runnable() {

            @Override
            public void run() {
                final DefaultComboBoxModel loadingNsgModel = new DefaultComboBoxModel(new String[] { NONE, "<Loading...>" }) {

                    @Override
                    public void setSelectedItem(Object o) {
                        super.setSelectedItem(o);
                        if (NONE.equals(o)) {
                            model.setNetworkSecurityGroup(null);
                        } else {
                        }
                    }
                };
                loadingNsgModel.setSelectedItem(null);
                nsgCombo.setModel(loadingNsgModel);
            }
        }, AzureTask.Modality.ANY);
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 8 with AzureString

use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.

the class SettingsStep method retrievePublicIpAddresses.

private void retrievePublicIpAddresses() {
    final AzureString title = AzureOperationBundle.title("vm.list_public_ips");
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setIndeterminate(true);
        if (publicIpAddresses == null) {
            publicIpAddresses = azure.publicIPAddresses().list();
        }
        AzureTaskManager.getInstance().runLater(() -> pipCombo.setModel(getPipAddressModel(model.getPublicIpAddress())));
    }));
    if (publicIpAddresses == null) {
        AzureTaskManager.getInstance().runAndWait(new Runnable() {

            @Override
            public void run() {
                final DefaultComboBoxModel loadingPipModel = new DefaultComboBoxModel(new String[] { NONE, CREATE_NEW, "<Loading...>" }) {

                    @Override
                    public void setSelectedItem(Object o) {
                        super.setSelectedItem(o);
                        if (CREATE_NEW.equals(o)) {
                            model.setWithNewPip(true);
                        } else if (NONE.equals(o)) {
                            model.setPublicIpAddress(null);
                            model.setWithNewPip(false);
                        } else {
                        }
                    }
                };
                loadingPipModel.setSelectedItem(null);
                pipCombo.setModel(loadingPipModel);
            }
        }, AzureTask.Modality.ANY);
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 9 with AzureString

use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.

the class SettingsStep method onFinish.

@Override
public boolean onFinish() {
    final boolean isNewResourceGroup = createNewRadioButton.isSelected();
    final String resourceGroupName = isNewResourceGroup ? resourceGrpField.getText() : resourceGrpCombo.getSelectedItem().toString();
    Operation operation = TelemetryManager.createOperation(VM, CREATE_VM);
    final AzureString title = AzureOperationBundle.title("vm.create", model.getName());
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setIndeterminate(true);
        try {
            operation.start();
            String certificate = model.getCertificate();
            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(model.getStorageAccountConfig())) {
                model.setStorageAccount(CreateStorageAccountAction.createStorageAccount(model.getStorageAccountConfig()));
            }
            final com.microsoft.azure.management.compute.VirtualMachine vm = AzureSDKManager.createVirtualMachine(model.getSubscription().getId(), model.getName(), resourceGroupName, createNewRadioButton.isSelected(), model.getSize(), model.getRegion().getName(), model.getVirtualMachineImage(), model.getKnownMachineImage(), model.isKnownMachineImage(), model.getStorageAccount(), model.getVirtualNetwork(), model.getNewNetwork(), model.isWithNewNetwork(), model.getSubnet(), model.getPublicIpAddress(), model.isWithNewPip(), model.getAvailabilitySet(), model.isWithNewAvailabilitySet(), model.getUserName(), model.getPassword(), certData.length > 0 ? new String(certData) : null);
            AzureTaskManager.getInstance().runLater(() -> {
                try {
                    parent.addChildNode(new com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMNode(parent, model.getSubscription().getId(), vm));
                } catch (AzureCmdException e) {
                    String msg = "An error occurred while attempting to refresh the list of virtual machines.";
                    DefaultLoader.getUIHelper().showException(msg, e, "Azure Services Explorer - Error Refreshing VM List", false, true);
                    AzurePlugin.log(msg, e);
                }
            });
        } catch (Exception e) {
            EventUtil.logError(operation, ErrorType.userError, e, null, null);
            String msg = "An error occurred while attempting to create the specified virtual machine." + "<br>" + String.format(message("webappExpMsg"), e.getMessage());
            DefaultLoader.getUIHelper().showException(msg, e, message("errTtl"), false, true);
            AzurePlugin.log(msg, e);
        } finally {
            operation.complete();
        }
    }));
    return super.onFinish();
}
Also used : AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) FileInputStream(java.io.FileInputStream) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) File(java.io.File)

Example 10 with AzureString

use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.

the class ProfileFlightRecordAction method actionPerformed.

@Override
protected void actionPerformed(NodeActionEvent nodeActionEvent) {
    EventUtil.executeWithLog(TelemetryConstants.WEBAPP, "start-flight-recorder", op -> {
        op.trackProperty(TelemetryConstants.SUBSCRIPTIONID, subscriptionId);
        final AzureString title = AzureOperationBundle.title("appservice|flight_recorder.profile");
        final AzureTask task = new AzureTask(project, title, true, this::doProfileFlightRecorderAll, AzureTask.Modality.ANY);
        AzureTaskManager.getInstance().runInBackground(task);
    });
}
Also used : AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Aggregations

AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)46 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)36 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)21 Project (com.intellij.openapi.project.Project)7 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)6 List (java.util.List)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 AzureOperationBundle (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle)5 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)5 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)5 EventUtil (com.microsoft.azuretools.telemetrywrapper.EventUtil)4 BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)4 IOException (java.io.IOException)4 MessageType (com.intellij.openapi.ui.MessageType)3 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)3 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)3 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)3 File (java.io.File)3 javax.swing (javax.swing)3 FileChooserDescriptorFactory (com.intellij.openapi.fileChooser.FileChooserDescriptorFactory)2