Search in sources :

Example 31 with AzureTask

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

the class SettingsStep method retrieveVirtualNetworks.

private void retrieveVirtualNetworks() {
    final AzureString title = AzureOperationBundle.title("vm.list_virtual_networks");
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setIndeterminate(true);
        if (virtualNetworks == null) {
            virtualNetworks = azure.networks().list();
        }
        final Runnable task = () -> networkComboBox.setModel(getVirtualNetworkModel(model.getVirtualNetwork(), model.getSubnet()));
        AzureTaskManager.getInstance().runLater(task);
    }));
    if (virtualNetworks == null) {
        AzureTaskManager.getInstance().runAndWait(() -> {
            final DefaultComboBoxModel loadingVNModel = new DefaultComboBoxModel(new String[] { CREATE_NEW, "<Loading...>" }) {

                @Override
                public void setSelectedItem(Object o) {
                    super.setSelectedItem(o);
                    if (CREATE_NEW.equals(o)) {
                        showNewVirtualNetworkForm();
                    } else {
                        model.setVirtualNetwork((Network) o);
                    }
                }
            };
            loadingVNModel.setSelectedItem(null);
            networkComboBox.setModel(loadingVNModel);
            subnetComboBox.removeAllItems();
            subnetComboBox.setEnabled(false);
        });
    }
}
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)

Example 32 with AzureTask

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

the class SettingsStep method retrieveStorageAccounts.

private void retrieveStorageAccounts() {
    final AzureString title = AzureOperationBundle.title("vm.list_storage_accounts");
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setIndeterminate(true);
        if (storageAccounts == null) {
            List<StorageAccount> accounts = Azure.az(AzureStorageAccount.class).subscription(model.getSubscription().getId()).list();
            storageAccounts = new TreeMap<>();
            for (StorageAccount storageAccount : accounts) {
                storageAccounts.put(storageAccount.name(), storageAccount);
            }
        }
        refreshStorageAccounts(null);
    }));
    if (storageAccounts == null) {
        final DefaultComboBoxModel loadingSAModel = new DefaultComboBoxModel(new String[] { CREATE_NEW, "<Loading...>" }) {

            @Override
            public void setSelectedItem(Object o) {
                if (CREATE_NEW.equals(o)) {
                    showNewStorageForm();
                } else {
                    super.setSelectedItem(o);
                }
            }
        };
        loadingSAModel.setSelectedItem(null);
        AzureTaskManager.getInstance().runAndWait(() -> storageComboBox.setModel(loadingSAModel), AzureTask.Modality.ANY);
    }
}
Also used : AzureStorageAccount(com.microsoft.azure.toolkit.lib.storage.service.AzureStorageAccount) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureStorageAccount(com.microsoft.azure.toolkit.lib.storage.service.AzureStorageAccount) StorageAccount(com.microsoft.azure.toolkit.lib.storage.service.StorageAccount) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 33 with AzureTask

use of com.microsoft.azure.toolkit.lib.common.task.AzureTask 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 34 with AzureTask

use of com.microsoft.azure.toolkit.lib.common.task.AzureTask 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 35 with AzureTask

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

Aggregations

AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)38 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)36 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)22 Project (com.intellij.openapi.project.Project)7 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)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 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)4 EventUtil (com.microsoft.azuretools.telemetrywrapper.EventUtil)4 BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)4 MessageType (com.intellij.openapi.ui.MessageType)3 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)3 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)3 File (java.io.File)3 List (java.util.List)3 javax.swing (javax.swing)3 FileChooserDescriptorFactory (com.intellij.openapi.fileChooser.FileChooserDescriptorFactory)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2