Example usage for org.apache.hadoop.yarn.api.records.timeline TimelineEntity getRelatedEntities

List of usage examples for org.apache.hadoop.yarn.api.records.timeline TimelineEntity getRelatedEntities

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records.timeline TimelineEntity getRelatedEntities.

Prototype

public Map<String, Set<String>> getRelatedEntities() 

Source Link

Document

Get the related entities

Usage

From source file:org.apache.tez.dag.history.logging.ats.TestHistoryEventTimelineConversion.java

License:Apache License

@Test(timeout = 5000)
public void testConvertTaskAttemptStartedEvent() {
    long startTime = random.nextLong();
    TaskAttemptStartedEvent event = new TaskAttemptStartedEvent(tezTaskAttemptID, "v1", startTime, containerId,
            nodeId, "inProgressURL", "logsURL", "nodeHttpAddress");

    TimelineEntity timelineEntity = HistoryEventTimelineConversion.convertToTimelineEntity(event);
    Assert.assertEquals(EntityTypes.TEZ_TASK_ATTEMPT_ID.name(), timelineEntity.getEntityType());
    Assert.assertEquals(tezTaskAttemptID.toString(), timelineEntity.getEntityId());

    Assert.assertEquals(startTime, timelineEntity.getStartTime().longValue());

    Assert.assertEquals(3, timelineEntity.getRelatedEntities().size());
    Assert.assertTrue(//from   www  .j a  v a  2  s  .c o  m
            timelineEntity.getRelatedEntities().get(ATSConstants.NODE_ID).contains(nodeId.toString()));
    Assert.assertTrue(timelineEntity.getRelatedEntities().get(ATSConstants.CONTAINER_ID)
            .contains(containerId.toString()));
    Assert.assertTrue(timelineEntity.getRelatedEntities().get(EntityTypes.TEZ_TASK_ID.name())
            .contains(tezTaskID.toString()));

    Assert.assertEquals(1, timelineEntity.getEvents().size());
    TimelineEvent timelineEvent = timelineEntity.getEvents().get(0);
    Assert.assertEquals(HistoryEventType.TASK_ATTEMPT_STARTED.name(), timelineEvent.getEventType());
    Assert.assertEquals(startTime, timelineEvent.getTimestamp());

    Assert.assertEquals(4, timelineEntity.getPrimaryFilters().size());
    Assert.assertTrue(timelineEntity.getPrimaryFilters().get(ATSConstants.APPLICATION_ID)
            .contains(applicationId.toString()));
    Assert.assertTrue(timelineEntity.getPrimaryFilters().get(EntityTypes.TEZ_DAG_ID.name())
            .contains(tezDAGID.toString()));
    Assert.assertTrue(timelineEntity.getPrimaryFilters().get(EntityTypes.TEZ_VERTEX_ID.name())
            .contains(tezVertexID.toString()));
    Assert.assertTrue(timelineEntity.getPrimaryFilters().get(EntityTypes.TEZ_TASK_ID.name())
            .contains(tezTaskID.toString()));

    Assert.assertTrue(timelineEntity.getOtherInfo().containsKey(ATSConstants.START_TIME));
    Assert.assertEquals("inProgressURL", timelineEntity.getOtherInfo().get(ATSConstants.IN_PROGRESS_LOGS_URL));
    Assert.assertEquals("logsURL", timelineEntity.getOtherInfo().get(ATSConstants.COMPLETED_LOGS_URL));
    Assert.assertEquals(nodeId.toString(), timelineEntity.getOtherInfo().get(ATSConstants.NODE_ID));
    Assert.assertEquals(containerId.toString(), timelineEntity.getOtherInfo().get(ATSConstants.CONTAINER_ID));
    Assert.assertEquals("nodeHttpAddress", timelineEntity.getOtherInfo().get(ATSConstants.NODE_HTTP_ADDRESS));
}

From source file:org.Microsoft.Telemetry.ServiceInformation.java

