public virtual void TestPutEntities()
 {
     TestTimelineWebServicesWithSSL.TestTimelineClient client = new TestTimelineWebServicesWithSSL.TestTimelineClient
                                                                    ();
     try
     {
         client.Init(conf);
         client.Start();
         TimelineEntity expectedEntity = new TimelineEntity();
         expectedEntity.SetEntityType("test entity type");
         expectedEntity.SetEntityId("test entity id");
         expectedEntity.SetDomainId("test domain id");
         TimelineEvent @event = new TimelineEvent();
         @event.SetEventType("test event type");
         @event.SetTimestamp(0L);
         expectedEntity.AddEvent(@event);
         TimelinePutResponse response = client.PutEntities(expectedEntity);
         NUnit.Framework.Assert.AreEqual(0, response.GetErrors().Count);
         NUnit.Framework.Assert.IsTrue(client.resp.ToString().Contains("https"));
         TimelineEntity actualEntity = store.GetEntity(expectedEntity.GetEntityId(), expectedEntity
                                                       .GetEntityType(), EnumSet.AllOf <TimelineReader.Field>());
         NUnit.Framework.Assert.IsNotNull(actualEntity);
         NUnit.Framework.Assert.AreEqual(expectedEntity.GetEntityId(), actualEntity.GetEntityId
                                             ());
         NUnit.Framework.Assert.AreEqual(expectedEntity.GetEntityType(), actualEntity.GetEntityType
                                             ());
     }
     finally
     {
         client.Stop();
         client.Close();
     }
 }
Пример #2
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();
                }
            }
        }
        public virtual void TestGetOldEntityWithOutDomainId()
        {
            TimelineEntity entity = dataManaer.GetEntity("OLD_ENTITY_TYPE_1", "OLD_ENTITY_ID_1"
                                                         , null, UserGroupInformation.GetCurrentUser());

            NUnit.Framework.Assert.IsNotNull(entity);
            NUnit.Framework.Assert.AreEqual("OLD_ENTITY_ID_1", entity.GetEntityId());
            NUnit.Framework.Assert.AreEqual("OLD_ENTITY_TYPE_1", entity.GetEntityType());
            NUnit.Framework.Assert.AreEqual(TimelineDataManager.DefaultDomainId, entity.GetDomainId
                                                ());
        }
Пример #4
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);
        }
Пример #5
0
 private void PutEntity(TimelineEntity entity)
 {
     try
     {
         if (Log.IsDebugEnabled())
         {
             Log.Debug("Publishing the entity " + entity.GetEntityId() + ", JSON-style content: "
                       + TimelineUtils.DumpTimelineRecordtoJSON(entity));
         }
         client.PutEntities(entity);
     }
     catch (Exception e)
     {
         Log.Error("Error when publishing entity [" + entity.GetEntityType() + "," + entity
                   .GetEntityId() + "]", e);
     }
 }
Пример #6
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual bool CheckAccess(UserGroupInformation callerUGI, ApplicationAccessType
                                        applicationAccessType, TimelineEntity entity)
        {
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Verifying the access of " + (callerUGI == null ? null : callerUGI.GetShortUserName
                                                            ()) + " on the timeline entity " + new EntityIdentifier(entity.GetEntityId(), entity
                                                                                                                    .GetEntityType()));
            }
            if (!adminAclsManager.AreACLsEnabled())
            {
                return(true);
            }
            // find domain owner and acls
            TimelineACLsManager.AccessControlListExt aclExt = aclExts[entity.GetDomainId()];
            if (aclExt == null)
            {
                aclExt = LoadDomainFromTimelineStore(entity.GetDomainId());
            }
            if (aclExt == null)
            {
                throw new YarnException("Domain information of the timeline entity " + new EntityIdentifier
                                            (entity.GetEntityId(), entity.GetEntityType()) + " doesn't exist.");
            }
            string            owner     = aclExt.owner;
            AccessControlList domainACL = aclExt.acls[applicationAccessType];

            if (domainACL == null)
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("ACL not found for access-type " + applicationAccessType + " for domain "
                              + entity.GetDomainId() + " owned by " + owner + ". Using default [" + YarnConfiguration
                              .DefaultYarnAppAcl + "]");
                }
                domainACL = new AccessControlList(YarnConfiguration.DefaultYarnAppAcl);
            }
            if (callerUGI != null && (adminAclsManager.IsAdmin(callerUGI) || callerUGI.GetShortUserName
                                          ().Equals(owner) || domainACL.IsUserAllowed(callerUGI)))
            {
                return(true);
            }
            return(false);
        }
Пример #7
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);
     }
 }
        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));
        }
Пример #11
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
                                       );
     }
 }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
0
 /// <exception cref="System.IO.IOException"/>
 public virtual bool Check(TimelineEntity entity)
 {
     try
     {
         return(this._enclosing.timelineACLsManager.CheckAccess(this.ugi, ApplicationAccessType
                                                                .ViewApp, entity));
     }
     catch (YarnException e)
     {
         TimelineDataManager.Log.Info("Error when verifying access for user " + this.ugi +
                                      " on the events of the timeline entity " + new EntityIdentifier(entity.GetEntityId
                                                                                                          (), entity.GetEntityType()), e);
         return(false);
     }
 }