Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 /// <exception cref="System.IO.IOException"/>
 public virtual TimelineEntities GetEntities(string entityType, long limit, long windowStart
                                             , long windowEnd, string fromId, long fromTs, NameValuePair primaryFilter, ICollection
                                             <NameValuePair> secondaryFilters, EnumSet <TimelineReader.Field> fields, TimelineDataManager.CheckAcl
                                             checkAcl)
 {
     lock (this)
     {
         if (limit == null)
         {
             limit = DefaultLimit;
         }
         if (windowStart == null)
         {
             windowStart = long.MinValue;
         }
         if (windowEnd == null)
         {
             windowEnd = long.MaxValue;
         }
         if (fields == null)
         {
             fields = EnumSet.AllOf <TimelineReader.Field>();
         }
         IEnumerator <TimelineEntity> entityIterator = null;
         if (fromId != null)
         {
             TimelineEntity firstEntity = entities[new EntityIdentifier(fromId, entityType)];
             if (firstEntity == null)
             {
                 return(new TimelineEntities());
             }
             else
             {
                 entityIterator = new TreeSet <TimelineEntity>(entities.Values).TailSet(firstEntity
                                                                                        , true).GetEnumerator();
             }
         }
         if (entityIterator == null)
         {
             entityIterator = new PriorityQueue <TimelineEntity>(entities.Values).GetEnumerator
                                  ();
         }
         IList <TimelineEntity> entitiesSelected = new AList <TimelineEntity>();
         while (entityIterator.HasNext())
         {
             TimelineEntity entity = entityIterator.Next();
             if (entitiesSelected.Count >= limit)
             {
                 break;
             }
             if (!entity.GetEntityType().Equals(entityType))
             {
                 continue;
             }
             if (entity.GetStartTime() <= windowStart)
             {
                 continue;
             }
             if (entity.GetStartTime() > windowEnd)
             {
                 continue;
             }
             if (fromTs != null && entityInsertTimes[new EntityIdentifier(entity.GetEntityId()
                                                                          , entity.GetEntityType())] > fromTs)
             {
                 continue;
             }
             if (primaryFilter != null && !MatchPrimaryFilter(entity.GetPrimaryFilters(), primaryFilter
                                                              ))
             {
                 continue;
             }
             if (secondaryFilters != null)
             {
                 // AND logic
                 bool flag = true;
                 foreach (NameValuePair secondaryFilter in secondaryFilters)
                 {
                     if (secondaryFilter != null && !MatchPrimaryFilter(entity.GetPrimaryFilters(), secondaryFilter
                                                                        ) && !MatchFilter(entity.GetOtherInfo(), secondaryFilter))
                     {
                         flag = false;
                         break;
                     }
                 }
                 if (!flag)
                 {
                     continue;
                 }
             }
             if (entity.GetDomainId() == null)
             {
                 entity.SetDomainId(TimelineDataManager.DefaultDomainId);
             }
             if (checkAcl == null || checkAcl.Check(entity))
             {
                 entitiesSelected.AddItem(entity);
             }
         }
         IList <TimelineEntity> entitiesToReturn = new AList <TimelineEntity>();
         foreach (TimelineEntity entitySelected in entitiesSelected)
         {
             entitiesToReturn.AddItem(MaskFields(entitySelected, fields));
         }
         entitiesToReturn.Sort();
         TimelineEntities entitiesWrapper = new TimelineEntities();
         entitiesWrapper.SetEntities(entitiesToReturn);
         return(entitiesWrapper);
     }
 }
Esempio n. 4
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);
        }