@Test public void testGetEntityCustomFields() throws Exception { // Specified fields in addition to default view will be returned. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO, Field.CONFIGS, Field.METRICS), null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(3, result.getConfigs().size()); Assert.assertEquals(3, result.getMetrics().size()); Assert.assertEquals(2, result.getInfo().size()); // No events will be returned Assert.assertEquals(0, result.getEvents().size()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Identifier)) { return false; } Identifier other = (Identifier) obj; if (id == null) { if (other.getId() != null) { return false; } } else if (!id.equals(other.getId())) { return false; } if (type == null) { if (other.getType() != null) { return false; } } else if (!type.equals(other.getType())) { return false; } return true; } }
Assert.assertEquals(flow2.getType(), app1.getParent().getType()); Assert.assertEquals(flow2.getId(), app1.getParent().getId()); app1.addInfo(ApplicationEntity.PARENT_INFO_KEY, "invalid parent object"); try { Assert.assertEquals(1, app1.getChildren().size()); Assert.assertEquals( appAttempt.getType(), app1.getChildren().iterator().next().getType()); Assert.assertEquals( appAttempt.getId(), app1.getChildren().iterator().next().getId()); app1.addInfo(ApplicationEntity.CHILDREN_INFO_KEY, Collections.singletonList("invalid children set"));
@Test public void testGetEntityDefaultView() throws Exception { // If no fields are specified, entity is returned with default view i.e. // only the id, type and created time. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(0, result.getConfigs().size()); Assert.assertEquals(0, result.getMetrics().size()); }
@Test public void testGetEntityAllFields() throws Exception { // All fields of TimelineEntity will be returned. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.ALL), null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(3, result.getConfigs().size()); Assert.assertEquals(3, result.getMetrics().size()); // All fields including events will be returned. Assert.assertEquals(2, result.getEvents().size()); }
public TimelineEntity() { identifier = new Identifier(); }
/** This test checks whether we can handle commas in app flow mapping csv. */ @Test public void testAppFlowMappingCsv() throws Exception { // Test getting an entity by cluster and app where flow entry // in app flow mapping csv has commas. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", null, null, null, "app2", "app", "id_5"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_5")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502050L, result.getCreatedTime()); }
@Test public void testGetEntityByClusterAndApp() throws Exception { // Cluster and AppId should be enough to get an entity. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", null, null, null, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(0, result.getConfigs().size()); Assert.assertEquals(0, result.getMetrics().size()); }
public void addChild(String type, String id) { addChild(new Identifier(type, id)); }
@Override public int hashCode() { return getIdentifier().hashCode(); }
private static TimelineEntity newEntity(String type, String id) { TimelineEntity entity = new TimelineEntity(); entity.setIdentifier(new TimelineEntity.Identifier(type, id)); return entity; }
public void setParent(Identifier parent) { validateParent(parent.getType()); addInfo(PARENT_INFO_KEY, parent); }
public String toString() { if (real == null) { return identifier.toString(); } else { return real.toString(); } }
private static ContainerEntity createContainerEntity( ContainerId containerId) { ContainerEntity entity = new ContainerEntity(); entity.setId(containerId.toString()); entity.setParent(new Identifier(TimelineEntityType.YARN_APPLICATION_ATTEMPT .name(), containerId.getApplicationAttemptId().toString())); return entity; }
private static ApplicationAttemptEntity createAppAttemptEntity( ApplicationAttemptId appAttemptId) { ApplicationAttemptEntity entity = new ApplicationAttemptEntity(); entity.setId(appAttemptId.toString()); entity.setParent(new Identifier(TimelineEntityType.YARN_APPLICATION.name(), appAttemptId.getApplicationId().toString())); return entity; }
public void setParent(String type, String id) { setParent(new Identifier(type, id)); }
private static ContainerEntity createContainerEntity( ContainerId containerId) { ContainerEntity entity = new ContainerEntity(); entity.setId(containerId.toString()); Identifier parentIdentifier = new Identifier(); parentIdentifier .setType(TimelineEntityType.YARN_APPLICATION_ATTEMPT.name()); parentIdentifier.setId(containerId.getApplicationAttemptId().toString()); entity.setParent(parentIdentifier); return entity; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof TimelineEntity)) { return false; } TimelineEntity other = (TimelineEntity) obj; return getIdentifier().equals(other.getIdentifier()); }
private void validateChild(Identifier child, TimelineEntityType thisType) { TimelineEntityType childType = TimelineEntityType.valueOf(child.getType()); if (!thisType.isChild(childType)) { throw new IllegalArgumentException( child.getType() + " is not the acceptable child of " + this.getType()); } } }