Search in sources :

Example 6 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method createButton.

private void createButton(Composite container) {
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayout(new RowLayout(SWT.VERTICAL));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    Button btnCreate = new Button(composite, SWT.NONE);
    btnCreate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            sendTelemetry("CREATE");
            EventUtil.logEvent(EventType.info, WEBAPP, OPEN_CREATEWEBAPP_DIALOG, buildProperties());
            createAppService(project);
        }
    });
    btnCreate.setText("Create...");
    btnDelete = new Button(composite, SWT.NONE);
    btnDelete.setEnabled(false);
    btnDelete.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            sendTelemetry("DELETE");
            deleteAppService();
        }
    });
    btnDelete.setText("Delete...");
    Button btnRefresh = new Button(composite, SWT.NONE);
    btnRefresh.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            sendTelemetry("REFRESH");
            EventUtil.executeWithLog(WEBAPP, REFRESH_METADATA, (operation) -> {
                table.removeAll();
                fillAppServiceDetails();
                doFillTable(true);
            });
        }
    });
    btnRefresh.setText("Refresh");
    btnDeployToRoot = new Button(composite, SWT.CHECK);
    btnDeployToRoot.setSelection(true);
    btnDeployToRoot.setText("Deploy to root");
    int size = btnDeployToRoot.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
    btnCreate.setLayoutData(new RowData(size, SWT.DEFAULT));
    btnDelete.setLayoutData(new RowData(size, SWT.DEFAULT));
    btnRefresh.setLayoutData(new RowData(size, SWT.DEFAULT));
    btnDeployToRoot.setLayoutData(new RowData(size, SWT.DEFAULT));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Azure(com.microsoft.azure.toolkit.lib.Azure) DefaultToolTip(org.eclipse.jface.window.DefaultToolTip) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) CommonUtils(com.microsoft.azuretools.webapp.util.CommonUtils) PluginUtil(com.microsoft.azuretools.core.utils.PluginUtil) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) REFRESH_METADATA(com.microsoft.azuretools.telemetry.TelemetryConstants.REFRESH_METADATA) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IWebAppDeploymentSlot(com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) ILog(org.eclipse.core.runtime.ILog) PlatformUI(org.eclipse.ui.PlatformUI) Runtime(com.microsoft.azure.toolkit.lib.appservice.model.Runtime) UpdateProgressIndicator(com.microsoft.azuretools.core.utils.UpdateProgressIndicator) ErrorType(com.microsoft.azuretools.telemetrywrapper.ErrorType) Status(org.eclipse.core.runtime.Status) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion) CountDownLatch(java.util.concurrent.CountDownLatch) Window(org.eclipse.jface.window.Window) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) SWT(org.eclipse.swt.SWT) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) SimpleDateFormat(java.text.SimpleDateFormat) CREATE_WEBAPP_SLOT(com.microsoft.azuretools.telemetry.TelemetryConstants.CREATE_WEBAPP_SLOT) IProject(org.eclipse.core.resources.IProject) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) ErrorWindow(com.microsoft.azuretools.core.ui.ErrorWindow) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) WebComponentExportDataModelProvider(org.eclipse.jst.j2ee.internal.web.archive.operations.WebComponentExportDataModelProvider) GridData(org.eclipse.swt.layout.GridData) RowData(org.eclipse.swt.layout.RowData) Link(org.eclipse.swt.widgets.Link) IWebAppBase(com.microsoft.azure.toolkit.lib.appservice.service.IWebAppBase) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) TableItem(org.eclipse.swt.widgets.TableItem) Shell(org.eclipse.swt.widgets.Shell) DELETE_WEBAPP(com.microsoft.azuretools.telemetry.TelemetryConstants.DELETE_WEBAPP) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) DataModelFactory(org.eclipse.wst.common.frameworks.datamodel.DataModelFactory) File(java.io.File) ProgressDialog(com.microsoft.azuretools.core.utils.ProgressDialog) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) GridLayout(org.eclipse.swt.layout.GridLayout) Activator(com.microsoft.azuretools.webapp.Activator) URL(java.net.URL) Date(java.util.Date) DEPLOY_WEBAPP(com.microsoft.azuretools.telemetry.TelemetryConstants.DEPLOY_WEBAPP) TableColumn(org.eclipse.swt.widgets.TableColumn) MavenUtils(com.microsoft.azuretools.core.utils.MavenUtils) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) IStatus(org.eclipse.core.runtime.IStatus) WebContainer(com.microsoft.azure.toolkit.lib.appservice.model.WebContainer) AzureWebAppMvpModel(com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel) Button(org.eclipse.swt.widgets.Button) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) UUID(java.util.UUID) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) AzureDeploymentProgressNotification(com.microsoft.azuretools.core.ui.views.AzureDeploymentProgressNotification) Optional(java.util.Optional) Label(org.eclipse.swt.widgets.Label) WEBAPP(com.microsoft.azuretools.telemetry.TelemetryConstants.WEBAPP) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) OPEN_CREATEWEBAPP_DIALOG(com.microsoft.azuretools.telemetry.TelemetryConstants.OPEN_CREATEWEBAPP_DIALOG) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) Table(org.eclipse.swt.widgets.Table) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) FocusListener(org.eclipse.swt.events.FocusListener) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) Schedulers(reactor.core.scheduler.Schedulers) FillLayout(org.eclipse.swt.layout.FillLayout) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) Combo(org.eclipse.swt.widgets.Combo) Job(org.eclipse.core.runtime.jobs.Job) IJ2EEComponentExportDataModelProperties(org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties) Group(org.eclipse.swt.widgets.Group) StringUtils(com.microsoft.azuretools.adauth.StringUtils) RowLayout(org.eclipse.swt.layout.RowLayout) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) AccessibilityUtils(com.microsoft.azuretools.core.utils.AccessibilityUtils) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) AppServiceBaseEntity(com.microsoft.azure.toolkit.lib.appservice.entity.AppServiceBaseEntity) AppInsightsClient(com.microsoft.azuretools.telemetry.AppInsightsClient) TelemetryManager(com.microsoft.azuretools.telemetrywrapper.TelemetryManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) WebAppSettingModel(com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel) Control(org.eclipse.swt.widgets.Control) RowData(org.eclipse.swt.layout.RowData) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point)

