use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity in project hadoop by apache.
the class TestTimelineReaderWebServices method testGetEntityAllFields.
@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(TimelineReaderManager.UID_KEY));
// Includes UID.
assertEquals(3, entity.getInfo().size());
assertEquals(2, entity.getEvents().size());
} finally {
client.destroy();
}
}
use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity in project hadoop by apache.
the class TestTimelineReaderWebServices method testGetEntitiesByEventFilters.
@Test
public void testGetEntitiesByEventFilters() throws Exception {
Client client = createClient();
try {
URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app?" + "eventfilters=event_2,event_4");
ClientResponse 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(1, entities.size());
assertTrue("Entity with id_3 should have been present in response.", entities.contains(newEntity("app", "id_3")));
} finally {
client.destroy();
}
}
use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity in project hadoop by apache.
the class TestTimelineReaderWebServices method testGetAppAttempt.
@Test
public void testGetAppAttempt() throws Exception {
Client client = createClient();
try {
URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/" + "YARN_APPLICATION_ATTEMPT/app-attempt-1");
ClientResponse resp = getResponse(client, uri);
TimelineEntity entities1 = resp.getEntity(new GenericType<TimelineEntity>() {
});
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
assertNotNull(entities1);
uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/appattempts/app-attempt-1");
resp = getResponse(client, uri);
TimelineEntity entities2 = resp.getEntity(new GenericType<TimelineEntity>() {
});
assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType());
assertNotNull(entities2);
assertEquals(entities1, entities2);
} finally {
client.destroy();
}
}
use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity in project hadoop by apache.
the class TestTimelineReaderWebServices method testGetEntityCustomFields.
@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(TimelineReaderManager.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();
}
}
use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity in project hadoop by apache.
the class TimelineReaderWebServices method getFlowRunApps.
/**
* Return a list of apps for given UID which is a delimited string containing
* clusterid, userid, flow name and flowrun id. If number of matching apps are
* more than the limit, most recent apps till the limit is reached, will be
* returned.
*
* @param req Servlet request.
* @param res Servlet response.
* @param uId a delimited string containing clusterid, userid, flow name and
* flowrun id which are extracted from UID and then used to query backend.
* (Mandatory path param).
* @param limit If specified, defines the number of apps to return. The
* maximum possible value for limit can be {@link Long#MAX_VALUE}. If it
* is not specified or has a value less than 0, then limit will be
* considered as 100. (Optional query param).
* @param createdTimeStart If specified, matched apps should not be created
* before this timestamp(Optional query param).
* @param createdTimeEnd If specified, matched apps should not be created
* after this timestamp(Optional query param).
* @param relatesTo If specified, matched apps should relate to given
* entities associated with a entity type. relatesto is a comma separated
* list in the format [entitytype]:[entityid1]:[entityid2]... (Optional
* query param).
* @param isRelatedTo If specified, matched apps should be related to given
* entities associated with a entity type. relatesto is a comma separated
* list in the format [entitytype]:[entityid1]:[entityid2]... (Optional
* query param).
* @param infofilters If specified, matched apps should have exact matches
* to the given info represented as key-value pairs. This is represented
* as infofilters=info1:value1,info2:value2... (Optional query param).
* @param conffilters If specified, matched apps should have exact matches
* to the given configs represented as key-value pairs. This is
* represented as conffilters=conf1:value1,conf2:value2... (Optional query
* param).
* @param metricfilters If specified, matched apps should contain the given
* metrics. This is represented as metricfilters=metricid1, metricid2...
* (Optional query param).
* @param eventfilters If specified, matched apps should contain the given
* events. This is represented as eventfilters=eventid1, eventid2...
* @param confsToRetrieve If specified, defines which configurations to
* retrieve and send back in response. These configs will be retrieved
* irrespective of whether configs are specified in fields to retrieve or
* not.
* @param metricsToRetrieve If specified, defines which metrics to retrieve
* and send back in response. These metrics will be retrieved
* irrespective of whether metrics are specified in fields to retrieve or
* not.
* @param fields Specifies which fields of the app entity object to retrieve,
* see {@link Field}. All fields will be retrieved if fields=ALL. If not
* specified, 3 fields i.e. entity type(equivalent to YARN_APPLICATION),
* app id and app created time is returned(Optional query param).
* @param metricsLimit If specified, defines the number of metrics to return.
* Considered only if fields contains METRICS/ALL or metricsToRetrieve is
* specified. Ignored otherwise. The maximum possible value for
* metricsLimit can be {@link Integer#MAX_VALUE}. If it is not specified
* or has a value less than 1, and metrics have to be retrieved, then
* metricsLimit will be considered as 1 i.e. latest single value of
* metric(s) will be returned. (Optional query param).
*
* @return If successful, a HTTP 200(OK) response having a JSON representing
* a set of <cite>TimelineEntity</cite> instances representing apps is
* returned.<br>
* On failures,<br>
* If any problem occurs in parsing request or UID is incorrect,
* HTTP 400(Bad Request) is returned.<br>
* For all other errors while retrieving data, HTTP 500(Internal Server
* Error) is returned.
*/
@GET
@Path("/run-uid/{uid}/apps")
@Produces(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8)
public Set<TimelineEntity> getFlowRunApps(@Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam("uid") String uId, @QueryParam("limit") String limit, @QueryParam("createdtimestart") String createdTimeStart, @QueryParam("createdtimeend") String createdTimeEnd, @QueryParam("relatesto") String relatesTo, @QueryParam("isrelatedto") String isRelatedTo, @QueryParam("infofilters") String infofilters, @QueryParam("conffilters") String conffilters, @QueryParam("metricfilters") String metricfilters, @QueryParam("eventfilters") String eventfilters, @QueryParam("confstoretrieve") String confsToRetrieve, @QueryParam("metricstoretrieve") String metricsToRetrieve, @QueryParam("fields") String fields, @QueryParam("metricslimit") String metricsLimit) {
String url = req.getRequestURI() + (req.getQueryString() == null ? "" : QUERY_STRING_SEP + req.getQueryString());
UserGroupInformation callerUGI = TimelineReaderWebServicesUtils.getUser(req);
LOG.info("Received URL " + url + " from user " + TimelineReaderWebServicesUtils.getUserName(callerUGI));
long startTime = Time.monotonicNow();
init(res);
TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
Set<TimelineEntity> entities = null;
try {
TimelineReaderContext context = TimelineUIDConverter.FLOWRUN_UID.decodeUID(uId);
if (context == null) {
throw new BadRequestException("Incorrect UID " + uId);
}
context.setEntityType(TimelineEntityType.YARN_APPLICATION.toString());
entities = timelineReaderManager.getEntities(context, TimelineReaderWebServicesUtils.createTimelineEntityFilters(limit, createdTimeStart, createdTimeEnd, relatesTo, isRelatedTo, infofilters, conffilters, metricfilters, eventfilters), TimelineReaderWebServicesUtils.createTimelineDataToRetrieve(confsToRetrieve, metricsToRetrieve, fields, metricsLimit));
} catch (Exception e) {
handleException(e, url, startTime, "createdTime start/end or limit or flowrunid");
}
long endTime = Time.monotonicNow();
if (entities == null) {
entities = Collections.emptySet();
}
LOG.info("Processed URL " + url + " (Took " + (endTime - startTime) + " ms.)");
return entities;
}
Aggregations