Search in sources :

Example 1 with HttpResponse

use of com.microsoft.azure.hdinsight.sdk.common.HttpResponse in project azure-tools-for-java by Microsoft.

the class SparkSubmitHelper method printoutJobLog.

private int printoutJobLog(Project project, int id, int from_index, IClusterDetail clusterDetail) throws IOException {
    HttpResponse httpResponse = SparkBatchSubmission.getInstance().getBatchJobFullLog(getLivyConnectionURL(clusterDetail), id);
    sparkJobLog = new Gson().fromJson(httpResponse.getMessage(), new TypeToken<SparkJobLog>() {
    }.getType());
    if (!HDInsightUtil.getSparkSubmissionToolWindowManager(project).getJobStatusManager().isApplicationGenerated()) {
        String sparkLogs = Joiner.on("").join(sparkJobLog.getLog());
        String applicationId = getApplicationIdFromYarnLog(sparkLogs);
        if (applicationId != null) {
            HDInsightUtil.getSparkSubmissionToolWindowManager(project).setBrowserButtonState(true);
            HDInsightUtil.getSparkSubmissionToolWindowManager(project).getJobStatusManager().setApplicationIdGenerated();
            HDInsightUtil.getSparkSubmissionToolWindowManager(project).getJobStatusManager().setApplicationId(applicationId);
        }
    }
    int counter = 0;
    if (sparkJobLog.getLog().size() > 0) {
        for (String line : sparkJobLog.getLog()) {
            if (counter >= from_index && !StringHelper.isNullOrWhiteSpace(line)) {
                HDInsightUtil.getSparkSubmissionToolWindowManager(project).setInfo(line, true);
            }
            counter++;
        }
    }
    return sparkJobLog.getTotal();
}
Also used : HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse) Gson(com.google.gson.Gson)

Example 2 with HttpResponse

use of com.microsoft.azure.hdinsight.sdk.common.HttpResponse 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(project, "Info : Submit to spark cluster successfully.");
        postEventProperty.put("IsSubmitSucceed", "true");
        String jobLink = selectedClusterDetail.isEmulator() ? ((EmulatorClusterDetail) selectedClusterDetail).getSparkHistoryEndpoint() : String.format("%s/sparkhistory", selectedClusterDetail.getConnectionUrl());
        HDInsightUtil.getSparkSubmissionToolWindowManager(project).setHyperLinkWithText("See spark job view from ", jobLink, jobLink);
        SparkSubmitResponse sparkSubmitResponse = new Gson().fromJson(response.getMessage(), new TypeToken<SparkSubmitResponse>() {
        }.getType());
        // Set submitted spark application id and http request info for stopping running application
        HDInsightUtil.getSparkSubmissionToolWindowManager(project).setSparkApplicationStopInfo(selectedClusterDetail, sparkSubmitResponse.getId());
        HDInsightUtil.getSparkSubmissionToolWindowManager(project).setStopButtonState(true);
        HDInsightUtil.getSparkSubmissionToolWindowManager(project).getJobStatusManager().resetJobStateManager();
        SparkSubmitHelper.getInstance().printRunningLogStreamingly(project, sparkSubmitResponse.getId(), selectedClusterDetail, postEventProperty);
    } else {
        HDInsightUtil.showErrorMessageOnSubmissionMessageWindow(project, 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(HDInsightBundle.message("SparkSubmissionButtonClickEvent"), null, postEventProperty);
    }
}
Also used : TypeToken(com.google.common.reflect.TypeToken) HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse) Gson(com.google.gson.Gson)

Example 3 with HttpResponse

use of com.microsoft.azure.hdinsight.sdk.common.HttpResponse in project azure-tools-for-java by Microsoft.

the class SparkSubmitHelper method printoutJobLog.

private int printoutJobLog(/*Project project,*/
int id, int from_index, IClusterDetail clusterDetail) throws IOException {
    HttpResponse httpResponse = SparkBatchSubmission.getInstance().getBatchJobFullLog(clusterDetail.getConnectionUrl() + "/livy/batches", id);
    sparkJobLog = new Gson().fromJson(httpResponse.getMessage(), new TypeToken<SparkJobLog>() {
    }.getType());
    if (!HDInsightUtil.getSparkSubmissionToolWindowView().getJobStatusManager().isApplicationGenerated()) {
        String sparkLogs = Joiner.on("").join(sparkJobLog.getLog());
        String applicationId = getApplicationIdFromYarnLog(sparkLogs);
        if (applicationId != null) {
            HDInsightUtil.getSparkSubmissionToolWindowView().setBrowserButtonState(true);
            HDInsightUtil.getSparkSubmissionToolWindowView().getJobStatusManager().setApplicationIdGenerated();
            HDInsightUtil.getSparkSubmissionToolWindowView().getJobStatusManager().setApplicationId(applicationId);
        }
    }
    int counter = 0;
    if (sparkJobLog.getLog().size() > 0) {
        for (String line : sparkJobLog.getLog()) {
            if (counter >= from_index && !StringHelper.isNullOrWhiteSpace(line)) {
                HDInsightUtil.getSparkSubmissionToolWindowView().setInfo(line, true);
            }
            counter++;
        }
    }
    return sparkJobLog.getTotal();
}
Also used : SparkJobLog(com.microsoft.azure.hdinsight.spark.common.SparkJobLog) HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse) Gson(com.google.gson.Gson)

Example 4 with HttpResponse

use of com.microsoft.azure.hdinsight.sdk.common.HttpResponse in project azure-tools-for-java by Microsoft.

the class AddNewEmulatorForm method checkAmbariEndpoint.

private boolean checkAmbariEndpoint() {
    SparkBatchSubmission.getInstance().setCredentialsProvider("admin", "admin");
    HttpResponse httpResponse = null;
    try {
        httpResponse = SparkBatchSubmission.getInstance().getHttpResponseViaGet(ambariEndpoint);
    } catch (Exception e) {
        return false;
    }
    return httpResponse.getCode() == 201 || httpResponse.getCode() == 200;
}
Also used : HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse)

Example 5 with HttpResponse

use of com.microsoft.azure.hdinsight.sdk.common.HttpResponse in project azure-tools-for-java by Microsoft.

the class AddNewEmulatorForm method checkLivyEndpoint.

private boolean checkLivyEndpoint() {
    SparkBatchSubmission.getInstance().setCredentialsProvider(userName, password);
    HttpResponse httpResponse = null;
    try {
        httpResponse = SparkBatchSubmission.getInstance().getAllBatchesSparkJobs(livyEndpoint + "/batches");
    } catch (Exception e) {
        return false;
    }
    return httpResponse.getCode() == 201 || httpResponse.getCode() == 200;
}
Also used : HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse)

Aggregations

HttpResponse (com.microsoft.azure.hdinsight.sdk.common.HttpResponse)16 Gson (com.google.gson.Gson)6 TypeToken (com.google.common.reflect.TypeToken)4 IOException (java.io.IOException)3 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)2 SparkSubmitResponse (com.microsoft.azure.hdinsight.spark.common.SparkSubmitResponse)2 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 PropertyChangeSupport (java.beans.PropertyChangeSupport)2 UISettings (com.intellij.ide.ui.UISettings)1 UISettingsListener (com.intellij.ide.ui.UISettingsListener)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 JSchException (com.jcraft.jsch.JSchException)1 SftpException (com.jcraft.jsch.SftpException)1 SparkJobLog (com.microsoft.azure.hdinsight.spark.common.SparkJobLog)1 SparkSubmissionToolWindowView (com.microsoft.azuretools.hdinsight.SparkSubmissionToolWindowView)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1