Example 7 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class SettingsStep method onFinish.

@Override
public boolean onFinish() {
    final boolean isNewResourceGroup = createNewRadioButton.isSelected();
    final String resourceGroupName = isNewResourceGroup ? resourceGrpField.getText() : resourceGrpCombo.getSelectedItem().toString();
    Operation operation = TelemetryManager.createOperation(VM, CREATE_VM);
    final AzureString title = AzureOperationBundle.title("vm.create", model.getName());
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setIndeterminate(true);
        try {
            operation.start();
            String certificate = model.getCertificate();
            byte[] certData = new byte[0];
            if (!certificate.isEmpty()) {
                File certFile = new File(certificate);
                if (certFile.exists()) {
                    try (FileInputStream certStream = new FileInputStream(certFile)) {
                        certData = new byte[(int) certFile.length()];
                        if (certStream.read(certData) != certData.length) {
                            throw new Exception("Unable to process certificate: stream longer than informed size.");
                        }
                    } finally {
                    }
                }
            }
            // create storage account when use choose to create new one
            if (Objects.nonNull(model.getStorageAccountConfig())) {
                model.setStorageAccount(CreateStorageAccountAction.createStorageAccount(model.getStorageAccountConfig()));
            }
            final com.microsoft.azure.management.compute.VirtualMachine vm = AzureSDKManager.createVirtualMachine(model.getSubscription().getId(), model.getName(), resourceGroupName, createNewRadioButton.isSelected(), model.getSize(), model.getRegion().getName(), model.getVirtualMachineImage(), model.getKnownMachineImage(), model.isKnownMachineImage(), model.getStorageAccount(), model.getVirtualNetwork(), model.getNewNetwork(), model.isWithNewNetwork(), model.getSubnet(), model.getPublicIpAddress(), model.isWithNewPip(), model.getAvailabilitySet(), model.isWithNewAvailabilitySet(), model.getUserName(), model.getPassword(), certData.length > 0 ? new String(certData) : null);
            AzureTaskManager.getInstance().runLater(() -> {
                try {
                    parent.addChildNode(new com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMNode(parent, model.getSubscription().getId(), vm));
                } catch (AzureCmdException e) {
                    String msg = "An error occurred while attempting to refresh the list of virtual machines.";
                    DefaultLoader.getUIHelper().showException(msg, e, "Azure Services Explorer - Error Refreshing VM List", false, true);
                    AzurePlugin.log(msg, e);
                }
            });
        } catch (Exception e) {
            EventUtil.logError(operation, ErrorType.userError, e, null, null);
            String msg = "An error occurred while attempting to create the specified virtual machine." + "<br>" + String.format(message("webappExpMsg"), e.getMessage());
            DefaultLoader.getUIHelper().showException(msg, e, message("errTtl"), false, true);
            AzurePlugin.log(msg, e);
        } finally {
            operation.complete();
        }
    }));
    return super.onFinish();
}
Also used : AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) FileInputStream(java.io.FileInputStream) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) File(java.io.File)

