Search in sources :

Example 21 with IClusterDetail

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

the class JobViewDummyHttpServer method initlize.

public static synchronized void initlize() {
    if (isEnabled) {
        return;
    }
    try {
        server = HttpServer.create(new InetSocketAddress(PORT), 10);
        server.createContext("/clusters/", new HttpHandler() {

            @Override
            public void handle(final HttpExchange httpExchange) throws IOException {
                requestDetail = RequestDetail.getRequestDetail(httpExchange.getRequestURI());
                if (requestDetail == null) {
                    return;
                }
                IClusterDetail clusterDetail = requestDetail.getClusterDetail();
                final String queryUrl = requestDetail.getQueryUrl();
                if (requestDetail.getApiType() == HttpRequestType.YarnHistory) {
                    TaskExecutor.submit(new YarnHistoryTask(clusterDetail, queryUrl, new HttpFutureCallback(httpExchange) {

                        @Override
                        public void onSuccess(String str) {
                            httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                            try {
                                // work around of get job result
                                // TODO: get job result by REST API
                                Document doc = Jsoup.parse(str);
                                Elements contentElements = doc.getElementsByClass("content");
                                if (contentElements.size() == 1) {
                                    Elements elements = contentElements.get(0).getElementsByTag("pre");
                                    if (elements.size() == 1) {
                                        str = elements.get(0).html();
                                    }
                                }
                                httpExchange.sendResponseHeaders(200, str.length());
                                OutputStream stream = httpExchange.getResponseBody();
                                stream.write(str.getBytes());
                                stream.close();
                            } catch (IOException e) {
                                int a = 1;
                            // LOGGER.error("Get job history error", e);
                            }
                        }
                    }));
                } else if (requestDetail.getApiType() == HttpRequestType.LivyBatchesRest) {
                    TaskExecutor.submit(new LivyTask(clusterDetail, queryUrl, new HttpFutureCallback(httpExchange) {

                        @Override
                        public void onSuccess(String str) {
                            httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                            try {
                                String applicationId = requestDetail.getProperty("applicationId");
                                if (applicationId != null) {
                                    str = JobUtils.getJobInformation(str, applicationId);
                                }
                                httpExchange.sendResponseHeaders(200, str.length());
                                OutputStream stream = httpExchange.getResponseBody();
                                stream.write(str.getBytes());
                                stream.close();
                            } catch (IOException e) {
                            // LOGGER.error("Get job history error", e);
                            }
                        }
                    }));
                } else if (requestDetail.getApiType() == HttpRequestType.MultiTask) {
                    TaskExecutor.submit(new MultiRestTask(clusterDetail, requestDetail.getQueryUrls(), new MultiHttpFutureCallback(httpExchange) {

                        public void onSuccess(List<String> strs) {
                            httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                            try {
                                String str = tasksDetailsConvert(strs);
                                httpExchange.sendResponseHeaders(200, str.length());
                                OutputStream stream = httpExchange.getResponseBody();
                                stream.write(str.getBytes());
                                stream.close();
                            } catch (IOException e) {
                            // LOGGER.error("Get job history error", e);
                            }
                        }
                    }));
                } else {
                    TaskExecutor.submit(new RestTask(clusterDetail, queryUrl, new HttpFutureCallback(httpExchange) {

                        @Override
                        public void onSuccess(@NotNull String str) {
                            httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                            try {
                                httpExchange.sendResponseHeaders(200, str.length());
                                OutputStream stream = httpExchange.getResponseBody();
                                stream.write(str.getBytes());
                                stream.close();
                            } catch (IOException e) {
                            // LOGGER.error("Get job history error", e);
                            }
                        }
                    }));
                }
            }
        });
        executorService = Executors.newFixedThreadPool(NO_OF_THREADS);
        server.setExecutor(executorService);
        server.start();
        isEnabled = true;
    } catch (IOException e) {
    // LOGGER.error("Get job history error", e);
    // DefaultLoader.getUIHelper().showError(e.getClass().getName(), e.getMessage());
    }
}
Also used : HttpHandler(com.sun.net.httpserver.HttpHandler) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) HttpExchange(com.sun.net.httpserver.HttpExchange) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) MultiHttpFutureCallback(com.microsoft.azure.hdinsight.common.MultiHttpFutureCallback) MultiHttpFutureCallback(com.microsoft.azure.hdinsight.common.MultiHttpFutureCallback) HttpFutureCallback(com.microsoft.azure.hdinsight.common.HttpFutureCallback)

Example 22 with IClusterDetail

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

the class SparkRestUtil method getSparkApplications.

@NotNull
public static List<Application> getSparkApplications(@NotNull IClusterDetail clusterDetail) throws HDIException, IOException {
    HttpEntity entity = getSparkRestEntity(clusterDetail, "");
    Optional<List<Application>> apps = ObjectConvertUtils.convertEntityToList(entity, Application.class);
    // spark job has at least one attempt
    return apps.orElse(RestUtil.getEmptyList(Application.class)).stream().filter(app -> app.getAttempts().size() != 0 && app.getAttempts().get(0).getAttemptId() != null).collect(Collectors.toList());
}
Also used : java.util(java.util) Application(com.microsoft.azure.hdinsight.sdk.rest.spark.Application) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull) Task(com.microsoft.azure.hdinsight.sdk.rest.spark.task.Task) ObjectConvertUtils(com.microsoft.azure.hdinsight.sdk.rest.ObjectConvertUtils) HDInsightLoader(com.microsoft.azure.hdinsight.common.HDInsightLoader) JSONObject(org.json.JSONObject) Charset(java.nio.charset.Charset) ZipFile(java.util.zip.ZipFile) JobStartEventLog(com.microsoft.azure.hdinsight.sdk.rest.spark.event.JobStartEventLog) AttemptWithAppId(com.microsoft.azure.hdinsight.sdk.rest.AttemptWithAppId) ZipEntry(java.util.zip.ZipEntry) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) HttpEntity(org.apache.http.HttpEntity) Executor(com.microsoft.azure.hdinsight.sdk.rest.spark.executor.Executor) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) Job(com.microsoft.azure.hdinsight.sdk.rest.spark.job.Job) Stage(com.microsoft.azure.hdinsight.sdk.rest.spark.stage.Stage) RestUtil(com.microsoft.azure.hdinsight.sdk.rest.RestUtil) InputStream(java.io.InputStream) HttpEntity(org.apache.http.HttpEntity) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

IClusterDetail (com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail)22 IOException (java.io.IOException)8 ExecutionException (com.intellij.execution.ExecutionException)6 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)5 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)5 URISyntaxException (java.net.URISyntaxException)4 Collectors (java.util.stream.Collectors)4 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)2 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)2 Project (com.intellij.openapi.project.Project)2 JSchException (com.jcraft.jsch.JSchException)2 ClusterDetail (com.microsoft.azure.hdinsight.sdk.cluster.ClusterDetail)2 AuthenticationException (com.microsoft.azure.hdinsight.sdk.common.AuthenticationException)2 ObjectConvertUtils (com.microsoft.azure.hdinsight.sdk.rest.ObjectConvertUtils)2 App (com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.App)2 SparkSubmissionParameter (com.microsoft.azure.hdinsight.spark.common.SparkSubmissionParameter)2 File (java.io.File)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2