Search in sources :

Example 21 with AzureTask

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

the class ResourceTemplateView method updateDeployment.

private void updateDeployment() {
    String oldTemplate = this.originTemplate;
    String oldParameters = this.originParameters;
    final AzureString title = AzureOperationBundle.title("arm|deployment.update", node.getDeployment().name());
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        EventUtil.executeWithLog(ARM, UPDATE_DEPLOYMENT_SHORTCUT, (operation -> {
            ResourceTemplateView.this.originTemplate = getTemplate();
            ResourceTemplateView.this.originParameters = getParameters();
            node.getDeployment().update().withTemplate(ResourceTemplateView.this.originTemplate).withParameters(ResourceTemplateView.this.originParameters).withMode(DeploymentMode.INCREMENTAL).apply();
            UIUtils.showNotification(project, NOTIFY_UPDATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
        }), (e) -> {
            // Fall back the origin value when update fail.
            ResourceTemplateView.this.originTemplate = oldTemplate;
            ResourceTemplateView.this.originParameters = oldParameters;
            UIUtils.showNotification(project, NOTIFY_UPDATE_DEPLOYMENT_FAIL + ", " + e.getMessage(), MessageType.ERROR);
        });
    }));
}
Also used : MessageType(com.intellij.openapi.ui.MessageType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiAwareTextEditorProvider(com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorProvider) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) DeploymentMode(com.microsoft.azure.management.resources.DeploymentMode) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) NOTIFY_UPDATE_DEPLOYMENT_FAIL(com.microsoft.azure.toolkit.intellij.arm.action.UpdateDeploymentAction.NOTIFY_UPDATE_DEPLOYMENT_FAIL) NOTIFY_UPDATE_DEPLOYMENT_SUCCESS(com.microsoft.azure.toolkit.intellij.arm.action.UpdateDeploymentAction.NOTIFY_UPDATE_DEPLOYMENT_SUCCESS) Project(com.intellij.openapi.project.Project) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) DeploymentNode(com.microsoft.tooling.msservices.serviceexplorer.azure.arm.deployments.DeploymentNode) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) UIUtils(com.microsoft.intellij.ui.util.UIUtils) BaseEditor(com.microsoft.azure.toolkit.intellij.common.BaseEditor) UPDATE_DEPLOYMENT_SHORTCUT(com.microsoft.azuretools.telemetry.TelemetryConstants.UPDATE_DEPLOYMENT_SHORTCUT) PsiAwareTextEditorImpl(com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorImpl) FileEditor(com.intellij.openapi.fileEditor.FileEditor) ARM(com.microsoft.azuretools.telemetry.TelemetryConstants.ARM) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) NotNull(org.jetbrains.annotations.NotNull) ARMLanguage(com.microsoft.intellij.language.arm.ARMLanguage) Utils(com.microsoft.azuretools.azurecommons.util.Utils) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) javax.swing(javax.swing) 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 22 with AzureTask

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

the class UpdateDeploymentForm method doOKAction.

@Override
protected void doOKAction() {
    String deploymentName = deploymentNode.getDeployment().name();
    final AzureString title = AzureOperationBundle.title("arm|deployment.update", deploymentName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.UPDATE_DEPLOYMENT, (operation -> {
            Deployment.Update update = deploymentNode.getDeployment().update();
            String templatePath = templateTextField.getText();
            update = update.withTemplate(IOUtils.toString(new FileReader(templatePath)));
            String parametersPath = parametersTextField.getText();
            if (!StringUtils.isEmpty(parametersPath)) {
                String parameters = IOUtils.toString(new FileReader(parametersPath));
                update = update.withParameters(DeploymentUtils.parseParameters(parameters));
            }
            update.withMode(DeploymentMode.INCREMENTAL).apply();
            UIUtils.showNotification(statusBar, NOTIFY_UPDATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
        }), (e) -> {
            UIUtils.showNotification(statusBar, NOTIFY_UPDATE_DEPLOYMENT_FAIL + ", " + e.getMessage(), MessageType.ERROR);
        });
    }));
    close(OK_EXIT_CODE, true);
}
Also used : FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) StringUtils(org.apache.commons.lang.StringUtils) MessageType(com.intellij.openapi.ui.MessageType) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) DeploymentMode(com.microsoft.azure.management.resources.DeploymentMode) NOTIFY_UPDATE_DEPLOYMENT_FAIL(com.microsoft.azure.toolkit.intellij.arm.action.UpdateDeploymentAction.NOTIFY_UPDATE_DEPLOYMENT_FAIL) StatusBar(com.intellij.openapi.wm.StatusBar) Map(java.util.Map) NOTIFY_UPDATE_DEPLOYMENT_SUCCESS(com.microsoft.azure.toolkit.intellij.arm.action.UpdateDeploymentAction.NOTIFY_UPDATE_DEPLOYMENT_SUCCESS) Project(com.intellij.openapi.project.Project) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) DeploymentNode(com.microsoft.tooling.msservices.serviceexplorer.azure.arm.deployments.DeploymentNode) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) Deployment(com.microsoft.azure.management.resources.Deployment) UIUtils(com.microsoft.intellij.ui.util.UIUtils) WindowManager(com.intellij.openapi.wm.WindowManager) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) Nullable(org.jetbrains.annotations.Nullable) Azure.az(com.microsoft.azure.toolkit.lib.Azure.az) List(java.util.List) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) FileReader(java.io.FileReader) BROWSE_TEMPLATE_SAMPLES(com.microsoft.azuretools.telemetry.TelemetryConstants.BROWSE_TEMPLATE_SAMPLES) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) javax.swing(javax.swing) Deployment(com.microsoft.azure.management.resources.Deployment) FileReader(java.io.FileReader) 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 23 with AzureTask

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

