Exemple #1
0
        private static TimelineEntity MaskFields(TimelineEntity entity, EnumSet <TimelineReader.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(TimelineReader.Field.Events))
            {
                entityToReturn.AddEvents(entity.GetEvents());
            }
            else
            {
                if (fields.Contains(TimelineReader.Field.LastEventOnly))
                {
                    entityToReturn.AddEvent(entity.GetEvents()[0]);
                }
                else
                {
                    entityToReturn.SetEvents(null);
                }
            }
            if (fields.Contains(TimelineReader.Field.RelatedEntities))
            {
                entityToReturn.AddRelatedEntities(entity.GetRelatedEntities());
            }
            else
            {
                entityToReturn.SetRelatedEntities(null);
            }
            if (fields.Contains(TimelineReader.Field.PrimaryFilters))
            {
                entityToReturn.AddPrimaryFilters(entity.GetPrimaryFilters());
            }
            else
            {
                entityToReturn.SetPrimaryFilters(null);
            }
            if (fields.Contains(TimelineReader.Field.OtherInfo))
            {
                entityToReturn.AddOtherInfo(entity.GetOtherInfo());
            }
            else
            {
                entityToReturn.SetOtherInfo(null);
            }
            return(entityToReturn);
        }
Exemple #2
0
 public virtual TimelineEvents GetEntityTimelines(string entityType, ICollection <string
                                                                                  > entityIds, long limit, long windowStart, long windowEnd, ICollection <string> eventTypes
                                                  )
 {
     lock (this)
     {
         TimelineEvents allEvents = new TimelineEvents();
         if (entityIds == null)
         {
             return(allEvents);
         }
         if (limit == null)
         {
             limit = DefaultLimit;
         }
         if (windowStart == null)
         {
             windowStart = long.MinValue;
         }
         if (windowEnd == null)
         {
             windowEnd = long.MaxValue;
         }
         foreach (string entityId in entityIds)
         {
             EntityIdentifier entityID = new EntityIdentifier(entityId, entityType);
             TimelineEntity   entity   = entities[entityID];
             if (entity == null)
             {
                 continue;
             }
             TimelineEvents.EventsOfOneEntity events = new TimelineEvents.EventsOfOneEntity();
             events.SetEntityId(entityId);
             events.SetEntityType(entityType);
             foreach (TimelineEvent @event in entity.GetEvents())
             {
                 if (events.GetEvents().Count >= limit)
                 {
                     break;
                 }
                 if (@event.GetTimestamp() <= windowStart)
                 {
                     continue;
                 }
                 if (@event.GetTimestamp() > windowEnd)
                 {
                     continue;
                 }
                 if (eventTypes != null && !eventTypes.Contains(@event.GetEventType()))
                 {
                     continue;
                 }
                 events.AddEvent(@event);
             }
             allEvents.AddEvent(events);
         }
         return(allEvents);
     }
 }