Example 8 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class SparkBatchJobDebuggerRunner method execute.

/**
 * Execute Spark remote debugging action, refer to {@link GenericDebuggerRunner#execute(ExecutionEnvironment)}
 * implementations, some internal API leveraged.
 *
 * @param environment the execution environment
 * @throws ExecutionException the exception in execution
 */
@Override
public void execute(final ExecutionEnvironment environment) throws ExecutionException {
    final RunProfileState state = environment.getState();
    if (state == null) {
        return;
    }
    final Operation operation = environment.getUserData(TelemetryKeys.OPERATION);
    final AsyncPromise<ExecutionEnvironment> jobDriverEnvReady = new AsyncPromise<>();
    final SparkBatchRemoteDebugState submissionState = (SparkBatchRemoteDebugState) state;
    final SparkSubmitModel submitModel = submissionState.getSubmitModel();
    // Create SSH debug session firstly
    final SparkBatchDebugSession session;
    try {
        session = SparkBatchDebugSession.factoryByAuth(getSparkJobUrl(submitModel), submitModel.getAdvancedConfigModel()).open().verifyCertificate();
    } catch (final Exception e) {
        final ExecutionException exp = new ExecutionException("Failed to create SSH session for debugging. " + ExceptionUtils.getRootCauseMessage(e));
        EventUtil.logErrorClassNameOnlyWithComplete(operation, ErrorType.systemError, exp, null, null);
        throw exp;
    }
    final Project project = submitModel.getProject();
    final ExecutionManager executionManager = ExecutionManager.getInstance(project);
    final IdeaSchedulers schedulers = new IdeaSchedulers(project);
    final PublishSubject<SparkBatchJobSubmissionEvent> debugEventSubject = PublishSubject.create();
    final ISparkBatchDebugJob sparkDebugBatch = (ISparkBatchDebugJob) submissionState.getSparkBatch().clone();
    final PublishSubject<SparkLogLine> ctrlSubject = (PublishSubject<SparkLogLine>) sparkDebugBatch.getCtrlSubject();
    final SparkBatchJobRemoteDebugProcess driverDebugProcess = new SparkBatchJobRemoteDebugProcess(schedulers, session, sparkDebugBatch, submitModel.getArtifactPath().orElseThrow(() -> new ExecutionException("No artifact selected")), submitModel.getSubmissionParameter().getMainClassName(), submitModel.getAdvancedConfigModel(), ctrlSubject);
    final SparkBatchJobDebugProcessHandler driverDebugHandler = new SparkBatchJobDebugProcessHandler(project, driverDebugProcess, debugEventSubject);
    // Prepare an independent submission console
    final ConsoleViewImpl submissionConsole = new ConsoleViewImpl(project, true);
    final RunContentDescriptor submissionDesc = new RunContentDescriptor(submissionConsole, driverDebugHandler, submissionConsole.getComponent(), String.format("Submit %s to cluster %s", submitModel.getSubmissionParameter().getMainClassName(), submitModel.getSubmissionParameter().getClusterName()));
    // Show the submission console view
    ExecutionManager.getInstance(project).getContentManager().showRunContent(environment.getExecutor(), submissionDesc);
    // Use the submission console to display the deployment ctrl message
    final Subscription jobSubscription = ctrlSubject.subscribe(typedMessage -> {
        final String line = typedMessage.getRawLog() + "\n";
        switch(typedMessage.getMessageInfoType()) {
            case Error:
                submissionConsole.print(line, ConsoleViewContentType.ERROR_OUTPUT);
                break;
            case Info:
                submissionConsole.print(line, ConsoleViewContentType.NORMAL_OUTPUT);
                break;
            case Log:
                submissionConsole.print(line, ConsoleViewContentType.SYSTEM_OUTPUT);
                break;
            case Warning:
                submissionConsole.print(line, ConsoleViewContentType.LOG_WARNING_OUTPUT);
                break;
        }
    }, err -> {
        submissionConsole.print(ExceptionUtils.getRootCauseMessage(err), ConsoleViewContentType.ERROR_OUTPUT);
        final String errMsg = "The Spark job remote debug is cancelled due to " + ExceptionUtils.getRootCauseMessage(err);
        jobDriverEnvReady.setError(errMsg);
        EventUtil.logErrorClassNameOnlyWithComplete(operation, ErrorType.systemError, new UncheckedExecutionException(errMsg, err), null, null);
    }, () -> {
        if (Optional.ofNullable(driverDebugHandler.getUserData(ProcessHandler.TERMINATION_REQUESTED)).orElse(false)) {
            final String errMsg = "The Spark job remote debug is cancelled by user.";
            jobDriverEnvReady.setError(errMsg);
            final Map<String, String> props = ImmutableMap.of("isDebugCancelled", "true");
            EventUtil.logErrorClassNameOnlyWithComplete(operation, ErrorType.userError, new ExecutionException(errMsg), props, null);
        }
    });
    // Call after completed or error
    debugEventSubject.subscribeOn(Schedulers.io()).doAfterTerminate(session::close).subscribe(debugEvent -> {
        try {
            if (debugEvent instanceof SparkBatchRemoteDebugHandlerReadyEvent) {
                final SparkBatchRemoteDebugHandlerReadyEvent handlerReadyEvent = (SparkBatchRemoteDebugHandlerReadyEvent) debugEvent;
                final SparkBatchDebugJobJdbPortForwardedEvent jdbReadyEvent = handlerReadyEvent.getJdbPortForwardedEvent();
                if (!jdbReadyEvent.getLocalJdbForwardedPort().isPresent()) {
                    return;
                }
                final int localPort = jdbReadyEvent.getLocalJdbForwardedPort().get();
                final ExecutionEnvironment forkEnv = forkEnvironment(environment, jdbReadyEvent.getRemoteHost().orElse("unknown"), jdbReadyEvent.isDriver());
                final RunProfile runProfile = forkEnv.getRunProfile();
                if (!(runProfile instanceof LivySparkBatchJobRunConfiguration)) {
                    ctrlSubject.onError(new UnsupportedOperationException("Only supports LivySparkBatchJobRunConfiguration type, but got type" + runProfile.getClass().getCanonicalName()));
                    return;
                }
                // Reuse the driver's Spark batch job
                ((LivySparkBatchJobRunConfiguration) runProfile).setSparkRemoteBatch(sparkDebugBatch);
                final SparkBatchRemoteDebugState forkState = jdbReadyEvent.isDriver() ? submissionState : (SparkBatchRemoteDebugState) forkEnv.getState();
                if (forkState == null) {
                    return;
                }
                // Set the debug connection to localhost and local forwarded port to the state
                forkState.setRemoteConnection(new RemoteConnection(true, "localhost", Integer.toString(localPort), false));
                // Prepare the debug tab console view UI
                SparkJobLogConsoleView jobOutputView = new SparkJobLogConsoleView(project);
                // Get YARN container log URL port
                int containerLogUrlPort = ((SparkBatchRemoteDebugJob) driverDebugProcess.getSparkJob()).getYarnContainerLogUrlPort().toBlocking().single();
                // Parse container ID and host URL from driver console view
                jobOutputView.getSecondaryConsoleView().addMessageFilter((line, entireLength) -> {
                    Matcher matcher = Pattern.compile("Launching container (\\w+).* on host ([a-zA-Z_0-9-.]+)", Pattern.CASE_INSENSITIVE).matcher(line);
                    while (matcher.find()) {
                        String containerId = matcher.group(1);
                        // TODO: get port from somewhere else rather than hard code here
                        URI hostUri = URI.create(String.format("http://%s:%d", matcher.group(2), containerLogUrlPort));
                        debugEventSubject.onNext(new SparkBatchJobExecutorCreatedEvent(hostUri, containerId));
                    }
                    return null;
                });
                jobOutputView.attachToProcess(handlerReadyEvent.getDebugProcessHandler());
                ExecutionResult result = new DefaultExecutionResult(jobOutputView, handlerReadyEvent.getDebugProcessHandler());
                forkState.setExecutionResult(result);
                forkState.setConsoleView(jobOutputView.getSecondaryConsoleView());
                forkState.setRemoteProcessCtrlLogHandler(handlerReadyEvent.getDebugProcessHandler());
                if (jdbReadyEvent.isDriver()) {
                    // Let the debug console view to handle the control log
                    jobSubscription.unsubscribe();
                    // Resolve job driver promise, handle the driver VM attaching separately
                    jobDriverEnvReady.setResult(forkEnv);
                } else {
                    // Start Executor debugging
                    executionManager.startRunProfile(forkEnv, () -> toIdeaPromise(attachAndDebug(forkEnv, forkState)));
                }
            } else if (debugEvent instanceof SparkBatchJobExecutorCreatedEvent) {
                SparkBatchJobExecutorCreatedEvent executorCreatedEvent = (SparkBatchJobExecutorCreatedEvent) debugEvent;
                final String containerId = executorCreatedEvent.getContainerId();
                final SparkBatchRemoteDebugJob debugJob = (SparkBatchRemoteDebugJob) driverDebugProcess.getSparkJob();
                URI internalHostUri = executorCreatedEvent.getHostUri();
                URI executorLogUrl = debugJob.convertToPublicLogUri(internalHostUri).map(uri -> uri.resolve(String.format("node/containerlogs/%s/livy", containerId))).toBlocking().singleOrDefault(internalHostUri);
                // Create an Executor Debug Process
                SparkBatchJobRemoteDebugExecutorProcess executorDebugProcess = new SparkBatchJobRemoteDebugExecutorProcess(schedulers, debugJob, internalHostUri.getHost(), driverDebugProcess.getDebugSession(), executorLogUrl.toString());
                SparkBatchJobDebugProcessHandler executorDebugHandler = new SparkBatchJobDebugProcessHandler(project, executorDebugProcess, debugEventSubject);
                executorDebugHandler.getRemoteDebugProcess().start();
            }
        } catch (final ExecutionException e) {
            EventUtil.logErrorClassNameOnlyWithComplete(operation, ErrorType.systemError, new UncheckedExecutionException(e), null, null);
            throw new UncheckedExecutionException(e);
        }
    });
    driverDebugHandler.getRemoteDebugProcess().start();
    // Driver side execute, leverage Intellij Async Promise, to wait for the Spark app deployed
    executionManager.startRunProfile(environment, () -> jobDriverEnvReady.thenAsync(driverEnv -> toIdeaPromise(attachAndDebug(driverEnv, state))));
}
Also used : ModalityState.any(com.intellij.openapi.application.ModalityState.any) ExecutionManager(com.intellij.execution.ExecutionManager) ModalityState(com.intellij.openapi.application.ModalityState) SparkJobLogConsoleView(com.microsoft.azure.hdinsight.spark.ui.SparkJobLogConsoleView) com.intellij.execution.configurations(com.intellij.execution.configurations) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Matcher(java.util.regex.Matcher) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) ClusterManagerEx(com.microsoft.azure.hdinsight.common.ClusterManagerEx) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) ExecutionResult(com.intellij.execution.ExecutionResult) URI(java.net.URI) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable) ImmutableMap(com.google.common.collect.ImmutableMap) WindowManager(com.intellij.openapi.wm.WindowManager) ErrorType(com.microsoft.azuretools.telemetrywrapper.ErrorType) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) GenericDebuggerRunnerSettings(com.intellij.debugger.impl.GenericDebuggerRunnerSettings) RxJavaExtKt.toIdeaPromise(com.microsoft.intellij.rxjava.RxJavaExtKt.toIdeaPromise) Optional(java.util.Optional) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) Pattern(java.util.regex.Pattern) Subscription(rx.Subscription) PublishSubject(rx.subjects.PublishSubject) com.microsoft.azure.hdinsight.spark.common(com.microsoft.azure.hdinsight.spark.common) GenericDebuggerRunner(com.intellij.debugger.impl.GenericDebuggerRunner) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) AsyncPromise(org.jetbrains.concurrency.AsyncPromise) TelemetryKeys(com.microsoft.intellij.telemetry.TelemetryKeys) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull) ExecutionException(com.intellij.execution.ExecutionException) LivyCluster(com.microsoft.azure.hdinsight.sdk.cluster.LivyCluster) IdeaSchedulers(com.microsoft.intellij.rxjava.IdeaSchedulers) Observable(rx.Observable) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) SparkBatchSubmission.getClusterSubmission(com.microsoft.azure.hdinsight.spark.common.SparkBatchSubmission.getClusterSubmission) Project(com.intellij.openapi.project.Project) LivySparkBatchJobRunConfiguration(com.microsoft.azure.hdinsight.spark.run.configuration.LivySparkBatchJobRunConfiguration) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) Key(com.intellij.openapi.util.Key) IOException(java.io.IOException) ProcessHandler(com.intellij.execution.process.ProcessHandler) ModalityState.stateForComponent(com.intellij.openapi.application.ModalityState.stateForComponent) SparkLogLine(com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine) SparkSubmissionAdvancedConfigPanel(com.microsoft.azure.hdinsight.spark.ui.SparkSubmissionAdvancedConfigPanel) javax.swing(javax.swing) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) Matcher(java.util.regex.Matcher) IdeaSchedulers(com.microsoft.intellij.rxjava.IdeaSchedulers) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AsyncPromise(org.jetbrains.concurrency.AsyncPromise) LivySparkBatchJobRunConfiguration(com.microsoft.azure.hdinsight.spark.run.configuration.LivySparkBatchJobRunConfiguration) URI(java.net.URI) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) PublishSubject(rx.subjects.PublishSubject) ExecutionException(com.intellij.execution.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Subscription(rx.Subscription) SparkJobLogConsoleView(com.microsoft.azure.hdinsight.spark.ui.SparkJobLogConsoleView) ExecutionManager(com.intellij.execution.ExecutionManager) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionResult(com.intellij.execution.ExecutionResult) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) ExecutionException(com.intellij.execution.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) SparkLogLine(com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine)

