public void transition(RMAppImpl app, RMAppEvent event) { RMAppRunningOnNodeEvent nodeAddedEvent = (RMAppRunningOnNodeEvent) event; // if final state already stored, notify RMNode if (isAppInFinalState(app)) { app.handler.handle( new RMNodeCleanAppEvent(nodeAddedEvent.getNodeId(), nodeAddedEvent .getApplicationId())); return; } // otherwise, add it to ranNodes for further process app.ranNodes.add(nodeAddedEvent.getNodeId()); if (!app.logAggregationStatus.containsKey(nodeAddedEvent.getNodeId())) { app.logAggregationStatus.put(nodeAddedEvent.getNodeId(), LogAggregationReport.newInstance(app.applicationId, app.logAggregationEnabled ? LogAggregationStatus.NOT_START : LogAggregationStatus.DISABLED, "")); } }
private static RMApp createRMApp(int id, Configuration conf, RMContext rmContext, final LogAggregationStatus aggStatus) { ApplicationId appId = ApplicationId.newInstance(CLUSTER_TIMESTAMP, id); ApplicationSubmissionContext submissionContext = ApplicationSubmissionContext.newInstance(appId, "test", "default", Priority.newInstance(0), null, true, true, 2, Resource.newInstance(10, 2), "test"); return new RMAppImpl(appId, rmContext, conf, "test", USER, "default", submissionContext, rmContext.getScheduler(), rmContext.getApplicationMasterService(), System.currentTimeMillis(), "test", null, null) { @Override public ApplicationReport createAndGetApplicationReport( String clientUserName, boolean allowAccess) { ApplicationReport report = super.createAndGetApplicationReport(clientUserName, allowAccess); report.setLogAggregationStatus(aggStatus); return report; } }; }
private void waitForJobLogs(List<ApplicationReport> projectsApps, YarnClient client) throws YarnException, IOException, InterruptedException { for (ApplicationReport appReport : projectsApps) { FinalApplicationStatus finalState = appReport.getFinalApplicationStatus(); while (finalState.equals(FinalApplicationStatus.UNDEFINED)) { client.killApplication(appReport.getApplicationId()); appReport = client.getApplicationReport(appReport.getApplicationId()); finalState = appReport.getFinalApplicationStatus(); } LogAggregationStatus logAggregationState = appReport.getLogAggregationStatus(); while (!YarnLogUtil.isFinal(logAggregationState)) { Thread.sleep(500); appReport = client.getApplicationReport(appReport.getApplicationId()); logAggregationState = appReport.getLogAggregationStatus(); } } }
private void sendLogAggregationReport( boolean logAggregationSucceedInThisCycle, String diagnosticMessage, boolean appFinished) { LogAggregationStatus logAggregationStatus = logAggregationSucceedInThisCycle ? LogAggregationStatus.RUNNING : LogAggregationStatus.RUNNING_WITH_FAILURE; sendLogAggregationReportInternal(logAggregationStatus, diagnosticMessage); if (appFinished) { // If the app is finished, one extra final report with log aggregation // status SUCCEEDED/FAILED will be sent to RM to inform the RM // that the log aggregation in this NM is completed. LogAggregationStatus finalLogAggregationStatus = renameTemporaryLogFileFailed || !logAggregationSucceedInThisCycle ? LogAggregationStatus.FAILED : LogAggregationStatus.SUCCEEDED; sendLogAggregationReportInternal(finalLogAggregationStatus, ""); } }
@Override public Map<NodeId, LogAggregationReport> getLogAggregationReportsForApp() { try { this.readLock.lock(); if (!isLogAggregationFinished() && isAppInFinalState(this) && System.currentTimeMillis() > this.logAggregationStartTime + this.logAggregationStatusTimeout) { for (Entry<NodeId, LogAggregationReport> output : logAggregationStatus.entrySet()) { if (!output.getValue().getLogAggregationStatus() .equals(LogAggregationStatus.TIME_OUT) && !output.getValue().getLogAggregationStatus() .equals(LogAggregationStatus.SUCCEEDED) && !output.getValue().getLogAggregationStatus() .equals(LogAggregationStatus.FAILED)) { output.getValue().setLogAggregationStatus( LogAggregationStatus.TIME_OUT); } } } return Collections.unmodifiableMap(logAggregationStatus); } finally { this.readLock.unlock(); } }
private static RMApp createRMApp(int id, Configuration conf, RMContext rmContext, final LogAggregationStatus aggStatus) throws IOException{ ApplicationId appId = ApplicationId.newInstance(CLUSTER_TIMESTAMP, id); ApplicationSubmissionContext submissionContext = ApplicationSubmissionContext.newInstance(appId, "test", "default", Priority.newInstance(0), null, true, true, 2, Resource.newInstance(10, 2), "test"); return new RMAppImpl(appId, rmContext, conf, "test", USER, "default", submissionContext, rmContext.getScheduler(), rmContext.getApplicationMasterService(), System.currentTimeMillis(), "test", null, null, null, null, null, null) { @Override public ApplicationReport createAndGetApplicationReport( String clientUserName, boolean allowAccess) { ApplicationReport report = super.createAndGetApplicationReport(clientUserName, allowAccess); report.setLogAggregationStatus(aggStatus); return report; } }; }
@Override public LogAggregationStatus getLogAggregationStatus() { ApplicationReportProtoOrBuilder p = viaProto ? proto : builder; if (!p.hasLogAggregationStatus()) { return null; } return convertFromProtoFormat(p.getLogAggregationStatus()); }
@Override public void setLogAggregationStatus( LogAggregationStatus logAggregationStatus) { maybeInitBuilder(); if (logAggregationStatus == null) { builder.clearLogAggregationStatus(); return; } builder.setLogAggregationStatus( convertToProtoFormat(logAggregationStatus)); }
@Public @Unstable public static LogAggregationReport newInstance(ApplicationId appId, LogAggregationStatus status, String diagnosticMessage) { LogAggregationReport report = Records.newRecord(LogAggregationReport.class); report.setApplicationId(appId); report.setLogAggregationStatus(status); report.setDiagnosticMessage(diagnosticMessage); return report; }
@Override public LogAggregationStatus getLogAggregationStatus() { LogAggregationReportProtoOrBuilder p = viaProto ? proto : builder; if (!p.hasLogAggregationStatus()) { return null; } return convertFromProtoFormat(p.getLogAggregationStatus()); }
@Override public void setLogAggregationStatus(LogAggregationStatus logAggregationStatus) { maybeInitBuilder(); if (logAggregationStatus == null) { builder.clearLogAggregationStatus(); return; } builder.setLogAggregationStatus(convertToProtoFormat(logAggregationStatus)); }
@Override protected LogAggregationStatus getLogAggregationStatus() { RMApp rmApp = this.rm.getRMContext().getRMApps().get(appID); if (rmApp == null) { return null; } return rmApp.getLogAggregationStatusForAppReport(); }
@Override public Map<NodeId, LogAggregationReport> getLogAggregationReportsForApp() { try { this.readLock.lock(); Map<NodeId, LogAggregationReport> outputs = new HashMap<NodeId, LogAggregationReport>(); outputs.putAll(logAggregationStatus); if (!isLogAggregationFinished()) { for (Entry<NodeId, LogAggregationReport> output : outputs.entrySet()) { if (!output.getValue().getLogAggregationStatus() .equals(LogAggregationStatus.TIME_OUT) && !output.getValue().getLogAggregationStatus() .equals(LogAggregationStatus.SUCCEEDED) && !output.getValue().getLogAggregationStatus() .equals(LogAggregationStatus.FAILED) && isAppInFinalState(this) && System.currentTimeMillis() > this.logAggregationStartTime + this.logAggregationStatusTimeout) { output.getValue().setLogAggregationStatus( LogAggregationStatus.TIME_OUT); } } } return outputs; } finally { this.readLock.unlock(); } }
private boolean isLogAggregationFinished() { return this.logAggregationStatusForAppReport .equals(LogAggregationStatus.SUCCEEDED) || this.logAggregationStatusForAppReport .equals(LogAggregationStatus.FAILED); }
private void updateLogAggregationDiagnosticMessages(NodeId nodeId, LogAggregationReport report) { if (report.getDiagnosticMessage() != null && !report.getDiagnosticMessage().isEmpty()) { if (report.getLogAggregationStatus() == LogAggregationStatus.RUNNING ) { List<String> diagnostics = logAggregationDiagnosticsForNMs.get(nodeId); if (diagnostics == null) { diagnostics = new ArrayList<String>(); logAggregationDiagnosticsForNMs.put(nodeId, diagnostics); } else { if (diagnostics.size() == maxLogAggregationDiagnosticsInMemory) { diagnostics.remove(0); } } diagnostics.add(report.getDiagnosticMessage()); this.logAggregationStatus.get(nodeId).setDiagnosticMessage( StringUtils.join(diagnostics, "\n")); } else if (report.getLogAggregationStatus() == LogAggregationStatus.RUNNING_WITH_FAILURE) { List<String> failureMessages = logAggregationFailureMessagesForNMs.get(nodeId); if (failureMessages == null) { failureMessages = new ArrayList<String>(); logAggregationFailureMessagesForNMs.put(nodeId, failureMessages); } else { if (failureMessages.size() == maxLogAggregationDiagnosticsInMemory) { failureMessages.remove(0); } } failureMessages.add(report.getDiagnosticMessage()); } } }
private void updateLogAggregationStatus(NodeId nodeId) { LogAggregationStatus status = this.logAggregationStatus.get(nodeId).getLogAggregationStatus(); if (status.equals(LogAggregationStatus.SUCCEEDED)) { this.logAggregationSucceed++; } else if (status.equals(LogAggregationStatus.FAILED)) { this.logAggregationFailed++; } if (this.logAggregationSucceed == this.logAggregationStatus.size()) { this.logAggregationStatusForAppReport = LogAggregationStatus.SUCCEEDED; // Since the log aggregation status for this application for all NMs // is SUCCEEDED, it means all logs are aggregated successfully. // We could remove all the cached log aggregation reports this.logAggregationStatus.clear(); this.logAggregationDiagnosticsForNMs.clear(); this.logAggregationFailureMessagesForNMs.clear(); } else if (this.logAggregationSucceed + this.logAggregationFailed == this.logAggregationStatus.size()) { this.logAggregationStatusForAppReport = LogAggregationStatus.FAILED; // We have collected the log aggregation status for all NMs. // The log aggregation status is FAILED which means the log // aggregation fails in some NMs. We are only interested in the // nodes where the log aggregation is failed. So we could remove // the log aggregation details for those succeeded NMs for (Iterator<Map.Entry<NodeId, LogAggregationReport>> it = this.logAggregationStatus.entrySet().iterator(); it.hasNext();) { Map.Entry<NodeId, LogAggregationReport> entry = it.next(); if (entry.getValue().getLogAggregationStatus() .equals(LogAggregationStatus.SUCCEEDED)) { it.remove(); } } // the log aggregation has finished/failed. // and the status will not be updated anymore. this.logAggregationDiagnosticsForNMs.clear(); } }
/** * If this test failes, then a new Log Aggregation Status was added. Make * sure that {@link HadoopArchiveLogs#filterAppsByAggregatedStatus()} and this test * are updated as well, if necessary. * @throws Exception */ @Test(timeout = 5000) public void testStatuses() throws Exception { LogAggregationStatus[] statuses = new LogAggregationStatus[7]; statuses[0] = LogAggregationStatus.DISABLED; statuses[1] = LogAggregationStatus.NOT_START; statuses[2] = LogAggregationStatus.RUNNING; statuses[3] = LogAggregationStatus.RUNNING_WITH_FAILURE; statuses[4] = LogAggregationStatus.SUCCEEDED; statuses[5] = LogAggregationStatus.FAILED; statuses[6] = LogAggregationStatus.TIME_OUT; Assert.assertArrayEquals(statuses, LogAggregationStatus.values()); }
public static LogAggregationStatus waitForLogAggregation(YarnMonitor monitor) throws InterruptedException, YarnException, IOException { LogAggregationStatus logAggregationStatus = monitor.getLogAggregationStatus(); while (!isFinal(logAggregationStatus)) { Thread.sleep(1000); logAggregationStatus = monitor.getLogAggregationStatus(); } return logAggregationStatus; }
public static boolean isFinal(LogAggregationStatus status){ switch(status){ case RUNNING: case RUNNING_WITH_FAILURE: case NOT_START: return false; default : return true; } }
private void sendLogAggregationReportInternal( LogAggregationStatus logAggregationStatus, String diagnosticMessage) { LogAggregationReport report = Records.newRecord(LogAggregationReport.class); report.setApplicationId(appId); report.setDiagnosticMessage(diagnosticMessage); report.setLogAggregationStatus(logAggregationStatus); this.context.getLogAggregationStatusForApps().add(report); }
private boolean isLogAggregationFinished() { return this.logAggregationStatusForAppReport .equals(LogAggregationStatus.SUCCEEDED) || this.logAggregationStatusForAppReport .equals(LogAggregationStatus.FAILED) || this.logAggregationStatusForAppReport .equals(LogAggregationStatus.TIME_OUT); }
public static LogAggregationStatusProto convertToProtoFormat( LogAggregationStatus e) { return LogAggregationStatusProto.valueOf(LOG_AGGREGATION_STATUS_PREFIX + e.name()); }
public static LogAggregationStatus convertFromProtoFormat( LogAggregationStatusProto e) { return LogAggregationStatus.valueOf(e.name().replace( LOG_AGGREGATION_STATUS_PREFIX, "")); }
private LogAggregationStatus convertFromProtoFormat( LogAggregationStatusProto s) { return ProtoUtils.convertFromProtoFormat(s); }
private LogAggregationStatusProto convertToProtoFormat(LogAggregationStatus s) { return ProtoUtils.convertToProtoFormat(s); }
protected LogAggregationStatus getLogAggregationStatus() { return null; }
@Public @Unstable public abstract void setLogAggregationStatus( LogAggregationStatus logAggregationStatus);
public LogAggregationStatus getLogAggregationStatus() { return this.logAggregationStatus; }