Exemple #3
0
        public virtual void TestMRTimelineEventHandling()
        {
            Configuration conf = new YarnConfiguration();

            conf.SetBoolean(YarnConfiguration.TimelineServiceEnabled, true);
            conf.SetBoolean(MRJobConfig.MapreduceJobEmitTimelineData, true);
            MiniMRYarnCluster cluster = null;

            try
            {
                cluster = new MiniMRYarnCluster(typeof(TestJobHistoryEventHandler).Name, 1);
                cluster.Init(conf);
                cluster.Start();
                conf.Set(YarnConfiguration.TimelineServiceWebappAddress, MiniYARNCluster.GetHostname
                             () + ":" + cluster.GetApplicationHistoryServer().GetPort());
                TimelineStore ts     = cluster.GetApplicationHistoryServer().GetTimelineStore();
                Path          inDir  = new Path("input");
                Path          outDir = new Path("output");
                RunningJob    job    = UtilsForTests.RunJobSucceed(new JobConf(conf), inDir, outDir);
                NUnit.Framework.Assert.AreEqual(JobStatus.Succeeded, job.GetJobStatus().GetState(
                                                    ).GetValue());
                TimelineEntities entities = ts.GetEntities("MAPREDUCE_JOB", null, null, null, null
                                                           , null, null, null, null, null);
                NUnit.Framework.Assert.AreEqual(1, entities.GetEntities().Count);
                TimelineEntity tEntity = entities.GetEntities()[0];
                NUnit.Framework.Assert.AreEqual(job.GetID().ToString(), tEntity.GetEntityId());
                NUnit.Framework.Assert.AreEqual("MAPREDUCE_JOB", tEntity.GetEntityType());
                NUnit.Framework.Assert.AreEqual(EventType.AmStarted.ToString(), tEntity.GetEvents
                                                    ()[tEntity.GetEvents().Count - 1].GetEventType());
                NUnit.Framework.Assert.AreEqual(EventType.JobFinished.ToString(), tEntity.GetEvents
                                                    ()[0].GetEventType());
                job = UtilsForTests.RunJobFail(new JobConf(conf), inDir, outDir);
                NUnit.Framework.Assert.AreEqual(JobStatus.Failed, job.GetJobStatus().GetState().GetValue
                                                    ());
                entities = ts.GetEntities("MAPREDUCE_JOB", null, null, null, null, null, null, null
                                          , null, null);
                NUnit.Framework.Assert.AreEqual(2, entities.GetEntities().Count);
                tEntity = entities.GetEntities()[0];
                NUnit.Framework.Assert.AreEqual(job.GetID().ToString(), tEntity.GetEntityId());
                NUnit.Framework.Assert.AreEqual("MAPREDUCE_JOB", tEntity.GetEntityType());
                NUnit.Framework.Assert.AreEqual(EventType.AmStarted.ToString(), tEntity.GetEvents
                                                    ()[tEntity.GetEvents().Count - 1].GetEventType());
                NUnit.Framework.Assert.AreEqual(EventType.JobFailed.ToString(), tEntity.GetEvents
                                                    ()[0].GetEventType());
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Stop();
                }
            }
        }
        private static ContainerReport ConvertToContainerReport(TimelineEntity entity, string
                                                                serverHttpAddress, string user)
        {
            int            allocatedMem             = 0;
            int            allocatedVcore           = 0;
            string         allocatedHost            = null;
            int            allocatedPort            = -1;
            int            allocatedPriority        = 0;
            long           createdTime              = 0;
            long           finishedTime             = 0;
            string         diagnosticsInfo          = null;
            int            exitStatus               = ContainerExitStatus.Invalid;
            ContainerState state                    = null;
            string         nodeHttpAddress          = null;
            IDictionary <string, object> entityInfo = entity.GetOtherInfo();

            if (entityInfo != null)
            {
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedMemoryEntityInfo))
                {
                    allocatedMem = (int)entityInfo[ContainerMetricsConstants.AllocatedMemoryEntityInfo
                                   ];
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedVcoreEntityInfo))
                {
                    allocatedVcore = (int)entityInfo[ContainerMetricsConstants.AllocatedVcoreEntityInfo
                                     ];
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedHostEntityInfo))
                {
                    allocatedHost = entityInfo[ContainerMetricsConstants.AllocatedHostEntityInfo].ToString
                                        ();
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedPortEntityInfo))
                {
                    allocatedPort = (int)entityInfo[ContainerMetricsConstants.AllocatedPortEntityInfo
                                    ];
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedPriorityEntityInfo))
                {
                    allocatedPriority = (int)entityInfo[ContainerMetricsConstants.AllocatedPriorityEntityInfo
                                        ];
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedHostHttpAddressEntityInfo
                                        ))
                {
                    nodeHttpAddress = (string)entityInfo[ContainerMetricsConstants.AllocatedHostHttpAddressEntityInfo
                                      ];
                }
            }
            IList <TimelineEvent> events = entity.GetEvents();

            if (events != null)
            {
                foreach (TimelineEvent @event in events)
                {
                    if (@event.GetEventType().Equals(ContainerMetricsConstants.CreatedEventType))
                    {
                        createdTime = @event.GetTimestamp();
                    }
                    else
                    {
                        if (@event.GetEventType().Equals(ContainerMetricsConstants.FinishedEventType))
                        {
                            finishedTime = @event.GetTimestamp();
                            IDictionary <string, object> eventInfo = @event.GetEventInfo();
                            if (eventInfo == null)
                            {
                                continue;
                            }
                            if (eventInfo.Contains(ContainerMetricsConstants.DiagnosticsInfoEventInfo))
                            {
                                diagnosticsInfo = eventInfo[ContainerMetricsConstants.DiagnosticsInfoEventInfo].ToString
                                                      ();
                            }
                            if (eventInfo.Contains(ContainerMetricsConstants.ExitStatusEventInfo))
                            {
                                exitStatus = (int)eventInfo[ContainerMetricsConstants.ExitStatusEventInfo];
                            }
                            if (eventInfo.Contains(ContainerMetricsConstants.StateEventInfo))
                            {
                                state = ContainerState.ValueOf(eventInfo[ContainerMetricsConstants.StateEventInfo
                                                               ].ToString());
                            }
                        }
                    }
                }
            }
            NodeId      allocatedNode = NodeId.NewInstance(allocatedHost, allocatedPort);
            ContainerId containerId   = ConverterUtils.ToContainerId(entity.GetEntityId());
            string      logUrl        = WebAppUtils.GetAggregatedLogURL(serverHttpAddress, allocatedNode.
                                                                        ToString(), containerId.ToString(), containerId.ToString(), user);

            return(ContainerReport.NewInstance(ConverterUtils.ToContainerId(entity.GetEntityId
                                                                                ()), Resource.NewInstance(allocatedMem, allocatedVcore), NodeId.NewInstance(allocatedHost
                                                                                                                                                            , allocatedPort), Priority.NewInstance(allocatedPriority), createdTime, finishedTime
                                               , diagnosticsInfo, logUrl, exitStatus, state, nodeHttpAddress));
        }
        private static ApplicationAttemptReport ConvertToApplicationAttemptReport(TimelineEntity
                                                                                  entity)
        {
            string      host                   = null;
            int         rpcPort                = -1;
            ContainerId amContainerId          = null;
            string      trackingUrl            = null;
            string      originalTrackingUrl    = null;
            string      diagnosticsInfo        = null;
            YarnApplicationAttemptState state  = null;
            IList <TimelineEvent>       events = entity.GetEvents();

            if (events != null)
            {
                foreach (TimelineEvent @event in events)
                {
                    if (@event.GetEventType().Equals(AppAttemptMetricsConstants.RegisteredEventType))
                    {
                        IDictionary <string, object> eventInfo = @event.GetEventInfo();
                        if (eventInfo == null)
                        {
                            continue;
                        }
                        if (eventInfo.Contains(AppAttemptMetricsConstants.HostEventInfo))
                        {
                            host = eventInfo[AppAttemptMetricsConstants.HostEventInfo].ToString();
                        }
                        if (eventInfo.Contains(AppAttemptMetricsConstants.RpcPortEventInfo))
                        {
                            rpcPort = (int)eventInfo[AppAttemptMetricsConstants.RpcPortEventInfo];
                        }
                        if (eventInfo.Contains(AppAttemptMetricsConstants.MasterContainerEventInfo))
                        {
                            amContainerId = ConverterUtils.ToContainerId(eventInfo[AppAttemptMetricsConstants
                                                                                   .MasterContainerEventInfo].ToString());
                        }
                    }
                    else
                    {
                        if (@event.GetEventType().Equals(AppAttemptMetricsConstants.FinishedEventType))
                        {
                            IDictionary <string, object> eventInfo = @event.GetEventInfo();
                            if (eventInfo == null)
                            {
                                continue;
                            }
                            if (eventInfo.Contains(AppAttemptMetricsConstants.TrackingUrlEventInfo))
                            {
                                trackingUrl = eventInfo[AppAttemptMetricsConstants.TrackingUrlEventInfo].ToString
                                                  ();
                            }
                            if (eventInfo.Contains(AppAttemptMetricsConstants.OriginalTrackingUrlEventInfo))
                            {
                                originalTrackingUrl = eventInfo[AppAttemptMetricsConstants.OriginalTrackingUrlEventInfo
                                                      ].ToString();
                            }
                            if (eventInfo.Contains(AppAttemptMetricsConstants.DiagnosticsInfoEventInfo))
                            {
                                diagnosticsInfo = eventInfo[AppAttemptMetricsConstants.DiagnosticsInfoEventInfo].
                                                  ToString();
                            }
                            if (eventInfo.Contains(AppAttemptMetricsConstants.StateEventInfo))
                            {
                                state = YarnApplicationAttemptState.ValueOf(eventInfo[AppAttemptMetricsConstants.
                                                                                      StateEventInfo].ToString());
                            }
                        }
                    }
                }
            }
            return(ApplicationAttemptReport.NewInstance(ConverterUtils.ToApplicationAttemptId
                                                            (entity.GetEntityId()), host, rpcPort, trackingUrl, originalTrackingUrl, diagnosticsInfo
                                                        , state, amContainerId));
        }
        private static ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt ConvertToApplicationReport
            (TimelineEntity entity, ApplicationHistoryManagerOnTimelineStore.ApplicationReportField
            field)
        {
            string user         = null;
            string queue        = null;
            string name         = null;
            string type         = null;
            long   createdTime  = 0;
            long   finishedTime = 0;
            ApplicationAttemptId latestApplicationAttemptId = null;
            string diagnosticsInfo = null;
            FinalApplicationStatus         finalStatus              = FinalApplicationStatus.Undefined;
            YarnApplicationState           state                    = null;
            ApplicationResourceUsageReport appResources             = null;
            IDictionary <ApplicationAccessType, string> appViewACLs = new Dictionary <ApplicationAccessType
                                                                                      , string>();
            IDictionary <string, object> entityInfo = entity.GetOtherInfo();

            if (entityInfo != null)
            {
                if (entityInfo.Contains(ApplicationMetricsConstants.UserEntityInfo))
                {
                    user = entityInfo[ApplicationMetricsConstants.UserEntityInfo].ToString();
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.AppViewAclsEntityInfo))
                {
                    string appViewACLsStr = entityInfo[ApplicationMetricsConstants.AppViewAclsEntityInfo
                                            ].ToString();
                    if (appViewACLsStr.Length > 0)
                    {
                        appViewACLs[ApplicationAccessType.ViewApp] = appViewACLsStr;
                    }
                }
                if (field == ApplicationHistoryManagerOnTimelineStore.ApplicationReportField.UserAndAcls)
                {
                    return(new ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt(ApplicationReport
                                                                                             .NewInstance(ConverterUtils.ToApplicationId(entity.GetEntityId()), latestApplicationAttemptId
                                                                                                          , user, queue, name, null, -1, null, state, diagnosticsInfo, null, createdTime,
                                                                                                          finishedTime, finalStatus, null, null, 1.0F, type, null), appViewACLs));
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.QueueEntityInfo))
                {
                    queue = entityInfo[ApplicationMetricsConstants.QueueEntityInfo].ToString();
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.NameEntityInfo))
                {
                    name = entityInfo[ApplicationMetricsConstants.NameEntityInfo].ToString();
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.TypeEntityInfo))
                {
                    type = entityInfo[ApplicationMetricsConstants.TypeEntityInfo].ToString();
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.AppCpuMetrics))
                {
                    long vcoreSeconds = long.Parse(entityInfo[ApplicationMetricsConstants.AppCpuMetrics
                                                   ].ToString());
                    long memorySeconds = long.Parse(entityInfo[ApplicationMetricsConstants.AppMemMetrics
                                                    ].ToString());
                    appResources = ApplicationResourceUsageReport.NewInstance(0, 0, null, null, null,
                                                                              memorySeconds, vcoreSeconds);
                }
            }
            IList <TimelineEvent> events = entity.GetEvents();

            if (events != null)
            {
                foreach (TimelineEvent @event in events)
                {
                    if (@event.GetEventType().Equals(ApplicationMetricsConstants.CreatedEventType))
                    {
                        createdTime = @event.GetTimestamp();
                    }
                    else
                    {
                        if (@event.GetEventType().Equals(ApplicationMetricsConstants.FinishedEventType))
                        {
                            finishedTime = @event.GetTimestamp();
                            IDictionary <string, object> eventInfo = @event.GetEventInfo();
                            if (eventInfo == null)
                            {
                                continue;
                            }
                            if (eventInfo.Contains(ApplicationMetricsConstants.LatestAppAttemptEventInfo))
                            {
                                latestApplicationAttemptId = ConverterUtils.ToApplicationAttemptId(eventInfo[ApplicationMetricsConstants
                                                                                                             .LatestAppAttemptEventInfo].ToString());
                            }
                            if (eventInfo.Contains(ApplicationMetricsConstants.DiagnosticsInfoEventInfo))
                            {
                                diagnosticsInfo = eventInfo[ApplicationMetricsConstants.DiagnosticsInfoEventInfo]
                                                  .ToString();
                            }
                            if (eventInfo.Contains(ApplicationMetricsConstants.FinalStatusEventInfo))
                            {
                                finalStatus = FinalApplicationStatus.ValueOf(eventInfo[ApplicationMetricsConstants
                                                                                       .FinalStatusEventInfo].ToString());
                            }
                            if (eventInfo.Contains(ApplicationMetricsConstants.StateEventInfo))
                            {
                                state = YarnApplicationState.ValueOf(eventInfo[ApplicationMetricsConstants.StateEventInfo
                                                                     ].ToString());
                            }
                        }
                    }
                }
            }
            return(new ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt(ApplicationReport
                                                                                     .NewInstance(ConverterUtils.ToApplicationId(entity.GetEntityId()), latestApplicationAttemptId
                                                                                                  , user, queue, name, null, -1, null, state, diagnosticsInfo, null, createdTime,
                                                                                                  finishedTime, finalStatus, appResources, null, 1.0F, type, null), appViewACLs));
        }
