Search in sources :

Example 1 with Error

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

the class SparkBatchJob method getSubmissionLog.

@Override
@NotNull
public Observable<SparkLogLine> getSubmissionLog() {
    if (getConnectUri() == null) {
        return Observable.error(new SparkJobNotConfiguredException("Can't get Spark job connection URI, " + "please configure Spark cluster which the Spark job will be submitted."));
    }
    // Those lines are carried per response,
    // if there is no value followed, the line should not be sent to console
    final Set<String> ignoredEmptyLines = new HashSet<>(Arrays.asList("stdout:", "stderr:", "yarn diagnostics:"));
    return Observable.create(ob -> {
        try {
            final int maxLinesPerGet = 128;
            int linesGot;
            boolean isFetching = true;
            while (isFetching) {
                final int start = nextLivyLogOffset;
                final boolean isAppIdAllocated = !this.getSparkJobApplicationIdObservable().isEmpty().toBlocking().lastOrDefault(true);
                final String logUrl = String.format("%s/%d/log?from=%d&size=%d", this.getConnectUri().toString(), batchId, start, maxLinesPerGet);
                final HttpResponse httpResponse = this.getSubmission().getHttpResponseViaGet(logUrl);
                final SparkJobLog sparkJobLog = ObjectConvertUtils.convertJsonToObject(httpResponse.getMessage(), SparkJobLog.class).orElseThrow(() -> new UnknownServiceException("Bad spark log response: " + httpResponse.getMessage()));
                synchronized (livyLogOffsetLock) {
                    if (start != nextLivyLogOffset) {
                        // The offset is moved by another fetching thread, re-do it with new offset
                        continue;
                    }
                    // To subscriber
                    sparkJobLog.getLog().stream().filter(line -> !ignoredEmptyLines.contains(line.trim().toLowerCase())).forEach(line -> ob.onNext(new SparkLogLine(LIVY, Log, line)));
                    linesGot = sparkJobLog.getLog().size();
                    nextLivyLogOffset += linesGot;
                }
                // Retry interval
                if (linesGot == 0) {
                    isFetching = "starting".equals(this.getState()) && !isAppIdAllocated;
                    sleep(TimeUnit.SECONDS.toMillis(this.getDelaySeconds()));
                }
            }
        } catch (final IOException ex) {
            ob.onNext(new SparkLogLine(TOOL, Error, ex.getMessage()));
        } catch (final InterruptedException ignored) {
        } finally {
            ob.onCompleted();
        }
    });
}
Also used : App(com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.App) java.util(java.util) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull) Error(com.microsoft.azure.hdinsight.common.MessageInfoType.Error) LivyCluster(com.microsoft.azure.hdinsight.sdk.cluster.LivyCluster) ObjectConvertUtils(com.microsoft.azure.hdinsight.sdk.rest.ObjectConvertUtils) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) StringUtils(org.apache.commons.lang3.StringUtils) ILogger(com.microsoft.azure.hdinsight.common.logger.ILogger) Observable(rx.Observable) Matcher(java.util.regex.Matcher) ClusterManagerEx(com.microsoft.azure.hdinsight.common.ClusterManagerEx) Cache(com.gargoylesoftware.htmlunit.Cache) Thread.sleep(java.lang.Thread.sleep) URI(java.net.URI) TOOL(com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine.TOOL) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) YarnCluster(com.microsoft.azure.hdinsight.sdk.cluster.YarnCluster) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable) Subscriber(rx.Subscriber) JobUtils(com.microsoft.azure.hdinsight.spark.jobs.JobUtils) Exceptions.propagate(rx.exceptions.Exceptions.propagate) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse) IOException(java.io.IOException) Observer(rx.Observer) File(java.io.File) HttpObservable(com.microsoft.azure.hdinsight.sdk.common.HttpObservable) AppResponse(com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.AppResponse) AppAttemptsResponse(com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.AppAttemptsResponse) TimeUnit(java.util.concurrent.TimeUnit) MessageInfoType(com.microsoft.azure.hdinsight.common.MessageInfoType) LIVY(com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine.LIVY) Pattern(java.util.regex.Pattern) SparkLogLine(com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine) PublishSubject(rx.subjects.PublishSubject) UnknownServiceException(java.net.UnknownServiceException) AppAttempt(com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.AppAttempt) IHDIStorageAccount(com.microsoft.azure.hdinsight.sdk.storage.IHDIStorageAccount) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) UnknownServiceException(java.net.UnknownServiceException) HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse) IOException(java.io.IOException) SparkLogLine(com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

Cache (com.gargoylesoftware.htmlunit.Cache)1 ClusterManagerEx (com.microsoft.azure.hdinsight.common.ClusterManagerEx)1 MessageInfoType (com.microsoft.azure.hdinsight.common.MessageInfoType)1 Error (com.microsoft.azure.hdinsight.common.MessageInfoType.Error)1 ILogger (com.microsoft.azure.hdinsight.common.logger.ILogger)1 IClusterDetail (com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail)1 LivyCluster (com.microsoft.azure.hdinsight.sdk.cluster.LivyCluster)1 YarnCluster (com.microsoft.azure.hdinsight.sdk.cluster.YarnCluster)1 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 HttpObservable (com.microsoft.azure.hdinsight.sdk.common.HttpObservable)1 HttpResponse (com.microsoft.azure.hdinsight.sdk.common.HttpResponse)1 ObjectConvertUtils (com.microsoft.azure.hdinsight.sdk.rest.ObjectConvertUtils)1 App (com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.App)1 AppAttempt (com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.AppAttempt)1 AppAttemptsResponse (com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.AppAttemptsResponse)1 AppResponse (com.microsoft.azure.hdinsight.sdk.rest.yarn.rm.AppResponse)1 IHDIStorageAccount (com.microsoft.azure.hdinsight.sdk.storage.IHDIStorageAccount)1 SparkLogLine (com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine)1 LIVY (com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine.LIVY)1 TOOL (com.microsoft.azure.hdinsight.spark.common.log.SparkLogLine.TOOL)1