Search in sources :

Example 1 with SparkSubmissionToolWindowView

use of com.microsoft.azuretools.hdinsight.SparkSubmissionToolWindowView in project azure-tools-for-java by Microsoft.

the class SparkSubmitModel method tryToCreateBatchSparkJob.

private void tryToCreateBatchSparkJob(@NotNull final IClusterDetail selectedClusterDetail) throws HDIException, IOException {
    SparkBatchSubmission.getInstance().setCredentialsProvider(selectedClusterDetail.getHttpUserName(), selectedClusterDetail.getHttpPassword());
    HttpResponse response = SparkBatchSubmission.getInstance().createBatchSparkJob(SparkSubmitHelper.getLivyConnectionURL(selectedClusterDetail), submissionParameter);
    if (response.getCode() == 201 || response.getCode() == 200) {
        HDInsightUtil.showInfoOnSubmissionMessageWindow("Info : Submit to spark cluster successfully.");
        postEventProperty.put("IsSubmitSucceed", "true");
        String jobLink = String.format("%s/sparkhistory", selectedClusterDetail.getConnectionUrl());
        HDInsightUtil.setHyperLinkWithText("See spark job view from ", jobLink, jobLink);
        @SuppressWarnings("serial") final SparkSubmitResponse sparkSubmitResponse = new Gson().fromJson(response.getMessage(), new TypeToken<SparkSubmitResponse>() {
        }.getType());
        // Set submitted spark application id and http request info for stopping running application
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                SparkSubmissionToolWindowView view = HDInsightUtil.getSparkSubmissionToolWindowView();
                view.setSparkApplicationStopInfo(selectedClusterDetail.getConnectionUrl(), sparkSubmitResponse.getId());
                view.setStopButtonState(true);
                view.getJobStatusManager().resetJobStateManager();
            }
        });
        SparkSubmitHelper.getInstance().printRunningLogStreamingly(sparkSubmitResponse.getId(), selectedClusterDetail, postEventProperty);
    } else {
        HDInsightUtil.showErrorMessageOnSubmissionMessageWindow(String.format("Error : Failed to submit to spark cluster. error code : %d, reason :  %s.", response.getCode(), response.getContent()));
        postEventProperty.put("IsSubmitSucceed", "false");
        postEventProperty.put("SubmitFailedReason", response.getContent());
        AppInsightsClient.create(Messages.SparkSubmissionButtonClickEvent, null, postEventProperty);
    }
}
Also used : SparkSubmitResponse(com.microsoft.azure.hdinsight.spark.common.SparkSubmitResponse) TypeToken(com.google.common.reflect.TypeToken) HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse) Gson(com.google.gson.Gson) SparkSubmissionToolWindowView(com.microsoft.azuretools.hdinsight.SparkSubmissionToolWindowView)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)1 Gson (com.google.gson.Gson)1 HttpResponse (com.microsoft.azure.hdinsight.sdk.common.HttpResponse)1 SparkSubmitResponse (com.microsoft.azure.hdinsight.spark.common.SparkSubmitResponse)1 SparkSubmissionToolWindowView (com.microsoft.azuretools.hdinsight.SparkSubmissionToolWindowView)1