Search in sources :

Example 1 with RunProfileState

use of com.intellij.execution.configurations.RunProfileState in project azure-tools-for-java by Microsoft.

the class SparkBatchJobDebuggerRunner method execute.

@Override
protected void execute(@NotNull ExecutionEnvironment environment, @Nullable Callback callback, @NotNull RunProfileState state) throws ExecutionException {
    SparkBatchJobSubmissionState submissionState = (SparkBatchJobSubmissionState) state;
    SparkSubmitModel submitModel = submissionState.getSubmitModel();
    SparkSubmissionParameter submissionParameter = submitModel.getSubmissionParameter();
    IClusterDetail clusterDetail = submitModel.getSelectedClusterDetail();
    Map<String, String> postEventProperty = new HashMap<>();
    submitModel.buildArtifactObservable(submissionParameter.getArtifactName()).flatMap((artifact) -> submitModel.deployArtifactObservable(artifact, clusterDetail).subscribeOn(Schedulers.io())).map((selectedClusterDetail) -> {
        // Create Batch Spark Debug Job
        try {
            return submitModel.tryToCreateBatchSparkDebugJob(selectedClusterDetail);
        } catch (Exception e) {
            HDInsightUtil.setJobRunningStatus(submitModel.getProject(), false);
            throw Exceptions.propagate(e);
        }
    }).flatMap((remoteDebugJob) -> startDebuggerObservable(environment, callback, submissionState, remoteDebugJob).subscribeOn(Schedulers.computation()).zipWith(submitModel.jobLogObservable(remoteDebugJob.getBatchId(), clusterDetail).subscribeOn(Schedulers.computation()), (session, ignore) -> session).doOnError(err -> {
        try {
            HDInsightUtil.showErrorMessageOnSubmissionMessageWindow(submitModel.getProject(), "Error : Spark batch debugging job is killed, got exception " + err);
            remoteDebugJob.killBatchJob();
            HDInsightUtil.setJobRunningStatus(submitModel.getProject(), false);
        } catch (IOException ignore) {
        }
    })).subscribe(sparkBatchDebugSession -> {
        HDInsightUtil.showInfoOnSubmissionMessageWindow(submitModel.getProject(), "Info : Debugging Spark batch job in cluster is done.");
        sparkBatchDebugSession.close();
        HDInsightUtil.setJobRunningStatus(submitModel.getProject(), false);
        postEventProperty.put("IsSubmitSucceed", "true");
        AppInsightsClient.create(HDInsightBundle.message("SparkRunConfigDebugButtonClick"), null, postEventProperty);
    }, (throwable) -> {
        // set the running flag to false
        HDInsightUtil.setJobRunningStatus(submitModel.getProject(), false);
        String errorMessage;
        if (throwable instanceof CompositeException) {
            CompositeException exceptions = (CompositeException) throwable;
            errorMessage = exceptions.getExceptions().stream().map(Throwable::getMessage).collect(Collectors.joining("; "));
        } else {
            errorMessage = throwable.getMessage();
        }
        HDInsightUtil.showErrorMessageOnSubmissionMessageWindow(submitModel.getProject(), "Error : Spark batch Job remote debug failed, got exception: " + errorMessage);
        postEventProperty.put("IsSubmitSucceed", "false");
        postEventProperty.put("SubmitFailedReason", errorMessage.substring(0, 50));
        AppInsightsClient.create(HDInsightBundle.message("SparkRunConfigDebugButtonClick"), null, postEventProperty);
    });
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) ExecutionException(com.intellij.execution.ExecutionException) Exceptions(rx.exceptions.Exceptions) URISyntaxException(java.net.URISyntaxException) HDInsightUtil(com.microsoft.azure.hdinsight.common.HDInsightUtil) RemoteDebugRunConfiguration(com.microsoft.azure.hdinsight.spark.run.configuration.RemoteDebugRunConfiguration) HashMap(java.util.HashMap) RunProfileState(com.intellij.execution.configurations.RunProfileState) Single(rx.Single) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Map(java.util.Map) HDInsightBundle(com.microsoft.intellij.hdinsight.messages.HDInsightBundle) Schedulers(rx.schedulers.Schedulers) URI(java.net.URI) SimpleEntry(java.util.AbstractMap.SimpleEntry) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) ConfigurationInfoProvider(com.intellij.execution.configurations.ConfigurationInfoProvider) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) RunProfile(com.intellij.execution.configurations.RunProfile) IOException(java.io.IOException) Executor(com.intellij.execution.Executor) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GenericDebuggerRunnerSettings(com.intellij.debugger.impl.GenericDebuggerRunnerSettings) AppInsightsClient(com.microsoft.azuretools.telemetry.AppInsightsClient) CompositeException(rx.exceptions.CompositeException) JSchException(com.jcraft.jsch.JSchException) NotNull(org.jetbrains.annotations.NotNull) com.microsoft.azure.hdinsight.spark.common(com.microsoft.azure.hdinsight.spark.common) GenericDebuggerRunner(com.intellij.debugger.impl.GenericDebuggerRunner) HashMap(java.util.HashMap) CompositeException(rx.exceptions.CompositeException) IOException(java.io.IOException) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) ExecutionException(com.intellij.execution.ExecutionException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CompositeException(rx.exceptions.CompositeException) JSchException(com.jcraft.jsch.JSchException)

Example 2 with RunProfileState

use of com.intellij.execution.configurations.RunProfileState in project intellij-community by JetBrains.

the class RerunFailedActionsTestTools method findRestartActionState.

/**
   * Searches for "rerun failed tests" action and fetches state from it
   *
   * @param descriptor previous run descriptor
   * @return state (if found)
   */
@Nullable
public static RunProfileState findRestartActionState(@NotNull final RunContentDescriptor descriptor) {
    final ExecutionEnvironment action = findRestartAction(descriptor);
    if (action == null) {
        return null;
    }
    final Ref<RunProfileState> stateRef = new Ref<>();
    ApplicationManager.getApplication().invokeAndWait(() -> {
        try {
            stateRef.set(action.getState());
        } catch (final ExecutionException e) {
            throw new IllegalStateException("Error obtaining execution state", e);
        }
    }, ModalityState.NON_MODAL);
    return stateRef.get();
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Ref(com.intellij.openapi.util.Ref) RunProfileState(com.intellij.execution.configurations.RunProfileState) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with RunProfileState

use of com.intellij.execution.configurations.RunProfileState in project intellij-community by JetBrains.

the class ExecutionManagerImpl method startRunProfile.

@Override
public void startRunProfile(@NotNull final RunProfileStarter starter, @NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) {
    final Project project = environment.getProject();
    RunContentDescriptor reuseContent = getContentManager().getReuseContent(environment);
    if (reuseContent != null) {
        reuseContent.setExecutionId(environment.getExecutionId());
        environment.setContentToReuse(reuseContent);
    }
    final Executor executor = environment.getExecutor();
    project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processStartScheduled(executor.getId(), environment);
    Runnable startRunnable;
    startRunnable = () -> {
        if (project.isDisposed()) {
            return;
        }
        RunProfile profile = environment.getRunProfile();
        project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processStarting(executor.getId(), environment);
        starter.executeAsync(state, environment).done(descriptor -> {
            AppUIUtil.invokeOnEdt(() -> {
                if (descriptor != null) {
                    final Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor> trinity = Trinity.create(descriptor, environment.getRunnerAndConfigurationSettings(), executor);
                    myRunningConfigurations.add(trinity);
                    Disposer.register(descriptor, () -> myRunningConfigurations.remove(trinity));
                    getContentManager().showRunContent(executor, descriptor, environment.getContentToReuse());
                    final ProcessHandler processHandler = descriptor.getProcessHandler();
                    if (processHandler != null) {
                        if (!processHandler.isStartNotified()) {
                            processHandler.startNotify();
                        }
                        project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processStarted(executor.getId(), environment, processHandler);
                        ProcessExecutionListener listener = new ProcessExecutionListener(project, executor.getId(), environment, processHandler, descriptor);
                        processHandler.addProcessListener(listener);
                        boolean terminating = processHandler.isProcessTerminating();
                        boolean terminated = processHandler.isProcessTerminated();
                        if (terminating || terminated) {
                            listener.processWillTerminate(new ProcessEvent(processHandler), false);
                            if (terminated) {
                                int exitCode = processHandler.isStartNotified() ? processHandler.getExitCode() : -1;
                                listener.processTerminated(new ProcessEvent(processHandler, exitCode));
                            }
                        }
                    }
                    environment.setContentToReuse(descriptor);
                } else {
                    project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processNotStarted(executor.getId(), environment);
                }
            }, o -> project.isDisposed());
        }).rejected(e -> {
            if (!(e instanceof ProcessCanceledException)) {
                ExecutionException error = e instanceof ExecutionException ? (ExecutionException) e : new ExecutionException(e);
                ExecutionUtil.handleExecutionError(project, ExecutionManager.getInstance(project).getContentManager().getToolWindowIdByEnvironment(environment), profile, error);
            }
            LOG.info(e);
            project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processNotStarted(executor.getId(), environment);
        });
    };
    if (ApplicationManager.getApplication().isUnitTestMode() && !myForceCompilationInTests) {
        startRunnable.run();
    } else {
        compileAndRun(() -> TransactionGuard.submitTransaction(project, startRunnable), environment, state, () -> {
            if (!project.isDisposed()) {
                project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processNotStarted(executor.getId(), environment);
            }
        });
    }
}
Also used : Trinity(com.intellij.openapi.util.Trinity) ModalityState(com.intellij.openapi.application.ModalityState) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) RunProfileState(com.intellij.execution.configurations.RunProfileState) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) SmartList(com.intellij.util.SmartList) SaveAndSyncHandler(com.intellij.ide.SaveAndSyncHandler) Disposer(com.intellij.openapi.util.Disposer) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) RunnerLayoutUi(com.intellij.execution.ui.RunnerLayoutUi) DumbService(com.intellij.openapi.project.DumbService) AppUIUtil(com.intellij.ui.AppUIUtil) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) Nullable(org.jetbrains.annotations.Nullable) ServiceManager(com.intellij.openapi.components.ServiceManager) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ProcessEvent(com.intellij.execution.process.ProcessEvent) ExecutionUtil(com.intellij.execution.runners.ExecutionUtil) Registry(com.intellij.openapi.util.registry.Registry) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) DataContext(com.intellij.openapi.actionSystem.DataContext) RunContentManager(com.intellij.execution.ui.RunContentManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RunContentManagerImpl(com.intellij.execution.ui.RunContentManagerImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) ProgramRunner(com.intellij.execution.runners.ProgramRunner) StringUtil(com.intellij.openapi.util.text.StringUtil) Key(com.intellij.openapi.util.Key) RunProfile(com.intellij.execution.configurations.RunProfile) Disposable(com.intellij.openapi.Disposable) ProcessHandler(com.intellij.execution.process.ProcessHandler) com.intellij.execution(com.intellij.execution) TestOnly(org.jetbrains.annotations.TestOnly) DockManager(com.intellij.ui.docking.DockManager) CompatibilityAwareRunProfile(com.intellij.execution.configuration.CompatibilityAwareRunProfile) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) TransactionGuard(com.intellij.openapi.application.TransactionGuard) Condition(com.intellij.openapi.util.Condition) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) Project(com.intellij.openapi.project.Project) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) Trinity(com.intellij.openapi.util.Trinity) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessHandler(com.intellij.execution.process.ProcessHandler) RunProfile(com.intellij.execution.configurations.RunProfile) CompatibilityAwareRunProfile(com.intellij.execution.configuration.CompatibilityAwareRunProfile) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 4 with RunProfileState