Exemple #7
0
 /// <exception cref="System.Exception"/>
 public virtual void TestPublishApplicationMetrics()
 {
     for (int i = 1; i <= 2; ++i)
     {
         ApplicationId appId = ApplicationId.NewInstance(0, i);
         RMApp         app   = CreateRMApp(appId);
         metricsPublisher.AppCreated(app, app.GetStartTime());
         metricsPublisher.AppFinished(app, RMAppState.Finished, app.GetFinishTime());
         if (i == 1)
         {
             metricsPublisher.AppACLsUpdated(app, "uers1,user2", 4L);
         }
         else
         {
             // in case user doesn't specify the ACLs
             metricsPublisher.AppACLsUpdated(app, null, 4L);
         }
         TimelineEntity entity = null;
         do
         {
             entity = store.GetEntity(appId.ToString(), ApplicationMetricsConstants.EntityType
                                      , EnumSet.AllOf <TimelineReader.Field>());
         }while (entity == null || entity.GetEvents().Count < 3);
         // ensure three events are both published before leaving the loop
         // verify all the fields
         NUnit.Framework.Assert.AreEqual(ApplicationMetricsConstants.EntityType, entity.GetEntityType
                                             ());
         NUnit.Framework.Assert.AreEqual(app.GetApplicationId().ToString(), entity.GetEntityId
                                             ());
         NUnit.Framework.Assert.AreEqual(app.GetName(), entity.GetOtherInfo()[ApplicationMetricsConstants
                                                                              .NameEntityInfo]);
         NUnit.Framework.Assert.AreEqual(app.GetQueue(), entity.GetOtherInfo()[ApplicationMetricsConstants
                                                                               .QueueEntityInfo]);
         NUnit.Framework.Assert.AreEqual(app.GetUser(), entity.GetOtherInfo()[ApplicationMetricsConstants
                                                                              .UserEntityInfo]);
         NUnit.Framework.Assert.AreEqual(app.GetApplicationType(), entity.GetOtherInfo()[ApplicationMetricsConstants
                                                                                         .TypeEntityInfo]);
         NUnit.Framework.Assert.AreEqual(app.GetSubmitTime(), entity.GetOtherInfo()[ApplicationMetricsConstants
                                                                                    .SubmittedTimeEntityInfo]);
         if (i == 1)
         {
             NUnit.Framework.Assert.AreEqual("uers1,user2", entity.GetOtherInfo()[ApplicationMetricsConstants
                                                                                  .AppViewAclsEntityInfo]);
         }
         else
         {
             NUnit.Framework.Assert.AreEqual(string.Empty, entity.GetOtherInfo()[ApplicationMetricsConstants
                                                                                 .AppViewAclsEntityInfo]);
             NUnit.Framework.Assert.AreEqual(app.GetRMAppMetrics().GetMemorySeconds(), long.Parse
                                                 (entity.GetOtherInfo()[ApplicationMetricsConstants.AppMemMetrics].ToString()));
             NUnit.Framework.Assert.AreEqual(app.GetRMAppMetrics().GetVcoreSeconds(), long.Parse
                                                 (entity.GetOtherInfo()[ApplicationMetricsConstants.AppCpuMetrics].ToString()));
         }
         bool hasCreatedEvent     = false;
         bool hasFinishedEvent    = false;
         bool hasACLsUpdatedEvent = false;
         foreach (TimelineEvent @event in entity.GetEvents())
         {
             if (@event.GetEventType().Equals(ApplicationMetricsConstants.CreatedEventType))
             {
                 hasCreatedEvent = true;
                 NUnit.Framework.Assert.AreEqual(app.GetStartTime(), @event.GetTimestamp());
             }
             else
             {
                 if (@event.GetEventType().Equals(ApplicationMetricsConstants.FinishedEventType))
                 {
                     hasFinishedEvent = true;
                     NUnit.Framework.Assert.AreEqual(app.GetFinishTime(), @event.GetTimestamp());
                     NUnit.Framework.Assert.AreEqual(app.GetDiagnostics().ToString(), @event.GetEventInfo
                                                         ()[ApplicationMetricsConstants.DiagnosticsInfoEventInfo]);
                     NUnit.Framework.Assert.AreEqual(app.GetFinalApplicationStatus().ToString(), @event
                                                     .GetEventInfo()[ApplicationMetricsConstants.FinalStatusEventInfo]);
                     NUnit.Framework.Assert.AreEqual(YarnApplicationState.Finished.ToString(), @event.
                                                     GetEventInfo()[ApplicationMetricsConstants.StateEventInfo]);
                 }
                 else
                 {
                     if (@event.GetEventType().Equals(ApplicationMetricsConstants.AclsUpdatedEventType
                                                      ))
                     {
                         hasACLsUpdatedEvent = true;
                         NUnit.Framework.Assert.AreEqual(4L, @event.GetTimestamp());
                     }
                 }
             }
         }
         NUnit.Framework.Assert.IsTrue(hasCreatedEvent && hasFinishedEvent && hasACLsUpdatedEvent
                                       );
     }
 }
