Search in sources :

Example 1 with JobStartEventLog

use of com.microsoft.azure.hdinsight.sdk.rest.spark.event.JobStartEventLog in project azure-tools-for-java by Microsoft.

the class SparkRestUtil method getSparkEventLogs.

public static List<JobStartEventLog> getSparkEventLogs(@NotNull ApplicationKey key) throws HDIException, IOException {
    String url = String.format("%s/logs", key.getAppId());
    String eventLogsPath = String.format("%s/SparkEventLogs/%s/eventLogs.zip", HDInsightLoader.getHDInsightHelper().getPluginRootPath(), key.getAppId());
    File file = new File(eventLogsPath);
    HttpEntity entity = getSparkRestEntity(key.getClusterDetails(), url);
    InputStream inputStream = entity.getContent();
    FileUtils.copyInputStreamToFile(inputStream, file);
    IOUtils.closeQuietly(inputStream);
    ZipFile zipFile = new ZipFile(file);
    List<? extends ZipEntry> entities = Collections.list(zipFile.entries());
    // every application has an attempt in event log
    // and the entity name should be in formation "{appId}_{attemptId}"
    String entityName = String.format("%s_%s", key.getAppId(), entities.size());
    ZipEntry lastEntity = zipFile.getEntry(entityName);
    if (lastEntity == null) {
        throw new HDIException(String.format("No Spark event log entity found for app: %s", key.getAppId()));
    }
    InputStream zipFileInputStream = zipFile.getInputStream(lastEntity);
    String entityContent = IOUtils.toString(zipFileInputStream, Charset.forName("utf-8"));
    String[] lines = entityContent.split("\n");
    List<JobStartEventLog> jobStartEvents = Arrays.stream(lines).filter(line -> {
        JSONObject jsonObject = new JSONObject(line);
        String eventName = jsonObject.getString("Event");
        return eventName.equalsIgnoreCase("SparkListenerJobStart");
    }).map(oneLine -> ObjectConvertUtils.convertToObjectQuietly(oneLine, JobStartEventLog.class)).filter(Objects::nonNull).collect(Collectors.toList());
    return jobStartEvents;
}
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) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) ZipFile(java.util.zip.ZipFile) JSONObject(org.json.JSONObject) JobStartEventLog(com.microsoft.azure.hdinsight.sdk.rest.spark.event.JobStartEventLog) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

HDInsightLoader (com.microsoft.azure.hdinsight.common.HDInsightLoader)1 IClusterDetail (com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail)1 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 AttemptWithAppId (com.microsoft.azure.hdinsight.sdk.rest.AttemptWithAppId)1 ObjectConvertUtils (com.microsoft.azure.hdinsight.sdk.rest.ObjectConvertUtils)1 RestUtil (com.microsoft.azure.hdinsight.sdk.rest.RestUtil)1 Application (com.microsoft.azure.hdinsight.sdk.rest.spark.Application)1 JobStartEventLog (com.microsoft.azure.hdinsight.sdk.rest.spark.event.JobStartEventLog)1 Executor (com.microsoft.azure.hdinsight.sdk.rest.spark.executor.Executor)1 Job (com.microsoft.azure.hdinsight.sdk.rest.spark.job.Job)1 Stage (com.microsoft.azure.hdinsight.sdk.rest.spark.stage.Stage)1 Task (com.microsoft.azure.hdinsight.sdk.rest.spark.task.Task)1 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 java.util (java.util)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1