private org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity createAppEntityWithJobMetrics(HistoryEvent event, JobId jobId) { ApplicationEntity entity = new ApplicationEntity(); entity.setId(jobId.getAppId().toString()); entity.setMetrics(event.getTimelineMetrics()); return entity; }
public ApplicationEntity(TimelineEntity entity) { super(entity); if (!entity.getType().equals( TimelineEntityType.YARN_APPLICATION.toString())) { throw new IllegalArgumentException("Incompatible entity type: " + getId()); } }
/** * @param te TimelineEntity object. * @param eventId event with this id needs to be fetched * @return TimelineEvent if TimelineEntity contains the desired event. */ public static TimelineEvent getApplicationEvent(TimelineEntity te, String eventId) { if (isApplicationEntity(te)) { for (TimelineEvent event : te.getEvents()) { if (event.getId().equals(eventId)) { return event; } } } return null; } }
private static ApplicationEntity createApplicationEntity( ApplicationId applicationId) { ApplicationEntity entity = new ApplicationEntity(); entity.setId(applicationId.toString()); return entity; }
ApplicationEntity app1 = new ApplicationEntity(); app1.setId(ApplicationId.newInstance(0, 1).toString()); app1.setQueue(queue.getId()); ApplicationEntity app2 = new ApplicationEntity(); app2.setId(ApplicationId.newInstance(0, 2).toString()); app2.setQueue(queue.getId()); flow2.setParent(TimelineEntityType.YARN_FLOW_RUN.toString(), flow1.getId()); flow2.addChild(TimelineEntityType.YARN_APPLICATION.toString(), app1.getId()); flow2.addChild(TimelineEntityType.YARN_APPLICATION.toString(), app2.getId()); app1.setParent(TimelineEntityType.YARN_FLOW_RUN.toString(), flow2.getId()); app1.addChild(TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), appAttempt.getId()); appAttempt .setParent(TimelineEntityType.YARN_APPLICATION.toString(), app1.getId()); app2.setParent(TimelineEntityType.YARN_FLOW_RUN.toString(), flow2.getId()); appAttempt.addChild(TimelineEntityType.YARN_CONTAINER.toString(), container.getId()); Assert.assertNotNull(app1.getParent()); Assert.assertEquals(flow2.getType(), app1.getParent().getType()); Assert.assertEquals(flow2.getId(), app1.getParent().getId()); app1.addInfo(ApplicationEntity.PARENT_INFO_KEY, "invalid parent object"); try { app1.getParent();
flow.setRunId(1L); flow.setParent(cluster.getType(), cluster.getId()); ApplicationEntity app = new ApplicationEntity(); app.setId(appId.toString()); flow.addChild(app.getType(), app.getId()); ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1);
ApplicationEntity appEntityForConfigs = new ApplicationEntity(); String appId = jobId.getAppId().toString(); appEntityForConfigs.setId(appId); try { int configSize = 0; timelineV2Client.putEntities(appEntityForConfigs); jobEntityForConfigs = createJobEntity(jobId); appEntityForConfigs = new ApplicationEntity(); appEntityForConfigs.setId(appId); appEntityForConfigs.addConfig(entry.getKey(), entry.getValue());
public void appCreated(RMApp app, long createdTime) { ApplicationEntity entity = createApplicationEntity(app.getApplicationId()); entity.setQueue(app.getQueue()); entity.setCreatedTime(createdTime); entityInfo.put(ApplicationMetricsConstants.APPLICATION_PRIORITY_INFO, app.getApplicationPriority().getPriority()); entity.getConfigs().put( ApplicationMetricsConstants.AM_NODE_LABEL_EXPRESSION, app.getAmNodeLabelExpression()); entity.getConfigs().put( ApplicationMetricsConstants.APP_NODE_LABEL_EXPRESSION, app.getAppNodeLabelExpression()); RMServerUtils.createApplicationState(app.getState()).toString()); entity.setInfo(entityInfo); TimelineEvent tEvent = new TimelineEvent(); tEvent.setId(ApplicationMetricsConstants.CREATED_EVENT_TYPE); tEvent.setTimestamp(createdTime); entity.addEvent(tEvent);
boolean isApplication = ApplicationEntity.isApplicationEntity(te); byte[] rowKey; if (isApplication) { ApplicationEntity.getApplicationEvent(te, ApplicationMetricsConstants.CREATED_EVENT_TYPE); FlowRunRowKey flowRunRowKey = event = ApplicationEntity.getApplicationEvent(te, ApplicationMetricsConstants.FINISHED_EVENT_TYPE); if (event != null) {
@SuppressWarnings("unchecked") @Override public void appFinished(RMApp app, RMAppState state, long finishedTime) { ApplicationEntity entity = createApplicationEntity(app.getApplicationId()); TimelineEvent tEvent = new TimelineEvent(); tEvent.setId(ApplicationMetricsConstants.FINISHED_EVENT_TYPE); tEvent.setTimestamp(finishedTime); entity.addEvent(tEvent); Map<String, Object> entityInfo = new HashMap<String, Object>(); entityInfo.put(ApplicationMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO, app.getDiagnostics().toString()); entityInfo.put(ApplicationMetricsConstants.FINAL_STATUS_EVENT_INFO, app.getFinalApplicationStatus().toString()); entityInfo.put(ApplicationMetricsConstants.STATE_EVENT_INFO, RMServerUtils.createApplicationState(state).toString()); ApplicationAttemptId appAttemptId = app.getCurrentAppAttempt() == null ? null : app.getCurrentAppAttempt().getAppAttemptId(); if (appAttemptId != null) { entityInfo.put(ApplicationMetricsConstants.LATEST_APP_ATTEMPT_EVENT_INFO, appAttemptId.toString()); } entity.setInfo(entityInfo); RMAppMetrics appMetrics = app.getRMAppMetrics(); Set<TimelineMetric> entityMetrics = getTimelinelineAppMetrics(appMetrics, finishedTime); entity.setMetrics(entityMetrics); getDispatcher().getEventHandler().handle( new ApplicationFinishPublishEvent(SystemMetricsEventType. PUBLISH_APPLICATION_FINISHED_ENTITY, entity, app)); }
public void setQueue(String queue) { addInfo(QUEUE_INFO_KEY, queue); }
@Test public void testGetApplicationEvent() { TimelineEntity te = null; TimelineEvent tEvent = ApplicationEntity.getApplicationEvent(te, "no event"); assertEquals(null, tEvent); te = new TimelineEntity(); te.setType(TimelineEntityType.YARN_APPLICATION.toString()); TimelineEvent event = new TimelineEvent(); event.setId("start_event"); event.setTimestamp(System.currentTimeMillis()); te.addEvent(event); tEvent = ApplicationEntity.getApplicationEvent(te, "start_event"); assertEquals(event, tEvent); te = new TimelineEntity(); te.setType(TimelineEntityType.YARN_CLUSTER.toString()); event = new TimelineEvent(); event.setId("start_event_cluster"); event.setTimestamp(System.currentTimeMillis()); te.addEvent(event); tEvent = ApplicationEntity.getApplicationEvent(te, "start_event_cluster"); assertEquals(null, tEvent); } }
@Test public void testIsApplicationEntity() { TimelineEntity te = new TimelineEntity(); te.setType(TimelineEntityType.YARN_APPLICATION.toString()); assertTrue(ApplicationEntity.isApplicationEntity(te)); te = null; assertEquals(false, ApplicationEntity.isApplicationEntity(te)); te = new TimelineEntity(); te.setType(TimelineEntityType.YARN_CLUSTER.toString()); assertEquals(false, ApplicationEntity.isApplicationEntity(te)); }