Exemple #8
0
        /// <exception cref="System.Exception"/>
        public virtual void TestPublishContainerMetrics()
        {
            ContainerId containerId = ContainerId.NewContainerId(ApplicationAttemptId.NewInstance
                                                                     (ApplicationId.NewInstance(0, 1), 1), 1);
            RMContainer container = CreateRMContainer(containerId);

            metricsPublisher.ContainerCreated(container, container.GetCreationTime());
            metricsPublisher.ContainerFinished(container, container.GetFinishTime());
            TimelineEntity entity = null;

            do
            {
                entity = store.GetEntity(containerId.ToString(), ContainerMetricsConstants.EntityType
                                         , EnumSet.AllOf <TimelineReader.Field>());
            }while (entity == null || entity.GetEvents().Count < 2);
            // ensure two events are both published before leaving the loop
            // verify all the fields
            NUnit.Framework.Assert.AreEqual(ContainerMetricsConstants.EntityType, entity.GetEntityType
                                                ());
            NUnit.Framework.Assert.AreEqual(containerId.ToString(), entity.GetEntityId());
            NUnit.Framework.Assert.AreEqual(containerId.GetApplicationAttemptId().ToString(),
                                            entity.GetPrimaryFilters()[ContainerMetricsConstants.ParentPrimariyFilter].GetEnumerator
                                                ().Next());
            NUnit.Framework.Assert.AreEqual(container.GetAllocatedNode().GetHost(), entity.GetOtherInfo
                                                ()[ContainerMetricsConstants.AllocatedHostEntityInfo]);
            NUnit.Framework.Assert.AreEqual(container.GetAllocatedNode().GetPort(), entity.GetOtherInfo
                                                ()[ContainerMetricsConstants.AllocatedPortEntityInfo]);
            NUnit.Framework.Assert.AreEqual(container.GetAllocatedResource().GetMemory(), entity
                                            .GetOtherInfo()[ContainerMetricsConstants.AllocatedMemoryEntityInfo]);
            NUnit.Framework.Assert.AreEqual(container.GetAllocatedResource().GetVirtualCores(
                                                ), entity.GetOtherInfo()[ContainerMetricsConstants.AllocatedVcoreEntityInfo]);
            NUnit.Framework.Assert.AreEqual(container.GetAllocatedPriority().GetPriority(), entity
                                            .GetOtherInfo()[ContainerMetricsConstants.AllocatedPriorityEntityInfo]);
            bool hasCreatedEvent  = false;
            bool hasFinishedEvent = false;

            foreach (TimelineEvent @event in entity.GetEvents())
            {
                if (@event.GetEventType().Equals(ContainerMetricsConstants.CreatedEventType))
                {
                    hasCreatedEvent = true;
                    NUnit.Framework.Assert.AreEqual(container.GetCreationTime(), @event.GetTimestamp(
                                                        ));
                }
                else
                {
                    if (@event.GetEventType().Equals(ContainerMetricsConstants.FinishedEventType))
                    {
                        hasFinishedEvent = true;
                        NUnit.Framework.Assert.AreEqual(container.GetFinishTime(), @event.GetTimestamp());
                        NUnit.Framework.Assert.AreEqual(container.GetDiagnosticsInfo(), @event.GetEventInfo
                                                            ()[ContainerMetricsConstants.DiagnosticsInfoEventInfo]);
                        NUnit.Framework.Assert.AreEqual(container.GetContainerExitStatus(), @event.GetEventInfo
                                                            ()[ContainerMetricsConstants.ExitStatusEventInfo]);
                        NUnit.Framework.Assert.AreEqual(container.GetContainerState().ToString(), @event.
                                                        GetEventInfo()[ContainerMetricsConstants.StateEventInfo]);
                    }
                }
            }
            NUnit.Framework.Assert.IsTrue(hasCreatedEvent && hasFinishedEvent);
        }
