Search in sources :

Example 1 with KnownLinuxVirtualMachineImage

use of com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage in project azure-tools-for-java by Microsoft.

the class MachineSettingsStep method prepare.

@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
    rootPanel.revalidate();
    boolean isLinux;
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        azure = azureManager.getAzure(((VMWizardModel) model).getSubscription().getSubscriptionId());
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
    }
    if (model.isKnownMachineImage()) {
        isLinux = model.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
    } else {
        isLinux = model.getVirtualMachineImage().osDiskImage().operatingSystem().equals(OperatingSystemTypes.LINUX);
    }
    if (isLinux) {
        certificateCheckBox.setEnabled(true);
        passwordCheckBox.setEnabled(true);
        certificateCheckBox.setSelected(false);
        passwordCheckBox.setSelected(true);
    } else {
        certificateCheckBox.setSelected(false);
        passwordCheckBox.setSelected(true);
        certificateCheckBox.setEnabled(false);
        passwordCheckBox.setEnabled(false);
    }
    validateEmptyFields();
    if (vmSizeComboBox.getItemCount() == 0) {
        vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading VM sizes...", false) {

            @Override
            public void run(@NotNull ProgressIndicator progressIndicator) {
                progressIndicator.setIndeterminate(true);
                PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().name());
                Collections.sort(sizes, new Comparator<VirtualMachineSize>() {

                    @Override
                    public int compare(VirtualMachineSize t0, VirtualMachineSize t1) {
                        if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
                            return t0.name().compareTo(t1.name());
                        } else if (t0.name().contains("Basic")) {
                            return -1;
                        } else if (t1.name().contains("Basic")) {
                            return 1;
                        }
                        int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
                        if (coreCompare == 0) {
                            return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
                        } else {
                            return coreCompare;
                        }
                    }
                });
                ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
                        selectDefaultSize();
                    }
                }, ModalityState.any());
            }
        });
    } else {
        selectDefaultSize();
    }
    return rootPanel;
}
Also used : Task(com.intellij.openapi.progress.Task) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) PagedList(com.microsoft.azure.PagedList) Comparator(java.util.Comparator) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 2 with KnownLinuxVirtualMachineImage

use of com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage in project azure-tools-for-java by Microsoft.

the class MachineSettingsStep method getTitle.

@Override
public String getTitle() {
    boolean isLinux;
    if (wizard.isKnownMachineImage()) {
        isLinux = wizard.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
    } else {
        isLinux = wizard.getVirtualMachineImage().osDiskImage().operatingSystem().equals(OperatingSystemTypes.LINUX);
    }
    if (isLinux) {
        certificateCheckBox.setEnabled(true);
        passwordCheckBox.setEnabled(true);
        certificateCheckBoxSelected(false);
        passwordCheckBox.setSelection(true);
    } else {
        certificateCheckBoxSelected(false);
        passwordCheckBox.setSelection(true);
        certificateCheckBox.setEnabled(false);
        passwordCheckBox.setEnabled(false);
    }
    validateEmptyFields();
    if (vmSizeComboBox.getItemCount() == 0) {
        vmSizeComboBox.setItems(new String[] { LOADING });
        AzureTaskManager.getInstance().runInBackground("Loading VM sizes...", new Runnable() {

            @Override
            public void run() {
                PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = wizard.getAzure().virtualMachines().sizes().listByRegion(wizard.getRegion().getName());
                Collections.sort(sizes, new Comparator<VirtualMachineSize>() {

                    @Override
                    public int compare(VirtualMachineSize t0, VirtualMachineSize t1) {
                        if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
                            return t0.name().compareTo(t1.name());
                        } else if (t0.name().contains("Basic")) {
                            return -1;
                        } else if (t1.name().contains("Basic")) {
                            return 1;
                        }
                        int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
                        if (coreCompare == 0) {
                            return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
                        } else {
                            return coreCompare;
                        }
                    }
                });
                DefaultLoader.getIdeHelper().invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        vmSizeComboBox.removeAll();
                        for (VirtualMachineSize size : sizes) {
                            vmSizeComboBox.add(size.name());
                            vmSizeComboBox.setData(size.name(), size);
                        }
                        if (sizes.size() > 0) {
                            vmSizeComboBox.select(0);
                        }
                    // selectDefaultSize();
                    }
                });
            }
        });
    } else {
        selectDefaultSize();
    }
    return super.getTitle();
}
Also used : VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) PagedList(com.microsoft.azure.PagedList)

