Search in sources :

Example 11 with AzureString

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

the class CreateDeploymentForm method doOKAction.

@Override
protected void doOKAction() {
    deploymentName = deploymentNameTextField.getText();
    final AzureString title = AzureOperationBundle.title("arm|deployment.deploy", deploymentName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.CREATE_DEPLOYMENT, (operation -> {
            Subscription subs = (Subscription) subscriptionCb.getSelectedItem();
            com.microsoft.azure.management.Azure azure = AuthMethodManager.getInstance().getAzureClient(subs.getId());
            WithTemplate template;
            if (createNewRgButton.isSelected()) {
                rgName = rgNameTextFiled.getText();
                final Region region = (Region) regionCb.getSelectedItem();
                template = azure.deployments().define(deploymentName).withNewResourceGroup(rgNameTextFiled.getText(), com.microsoft.azure.management.resources.fluentcore.arm.Region.fromName(region.getName()));
            } else {
                ResourceGroup rg = (ResourceGroup) rgNameCb.getSelectedItem();
                List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance().getDeploymentByRgName(subs.getId(), rg.getName());
                boolean isExist = deployments.parallelStream().anyMatch(deployment -> deployment.getResource().name().equals(deploymentName));
                if (isExist) {
                    throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME);
                }
                rgName = rg.getName();
                template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg.getName());
            }
            String fileText = templateTextField.getText();
            String content = IOUtils.toString(new FileReader(fileText));
            String parametersPath = parametersTextField.getText();
            String parameters = StringUtils.isEmpty(parametersPath) ? "{}" : IOUtils.toString(new FileReader(parametersPath));
            parameters = DeploymentUtils.parseParameters(parameters);
            template.withTemplate(content).withParameters(parameters).withMode(DeploymentMode.INCREMENTAL).create();
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
            updateUI();
        }), (ex) -> {
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_FAIL + ", " + ex.getMessage(), MessageType.ERROR);
            updateUI();
        });
    }));
    close(DialogWrapper.OK_EXIT_CODE, true);
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) Azure(com.microsoft.azure.toolkit.lib.Azure) NOTIFY_CREATE_DEPLOYMENT_FAIL(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_FAIL) MessageType(com.intellij.openapi.ui.MessageType) SimpleListCellRenderer(com.intellij.ui.SimpleListCellRenderer) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) StringUtils(org.apache.commons.lang3.StringUtils) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) NOTIFY_CREATE_DEPLOYMENT_SUCCESS(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_SUCCESS) StatusBar(com.intellij.openapi.wm.StatusBar) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) ResourceManagementNode(com.microsoft.tooling.msservices.serviceexplorer.azure.arm.ResourceManagementNode) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) JComboBox(javax.swing.JComboBox) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) WindowManager(com.intellij.openapi.wm.WindowManager) JRadioButton(javax.swing.JRadioButton) RegionComboBox(com.microsoft.azure.toolkit.intellij.common.component.RegionComboBox) IOUtils(org.apache.commons.io.IOUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureMvpModel(com.microsoft.azuretools.core.mvp.model.AzureMvpModel) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) JPanel(javax.swing.JPanel) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) JTextField(javax.swing.JTextField) AzureUIRefreshCore(com.microsoft.azuretools.utils.AzureUIRefreshCore) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Region(com.microsoft.azure.toolkit.lib.common.model.Region) DeploymentMode(com.microsoft.azure.management.resources.DeploymentMode) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) JComponent(javax.swing.JComponent) Deployment(com.microsoft.azure.management.resources.Deployment) ButtonGroup(javax.swing.ButtonGroup) UIUtils(com.microsoft.intellij.ui.util.UIUtils) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) JList(javax.swing.JList) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) JLabel(javax.swing.JLabel) FileReader(java.io.FileReader) SubscriptionComboBox(com.microsoft.azure.toolkit.intellij.common.component.SubscriptionComboBox) BROWSE_TEMPLATE_SAMPLES(com.microsoft.azuretools.telemetry.TelemetryConstants.BROWSE_TEMPLATE_SAMPLES) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) Region(com.microsoft.azure.toolkit.lib.common.model.Region) FileReader(java.io.FileReader) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 12 with AzureString

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

the class SSHIntoWebAppAction method actionPerformed.

@Override
protected void actionPerformed(NodeActionEvent nodeActionEvent) throws AzureCmdException {
    logger.info(message("webapp.ssh.hint.startSSH", webAppName));
    // ssh to connect to remote web app container.
    final AzureString title = title("webapp|ssh.connect", webAppName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final TunnelProxy proxy = new TunnelProxy(webApp);
        int localPort;
        try {
            localPort = proxy.start();
        } catch (IOException e) {
            try {
                proxy.close();
            } catch (Throwable ex) {
            // ignore
            }
            throw new AzureToolkitRuntimeException(message("webapp.ssh.error.message"));
        }
        final int finalLocalPort = localPort;
        // ssh to local proxy and open terminal.
        AzureTaskManager.getInstance().runAndWait(() -> {
            // create a new terminal tab.
            TerminalView terminalView = TerminalView.getInstance(project);
            ShellTerminalWidget shellTerminalWidget = terminalView.createLocalShellWidget(null, String.format(WEBAPP_TERMINAL_TABLE_NAME, webAppName));
            final AzureString messageTitle = title("webapp|ssh.open", webAppName);
            AzureTaskManager.getInstance().runInBackground(new AzureTask(project, messageTitle, false, () -> {
                // create connection to the local proxy.
                final SSHTerminalManager.CreateRemoteConnectionInfo info = new SSHTerminalManager.CreateRemoteConnectionInfo();
                info.setUsername(TunnelProxy.DEFAULT_SSH_USERNAME);
                info.setPassword(TunnelProxy.DEFAULT_SSH_PASSWORD);
                info.setPort(finalLocalPort);
                SSHTerminalManager.INSTANCE.openConnectionInTerminal(shellTerminalWidget, info);
            }));
        }, AzureTask.Modality.ANY);
    }));
    logger.info(message("webapp.ssh.hint.SSHDone", webAppName));
}
Also used : TerminalView(org.jetbrains.plugins.terminal.TerminalView) TunnelProxy(com.microsoft.azure.toolkit.lib.appservice.TunnelProxy) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) ShellTerminalWidget(org.jetbrains.plugins.terminal.ShellTerminalWidget) IOException(java.io.IOException) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 13 with AzureString

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