use of com.intellij.execution.configurations.RunProfileState in project intellij-community by JetBrains.

the class RemoteProcessSupport method startProcess.

private void startProcess(Target target, Parameters configuration, @NotNull Pair<Target, Parameters> key) {
    ProgramRunner runner = new DefaultProgramRunner() {

        @Override
        @NotNull
        public String getRunnerId() {
            return "MyRunner";
        }

        @Override
        public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
            return true;
        }
    };
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    ProcessHandler processHandler;
    try {
        RunProfileState state = getRunProfileState(target, configuration, executor);
        ExecutionResult result = state.execute(executor, runner);
        //noinspection ConstantConditions
        processHandler = result.getProcessHandler();
    } catch (Exception e) {
        dropProcessInfo(key, e instanceof ExecutionException ? e.getMessage() : ExceptionUtil.getUserStackTrace(e, LOG), null);
        return;
    }
    processHandler.addProcessListener(getProcessListener(key));
    processHandler.startNotify();
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) RunProfileState(com.intellij.execution.configurations.RunProfileState) DefaultProgramRunner(com.intellij.execution.runners.DefaultProgramRunner) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) DefaultProgramRunner(com.intellij.execution.runners.DefaultProgramRunner) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull) ExecutionException(com.intellij.execution.ExecutionException)

