Search in sources :

Example 41 with AzureString

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

the class SettingsStep method retrieveAvailabilitySets.

private void retrieveAvailabilitySets() {
    final AzureString title = AzureOperationBundle.title("vm.list_availability_sets");
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setIndeterminate(true);
        if (availabilitySets == null) {
            availabilitySets = azure.availabilitySets().list();
        }
        AzureTaskManager.getInstance().runLater(() -> availabilityComboBox.setModel(getAvailabilitySetsModel(model.getAvailabilitySet())));
    }));
    if (availabilitySets == 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.setWithNewAvailabilitySet(true);
                            model.setAvailabilitySet(null);
                        } else if (NONE.equals(o)) {
                            model.setAvailabilitySet(null);
                            model.setWithNewAvailabilitySet(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 42 with AzureString

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

the class ContainerRegistryPropertyView method pullImage.

private void pullImage() {
    final AzureString title = AzureOperationBundle.title("docker|image.pull", currentRepo);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(null, title, false, () -> {
        try {
            if (Utils.isEmptyString(currentRepo) || Utils.isEmptyString(currentTag)) {
                throw new Exception(REPO_TAG_NOT_AVAILABLE);
            }
            final Registry registry = ContainerRegistryMvpModel.getInstance().getContainerRegistry(subscriptionId, registryId);
            final PrivateRegistryImageSetting setting = ContainerRegistryMvpModel.getInstance().createImageSettingWithRegistry(registry);
            final String image = String.format("%s:%s", currentRepo, currentTag);
            final String fullImageTagName = String.format("%s/%s", registry.loginServerUrl(), image);
            DockerClient docker = DefaultDockerClient.fromEnv().build();
            DockerUtil.pullImage(docker, registry.loginServerUrl(), setting.getUsername(), setting.getPassword(), fullImageTagName);
            String message = String.format(IMAGE_PULL_SUCCESS, fullImageTagName);
            UIUtils.showNotification(statusBar, message, MessageType.INFO);
            sendTelemetry(true, subscriptionId, null);
        } catch (Exception e) {
            UIUtils.showNotification(statusBar, e.getMessage(), MessageType.ERROR);
            sendTelemetry(false, subscriptionId, e.getMessage());
        }
    }));
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) Registry(com.microsoft.azure.management.containerregistry.Registry) 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 43 with AzureString

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

the class CreateWebAppAction method createWebApp.

@AzureOperation(name = "webapp.create_detail", params = { "config.getName()" }, type = AzureOperation.Type.ACTION)
private Single<IWebApp> createWebApp(final WebAppConfig config) {
    final AzureString title = title("webapp.create_detail", config.getName());
    final AzureTask<IWebApp> task = new AzureTask<>(null, title, false, () -> {
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        indicator.setIndeterminate(true);
        return webappService.createWebApp(config);
    });
    return AzureTaskManager.getInstance().runInModalAsObservable(task).toSingle().doOnSuccess(app -> {
        this.notifyCreationSuccess(app);
        this.refreshAzureExplorer(app);
    });
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 44 with AzureString

use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString 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)

Example 45 with AzureString

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

the class SelectImageStep method fillPublishers.

private void fillPublishers() {
    if (customImageBtn.isSelected()) {
        disableNext();
        final AzureString title = AzureOperationBundle.title("vm|publisher.list");
        AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
            final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
            progressIndicator.setIndeterminate(true);
            final Object selectedItem = regionComboBox.getSelectedItem();
            final Region location = selectedItem instanceof Region ? (Region) selectedItem : null;
            if (location == null) {
                return;
            }
            clearSelection(publisherComboBox, offerComboBox, skuComboBox, imageLabelList);
            RxJavaUtils.unsubscribeSubscription(fillPublisherSubscription);
            fillPublisherSubscription = Observable.fromCallable(() -> azure.virtualMachineImages().publishers().listByRegion(location.getName())).subscribeOn(Schedulers.io()).subscribe(publisherList -> DefaultLoader.getIdeHelper().invokeLater(() -> {
                publisherComboBox.setModel(new DefaultComboBoxModel(publisherList.toArray()));
                fillOffers();
            }), error -> {
                final String msg = String.format(ERROR_MESSAGE_LIST_PUBLISHER, String.format(message("webappExpMsg"), error.getMessage()));
                handleError(msg, error);
            });
        }));
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Region(com.microsoft.azure.toolkit.lib.common.model.Region) 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)

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