the class StartStreamingLogsAction method actionPerformed.

@Override
protected void actionPerformed(NodeActionEvent nodeActionEvent) throws AzureCmdException {
    final AzureString title = AzureOperationBundle.title("appservice|log_stream.start", ResourceUtils.nameFromResourceId(resourceId));
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        switch(operation) {
            case START_STREAMING_LOG_FUNCTION_APP:
                AppServiceStreamingLogManager.INSTANCE.showFunctionStreamingLog(project, resourceId);
                break;
            case START_STREAMING_LOG_WEBAPP:
                AppServiceStreamingLogManager.INSTANCE.showWebAppStreamingLog(project, resourceId);
                break;
            case START_STREAMING_LOG_WEBAPP_SLOT:
                AppServiceStreamingLogManager.INSTANCE.showWebAppDeploymentSlotStreamingLog(project, resourceId);
                break;
            default:
                DefaultLoader.getUIHelper().showError("Unsupported operation", "Unsupported operation");
                break;
        }
    }));
}
Also used : AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 14 with AzureString

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

the class ApplicationInsightsNewDialog method doOKAction.

@Override
protected void doOKAction() {
    final boolean grpNotSelected = Objects.isNull(comboGrp.getSelectedItem()) || ((String) comboGrp.getSelectedItem()).isEmpty();
    final boolean regNotSelected = Objects.isNull(comboReg.getSelectedItem()) || ((String) comboReg.getSelectedItem()).isEmpty();
    final boolean subNotSelected = comboSub.getSelectedItem() == null;
    if (txtName.getText().trim().isEmpty() || subNotSelected || (grpNotSelected && useExistingBtn.isSelected()) || (textGrp.getText().isEmpty() && createNewBtn.isSelected()) || regNotSelected) {
        if (subNotSelected || comboSub.getItemCount() <= 0) {
            PluginUtil.displayErrorDialog(message("aiErrTtl"), message("noSubErrMsg"));
        } else if (grpNotSelected || comboGrp.getItemCount() <= 0) {
            PluginUtil.displayErrorDialog(message("aiErrTtl"), message("noResGrpErrMsg"));
        } else {
            PluginUtil.displayErrorDialog(message("aiErrTtl"), message("nameEmptyMsg"));
        }
    } else {
        boolean isNewGroup = createNewBtn.isSelected();
        String resourceGroup = isNewGroup ? textGrp.getText() : (String) comboGrp.getSelectedItem();
        final AzureString title = AzureOperationBundle.title("ai.create.rg", txtName.getText(), resourceGroup);
        AzureTaskManager.getInstance().runInBackground(new AzureTask(null, title, false, () -> {
            try {
                ApplicationInsightsComponent resource = AzureSDKManager.createInsightsResource(currentSub, resourceGroup, isNewGroup, txtName.getText(), (String) comboReg.getSelectedItem());
                resourceToAdd = new ApplicationInsightsResource(resource, currentSub, true);
                if (onCreate != null) {
                    onCreate.run();
                }
            } catch (Exception ex) {
                PluginUtil.displayErrorDialogInAWTAndLog(message("aiErrTtl"), message("resCreateErrMsg"), ex);
            }
        }));
        super.doOKAction();
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ApplicationInsightsComponent(com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent) 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 15 with AzureString

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

the class IDEHelperImpl method saveAppServiceFile.

@SneakyThrows
@Override
public void saveAppServiceFile(@NotNull AppServiceFile file, @NotNull Object context, @Nullable File dest) {
    final File destFile = Objects.isNull(dest) ? DefaultLoader.getUIHelper().showFileSaver("Download", file.getName()) : dest;
    if (Objects.isNull(destFile)) {
        return;
    }
    final OutputStream output = new FileOutputStream(destFile);
    final Project project = (Project) context;
    final AzureString title = AzureOperationBundle.title("appservice|file.download", file.getName());
    final AzureTask<Void> task = new AzureTask<>(project, title, false, () -> {
        ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
        file.getApp().getFileContent(file.getPath()).doOnComplete(() -> notifyDownloadSuccess(file.getName(), destFile, ((Project) context))).doOnTerminate(() -> 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 write data into local file";
                final String action = "try later";
                throw new AzureToolkitRuntimeException(error, e, action);
            }
        }, IDEHelperImpl::onRxException);
    });
    AzureTaskManager.getInstance().runInModal(task);
}
Also used : Project(com.intellij.openapi.project.Project) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) AppServiceFile(com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile) File(java.io.File) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) SneakyThrows(lombok.SneakyThrows)

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