Beispiel #1
0
 void toDataTableArrays(Collection<RMAppState> requiredAppStates, PrintWriter out) {
   out.append('[');
   boolean first = true;
   for (RMApp app : apps.values()) {
     if (requiredAppStates != null && !requiredAppStates.contains(app.getState())) {
       continue;
     }
     AppInfo appInfo = new AppInfo(app, true);
     String startTime = Times.format(appInfo.getStartTime());
     String finishTime = Times.format(appInfo.getFinishTime());
     if (first) {
       first = false;
     } else {
       out.append(",\n");
     }
     out.append("[\"");
     appendSortable(out, appInfo.getAppIdNum());
     appendLink(out, appInfo.getAppId(), rc.prefix(), "app", appInfo.getAppId())
         .append(_SEP)
         .append(escapeHtml(appInfo.getUser()))
         .append(_SEP)
         .append(escapeJavaScript(escapeHtml(appInfo.getName())))
         .append(_SEP)
         .append(escapeHtml(appInfo.getQueue()))
         .append(_SEP);
     appendSortable(out, appInfo.getStartTime()).append(startTime).append(_SEP);
     appendSortable(out, appInfo.getFinishTime())
         .append(finishTime)
         .append(_SEP)
         .append(appInfo.getState())
         .append(_SEP)
         .append(appInfo.getFinalStatus())
         .append(_SEP);
     appendProgressBar(out, appInfo.getProgress()).append(_SEP);
     appendLink(
             out,
             appInfo.getTrackingUI(),
             rc.prefix(),
             !appInfo.isTrackingUrlReady() ? "#" : appInfo.getTrackingUrlPretty())
         .append("\"]");
   }
   out.append(']');
 }
Beispiel #2
0
  public JobInfo(Job job, Boolean hasAccess) {
    this.id = MRApps.toString(job.getID());
    JobReport report = job.getReport();
    this.startTime = report.getStartTime();
    this.finishTime = report.getFinishTime();
    this.elapsedTime = Times.elapsed(this.startTime, this.finishTime);
    if (this.elapsedTime == -1) {
      this.elapsedTime = 0;
    }
    this.name = job.getName().toString();
    this.user = job.getUserName();
    this.queue = job.getQueueName();
    this.state = job.getState();
    this.mapsTotal = job.getTotalMaps();
    this.mapsCompleted = job.getCompletedMaps();
    this.mapProgress = report.getMapProgress() * 100;
    this.mapProgressPercent = StringUtils.formatPercent(report.getMapProgress(), 2);
    this.reducesTotal = job.getTotalReduces();
    this.reducesCompleted = job.getCompletedReduces();
    this.reduceProgress = report.getReduceProgress() * 100;
    this.reduceProgressPercent = StringUtils.formatPercent(report.getReduceProgress(), 2);

    this.acls = new ArrayList<ConfEntryInfo>();
    if (hasAccess) {
      this.diagnostics = "";
      countTasksAndAttempts(job);

      this.uberized = job.isUber();

      List<String> diagnostics = job.getDiagnostics();
      if (diagnostics != null && !diagnostics.isEmpty()) {
        StringBuffer b = new StringBuffer();
        for (String diag : diagnostics) {
          b.append(diag);
        }
        this.diagnostics = b.toString();
      }

      Map<JobACL, AccessControlList> allacls = job.getJobACLs();
      if (allacls != null) {
        for (Map.Entry<JobACL, AccessControlList> entry : allacls.entrySet()) {
          this.acls.add(
              new ConfEntryInfo(entry.getKey().getAclName(), entry.getValue().getAclString()));
        }
      }
    }
  }
 /** @param context */
 public AppInfo(StramAppContext context) {
   this.appId = context.getApplicationID().toString();
   this.name = context.getApplicationName();
   this.docLink = context.getApplicationDocLink();
   this.user = context.getUser().toString();
   this.startTime = context.getStartTime();
   this.elapsedTime = Times.elapsed(this.startTime, 0);
   this.appPath = context.getApplicationPath();
   this.appMasterTrackingUrl = context.getAppMasterTrackingUrl();
   this.stats = context.getStats();
   this.gatewayAddress = context.getGatewayAddress();
   this.version = VersionInfo.getBuildVersion();
   this.attributes = new TreeMap<String, Object>();
   for (Map.Entry<Attribute<Object>, Object> entry :
       AttributeMap.AttributeInitializer.getAllAttributes(context, DAGContext.class).entrySet()) {
     this.attributes.put(entry.getKey().getSimpleName(), entry.getValue());
   }
   this.gatewayConnected = context.isGatewayConnected();
   this.appDataSources = context.getAppDataSources();
   this.metrics = context.getMetrics();
 }
  private boolean readContainerLogs(Block html,
      AggregatedLogFormat.ContainerLogsReader logReader, LogLimits logLimits,
      String desiredLogType, long logUpLoadTime) throws IOException {
    int bufferSize = 65536;
    char[] cbuf = new char[bufferSize];

    boolean foundLog = false;
    String logType = logReader.nextLog();
    while (logType != null) {
      if (desiredLogType == null || desiredLogType.isEmpty()
          || desiredLogType.equals(logType)) {
        long logLength = logReader.getCurrentLogLength();
        if (foundLog) {
          html.pre()._("\n\n")._();
        }

        html.p()._("Log Type: " + logType)._();
        html.p()._("Log Upload Time: " + Times.format(logUpLoadTime))._();
        html.p()._("Log Length: " + Long.toString(logLength))._();

        long start = logLimits.start < 0
            ? logLength + logLimits.start : logLimits.start;
        start = start < 0 ? 0 : start;
        start = start > logLength ? logLength : start;
        long end = logLimits.end < 0
            ? logLength + logLimits.end : logLimits.end;
        end = end < 0 ? 0 : end;
        end = end > logLength ? logLength : end;
        end = end < start ? start : end;

        long toRead = end - start;
        if (toRead < logLength) {
            html.p()._("Showing " + toRead + " bytes of " + logLength
                + " total. Click ")
                .a(url("logs", $(NM_NODENAME), $(CONTAINER_ID),
                    $(ENTITY_STRING), $(APP_OWNER),
                    logType, "?start=0"), "here").
                    _(" for the full log.")._();
        }

        long totalSkipped = 0;
        while (totalSkipped < start) {
          long ret = logReader.skip(start - totalSkipped);
          if (ret == 0) {
            //Read one byte
            int nextByte = logReader.read();
            // Check if we have reached EOF
            if (nextByte == -1) {
              throw new IOException( "Premature EOF from container log");
            }
            ret = 1;
          }
          totalSkipped += ret;
        }

        int len = 0;
        int currentToRead = toRead > bufferSize ? bufferSize : (int) toRead;
        PRE<Hamlet> pre = html.pre();

        while (toRead > 0
            && (len = logReader.read(cbuf, 0, currentToRead)) > 0) {
          pre._(new String(cbuf, 0, len));
          toRead = toRead - len;
          currentToRead = toRead > bufferSize ? bufferSize : (int) toRead;
        }

        pre._();
        foundLog = true;
      }

      logType = logReader.nextLog();
    }

    return foundLog;
  }