@XmlElement(name = "id") public String getId() { if (real == null) { return identifier.id; } else { return real.getId(); } }
@Override public int compareTo(TimelineEntity other) { int comparison = getType().compareTo(other.getType()); if (comparison == 0) { if (getIdPrefix() > other.getIdPrefix()) { // Descending order by entity id prefix return -1; } else if (getIdPrefix() < other.getIdPrefix()) { return 1; } else { return getId().compareTo(other.getId()); } } else { return comparison; } }
public boolean isValid() { return (getId() != null && getType() != null); }
EntityRowKey entityRowKey = new EntityRowKey(clusterId, userId, flowName, flowRunId, appId, te.getType(), te.getIdPrefix(), te.getId()); rowKey = entityRowKey.getRowKey(); store(rowKey, te, flowVersion, Tables.ENTITY_TABLE); SubApplicationRowKey subApplicationRowKey = new SubApplicationRowKey(subApplicationUser, clusterId, te.getType(), te.getIdPrefix(), te.getId(), userId); rowKey = subApplicationRowKey.getRowKey(); store(rowKey, te, flowVersion, Tables.SUBAPPLICATION_TABLE);
@XmlElement(name = "id") @Override public String getId() { // flow activity: cluster/day/user@flow_name String id = super.getId(); if (id == null) { StringBuilder sb = new StringBuilder(); sb.append(getCluster()); sb.append('/'); sb.append(getDate().getTime()); sb.append('/'); sb.append(getUser()); sb.append('@'); sb.append(getFlowName()); id = sb.toString(); setId(id); } return id; }
private static void writeEntityFile(TimelineEntity entity, File dir) throws Exception { if (!dir.exists()) { if (!dir.mkdirs()) { throw new IOException("Could not create directories for " + dir); } } String fileName = dir.getAbsolutePath() + File.separator + entity.getId() + ".thist"; try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)))){ out.println(TimelineUtils.dumpTimelineRecordtoJSON(entity)); out.write("\n"); out.close(); } }
private void printReceivedEntities() { for (int i = 0; i < client.getNumOfTimelineEntitiesPublished(); i++) { TimelineEntities publishedEntities = client.getPublishedEntities(i); StringBuilder entitiesPerPublish = new StringBuilder(); for (TimelineEntity entity : publishedEntities.getEntities()) { entitiesPerPublish.append(entity.getId()); entitiesPerPublish.append(","); } LOG.info("Entities Published @ index " + i + " : " + entitiesPerPublish.toString()); } }
private static void verifyEntity(File entityTypeDir, String id, String type) throws IOException { File entityFile = new File(entityTypeDir, id + FileSystemTimelineWriterImpl.TIMELINE_SERVICE_STORAGE_EXTENSION); assertTrue(entityFile.exists()); TimelineEntity entity = readEntityFile(entityFile); assertNotNull(entity); assertEquals(id, entity.getId()); assertEquals(type, entity.getType()); }
TimelineEntity timelineEntity = publishedEntities.getEntities() .get(publishedEntities.getEntities().size() - 1); if (!timelineEntity.getId().equals("19")) { Thread.sleep(2 * TIME_TO_SLEEP); TimelineEntity timelineEntity = publishedEntities.getEntities() .get(publishedEntities.getEntities().size() - 1); Assert.assertEquals("", "19", timelineEntity.getId());
@Test public void testGetEntitiesWithLimit() throws Exception { Set<TimelineEntity> result = reader.getEntities( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters.Builder().entityLimit(2L).build(), new TimelineDataToRetrieve()); Assert.assertEquals(2, result.size()); // Needs to be rewritten once hashcode and equals for // TimelineEntity is implemented // Entities with id_1 and id_4 should be returned, // based on created time, descending. for (TimelineEntity entity : result) { if (!entity.getId().equals("id_1") && !entity.getId().equals("id_4")) { Assert.fail("Entity not sorted by created time"); } } result = reader.getEntities( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters.Builder().entityLimit(3L).build(), new TimelineDataToRetrieve()); // Even though 2 entities out of 4 have same created time, one entity // is left out due to limit Assert.assertEquals(3, result.size()); }
@Test public void testASyncCallMerge() throws Exception { client.setSleepBeforeReturn(true); try { client.putEntitiesAsync(generateEntity("1")); Thread.sleep(TIME_TO_SLEEP / 2); // by the time first put response comes push 2 entities in the queue client.putEntitiesAsync(generateEntity("2")); client.putEntitiesAsync(generateEntity("3")); } catch (YarnException e) { Assert.fail("Exception is not expected"); } for (int i = 0; i < 4; i++) { if (client.getNumOfTimelineEntitiesPublished() == 2) { break; } Thread.sleep(TIME_TO_SLEEP); } Assert.assertEquals("two merged TimelineEntities needs to be published", 2, client.getNumOfTimelineEntitiesPublished()); TimelineEntities secondPublishedEntities = client.getPublishedEntities(1); Assert.assertEquals( "Merged TimelineEntities Object needs to 2 TimelineEntity Object", 2, secondPublishedEntities.getEntities().size()); Assert.assertEquals("Order of Async Events Needs to be FIFO", "2", secondPublishedEntities.getEntities().get(0).getId()); Assert.assertEquals("Order of Async Events Needs to be FIFO", "3", secondPublishedEntities.getEntities().get(1).getId()); }
@Test public void testGetEntityCustomFields() throws Exception { Client client = createClient(); try { // Fields are case insensitive. URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app/id_1?" + "fields=CONFIGS,Metrics,info"); ClientResponse resp = getResponse(client, uri); TimelineEntity entity = resp.getEntity(TimelineEntity.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString()); assertNotNull(entity); assertEquals("id_1", entity.getId()); assertEquals("app", entity.getType()); assertEquals(3, entity.getConfigs().size()); assertEquals(3, entity.getMetrics().size()); assertTrue("UID should be present", entity.getInfo().containsKey(TimelineReaderUtils.UID_KEY)); // Includes UID. assertEquals(3, entity.getInfo().size()); // No events will be returned as events are not part of fields. assertEquals(0, entity.getEvents().size()); } finally { client.destroy(); } }
if (!entity.getId().equals("id_4")) { Assert.fail("Incorrect filtering based on created time range"); Assert.assertEquals(3, result.size()); for (TimelineEntity entity : result) { if (entity.getId().equals("id_4")) { Assert.fail("Incorrect filtering based on created time range"); Assert.assertEquals(1, result.size()); for (TimelineEntity entity : result) { if (!entity.getId().equals("id_4")) { Assert.fail("Incorrect filtering based on created time range");
@Test public void testGetEntityAllFields() throws Exception { Client client = createClient(); try { URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app/id_1?" + "fields=ALL"); ClientResponse resp = getResponse(client, uri); TimelineEntity entity = resp.getEntity(TimelineEntity.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString()); assertNotNull(entity); assertEquals("id_1", entity.getId()); assertEquals("app", entity.getType()); assertEquals(3, entity.getConfigs().size()); assertEquals(3, entity.getMetrics().size()); assertTrue("UID should be present", entity.getInfo().containsKey(TimelineReaderUtils.UID_KEY)); // Includes UID. assertEquals(3, entity.getInfo().size()); assertEquals(2, entity.getEvents().size()); } finally { client.destroy(); } }
@Test public void testQueryWithoutCluster() throws Exception { Client client = createClient(); try { URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/apps/app1/entities/app/id_1"); ClientResponse resp = getResponse(client, uri); TimelineEntity entity = resp.getEntity(TimelineEntity.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString()); assertNotNull(entity); assertEquals("id_1", entity.getId()); assertEquals("app", entity.getType()); uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/apps/app1/entities/app"); resp = getResponse(client, uri); Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>(){}); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString()); assertNotNull(entities); assertEquals(4, entities.size()); } finally { client.destroy(); } }
secondPublishedEntities.getEntities().size()); Assert.assertEquals("Order of Async Events Needs to be FIFO", "2", secondPublishedEntities.getEntities().get(0).getId()); Assert.assertEquals("Order of Async Events Needs to be FIFO", "3", secondPublishedEntities.getEntities().get(1).getId()); thirdPublishedEntities.getEntities().size()); Assert.assertEquals("Expected last sync Event is not proper", "4", thirdPublishedEntities.getEntities().get(0).getId());
@Test public void testGetEntityDefaultView() throws Exception { Client client = createClient(); try { URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app/id_1"); ClientResponse resp = getResponse(client, uri); TimelineEntity entity = resp.getEntity(TimelineEntity.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString()); assertNotNull(entity); assertEquals("id_1", entity.getId()); assertEquals("app", entity.getType()); assertEquals((Long)1425016502000L, entity.getCreatedTime()); // Default view i.e. when no fields are specified, entity contains only // entity id, entity type and created time. assertEquals(0, entity.getConfigs().size()); assertEquals(0, entity.getMetrics().size()); } finally { client.destroy(); } }
@Test public void testGetEntityWithUserAndFlowInfo() throws Exception { Client client = createClient(); try { URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app/id_1?" + "userid=user1&flowname=flow1&flowrunid=1"); ClientResponse resp = getResponse(client, uri); TimelineEntity entity = resp.getEntity(TimelineEntity.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString()); assertNotNull(entity); assertEquals("id_1", entity.getId()); assertEquals("app", entity.getType()); assertEquals((Long)1425016502000L, entity.getCreatedTime()); } finally { client.destroy(); } }
case APPLICATION_TABLE: ColumnRWHelper.store(rowKey, applicationTable, ApplicationColumn.ID, null, te.getId()); ColumnRWHelper.store(rowKey, applicationTable, ApplicationColumn.CREATED_TIME, null, te.getCreatedTime()); case ENTITY_TABLE: ColumnRWHelper.store(rowKey, entityTable, EntityColumn.ID, null, te.getId()); ColumnRWHelper.store(rowKey, entityTable, EntityColumn.TYPE, null, te.getType()); case SUBAPPLICATION_TABLE: ColumnRWHelper.store(rowKey, subApplicationTable, SubApplicationColumn.ID, null, te.getId()); ColumnRWHelper.store(rowKey, subApplicationTable, SubApplicationColumn.TYPE, null, te.getType());