use of com.microsoft.azure.hdinsight.sdk.rest.spark.YarnAppWithJobs 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);
}
}
Aggregations