Exemple #9
0
        /// <exception cref="System.Exception"/>
        public virtual void TestPublishAppAttemptMetrics()
        {
            ApplicationAttemptId appAttemptId = ApplicationAttemptId.NewInstance(ApplicationId
                                                                                 .NewInstance(0, 1), 1);
            RMAppAttempt appAttempt = CreateRMAppAttempt(appAttemptId);

            metricsPublisher.AppAttemptRegistered(appAttempt, int.MaxValue + 1L);
            RMApp app = Org.Mockito.Mockito.Mock <RMApp>();

            Org.Mockito.Mockito.When(app.GetFinalApplicationStatus()).ThenReturn(FinalApplicationStatus
                                                                                 .Undefined);
            metricsPublisher.AppAttemptFinished(appAttempt, RMAppAttemptState.Finished, app,
                                                int.MaxValue + 2L);
            TimelineEntity entity = null;

            do
            {
                entity = store.GetEntity(appAttemptId.ToString(), AppAttemptMetricsConstants.EntityType
                                         , EnumSet.AllOf <TimelineReader.Field>());
            }while (entity == null || entity.GetEvents().Count < 2);
            // ensure two events are both published before leaving the loop
            // verify all the fields
            NUnit.Framework.Assert.AreEqual(AppAttemptMetricsConstants.EntityType, entity.GetEntityType
                                                ());
            NUnit.Framework.Assert.AreEqual(appAttemptId.ToString(), entity.GetEntityId());
            NUnit.Framework.Assert.AreEqual(appAttemptId.GetApplicationId().ToString(), entity
                                            .GetPrimaryFilters()[AppAttemptMetricsConstants.ParentPrimaryFilter].GetEnumerator
                                                ().Next());
            bool hasRegisteredEvent = false;
            bool hasFinishedEvent   = false;

            foreach (TimelineEvent @event in entity.GetEvents())
            {
                if (@event.GetEventType().Equals(AppAttemptMetricsConstants.RegisteredEventType))
                {
                    hasRegisteredEvent = true;
                    NUnit.Framework.Assert.AreEqual(appAttempt.GetHost(), @event.GetEventInfo()[AppAttemptMetricsConstants
                                                                                                .HostEventInfo]);
                    NUnit.Framework.Assert.AreEqual(appAttempt.GetRpcPort(), @event.GetEventInfo()[AppAttemptMetricsConstants
                                                                                                   .RpcPortEventInfo]);
                    NUnit.Framework.Assert.AreEqual(appAttempt.GetMasterContainer().GetId().ToString(
                                                        ), @event.GetEventInfo()[AppAttemptMetricsConstants.MasterContainerEventInfo]);
                }
                else
                {
                    if (@event.GetEventType().Equals(AppAttemptMetricsConstants.FinishedEventType))
                    {
                        hasFinishedEvent = true;
                        NUnit.Framework.Assert.AreEqual(appAttempt.GetDiagnostics(), @event.GetEventInfo(
                                                            )[AppAttemptMetricsConstants.DiagnosticsInfoEventInfo]);
                        NUnit.Framework.Assert.AreEqual(appAttempt.GetTrackingUrl(), @event.GetEventInfo(
                                                            )[AppAttemptMetricsConstants.TrackingUrlEventInfo]);
                        NUnit.Framework.Assert.AreEqual(appAttempt.GetOriginalTrackingUrl(), @event.GetEventInfo
                                                            ()[AppAttemptMetricsConstants.OriginalTrackingUrlEventInfo]);
                        NUnit.Framework.Assert.AreEqual(FinalApplicationStatus.Undefined.ToString(), @event
                                                        .GetEventInfo()[AppAttemptMetricsConstants.FinalStatusEventInfo]);
                        NUnit.Framework.Assert.AreEqual(YarnApplicationAttemptState.Finished.ToString(),
                                                        @event.GetEventInfo()[AppAttemptMetricsConstants.StateEventInfo]);
                    }
                }
            }
            NUnit.Framework.Assert.IsTrue(hasRegisteredEvent && hasFinishedEvent);
        }