private void putToLog(TimelineEntity entity) throws Exception {

    try {/*from  w w w .jav a  2  s . c  o m*/

        WriteToFileLog("Entity Type  :", entity.getEntityType());

        WriteToFileLog("Entity ID  :", entity.getEntityId());

        WriteToFileLog("Domain ID  :", entity.getDomainId());

        if (entity.getStartTime() != null) {
            WriteToFileLog("Start Time :", CastFromTimeToStringFormat(entity.getStartTime()));
        }

        // print all events of Entity
        WriteToFileLog("\tprint all events   ", "");

        LOG.info(PATTERN_LOG_INFO + " print all events of Entity Name :" + String.format(
                "Entity ID :%s , Entity Type : %s )\n\n", entity.getEntityId(), entity.getEntityType()));

        if (entity.getEvents() != null) {
            List<TimelineEvent> events = entity.getEvents();

            WriteToFileLog("Start List of events of  ( ", String.format(
                    "Entity ID :%s , Entity Type : %s )\n\n", entity.getEntityId(), entity.getEntityType()));

            for (TimelineEvent event : events) {

                WriteToFileLog("\tEvent Type  :", event.getEventType() + ",");
                WriteToFileLog("\tTime Stamp  :", CastFromTimeToStringFormat(event.getTimestamp()) + ",");

                if (event.getEventInfo() != null) {
                    WriteToFileLog("\tprint all Event Info  ", "");
                    // Get an iterator
                    Set set = event.getEventInfo().entrySet();

                    Iterator iter = set.iterator();

                    if (set.size() > 0) {
                        WriteToFileLog("\t\tStart List Event Info  ", "");
                    }

                    while (iter.hasNext()) {
                        // Display elements
                        Map.Entry me = (Map.Entry) iter.next();

                        //sed information to history file
                        WriteObjectToLog("\t\t { Key : " + me.getKey() + ", Value: ", me.getValue());

                    }
                    if (set.size() > 0) {
                        WriteToFileLog("\n\t\tEnd List Event Info  ", "");
                    }
                }

            }
            WriteToFileLog("End List of events of  :", entity.getEntityType() + "\n\n");
        } else {
            LOG.info(PATTERN_LOG_INFO + "variable  events of entity is null ");
        }

        // print all Related Entities of Entity
        WriteToFileLog("\tprint all Related Entities   ", "");
        LOG.info(PATTERN_LOG_INFO + "print all Related Entities of Entity Name :" + String.format(
                "Entity ID :%s , Entity Type : %s )\n\n", entity.getEntityId(), entity.getEntityType()));
        if (entity.getRelatedEntities() != null) {
            //Map<String, Set<String>> RelatedEntities = entity.getRelatedEntities();

            WriteToFileLog("Start List of Related Entities of  ( ", String.format(
                    "Entity ID :%s , Entity Type : %s )\n\n", entity.getEntityId(), entity.getEntityType()));

            Set set = entity.getRelatedEntities().entrySet();

            Iterator iter = set.iterator();

            if (set.size() > 0) {
                WriteToFileLog("\t\tStart List Related Entities  ", "");
            }
            while (iter.hasNext()) {
                // Display elements
                Map.Entry me = (Map.Entry) iter.next();

                //send information to history file
                Set<String> setcoll = (Set<String>) me.getValue();

                if (setcoll.size() > 0) {
                    WriteToFileLog("\t\t { Key: (" + me.getKey() + " )  ", "\n\t\t\t[");
                } else {
                    WriteToFileLog("\t\t { Key: (" + me.getKey() + " )  ", "\n\t\t\t Empty Value");
                }
                //over all parts of set<string>
                for (String str : setcoll) {
                    WriteToFileLog("\t\t\t", str + ",");
                }
                WriteToFileLog("\n\t\t\t]", "\n}");

            }
            if (set.size() > 0) {
                WriteToFileLog("\t\tEnd List Related Entities  ", "");
            }
            WriteToFileLog("\t\t}", "");
            WriteToFileLog("End List of Related Entities  of  :", entity.getEntityType() + "\n\n");

        } else {
            LOG.info(PATTERN_LOG_INFO + "variable  Related Entities is null ");
        }

        // print all Primary Filters of Entity
        WriteToFileLog("\tprint all Primary Filters   ", "");
        LOG.info(PATTERN_LOG_INFO + "print all Primary Filters of Entity Name :" + String.format(
                "Entity ID :%s , Entity Type : %s )\n\n", entity.getEntityId(), entity.getEntityType()));

        if (entity.getPrimaryFilters() != null) {
            //Map<String, Set<Object>> PrimaryFilters = entity.getRelatedEntities();

            WriteToFileLog("Start List of Primary Filters of  ( ", String.format(
                    "Entity ID :%s , Entity Type : %s )\n\n", entity.getEntityId(), entity.getEntityType()));

            Set set = entity.getPrimaryFilters().entrySet();

            Iterator iter = set.iterator();

            if (set.size() > 0) {
                WriteToFileLog("\t\tStart List Primary Filters   ", "");
            }
            while (iter.hasNext()) {
                // Display elements
                Map.Entry me = (Map.Entry) iter.next();

                //sed information to history file
                Set<Object> setcoll = (Set<Object>) me.getValue();

                if (setcoll.size() > 0) {
                    WriteToFileLog("\t\t { Key: (" + me.getKey() + " )  ", "\n\t\t\t[");
                } else {
                    WriteToFileLog("\t\t { Key: (" + me.getKey() + " )  ", "\n\t\t\t Empty Value");
                }
                //over all parts of set<Object>
                for (Object obj : setcoll) {
                    WriteObjectToLog("", obj);
                }
                WriteToFileLog("\n\t\t\t]", "\n}");

            }
            if (set.size() > 0) {
                WriteToFileLog("\t\tEnd List Related Entities  ", "");
            }
            WriteToFileLog("\t\t}", "");
            WriteToFileLog("End List of Primary Filters  of  :", entity.getEntityType() + "\n\n");

        } else {
            LOG.info(PATTERN_LOG_INFO + "variable  Primary Filters is null ");
        }

        // print all Other Info of Entity
        WriteToFileLog("\tprint all Other Info   ", "");
        LOG.info(PATTERN_LOG_INFO + "print all Other Info of Entity Name :" + String.format(
                "Entity ID :%s , Entity Type : %s )\n\n", entity.getEntityId(), entity.getEntityType()));

        if (entity.getOtherInfo() != null) {
            // Map<String,Object> OtherInfo = entity.getOtherInfo();

            Set set = entity.getOtherInfo().entrySet();

            if (set.size() > 0) {
                WriteToFileLog("Start List of Other Info of  ( ",
                        String.format("Entity ID :%s , Entity Type : %s )\n\n", entity.getEntityId(),
                                entity.getEntityType()));
            }
            Iterator iter = set.iterator();

            while (iter.hasNext()) {
                // Display elements
                Map.Entry me = (Map.Entry) iter.next();

                //sed information to history file
                WriteObjectToLog("\t Key : " + me.getKey() + "   : Value : ", me.getValue());
            }
            if (set.size() > 0) {
                WriteToFileLog("\nEnd List of Other Info  of  :", entity.getEntityType() + "\n\n");
            }

        } else {
            LOG.info(PATTERN_LOG_INFO + "variable  Other Info is null ");
        }

        LOG.info(PATTERN_LOG_INFO + "Finished to print all information of Entity Name :" + String.format(
                "Entity ID :%s , Entity Type : %s )\n\n\n\n", entity.getEntityId(), entity.getEntityType()));

    } catch (Exception e) {

        String message = PATTERN_LOG_ERROR + "Creating a problem while writing the history  file";
        LOG.error(message, e);

        throw e;
    } finally {

    }
}