Java Code Examples for org.apache.hadoop.yarn.api.records.timeline.TimelineEntity#setStartTime()
The following examples show how to use
org.apache.hadoop.yarn.api.records.timeline.TimelineEntity#setStartTime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistoryEventTimelineConversion.java From tez with Apache License 2.0 | 6 votes |
private static TimelineEntity convertAMLaunchedEvent(AMLaunchedEvent event) { TimelineEntity atsEntity = new TimelineEntity(); atsEntity.setEntityId("tez_" + event.getApplicationAttemptId().toString()); atsEntity.setEntityType(EntityTypes.TEZ_APPLICATION_ATTEMPT.name()); atsEntity.addPrimaryFilter(ATSConstants.USER, event.getUser()); atsEntity.addPrimaryFilter(ATSConstants.APPLICATION_ID, event.getApplicationAttemptId().getApplicationId().toString()); atsEntity.setStartTime(event.getLaunchTime()); TimelineEvent launchEvt = new TimelineEvent(); launchEvt.setEventType(HistoryEventType.AM_LAUNCHED.name()); launchEvt.setTimestamp(event.getLaunchTime()); atsEntity.addEvent(launchEvt); atsEntity.addOtherInfo(ATSConstants.APP_SUBMIT_TIME, event.getAppSubmitTime()); atsEntity.addOtherInfo(ATSConstants.APPLICATION_ID, event.getApplicationAttemptId().getApplicationId().toString()); atsEntity.addOtherInfo(ATSConstants.APPLICATION_ATTEMPT_ID, event.getApplicationAttemptId().toString()); atsEntity.addOtherInfo(ATSConstants.USER, event.getUser()); return atsEntity; }
Example 2
Source File: HistoryEventTimelineConversion.java From tez with Apache License 2.0 | 6 votes |
private static TimelineEntity convertDAGSubmittedToDAGExtraInfoEntity(DAGSubmittedEvent event) { TimelineEntity atsEntity = new TimelineEntity(); atsEntity.setEntityId(event.getDagID().toString()); atsEntity.setEntityType(EntityTypes.TEZ_DAG_EXTRA_INFO.name()); atsEntity.addRelatedEntity(EntityTypes.TEZ_DAG_ID.name(), event.getDagID().toString()); TimelineEvent submitEvt = new TimelineEvent(); submitEvt.setEventType(HistoryEventType.DAG_SUBMITTED.name()); submitEvt.setTimestamp(event.getSubmitTime()); atsEntity.addEvent(submitEvt); atsEntity.setStartTime(event.getSubmitTime()); try { atsEntity.addOtherInfo(ATSConstants.DAG_PLAN, DAGUtils.convertDAGPlanToATSMap(event.getDAGPlan())); } catch (IOException e) { throw new TezUncheckedException(e); } return atsEntity; }
Example 3
Source File: HistoryEventTimelineConversion.java From tez with Apache License 2.0 | 6 votes |
private static TimelineEntity convertAppLaunchedEvent(AppLaunchedEvent event) { TimelineEntity atsEntity = new TimelineEntity(); atsEntity.setEntityId("tez_" + event.getApplicationId().toString()); atsEntity.setEntityType(EntityTypes.TEZ_APPLICATION.name()); atsEntity.addPrimaryFilter(ATSConstants.USER, event.getUser()); atsEntity.addOtherInfo(ATSConstants.CONFIG, DAGUtils.convertConfigurationToATSMap(event.getConf())); atsEntity.addOtherInfo(ATSConstants.APPLICATION_ID, event.getApplicationId().toString()); atsEntity.addOtherInfo(ATSConstants.USER, event.getUser()); atsEntity.setStartTime(event.getLaunchTime()); if (event.getVersion() != null) { atsEntity.addOtherInfo(ATSConstants.TEZ_VERSION, DAGUtils.convertTezVersionToATSMap(event.getVersion())); } atsEntity.addOtherInfo(ATSConstants.DAG_AM_WEB_SERVICE_VERSION, AMWebController.VERSION); return atsEntity; }
Example 4
Source File: TimelineStoreTestUtils.java From hadoop with Apache License 2.0 | 6 votes |
/** * Create a test entity */ protected static TimelineEntity createEntity(String entityId, String entityType, Long startTime, List<TimelineEvent> events, Map<String, Set<String>> relatedEntities, Map<String, Set<Object>> primaryFilters, Map<String, Object> otherInfo, String domainId) { TimelineEntity entity = new TimelineEntity(); entity.setEntityId(entityId); entity.setEntityType(entityType); entity.setStartTime(startTime); entity.setEvents(events); if (relatedEntities != null) { for (Entry<String, Set<String>> e : relatedEntities.entrySet()) { for (String v : e.getValue()) { entity.addRelatedEntity(e.getKey(), v); } } } else { entity.setRelatedEntities(null); } entity.setPrimaryFilters(primaryFilters); entity.setOtherInfo(otherInfo); entity.setDomainId(domainId); return entity; }
Example 5
Source File: TestTimelineClient.java From big-c with Apache License 2.0 | 6 votes |
private static TimelineEntity generateEntity() { TimelineEntity entity = new TimelineEntity(); entity.setEntityId("entity id"); entity.setEntityType("entity type"); entity.setStartTime(System.currentTimeMillis()); for (int i = 0; i < 2; ++i) { TimelineEvent event = new TimelineEvent(); event.setTimestamp(System.currentTimeMillis()); event.setEventType("test event type " + i); event.addEventInfo("key1", "val1"); event.addEventInfo("key2", "val2"); entity.addEvent(event); } entity.addRelatedEntity("test ref type 1", "test ref id 1"); entity.addRelatedEntity("test ref type 2", "test ref id 2"); entity.addPrimaryFilter("pkey1", "pval1"); entity.addPrimaryFilter("pkey2", "pval2"); entity.addOtherInfo("okey1", "oval1"); entity.addOtherInfo("okey2", "oval2"); entity.setDomainId("domain id 1"); return entity; }
Example 6
Source File: HistoryEventTimelineConversion.java From tez with Apache License 2.0 | 6 votes |
private static TimelineEntity convertContainerLaunchedEvent(ContainerLaunchedEvent event) { TimelineEntity atsEntity = new TimelineEntity(); atsEntity.setEntityId("tez_" + event.getContainerId().toString()); atsEntity.setEntityType(EntityTypes.TEZ_CONTAINER_ID.name()); atsEntity.addRelatedEntity(EntityTypes.TEZ_APPLICATION_ATTEMPT.name(), "tez_" + event.getApplicationAttemptId().toString()); atsEntity.addPrimaryFilter(ATSConstants.APPLICATION_ID, event.getApplicationAttemptId().getApplicationId().toString()); atsEntity.addOtherInfo(ATSConstants.CONTAINER_ID, event.getContainerId().toString()); atsEntity.setStartTime(event.getLaunchTime()); TimelineEvent launchEvt = new TimelineEvent(); launchEvt.setEventType(HistoryEventType.CONTAINER_LAUNCHED.name()); launchEvt.setTimestamp(event.getLaunchTime()); atsEntity.addEvent(launchEvt); return atsEntity; }
Example 7
Source File: TestTimelineWebServices.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testPostEntitiesWithPrimaryFilter() throws Exception { TimelineEntities entities = new TimelineEntities(); TimelineEntity entity = new TimelineEntity(); Map<String, Set<Object>> filters = new HashMap<String, Set<Object>>(); filters.put(TimelineStore.SystemFilter.ENTITY_OWNER.toString(), new HashSet<Object>()); entity.setPrimaryFilters(filters); entity.setEntityId("test id 6"); entity.setEntityType("test type 6"); entity.setStartTime(System.currentTimeMillis()); entities.addEntity(entity); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("timeline") .queryParam("user.name", "tester") .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .post(ClientResponse.class, entities); TimelinePutResponse putResposne = response.getEntity(TimelinePutResponse.class); Assert.assertEquals(0, putResposne.getErrors().size()); }
Example 8
Source File: TestTimelineClient.java From hadoop with Apache License 2.0 | 6 votes |
private static TimelineEntity generateEntity() { TimelineEntity entity = new TimelineEntity(); entity.setEntityId("entity id"); entity.setEntityType("entity type"); entity.setStartTime(System.currentTimeMillis()); for (int i = 0; i < 2; ++i) { TimelineEvent event = new TimelineEvent(); event.setTimestamp(System.currentTimeMillis()); event.setEventType("test event type " + i); event.addEventInfo("key1", "val1"); event.addEventInfo("key2", "val2"); entity.addEvent(event); } entity.addRelatedEntity("test ref type 1", "test ref id 1"); entity.addRelatedEntity("test ref type 2", "test ref id 2"); entity.addPrimaryFilter("pkey1", "pval1"); entity.addPrimaryFilter("pkey2", "pval2"); entity.addOtherInfo("okey1", "oval1"); entity.addOtherInfo("okey2", "oval2"); entity.setDomainId("domain id 1"); return entity; }
Example 9
Source File: TimelineStoreTestUtils.java From big-c with Apache License 2.0 | 6 votes |
/** * Create a test entity */ protected static TimelineEntity createEntity(String entityId, String entityType, Long startTime, List<TimelineEvent> events, Map<String, Set<String>> relatedEntities, Map<String, Set<Object>> primaryFilters, Map<String, Object> otherInfo, String domainId) { TimelineEntity entity = new TimelineEntity(); entity.setEntityId(entityId); entity.setEntityType(entityType); entity.setStartTime(startTime); entity.setEvents(events); if (relatedEntities != null) { for (Entry<String, Set<String>> e : relatedEntities.entrySet()) { for (String v : e.getValue()) { entity.addRelatedEntity(e.getKey(), v); } } } else { entity.setRelatedEntities(null); } entity.setPrimaryFilters(primaryFilters); entity.setOtherInfo(otherInfo); entity.setDomainId(domainId); return entity; }
Example 10
Source File: TestTimelineWebServices.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testPostEntities() throws Exception { TimelineEntities entities = new TimelineEntities(); TimelineEntity entity = new TimelineEntity(); entity.setEntityId("test id 1"); entity.setEntityType("test type 1"); entity.setStartTime(System.currentTimeMillis()); entity.setDomainId("domain_id_1"); entities.addEntity(entity); WebResource r = resource(); // No owner, will be rejected ClientResponse response = r.path("ws").path("v1").path("timeline") .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .post(ClientResponse.class, entities); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); assertEquals(ClientResponse.Status.FORBIDDEN, response.getClientResponseStatus()); response = r.path("ws").path("v1").path("timeline") .queryParam("user.name", "tester") .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .post(ClientResponse.class, entities); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); TimelinePutResponse putResposne = response.getEntity(TimelinePutResponse.class); Assert.assertNotNull(putResposne); Assert.assertEquals(0, putResposne.getErrors().size()); // verify the entity exists in the store response = r.path("ws").path("v1").path("timeline") .path("test type 1").path("test id 1") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNotNull(entity); Assert.assertEquals("test id 1", entity.getEntityId()); Assert.assertEquals("test type 1", entity.getEntityType()); }
Example 11
Source File: HistoryEventTimelineConversion.java From incubator-tez with Apache License 2.0 | 5 votes |
private static TimelineEntity convertTaskAttemptStartedEvent(TaskAttemptStartedEvent event) { TimelineEntity atsEntity = new TimelineEntity(); atsEntity.setEntityId(event.getTaskAttemptID().toString()); atsEntity.setEntityType(EntityTypes.TEZ_TASK_ATTEMPT_ID.name()); atsEntity.setStartTime(event.getStartTime()); atsEntity.addRelatedEntity(ATSConstants.NODE_ID, event.getNodeId().toString()); atsEntity.addRelatedEntity(ATSConstants.CONTAINER_ID, event.getContainerId().toString()); atsEntity.addRelatedEntity(EntityTypes.TEZ_TASK_ID.name(), event.getTaskAttemptID().getTaskID().toString()); atsEntity.addPrimaryFilter(EntityTypes.TEZ_DAG_ID.name(), event.getTaskAttemptID().getTaskID().getVertexID().getDAGId().toString()); atsEntity.addPrimaryFilter(EntityTypes.TEZ_VERTEX_ID.name(), event.getTaskAttemptID().getTaskID().getVertexID().toString()); atsEntity.addPrimaryFilter(EntityTypes.TEZ_TASK_ID.name(), event.getTaskAttemptID().getTaskID().toString()); TimelineEvent startEvt = new TimelineEvent(); startEvt.setEventType(HistoryEventType.TASK_ATTEMPT_STARTED.name()); startEvt.setTimestamp(event.getStartTime()); atsEntity.addEvent(startEvt); atsEntity.addOtherInfo(ATSConstants.START_TIME, event.getStartTime()); atsEntity.addOtherInfo(ATSConstants.IN_PROGRESS_LOGS_URL, event.getInProgressLogsUrl()); atsEntity.addOtherInfo(ATSConstants.COMPLETED_LOGS_URL, event.getCompletedLogsUrl()); return atsEntity; }
Example 12
Source File: HistoryEventTimelineConversion.java From incubator-tez with Apache License 2.0 | 5 votes |
private static TimelineEntity convertDAGSubmittedEvent(DAGSubmittedEvent event) { TimelineEntity atsEntity = new TimelineEntity(); atsEntity.setEntityId(event.getDagID().toString()); atsEntity.setEntityType(EntityTypes.TEZ_DAG_ID.name()); atsEntity.addRelatedEntity(EntityTypes.TEZ_APPLICATION_ATTEMPT.name(), "tez_" + event.getApplicationAttemptId().toString()); atsEntity.addRelatedEntity(ATSConstants.APPLICATION_ID, event.getApplicationAttemptId().getApplicationId().toString()); atsEntity.addRelatedEntity(ATSConstants.APPLICATION_ATTEMPT_ID, event.getApplicationAttemptId().toString()); atsEntity.addRelatedEntity(ATSConstants.USER, event.getUser()); TimelineEvent submitEvt = new TimelineEvent(); submitEvt.setEventType(HistoryEventType.DAG_SUBMITTED.name()); submitEvt.setTimestamp(event.getSubmitTime()); atsEntity.addEvent(submitEvt); atsEntity.setStartTime(event.getSubmitTime()); atsEntity.addPrimaryFilter(ATSConstants.USER, event.getUser()); atsEntity.addPrimaryFilter(ATSConstants.DAG_NAME, event.getDAGName()); try { atsEntity.addOtherInfo(ATSConstants.DAG_PLAN, DAGUtils.convertDAGPlanToATSMap(event.getDAGPlan())); } catch (IOException e) { throw new TezUncheckedException(e); } atsEntity.addOtherInfo(ATSConstants.APPLICATION_ID, event.getApplicationAttemptId().getApplicationId().toString()); return atsEntity; }
Example 13
Source File: HistoryEventTimelineConversion.java From tez with Apache License 2.0 | 5 votes |
private static TimelineEntity convertVertexInitializedEvent(VertexInitializedEvent event) { TimelineEntity atsEntity = new TimelineEntity(); atsEntity.setEntityId(event.getVertexID().toString()); atsEntity.setEntityType(EntityTypes.TEZ_VERTEX_ID.name()); atsEntity.addRelatedEntity(EntityTypes.TEZ_DAG_ID.name(), event.getVertexID().getDAGId().toString()); atsEntity.addPrimaryFilter(ATSConstants.APPLICATION_ID, event.getVertexID().getDAGId().getApplicationId().toString()); atsEntity.addPrimaryFilter(EntityTypes.TEZ_DAG_ID.name(), event.getVertexID().getDAGId().toString()); TimelineEvent initEvt = new TimelineEvent(); initEvt.setEventType(HistoryEventType.VERTEX_INITIALIZED.name()); initEvt.setTimestamp(event.getInitedTime()); atsEntity.addEvent(initEvt); atsEntity.setStartTime(event.getInitedTime()); atsEntity.addOtherInfo(ATSConstants.VERTEX_NAME, event.getVertexName()); atsEntity.addOtherInfo(ATSConstants.INIT_REQUESTED_TIME, event.getInitRequestedTime()); atsEntity.addOtherInfo(ATSConstants.INIT_TIME, event.getInitedTime()); atsEntity.addOtherInfo(ATSConstants.NUM_TASKS, event.getNumTasks()); atsEntity.addOtherInfo(ATSConstants.PROCESSOR_CLASS_NAME, event.getProcessorName()); if (event.getServicePluginInfo() != null) { atsEntity.addOtherInfo(ATSConstants.SERVICE_PLUGIN, DAGUtils.convertServicePluginToATSMap(event.getServicePluginInfo())); } return atsEntity; }
Example 14
Source File: TestTimelineWebServices.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testPostEntitiesToDefaultDomain() throws Exception { AdminACLsManager oldAdminACLsManager = timelineACLsManager.setAdminACLsManager(adminACLsManager); try { TimelineEntities entities = new TimelineEntities(); TimelineEntity entity = new TimelineEntity(); entity.setEntityId("test id 7"); entity.setEntityType("test type 7"); entity.setStartTime(System.currentTimeMillis()); entities.addEntity(entity); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("timeline") .queryParam("user.name", "anybody_1") .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .post(ClientResponse.class, entities); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); TimelinePutResponse putResposne = response.getEntity(TimelinePutResponse.class); Assert.assertNotNull(putResposne); Assert.assertEquals(0, putResposne.getErrors().size()); // verify the entity exists in the store response = r.path("ws").path("v1").path("timeline") .path("test type 7").path("test id 7") .queryParam("user.name", "any_body_2") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNotNull(entity); Assert.assertEquals("test id 7", entity.getEntityId()); Assert.assertEquals("test type 7", entity.getEntityType()); Assert.assertEquals(TimelineDataManager.DEFAULT_DOMAIN_ID, entity.getDomainId()); } finally { timelineACLsManager.setAdminACLsManager(oldAdminACLsManager); } }
Example 15
Source File: MemoryTimelineStore.java From big-c with Apache License 2.0 | 5 votes |
private static TimelineEntity maskFields( TimelineEntity entity, EnumSet<Field> fields) { // Conceal the fields that are not going to be exposed TimelineEntity entityToReturn = new TimelineEntity(); entityToReturn.setEntityId(entity.getEntityId()); entityToReturn.setEntityType(entity.getEntityType()); entityToReturn.setStartTime(entity.getStartTime()); entityToReturn.setDomainId(entity.getDomainId()); // Deep copy if (fields.contains(Field.EVENTS)) { entityToReturn.addEvents(entity.getEvents()); } else if (fields.contains(Field.LAST_EVENT_ONLY)) { entityToReturn.addEvent(entity.getEvents().get(0)); } else { entityToReturn.setEvents(null); } if (fields.contains(Field.RELATED_ENTITIES)) { entityToReturn.addRelatedEntities(entity.getRelatedEntities()); } else { entityToReturn.setRelatedEntities(null); } if (fields.contains(Field.PRIMARY_FILTERS)) { entityToReturn.addPrimaryFilters(entity.getPrimaryFilters()); } else { entityToReturn.setPrimaryFilters(null); } if (fields.contains(Field.OTHER_INFO)) { entityToReturn.addOtherInfo(entity.getOtherInfo()); } else { entityToReturn.setOtherInfo(null); } return entityToReturn; }
Example 16
Source File: TestTimelineWebServices.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testPostEntitiesToDefaultDomain() throws Exception { AdminACLsManager oldAdminACLsManager = timelineACLsManager.setAdminACLsManager(adminACLsManager); try { TimelineEntities entities = new TimelineEntities(); TimelineEntity entity = new TimelineEntity(); entity.setEntityId("test id 7"); entity.setEntityType("test type 7"); entity.setStartTime(System.currentTimeMillis()); entities.addEntity(entity); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("timeline") .queryParam("user.name", "anybody_1") .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .post(ClientResponse.class, entities); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); TimelinePutResponse putResposne = response.getEntity(TimelinePutResponse.class); Assert.assertNotNull(putResposne); Assert.assertEquals(0, putResposne.getErrors().size()); // verify the entity exists in the store response = r.path("ws").path("v1").path("timeline") .path("test type 7").path("test id 7") .queryParam("user.name", "any_body_2") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNotNull(entity); Assert.assertEquals("test id 7", entity.getEntityId()); Assert.assertEquals("test type 7", entity.getEntityType()); Assert.assertEquals(TimelineDataManager.DEFAULT_DOMAIN_ID, entity.getDomainId()); } finally { timelineACLsManager.setAdminACLsManager(oldAdminACLsManager); } }
Example 17
Source File: HistoryEventTimelineConversion.java From tez with Apache License 2.0 | 5 votes |
private static TimelineEntity convertTaskAttemptStartedEvent(TaskAttemptStartedEvent event) { TimelineEntity atsEntity = new TimelineEntity(); atsEntity.setEntityId(event.getTaskAttemptID().toString()); atsEntity.setEntityType(EntityTypes.TEZ_TASK_ATTEMPT_ID.name()); atsEntity.setStartTime(event.getStartTime()); atsEntity.addRelatedEntity(EntityTypes.TEZ_TASK_ID.name(), event.getTaskAttemptID().getTaskID().toString()); atsEntity.addPrimaryFilter(ATSConstants.APPLICATION_ID, event.getTaskAttemptID().getTaskID().getVertexID().getDAGId().getApplicationId().toString()); atsEntity.addPrimaryFilter(EntityTypes.TEZ_DAG_ID.name(), event.getTaskAttemptID().getTaskID().getVertexID().getDAGId().toString()); atsEntity.addPrimaryFilter(EntityTypes.TEZ_VERTEX_ID.name(), event.getTaskAttemptID().getTaskID().getVertexID().toString()); atsEntity.addPrimaryFilter(EntityTypes.TEZ_TASK_ID.name(), event.getTaskAttemptID().getTaskID().toString()); TimelineEvent startEvt = new TimelineEvent(); startEvt.setEventType(HistoryEventType.TASK_ATTEMPT_STARTED.name()); startEvt.setTimestamp(event.getStartTime()); atsEntity.addEvent(startEvt); atsEntity.addOtherInfo(ATSConstants.START_TIME, event.getStartTime()); if (event.getInProgressLogsUrl() != null) { atsEntity.addOtherInfo(ATSConstants.IN_PROGRESS_LOGS_URL, event.getInProgressLogsUrl()); } if (event.getCompletedLogsUrl() != null) { atsEntity.addOtherInfo(ATSConstants.COMPLETED_LOGS_URL, event.getCompletedLogsUrl()); } atsEntity.addOtherInfo(ATSConstants.NODE_ID, event.getNodeId().toString()); atsEntity.addOtherInfo(ATSConstants.NODE_HTTP_ADDRESS, event.getNodeHttpAddress()); atsEntity.addOtherInfo(ATSConstants.CONTAINER_ID, event.getContainerId().toString()); atsEntity.addOtherInfo(ATSConstants.STATUS, TaskAttemptState.RUNNING.name()); return atsEntity; }
Example 18
Source File: MemoryTimelineStore.java From hadoop with Apache License 2.0 | 5 votes |
private static TimelineEntity maskFields( TimelineEntity entity, EnumSet<Field> fields) { // Conceal the fields that are not going to be exposed TimelineEntity entityToReturn = new TimelineEntity(); entityToReturn.setEntityId(entity.getEntityId()); entityToReturn.setEntityType(entity.getEntityType()); entityToReturn.setStartTime(entity.getStartTime()); entityToReturn.setDomainId(entity.getDomainId()); // Deep copy if (fields.contains(Field.EVENTS)) { entityToReturn.addEvents(entity.getEvents()); } else if (fields.contains(Field.LAST_EVENT_ONLY)) { entityToReturn.addEvent(entity.getEvents().get(0)); } else { entityToReturn.setEvents(null); } if (fields.contains(Field.RELATED_ENTITIES)) { entityToReturn.addRelatedEntities(entity.getRelatedEntities()); } else { entityToReturn.setRelatedEntities(null); } if (fields.contains(Field.PRIMARY_FILTERS)) { entityToReturn.addPrimaryFilters(entity.getPrimaryFilters()); } else { entityToReturn.setPrimaryFilters(null); } if (fields.contains(Field.OTHER_INFO)) { entityToReturn.addOtherInfo(entity.getOtherInfo()); } else { entityToReturn.setOtherInfo(null); } return entityToReturn; }
Example 19
Source File: TestTimelineWebServices.java From big-c with Apache License 2.0 | 4 votes |
@Test public void testGetEntityWithYarnACLsEnabled() throws Exception { AdminACLsManager oldAdminACLsManager = timelineACLsManager.setAdminACLsManager(adminACLsManager); try { TimelineEntities entities = new TimelineEntities(); TimelineEntity entity = new TimelineEntity(); entity.setEntityId("test id 3"); entity.setEntityType("test type 3"); entity.setStartTime(System.currentTimeMillis()); entity.setDomainId("domain_id_1"); entities.addEntity(entity); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("timeline") .queryParam("user.name", "writer_user_1") .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .post(ClientResponse.class, entities); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); TimelinePutResponse putResponse = response.getEntity(TimelinePutResponse.class); Assert.assertEquals(0, putResponse.getErrors().size()); // verify the system data will not be exposed // 1. No field specification response = r.path("ws").path("v1").path("timeline") .path("test type 3").path("test id 3") .queryParam("user.name", "reader_user_1") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNull(entity.getPrimaryFilters().get( TimelineStore.SystemFilter.ENTITY_OWNER.toString())); // 2. other field response = r.path("ws").path("v1").path("timeline") .path("test type 3").path("test id 3") .queryParam("fields", "relatedentities") .queryParam("user.name", "reader_user_1") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNull(entity.getPrimaryFilters().get( TimelineStore.SystemFilter.ENTITY_OWNER.toString())); // 3. primaryfilters field response = r.path("ws").path("v1").path("timeline") .path("test type 3").path("test id 3") .queryParam("fields", "primaryfilters") .queryParam("user.name", "reader_user_1") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNull(entity.getPrimaryFilters().get( TimelineStore.SystemFilter.ENTITY_OWNER.toString())); // get entity with other user response = r.path("ws").path("v1").path("timeline") .path("test type 3").path("test id 3") .queryParam("user.name", "reader_user_2") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); assertEquals(ClientResponse.Status.NOT_FOUND, response.getClientResponseStatus()); } finally { timelineACLsManager.setAdminACLsManager(oldAdminACLsManager); } }
Example 20
Source File: TestTimelineWebServices.java From hadoop with Apache License 2.0 | 4 votes |
@Test public void testGetEntityWithYarnACLsEnabled() throws Exception { AdminACLsManager oldAdminACLsManager = timelineACLsManager.setAdminACLsManager(adminACLsManager); try { TimelineEntities entities = new TimelineEntities(); TimelineEntity entity = new TimelineEntity(); entity.setEntityId("test id 3"); entity.setEntityType("test type 3"); entity.setStartTime(System.currentTimeMillis()); entity.setDomainId("domain_id_1"); entities.addEntity(entity); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("timeline") .queryParam("user.name", "writer_user_1") .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .post(ClientResponse.class, entities); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); TimelinePutResponse putResponse = response.getEntity(TimelinePutResponse.class); Assert.assertEquals(0, putResponse.getErrors().size()); // verify the system data will not be exposed // 1. No field specification response = r.path("ws").path("v1").path("timeline") .path("test type 3").path("test id 3") .queryParam("user.name", "reader_user_1") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNull(entity.getPrimaryFilters().get( TimelineStore.SystemFilter.ENTITY_OWNER.toString())); // 2. other field response = r.path("ws").path("v1").path("timeline") .path("test type 3").path("test id 3") .queryParam("fields", "relatedentities") .queryParam("user.name", "reader_user_1") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNull(entity.getPrimaryFilters().get( TimelineStore.SystemFilter.ENTITY_OWNER.toString())); // 3. primaryfilters field response = r.path("ws").path("v1").path("timeline") .path("test type 3").path("test id 3") .queryParam("fields", "primaryfilters") .queryParam("user.name", "reader_user_1") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); entity = response.getEntity(TimelineEntity.class); Assert.assertNull(entity.getPrimaryFilters().get( TimelineStore.SystemFilter.ENTITY_OWNER.toString())); // get entity with other user response = r.path("ws").path("v1").path("timeline") .path("test type 3").path("test id 3") .queryParam("user.name", "reader_user_2") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); assertEquals(ClientResponse.Status.NOT_FOUND, response.getClientResponseStatus()); } finally { timelineACLsManager.setAdminACLsManager(oldAdminACLsManager); } }