Example 5 with RunProfileState

use of com.intellij.execution.configurations.RunProfileState in project intellij-plugins by JetBrains.

the class FlexUnitTestRunner method execute.

@Override
public void execute(@NotNull final ExecutionEnvironment env, @Nullable final Callback callback) throws ExecutionException {
    final Project project = env.getProject();
    final RunProfileState state = env.getState();
    if (state == null) {
        return;
    }
    Runnable startRunnable = () -> {
        try {
            if (project.isDisposed())
                return;
            final RunContentDescriptor descriptor = doExecute(state, env);
            if (callback != null)
                callback.processStarted(descriptor);
            if (descriptor != null) {
                ExecutionManager.getInstance(project).getContentManager().showRunContent(env.getExecutor(), descriptor);
                final ProcessHandler processHandler = descriptor.getProcessHandler();
                if (processHandler != null)
                    processHandler.startNotify();
            }
        } catch (ExecutionException e) {
            ExecutionUtil.handleExecutionError(env, e);
        }
    };
    ExecutionManager.getInstance(project).compileAndRun(startRunnable, env, state, null);
}
Also used : Project(com.intellij.openapi.project.Project) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RunProfileState(com.intellij.execution.configurations.RunProfileState) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

RunProfileState (com.intellij.execution.configurations.RunProfileState)5 ExecutionException (com.intellij.execution.ExecutionException)4 RunProfile (com.intellij.execution.configurations.RunProfile)3 ProcessHandler (com.intellij.execution.process.ProcessHandler)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 Executor (com.intellij.execution.Executor)2 ProgramRunner (com.intellij.execution.runners.ProgramRunner)2 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)2 Project (com.intellij.openapi.project.Project)2 CommonBundle (com.intellij.CommonBundle)1 GenericDebuggerRunner (com.intellij.debugger.impl.GenericDebuggerRunner)1 GenericDebuggerRunnerSettings (com.intellij.debugger.impl.GenericDebuggerRunnerSettings)1 com.intellij.execution (com.intellij.execution)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 CompatibilityAwareRunProfile (com.intellij.execution.configuration.CompatibilityAwareRunProfile)1 ConfigurationInfoProvider (com.intellij.execution.configurations.ConfigurationInfoProvider)1 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1