Example 9 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class AzureRunProfileState method execute.

@Nullable
@Override
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner programRunner) throws ExecutionException {
    final RunProcessHandler processHandler = new RunProcessHandler();
    processHandler.addDefaultListener();
    ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(this.project).getConsole();
    processHandler.startNotify();
    consoleView.attachToProcess(processHandler);
    final Operation operation = createOperation();
    final Disposable subscribe = Mono.fromCallable(() -> {
        try {
            operation.start();
            return this.executeSteps(processHandler, operation);
        } finally {
            // Once the operation done, whether success or not, `setText` should not throw new exception
            processHandler.setProcessTerminatedHandler(RunProcessHandler.DO_NOTHING);
        }
    }).subscribeOn(Schedulers.boundedElastic()).subscribe((res) -> {
        this.sendTelemetry(operation, null);
        this.onSuccess(res, processHandler);
    }, (err) -> {
        err.printStackTrace();
        this.sendTelemetry(operation, err);
        this.onFail(err, processHandler);
    });
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(@NotNull ProcessEvent event) {
            subscribe.dispose();
        }
    });
    return new DefaultExecutionResult(consoleView, processHandler);
}
Also used : Disposable(reactor.core.Disposable) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) ConsoleView(com.intellij.execution.ui.ConsoleView) ProcessEvent(com.intellij.execution.process.ProcessEvent) RunProcessHandler(com.microsoft.intellij.RunProcessHandler) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class SparkBatchJobRunner method doExecute.

