Search in sources :

Example 1 with SparkBatchJobDisconnectAction

use of com.microsoft.azure.hdinsight.spark.run.action.SparkBatchJobDisconnectAction 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

DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 Project (com.intellij.openapi.project.Project)1 SparkLogLine (com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine)1 SparkBatchJobDisconnectAction (com.microsoft.azure.hdinsight.spark.run.action.SparkBatchJobDisconnectAction)1 SparkJobLogConsoleView (com.microsoft.azure.hdinsight.spark.ui.SparkJobLogConsoleView)1 Nullable (com.microsoft.azuretools.azurecommons.helpers.Nullable)1 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)1 IdeaSchedulers (com.microsoft.intellij.rxjava.IdeaSchedulers)1 PublishSubject (rx.subjects.PublishSubject)1