Example 3 with KnownLinuxVirtualMachineImage

use of com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage in project azure-tools-for-java by Microsoft.

the class MachineSettingsStep method prepare.

@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
    rootPanel.revalidate();
    boolean isLinux;
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        azure = azureManager.getAzure(model.getSubscription().getId());
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
    }
    if (model.isKnownMachineImage()) {
        isLinux = model.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
    } else {
        isLinux = model.getVirtualMachineImage().osDiskImage().operatingSystem() == OperatingSystemTypes.LINUX;
    }
    if (isLinux) {
        certificateCheckBox.setEnabled(true);
        passwordCheckBox.setEnabled(true);
        certificateCheckBox.setSelected(false);
        passwordCheckBox.setSelected(true);
    } else {
        certificateCheckBox.setSelected(false);
        passwordCheckBox.setSelected(true);
        certificateCheckBox.setEnabled(false);
        passwordCheckBox.setEnabled(false);
    }
    validateEmptyFields();
    if (model.getRegion() != null && (vmSizeComboBox.getItemCount() == 0 || vmSizeComboBox.getItemAt(0).contains("<Loading...>"))) {
        vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
        final AzureString title = AzureOperationBundle.title("vm.list_sizes.region", model.getRegion().getName());
        AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
            final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
            progressIndicator.setIndeterminate(true);
            PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().getName());
            sizes.sort((t0, t1) -> {
                if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
                    return t0.name().compareTo(t1.name());
                } else if (t0.name().contains("Basic")) {
                    return -1;
                } else if (t1.name().contains("Basic")) {
                    return 1;
                }
                int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
                if (coreCompare == 0) {
                    return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
                } else {
                    return coreCompare;
                }
            });
            AzureTaskManager.getInstance().runAndWait(() -> {
                vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
                selectDefaultSize();
            }, AzureTask.Modality.ANY);
        }));
    } else {
        selectDefaultSize();
    }
    return rootPanel;
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) VMWizardModel(com.microsoft.azure.toolkit.intellij.vm.VMWizardModel) DocumentListener(javax.swing.event.DocumentListener) ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) WizardNavigationState(com.intellij.ui.wizard.WizardNavigationState) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) ItemListener(java.awt.event.ItemListener) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Azure(com.microsoft.azure.management.Azure) PagedList(com.microsoft.azure.PagedList) OperatingSystemTypes(com.microsoft.azure.management.compute.OperatingSystemTypes) Map(java.util.Map) Project(com.intellij.openapi.project.Project) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) URI(java.net.URI) DocumentEvent(javax.swing.event.DocumentEvent) ProgressManager(com.intellij.openapi.progress.ProgressManager) ItemEvent(java.awt.event.ItemEvent) JXHyperlink(org.jdesktop.swingx.JXHyperlink) ActionEvent(java.awt.event.ActionEvent) java.awt(java.awt) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureWizardStep(com.microsoft.intellij.ui.components.AzureWizardStep) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) TelemetryProperties(com.microsoft.azuretools.telemetry.TelemetryProperties) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) WizardStep(com.intellij.ui.wizard.WizardStep) FileChooser(com.intellij.openapi.fileChooser.FileChooser) Consumer(com.intellij.util.Consumer) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) javax.swing(javax.swing) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) PagedList(com.microsoft.azure.PagedList) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask)

Aggregations

PagedList (com.microsoft.azure.PagedList)3 KnownLinuxVirtualMachineImage (com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage)3 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 WizardNavigationState (com.intellij.ui.wizard.WizardNavigationState)1 WizardStep (com.intellij.ui.wizard.WizardStep)1 Consumer (com.intellij.util.Consumer)1 Azure (com.microsoft.azure.management.Azure)1 OperatingSystemTypes (com.microsoft.azure.management.compute.OperatingSystemTypes)1 VMWizardModel (com.microsoft.azure.toolkit.intellij.vm.VMWizardModel)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 AzureOperationBundle (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle)1 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)1