Search in sources :

Example 1 with JobRequestDetails

use of com.microsoft.azure.hdinsight.spark.jobs.framework.JobRequestDetails in project azure-tools-for-java by Microsoft.

the class YarnJobHttpHandler method handle.

@Override
public void handle(HttpExchange httpExchange) throws IOException {
    httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
    JobRequestDetails requestDetail = JobRequestDetails.getJobRequestDetail(httpExchange);
    String path = requestDetail.getRequestPath();
    try {
        if (path.contains("/apps/app") && requestDetail.isSpecificApp()) {
            App app = JobViewCacheManager.getYarnApp(new ApplicationKey(requestDetail.getCluster(), requestDetail.getAppId()));
            Optional<String> responseString = ObjectConvertUtils.convertObjectToJsonString(app);
            JobUtils.setResponse(httpExchange, responseString.orElseThrow(IOException::new));
        } else if (path.contains("/apps/logs") && requestDetail.isSpecificApp()) {
            ApplicationMasterLogs logs = JobViewCacheManager.getYarnLogs(new ApplicationKey(requestDetail.getCluster(), requestDetail.getAppId()));
            Optional<String> responseString = ObjectConvertUtils.convertObjectToJsonString(logs);
            JobUtils.setResponse(httpExchange, responseString.orElseThrow(IOException::new));
        }
    } catch (ExecutionException e) {
        JobUtils.setResponse(httpExchange, e.getMessage(), 500);
    }
}
Also used : App(com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.App) Optional(java.util.Optional) JobRequestDetails(com.microsoft.azure.hdinsight.spark.jobs.framework.JobRequestDetails) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ApplicationMasterLogs(com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.ApplicationMasterLogs)

Example 2 with JobRequestDetails

use of com.microsoft.azure.hdinsight.spark.jobs.framework.JobRequestDetails in project azure-tools-for-java by Microsoft.

the class SparkJobHttpHandler method handle.

@Override
public void handle(HttpExchange httpExchange) throws IOException {
    httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
    JobRequestDetails requestDetail = JobRequestDetails.getJobRequestDetail(httpExchange);
    try {
        String path = requestDetail.getRequestPath();
        if (path.equalsIgnoreCase("/applications/") && requestDetail.getAppId().equalsIgnoreCase("0")) {
            try {
                List<Application> applications = SparkRestUtil.getSparkApplications(requestDetail.getCluster());
                Optional<String> responseString = ObjectConvertUtils.convertObjectToJsonString(applications);
                JobUtils.setResponse(httpExchange, responseString.orElseThrow(IOException::new));
            } catch (HDIException e) {
                DefaultLoader.getUIHelper().logError("get applications list error", e);
            }
        } else if (path.contains("application_graph")) {
            ApplicationKey key = new ApplicationKey(requestDetail.getCluster(), requestDetail.getAppId());
            List<Job> jobs = JobViewCacheManager.getJob(key);
            App app = JobViewCacheManager.getYarnApp(key);
            List<JobStartEventLog> jobStartEventLogs = JobViewCacheManager.getJobStartEventLogs(key);
            YarnAppWithJobs yarnAppWithJobs = new YarnAppWithJobs(app, jobs, jobStartEventLogs);
            Optional<String> responseString = ObjectConvertUtils.convertObjectToJsonString(yarnAppWithJobs);
            JobUtils.setResponse(httpExchange, responseString.orElseThrow(IOException::new));
        } else if (path.contains("stages_summary")) {
            List<Stage> stages = JobViewCacheManager.getStages(new ApplicationKey(requestDetail.getCluster(), requestDetail.getAppId()));
            Optional<String> responseString = ObjectConvertUtils.convertObjectToJsonString(stages);
            JobUtils.setResponse(httpExchange, responseString.orElseThrow(IOException::new));
        } else if (path.contains("executors_summary")) {
            List<Executor> executors = JobViewCacheManager.getExecutors(new ApplicationKey(requestDetail.getCluster(), requestDetail.getAppId()));
            Optional<String> responseString = ObjectConvertUtils.convertObjectToJsonString(executors);
            JobUtils.setResponse(httpExchange, responseString.orElseThrow(IOException::new));
        } else if (path.contains("tasks_summary")) {
            List<Task> tasks = JobViewCacheManager.getTasks(new ApplicationKey(requestDetail.getCluster(), requestDetail.getAppId()));
            Optional<String> responseString = ObjectConvertUtils.convertObjectToJsonString(tasks);
            JobUtils.setResponse(httpExchange, responseString.orElseThrow(IOException::new));
        }
    } catch (ExecutionException e) {
        JobUtils.setResponse(httpExchange, e.getMessage(), 500);
    }
}
Also used : App(com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.App) Task(com.microsoft.azure.hdinsight.sdk.rest.spark.task.Task) Optional(java.util.Optional) JobRequestDetails(com.microsoft.azure.hdinsight.spark.jobs.framework.JobRequestDetails) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) IOException(java.io.IOException) Stage(com.microsoft.azure.hdinsight.sdk.rest.spark.stage.Stage) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Application(com.microsoft.azure.hdinsight.sdk.rest.spark.Application) YarnAppWithJobs(com.microsoft.azure.hdinsight.sdk.rest.spark.YarnAppWithJobs)

Example 3 with JobRequestDetails

use of com.microsoft.azure.hdinsight.spark.jobs.framework.JobRequestDetails in project azure-tools-for-java by Microsoft.

the class ActionHttpHandler method handle.

@Override
public void handle(HttpExchange httpExchange) throws IOException {
    httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
    JobRequestDetails requestDetail = JobRequestDetails.getJobRequestDetail(httpExchange);
    final String path = requestDetail.getRequestPath();
    final String clusterConnectString = requestDetail.getCluster().getConnectionUrl();
    if (path.contains("yarnui")) {
        JobUtils.openYarnUIHistory(clusterConnectString, requestDetail.getAppId());
    } else if (path.contains("sparkui")) {
        try {
            Application application = JobViewCacheManager.getSingleSparkApplication(new ApplicationKey(requestDetail.getCluster(), requestDetail.getAppId()));
            JobUtils.openSparkUIHistory(clusterConnectString, requestDetail.getAppId(), application.getLastAttemptId());
            JobUtils.setResponse(httpExchange, "open browser successfully");
        } catch (ExecutionException e) {
            JobUtils.setResponse(httpExchange, "open browser error", 500);
            DefaultLoader.getUIHelper().showError(e.getMessage(), "open browser error");
        }
    }
}
Also used : JobRequestDetails(com.microsoft.azure.hdinsight.spark.jobs.framework.JobRequestDetails) ExecutionException(java.util.concurrent.ExecutionException) Application(com.microsoft.azure.hdinsight.sdk.rest.spark.Application)

Aggregations

JobRequestDetails (com.microsoft.azure.hdinsight.spark.jobs.framework.JobRequestDetails)3 ExecutionException (java.util.concurrent.ExecutionException)3 Application (com.microsoft.azure.hdinsight.sdk.rest.spark.Application)2 App (com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.App)2 IOException (java.io.IOException)2 Optional (java.util.Optional)2 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 YarnAppWithJobs (com.microsoft.azure.hdinsight.sdk.rest.spark.YarnAppWithJobs)1 Stage (com.microsoft.azure.hdinsight.sdk.rest.spark.stage.Stage)1 Task (com.microsoft.azure.hdinsight.sdk.rest.spark.task.Task)1 ApplicationMasterLogs (com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.ApplicationMasterLogs)1 List (java.util.List)1