the class AppServiceFileNode method onNodeDblClicked.

@Override
public void onNodeDblClicked(Object context) {
    if (this.file.getType() == AppServiceFile.Type.DIRECTORY) {
        return;
    } else if (this.file.getSize() > SIZE_20MB) {
        DefaultLoader.getUIHelper().showError("File is too large, please download it first", "File is Too Large");
        return;
    }
    final Runnable runnable = () -> open(context);
    final AzureString title = AzureOperationBundle.title("appservice|file.get_content", file.getName(), file.getApp().name());
    AzureTaskManager.getInstance().runInBackground(new AzureTask(this.getProject(), title, false, runnable));
}
Also used : AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 24 with AzureTask

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

the class SignInCommandHandler method loginNonDeviceCodeSingle.

private static Single<AuthMethodDetails> loginNonDeviceCodeSingle(AuthConfiguration auth) {
    final AzureString title = AzureOperationBundle.title("account.sign_in");
    final AzureTask<AuthMethodDetails> task = new AzureTask<>(null, title, true, () -> doLogin(AzureTaskContext.current().getTask().getMonitor(), auth));
    return AzureTaskManager.getInstance().runInBackgroundAsObservable(task).toSingle();
}
Also used : AuthMethodDetails(com.microsoft.azuretools.authmanage.models.AuthMethodDetails) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 25 with AzureTask

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

the class IDEHelperImpl method openAppServiceFile.

@AzureOperation(name = "appservice|file.open", params = { "target.getName()" }, type = AzureOperation.Type.SERVICE)
@SneakyThrows
public void openAppServiceFile(AppServiceFile target, Object context) {
    final IAppService appService = target.getApp();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance((Project) context);
    final VirtualFile virtualFile = getOrCreateVirtualFile(target, fileEditorManager);
    final OutputStream output = virtualFile.getOutputStream(null);
    final AzureString title = AzureOperationBundle.title("appservice|file.open", virtualFile.getName());
    final AzureTask<Void> task = new AzureTask<>(null, title, false, () -> {
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        indicator.setIndeterminate(true);
        indicator.setText2("Checking file existence");
        final AppServiceFile file = appService.getFileByPath(target.getPath());
        if (file == null) {
            final String failureFileDeleted = String.format("Target file (%s) has been deleted", target.getName());
            UIUtil.invokeLaterIfNeeded(() -> Messages.showWarningDialog(failureFileDeleted, "Open File"));
            return;
        }
        indicator.setText2("Loading file content");
        final String failure = String.format("Can not open file (%s). Try downloading it first and open it manually.", virtualFile.getName());
        appService.getFileContent(file.getPath()).doOnComplete(() -> AzureTaskManager.getInstance().runLater(() -> {
            final Consumer<String> contentSaver = content -> saveFileToAzure(target, content, fileEditorManager.getProject());
            if (!openFileInEditor(contentSaver, virtualFile, fileEditorManager)) {
                Messages.showWarningDialog(failure, "Open File");
            }
        }, AzureTask.Modality.NONE)).doAfterTerminate(() -> IOUtils.closeQuietly(output, null)).subscribe(bytes -> {
            try {
                if (bytes != null) {
                    output.write(bytes.array(), 0, bytes.limit());
                }
            } catch (final IOException e) {
                final String error = "failed to load data into editor";
                final String action = "try later or downloading it first";
                throw new AzureToolkitRuntimeException(error, e, action);
            }
        }, IDEHelperImpl::onRxException);
    });
    AzureTaskManager.getInstance().runInModal(task);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IAppService(com.microsoft.azure.toolkit.lib.appservice.service.IAppService) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Consumer(com.intellij.util.Consumer) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AppServiceFile(com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) SneakyThrows(lombok.SneakyThrows)

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