@Nullable
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    final SparkBatchRemoteRunProfileState submissionState = (SparkBatchRemoteRunProfileState) state;
    final SparkSubmitModel submitModel = submissionState.getSubmitModel();
    final Project project = submitModel.getProject();
    // Prepare the run table console view UI
    final SparkJobLogConsoleView jobOutputView = new SparkJobLogConsoleView(project);
    final String artifactPath = submitModel.getArtifactPath().orElse(null);
    assert artifactPath != null : "artifactPath should be checked in LivySparkBatchJobRunConfiguration::checkSubmissionConfigurationBeforeRun";
    // To address issue https://github.com/microsoft/azure-tools-for-java/issues/4021.
    // In this issue, when user click rerun button, we are still using the legacy ctrlSubject which has already sent
    // "onComplete" message when the job is done in the previous time. To avoid this issue,  We clone a new Spark
    // batch job instance to re-initialize everything in the object.
    final ISparkBatchJob sparkBatch = submissionState.getSparkBatch().clone();
    final PublishSubject<SparkLogLine> ctrlSubject = (PublishSubject<SparkLogLine>) sparkBatch.getCtrlSubject();
    final SparkBatchJobRemoteProcess remoteProcess = new SparkBatchJobRemoteProcess(new IdeaSchedulers(project), sparkBatch, artifactPath, submitModel.getSubmissionParameter().getMainClassName(), ctrlSubject);
    final SparkBatchJobRunProcessHandler processHandler = new SparkBatchJobRunProcessHandler(remoteProcess, "Package and deploy the job to Spark cluster", null);
    // After attaching, the console view can read the process inputStreams and display them
    jobOutputView.attachToProcess(processHandler);
    remoteProcess.start();
    final Operation operation = environment.getUserData(TelemetryKeys.OPERATION);
    // After we define a new AnAction class, IntelliJ will construct a new AnAction instance for us.
    // Use one action instance can keep behaviours like isEnabled() consistent
    final SparkBatchJobDisconnectAction disconnectAction = (SparkBatchJobDisconnectAction) ActionManager.getInstance().getAction("Actions.SparkJobDisconnect");
    disconnectAction.init(remoteProcess, operation);
    sendTelemetryForParameters(submitModel, operation);
    final ExecutionResult result = new DefaultExecutionResult(jobOutputView, processHandler, Separator.getInstance(), disconnectAction);
    submissionState.setExecutionResult(result);
    final ConsoleView consoleView = jobOutputView.getSecondaryConsoleView();
    submissionState.setConsoleView(consoleView);
    addConsoleViewFilter(remoteProcess.getSparkJob(), consoleView);
    submissionState.setRemoteProcessCtrlLogHandler(processHandler);
    ctrlSubject.subscribe(messageWithType -> {
    }, err -> disconnectAction.setEnabled(false), () -> disconnectAction.setEnabled(false));
    return super.doExecute(state, environment);
}
Also used : DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) SparkJobLogConsoleView(com.microsoft.azure.hdinsight.spark.ui.SparkJobLogConsoleView) ConsoleView(com.intellij.execution.ui.ConsoleView) IdeaSchedulers(com.microsoft.intellij.rxjava.IdeaSchedulers) ExecutionResult(com.intellij.execution.ExecutionResult) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) Project(com.intellij.openapi.project.Project) SparkBatchJobDisconnectAction(com.microsoft.azure.hdinsight.spark.run.action.SparkBatchJobDisconnectAction) PublishSubject(rx.subjects.PublishSubject) SparkJobLogConsoleView(com.microsoft.azure.hdinsight.spark.ui.SparkJobLogConsoleView) SparkLogLine(com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable)

Aggregations

Operation (com.microsoft.azuretools.telemetrywrapper.Operation)29 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)9 IOException (java.io.IOException)8 File (java.io.File)7 HashMap (java.util.HashMap)7 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)6 EventUtil (com.microsoft.azuretools.telemetrywrapper.EventUtil)6 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)5 TelemetryConstants (com.microsoft.azuretools.telemetry.TelemetryConstants)5 ErrorType (com.microsoft.azuretools.telemetrywrapper.ErrorType)5 Map (java.util.Map)5 Project (com.intellij.openapi.project.Project)4 MsalClientException (com.microsoft.aad.msal4j.MsalClientException)4 TelemetryManager (com.microsoft.azuretools.telemetrywrapper.TelemetryManager)4 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)4 Path (java.nio.file.Path)4 CancellationException (java.util.concurrent.CancellationException)4 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)3