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);
});
}
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();
}
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);
}
});
}
}
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();
}
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);
}
Aggregations