|
@@ -33,6 +33,7 @@ import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
|
|
import org.apache.hadoop.yarn.api.records.timeline.TimelineEntity;
|
|
|
import org.apache.hadoop.yarn.api.records.timeline.TimelineEvent;
|
|
|
import org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse;
|
|
@@ -54,6 +55,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptS
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
|
|
|
import org.apache.hadoop.yarn.util.timeline.TimelineUtils;
|
|
|
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
|
+
|
|
|
/**
|
|
|
* The class that helps RM publish metrics to the timeline server. RM will
|
|
|
* always invoke the methods of this class regardless the service is enabled or
|
|
@@ -157,6 +160,18 @@ public class SystemMetricsPublisher extends CompositeService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void appStateUpdated(RMApp app, YarnApplicationState appState,
|
|
|
+ long updatedTime) {
|
|
|
+ if (publishSystemMetrics) {
|
|
|
+ dispatcher.getEventHandler().handle(
|
|
|
+ new ApplicaitonStateUpdatedEvent(
|
|
|
+ app.getApplicationId(),
|
|
|
+ appState,
|
|
|
+ updatedTime));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public void appAttemptRegistered(RMAppAttempt appAttempt,
|
|
|
long registeredTime) {
|
|
@@ -235,32 +250,36 @@ public class SystemMetricsPublisher extends CompositeService {
|
|
|
protected void handleSystemMetricsEvent(
|
|
|
SystemMetricsEvent event) {
|
|
|
switch (event.getType()) {
|
|
|
- case APP_CREATED:
|
|
|
- publishApplicationCreatedEvent((ApplicationCreatedEvent) event);
|
|
|
- break;
|
|
|
- case APP_FINISHED:
|
|
|
- publishApplicationFinishedEvent((ApplicationFinishedEvent) event);
|
|
|
- break;
|
|
|
- case APP_ACLS_UPDATED:
|
|
|
- publishApplicationACLsUpdatedEvent((ApplicationACLsUpdatedEvent) event);
|
|
|
- break;
|
|
|
- case APP_UPDATED:
|
|
|
- publishApplicationUpdatedEvent((ApplicationUpdatedEvent) event);
|
|
|
- break;
|
|
|
- case APP_ATTEMPT_REGISTERED:
|
|
|
- publishAppAttemptRegisteredEvent((AppAttemptRegisteredEvent) event);
|
|
|
- break;
|
|
|
- case APP_ATTEMPT_FINISHED:
|
|
|
- publishAppAttemptFinishedEvent((AppAttemptFinishedEvent) event);
|
|
|
- break;
|
|
|
- case CONTAINER_CREATED:
|
|
|
- publishContainerCreatedEvent((ContainerCreatedEvent) event);
|
|
|
- break;
|
|
|
- case CONTAINER_FINISHED:
|
|
|
- publishContainerFinishedEvent((ContainerFinishedEvent) event);
|
|
|
- break;
|
|
|
- default:
|
|
|
- LOG.error("Unknown SystemMetricsEvent type: " + event.getType());
|
|
|
+ case APP_CREATED:
|
|
|
+ publishApplicationCreatedEvent((ApplicationCreatedEvent) event);
|
|
|
+ break;
|
|
|
+ case APP_FINISHED:
|
|
|
+ publishApplicationFinishedEvent((ApplicationFinishedEvent) event);
|
|
|
+ break;
|
|
|
+ case APP_ACLS_UPDATED:
|
|
|
+ publishApplicationACLsUpdatedEvent((ApplicationACLsUpdatedEvent) event);
|
|
|
+ break;
|
|
|
+ case APP_UPDATED:
|
|
|
+ publishApplicationUpdatedEvent((ApplicationUpdatedEvent) event);
|
|
|
+ break;
|
|
|
+ case APP_STATE_UPDATED:
|
|
|
+ publishApplicationStateUpdatedEvent(
|
|
|
+ (ApplicaitonStateUpdatedEvent)event);
|
|
|
+ break;
|
|
|
+ case APP_ATTEMPT_REGISTERED:
|
|
|
+ publishAppAttemptRegisteredEvent((AppAttemptRegisteredEvent) event);
|
|
|
+ break;
|
|
|
+ case APP_ATTEMPT_FINISHED:
|
|
|
+ publishAppAttemptFinishedEvent((AppAttemptFinishedEvent) event);
|
|
|
+ break;
|
|
|
+ case CONTAINER_CREATED:
|
|
|
+ publishContainerCreatedEvent((ContainerCreatedEvent) event);
|
|
|
+ break;
|
|
|
+ case CONTAINER_FINISHED:
|
|
|
+ publishContainerFinishedEvent((ContainerFinishedEvent) event);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ LOG.error("Unknown SystemMetricsEvent type: " + event.getType());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -352,6 +371,20 @@ public class SystemMetricsPublisher extends CompositeService {
|
|
|
putEntity(entity);
|
|
|
}
|
|
|
|
|
|
+ private void publishApplicationStateUpdatedEvent(
|
|
|
+ ApplicaitonStateUpdatedEvent event) {
|
|
|
+ TimelineEntity entity = createApplicationEntity(event.getApplicationId());
|
|
|
+ Map<String, Object> eventInfo = new HashMap<String, Object>();
|
|
|
+ eventInfo.put(ApplicationMetricsConstants.STATE_EVENT_INFO,
|
|
|
+ event.getAppState());
|
|
|
+ TimelineEvent tEvent = new TimelineEvent();
|
|
|
+ tEvent.setEventType(ApplicationMetricsConstants.STATE_UPDATED_EVENT_TYPE);
|
|
|
+ tEvent.setTimestamp(event.getTimestamp());
|
|
|
+ tEvent.setEventInfo(eventInfo);
|
|
|
+ entity.addEvent(tEvent);
|
|
|
+ putEntity(entity);
|
|
|
+ }
|
|
|
+
|
|
|
private void publishApplicationACLsUpdatedEvent(
|
|
|
ApplicationACLsUpdatedEvent event) {
|
|
|
TimelineEntity entity =
|
|
@@ -501,7 +534,9 @@ public class SystemMetricsPublisher extends CompositeService {
|
|
|
return entity;
|
|
|
}
|
|
|
|
|
|
- private void putEntity(TimelineEntity entity) {
|
|
|
+ @Private
|
|
|
+ @VisibleForTesting
|
|
|
+ public void putEntity(TimelineEntity entity) {
|
|
|
try {
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
LOG.debug("Publishing the entity " + entity.getEntityId() +
|