Пример #1
0
        private static TimelineEntity GenerateEntity()
        {
            TimelineEntity entity = new TimelineEntity();

            entity.SetEntityId("entity id");
            entity.SetEntityType("entity type");
            entity.SetStartTime(Runtime.CurrentTimeMillis());
            for (int i = 0; i < 2; ++i)
            {
                TimelineEvent @event = new TimelineEvent();
                @event.SetTimestamp(Runtime.CurrentTimeMillis());
                @event.SetEventType("test event type " + i);
                @event.AddEventInfo("key1", "val1");
                @event.AddEventInfo("key2", "val2");
                entity.AddEvent(@event);
            }
            entity.AddRelatedEntity("test ref type 1", "test ref id 1");
            entity.AddRelatedEntity("test ref type 2", "test ref id 2");
            entity.AddPrimaryFilter("pkey1", "pval1");
            entity.AddPrimaryFilter("pkey2", "pval2");
            entity.AddOtherInfo("okey1", "oval1");
            entity.AddOtherInfo("okey2", "oval2");
            entity.SetDomainId("domain id 1");
            return(entity);
        }
 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();
     }
 }
Пример #3
0
        private void PublishApplicationFinishedEvent(ApplicationFinishedEvent @event)
        {
            TimelineEntity entity = CreateApplicationEntity(@event.GetApplicationId());
            TimelineEvent  tEvent = new TimelineEvent();

            tEvent.SetEventType(ApplicationMetricsConstants.FinishedEventType);
            tEvent.SetTimestamp(@event.GetTimestamp());
            IDictionary <string, object> eventInfo = new Dictionary <string, object>();

            eventInfo[ApplicationMetricsConstants.DiagnosticsInfoEventInfo] = @event.GetDiagnosticsInfo
                                                                                  ();
            eventInfo[ApplicationMetricsConstants.FinalStatusEventInfo] = @event.GetFinalApplicationStatus
                                                                              ().ToString();
            eventInfo[ApplicationMetricsConstants.StateEventInfo] = @event.GetYarnApplicationState
                                                                        ().ToString();
            if (@event.GetLatestApplicationAttemptId() != null)
            {
                eventInfo[ApplicationMetricsConstants.LatestAppAttemptEventInfo] = @event.GetLatestApplicationAttemptId
                                                                                       ().ToString();
            }
            RMAppMetrics appMetrics = @event.GetAppMetrics();

            entity.AddOtherInfo(ApplicationMetricsConstants.AppCpuMetrics, appMetrics.GetVcoreSeconds
                                    ());
            entity.AddOtherInfo(ApplicationMetricsConstants.AppMemMetrics, appMetrics.GetMemorySeconds
                                    ());
            tEvent.SetEventInfo(eventInfo);
            entity.AddEvent(tEvent);
            PutEntity(entity);
        }
Пример #4
0
        private void PublishContainerCreatedEvent(ContainerCreatedEvent @event)
        {
            TimelineEntity entity = CreateContainerEntity(@event.GetContainerId());
            IDictionary <string, object> entityInfo = new Dictionary <string, object>();

            entityInfo[ContainerMetricsConstants.AllocatedMemoryEntityInfo] = @event.GetAllocatedResource
                                                                                  ().GetMemory();
            entityInfo[ContainerMetricsConstants.AllocatedVcoreEntityInfo] = @event.GetAllocatedResource
                                                                                 ().GetVirtualCores();
            entityInfo[ContainerMetricsConstants.AllocatedHostEntityInfo] = @event.GetAllocatedNode
                                                                                ().GetHost();
            entityInfo[ContainerMetricsConstants.AllocatedPortEntityInfo] = @event.GetAllocatedNode
                                                                                ().GetPort();
            entityInfo[ContainerMetricsConstants.AllocatedPriorityEntityInfo] = @event.GetAllocatedPriority
                                                                                    ().GetPriority();
            entityInfo[ContainerMetricsConstants.AllocatedHostHttpAddressEntityInfo] = @event
                                                                                       .GetNodeHttpAddress();
            entity.SetOtherInfo(entityInfo);
            TimelineEvent tEvent = new TimelineEvent();

            tEvent.SetEventType(ContainerMetricsConstants.CreatedEventType);
            tEvent.SetTimestamp(@event.GetTimestamp());
            entity.AddEvent(tEvent);
            PutEntity(entity);
        }
Пример #5
0
        public virtual TimelineEntity GetEntity(HttpServletRequest req, HttpServletResponse
                                                res, string entityType, string entityId, string fields)
        {
            /* , MediaType.APPLICATION_XML */
            Init(res);
            TimelineEntity entity = null;

            try
            {
                entity = timelineDataManager.GetEntity(ParseStr(entityType), ParseStr(entityId),
                                                       ParseFieldsStr(fields, ","), GetUser(req));
            }
            catch (ArgumentException)
            {
                throw new BadRequestException("requested invalid field.");
            }
            catch (Exception e)
            {
                Log.Error("Error getting entity", e);
                throw new WebApplicationException(e, Response.Status.InternalServerError);
            }
            if (entity == null)
            {
                throw new NotFoundException("Timeline entity " + new EntityIdentifier(ParseStr(entityId
                                                                                               ), ParseStr(entityType)) + " is not found");
            }
            return(entity);
        }
Пример #6
0
        private static TimelineEntity CreateApplicationTimelineEntity(ApplicationId appId
                                                                      , bool emptyACLs, bool noAttemptId, bool wrongAppId)
        {
            TimelineEntity entity = new TimelineEntity();

            entity.SetEntityType(ApplicationMetricsConstants.EntityType);
            if (wrongAppId)
            {
                entity.SetEntityId("wrong_app_id");
            }
            else
            {
                entity.SetEntityId(appId.ToString());
            }
            entity.SetDomainId(TimelineDataManager.DefaultDomainId);
            entity.AddPrimaryFilter(TimelineStore.SystemFilter.EntityOwner.ToString(), "yarn"
                                    );
            IDictionary <string, object> entityInfo = new Dictionary <string, object>();

            entityInfo[ApplicationMetricsConstants.NameEntityInfo]          = "test app";
            entityInfo[ApplicationMetricsConstants.TypeEntityInfo]          = "test app type";
            entityInfo[ApplicationMetricsConstants.UserEntityInfo]          = "user1";
            entityInfo[ApplicationMetricsConstants.QueueEntityInfo]         = "test queue";
            entityInfo[ApplicationMetricsConstants.SubmittedTimeEntityInfo] = int.MaxValue +
                                                                              1L;
            entityInfo[ApplicationMetricsConstants.AppMemMetrics] = 123;
            entityInfo[ApplicationMetricsConstants.AppCpuMetrics] = 345;
            if (emptyACLs)
            {
                entityInfo[ApplicationMetricsConstants.AppViewAclsEntityInfo] = string.Empty;
            }
            else
            {
                entityInfo[ApplicationMetricsConstants.AppViewAclsEntityInfo] = "user2";
            }
            entity.SetOtherInfo(entityInfo);
            TimelineEvent tEvent = new TimelineEvent();

            tEvent.SetEventType(ApplicationMetricsConstants.CreatedEventType);
            tEvent.SetTimestamp(int.MaxValue + 2L + appId.GetId());
            entity.AddEvent(tEvent);
            tEvent = new TimelineEvent();
            tEvent.SetEventType(ApplicationMetricsConstants.FinishedEventType);
            tEvent.SetTimestamp(int.MaxValue + 3L + appId.GetId());
            IDictionary <string, object> eventInfo = new Dictionary <string, object>();

            eventInfo[ApplicationMetricsConstants.DiagnosticsInfoEventInfo] = "test diagnostics info";
            eventInfo[ApplicationMetricsConstants.FinalStatusEventInfo]     = FinalApplicationStatus
                                                                              .Undefined.ToString();
            eventInfo[ApplicationMetricsConstants.StateEventInfo] = YarnApplicationState.Finished
                                                                    .ToString();
            if (!noAttemptId)
            {
                eventInfo[ApplicationMetricsConstants.LatestAppAttemptEventInfo] = ApplicationAttemptId
                                                                                   .NewInstance(appId, 1);
            }
            tEvent.SetEventInfo(eventInfo);
            entity.AddEvent(tEvent);
            return(entity);
        }
Пример #7
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);
     }
 }
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 /// <exception cref="System.IO.IOException"/>
 private ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt GenerateApplicationReport
     (TimelineEntity entity, ApplicationHistoryManagerOnTimelineStore.ApplicationReportField
     field)
 {
     ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt app = ConvertToApplicationReport
                                                                             (entity, field);
     // If only user and acls are pulled to check attempt(s)/container(s) access
     // control, we can return immediately
     if (field == ApplicationHistoryManagerOnTimelineStore.ApplicationReportField.UserAndAcls)
     {
         return(app);
     }
     try
     {
         CheckAccess(app);
         if (app.appReport.GetCurrentApplicationAttemptId() != null)
         {
             ApplicationAttemptReport appAttempt = GetApplicationAttempt(app.appReport.GetCurrentApplicationAttemptId
                                                                             (), false);
             app.appReport.SetHost(appAttempt.GetHost());
             app.appReport.SetRpcPort(appAttempt.GetRpcPort());
             app.appReport.SetTrackingUrl(appAttempt.GetTrackingUrl());
             app.appReport.SetOriginalTrackingUrl(appAttempt.GetOriginalTrackingUrl());
         }
     }
     catch (Exception)
     {
         // AuthorizationException is thrown because the user doesn't have access
         // It's possible that the app is finished before the first attempt is created.
         app.appReport.SetDiagnostics(null);
         app.appReport.SetCurrentApplicationAttemptId(null);
     }
     if (app.appReport.GetCurrentApplicationAttemptId() == null)
     {
         app.appReport.SetCurrentApplicationAttemptId(ApplicationAttemptId.NewInstance(app
                                                                                       .appReport.GetApplicationId(), -1));
     }
     if (app.appReport.GetHost() == null)
     {
         app.appReport.SetHost(Unavailable);
     }
     if (app.appReport.GetRpcPort() < 0)
     {
         app.appReport.SetRpcPort(-1);
     }
     if (app.appReport.GetTrackingUrl() == null)
     {
         app.appReport.SetTrackingUrl(Unavailable);
     }
     if (app.appReport.GetOriginalTrackingUrl() == null)
     {
         app.appReport.SetOriginalTrackingUrl(Unavailable);
     }
     if (app.appReport.GetDiagnostics() == null)
     {
         app.appReport.SetDiagnostics(string.Empty);
     }
     return(app);
 }
Пример #9
0
 private static void AddDefaultDomainIdIfAbsent(TimelineEntity entity)
 {
     // be compatible with the timeline data created before 2.6
     if (entity.GetDomainId() == null)
     {
         entity.SetDomainId(DefaultDomainId);
     }
 }
Пример #10
0
        private static TimelineEntity CreateApplicationEntity(ApplicationId applicationId
                                                              )
        {
            TimelineEntity entity = new TimelineEntity();

            entity.SetEntityType(ApplicationMetricsConstants.EntityType);
            entity.SetEntityId(applicationId.ToString());
            return(entity);
        }
Пример #11
0
        private static TimelineEntity CreateContainerEntity(ContainerId containerId)
        {
            TimelineEntity entity = new TimelineEntity();

            entity.SetEntityType(ContainerMetricsConstants.EntityType);
            entity.SetEntityId(containerId.ToString());
            entity.AddPrimaryFilter(ContainerMetricsConstants.ParentPrimariyFilter, containerId
                                    .GetApplicationAttemptId().ToString());
            return(entity);
        }
Пример #12
0
 public Timeline(TimelineEntity ObjEntity)
 {
     Init();
     Fields = ObjEntity;
     if (Fields.ID != null && Fields.ID != default(Guid))
     {
         IsNew = false;
     }
     InitBaseFields();
 }
Пример #13
0
        private static TimelineEntity CreateAppAttemptEntity(ApplicationAttemptId appAttemptId
                                                             )
        {
            TimelineEntity entity = new TimelineEntity();

            entity.SetEntityType(AppAttemptMetricsConstants.EntityType);
            entity.SetEntityId(appAttemptId.ToString());
            entity.AddPrimaryFilter(AppAttemptMetricsConstants.ParentPrimaryFilter, appAttemptId
                                    .GetApplicationId().ToString());
            return(entity);
        }
Пример #14
0
        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
                                                ());
        }
Пример #15
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();
                }
            }
        }
Пример #16
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);
        }
Пример #17
0
        internal static List <TimelineEntity> MapTimelineAsListOfEntities(DataSet dsFields)
        {
            List <TimelineEntity> lst = new List <TimelineEntity>();
            TimelineEntity        entityObject;

            foreach (DataRow row in dsFields.Tables[0].Rows)
            {
                entityObject = new TimelineEntity();
                FillTimelineEntityObject(entityObject, row);
                lst.Add(entityObject);
            }

            return(lst);
        }
Пример #18
0
        private static void FillTimelineEntityObject(TimelineEntity Fields, DataRow row)
        {
            //Base
            Fields.ID = (row["ID"] != DBNull.Value) ? (Guid?)row["ID"] : null;

            //TimelineEntity
            Fields.UserID       = (Guid)row["UserID"];
            Fields.TypeID       = (Guid)row["TypeID"];
            Fields.TypePlace    = row["TypePlace"].ToString();
            Fields.TypePosition = row["TypePosition"].ToString();
            Fields.TypeField    = row["TypeField"].ToString();
            Fields.StartDate    = (DateTime)row["StartDate"];
            Fields.EndDate      = (row["EndDate"] != DBNull.Value) ? (DateTime?)row["EndDate"] : null;
        }
Пример #19
0
        private void PublishApplicationACLsUpdatedEvent(ApplicationACLsUpdatedEvent @event
                                                        )
        {
            TimelineEntity entity = CreateApplicationEntity(@event.GetApplicationId());
            TimelineEvent  tEvent = new TimelineEvent();
            IDictionary <string, object> entityInfo = new Dictionary <string, object>();

            entityInfo[ApplicationMetricsConstants.AppViewAclsEntityInfo] = @event.GetViewAppACLs
                                                                                ();
            entity.SetOtherInfo(entityInfo);
            tEvent.SetEventType(ApplicationMetricsConstants.AclsUpdatedEventType);
            tEvent.SetTimestamp(@event.GetTimestamp());
            entity.AddEvent(tEvent);
            PutEntity(entity);
        }
Пример #20
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);
     }
 }
Пример #21
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);
     }
 }
Пример #22
0
        public virtual void TestUpdatingOldEntityWithoutDomainId()
        {
            // Set the domain to the default domain when updating
            TimelineEntity entity = new TimelineEntity();

            entity.SetEntityType("OLD_ENTITY_TYPE_1");
            entity.SetEntityId("OLD_ENTITY_ID_1");
            entity.SetDomainId(TimelineDataManager.DefaultDomainId);
            entity.AddOtherInfo("NEW_OTHER_INFO_KEY", "NEW_OTHER_INFO_VALUE");
            TimelineEntities entities = new TimelineEntities();

            entities.AddEntity(entity);
            TimelinePutResponse response = dataManaer.PostEntities(entities, UserGroupInformation
                                                                   .GetCurrentUser());

            NUnit.Framework.Assert.AreEqual(0, response.GetErrors().Count);
            entity = store.GetEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1", null);
            NUnit.Framework.Assert.IsNotNull(entity);
            // Even in leveldb, the domain is updated to the default domain Id
            NUnit.Framework.Assert.AreEqual(TimelineDataManager.DefaultDomainId, entity.GetDomainId
                                                ());
            NUnit.Framework.Assert.AreEqual(1, entity.GetOtherInfo().Count);
            NUnit.Framework.Assert.AreEqual("NEW_OTHER_INFO_KEY", entity.GetOtherInfo().Keys.
                                            GetEnumerator().Next());
            NUnit.Framework.Assert.AreEqual("NEW_OTHER_INFO_VALUE", entity.GetOtherInfo().Values
                                            .GetEnumerator().Next());
            // Set the domain to the non-default domain when updating
            entity = new TimelineEntity();
            entity.SetEntityType("OLD_ENTITY_TYPE_1");
            entity.SetEntityId("OLD_ENTITY_ID_2");
            entity.SetDomainId("NON_DEFAULT");
            entity.AddOtherInfo("NEW_OTHER_INFO_KEY", "NEW_OTHER_INFO_VALUE");
            entities = new TimelineEntities();
            entities.AddEntity(entity);
            response = dataManaer.PostEntities(entities, UserGroupInformation.GetCurrentUser(
                                                   ));
            NUnit.Framework.Assert.AreEqual(1, response.GetErrors().Count);
            NUnit.Framework.Assert.AreEqual(TimelinePutResponse.TimelinePutError.AccessDenied
                                            , response.GetErrors()[0].GetErrorCode());
            entity = store.GetEntity("OLD_ENTITY_ID_2", "OLD_ENTITY_TYPE_1", null);
            NUnit.Framework.Assert.IsNotNull(entity);
            // In leveldb, the domain Id is still null
            NUnit.Framework.Assert.IsNull(entity.GetDomainId());
            // Updating is not executed
            NUnit.Framework.Assert.AreEqual(0, entity.GetOtherInfo().Count);
        }
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        private ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt GetApplication
            (ApplicationId appId, ApplicationHistoryManagerOnTimelineStore.ApplicationReportField
            field)
        {
            TimelineEntity entity = timelineDataManager.GetEntity(ApplicationMetricsConstants
                                                                  .EntityType, appId.ToString(), EnumSet.AllOf <TimelineReader.Field>(), UserGroupInformation
                                                                  .GetLoginUser());

            if (entity == null)
            {
                throw new ApplicationNotFoundException("The entity for application " + appId + " doesn't exist in the timeline store"
                                                       );
            }
            else
            {
                return(GenerateApplicationReport(entity, field));
            }
        }
Пример #24
0
        /// <summary>Get the single timeline entity that the given user has access to.</summary>
        /// <remarks>
        /// Get the single timeline entity that the given user has access to. The
        /// meaning of each argument has been documented with
        /// <see cref="TimelineReader.GetEntity(string, string, Sharpen.EnumSet{E})"/>
        /// .
        /// </remarks>
        /// <seealso cref="TimelineReader.GetEntity(string, string, Sharpen.EnumSet{E})"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual TimelineEntity GetEntity(string entityType, string entityId, EnumSet
                                                <TimelineReader.Field> fields, UserGroupInformation callerUGI)
        {
            TimelineEntity entity = null;

            entity = store.GetEntity(entityId, entityType, fields);
            if (entity != null)
            {
                AddDefaultDomainIdIfAbsent(entity);
                // check ACLs
                if (!timelineACLsManager.CheckAccess(callerUGI, ApplicationAccessType.ViewApp, entity
                                                     ))
                {
                    entity = null;
                }
            }
            return(entity);
        }
Пример #25
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);
        }
            /// <exception cref="System.Exception"/>
            public Void Call()
            {
                TimelineClient client        = this._enclosing.CreateTimelineClientForUGI();
                TimelineEntity entityToStore = new TimelineEntity();

                entityToStore.SetEntityType(typeof(Org.Apache.Hadoop.Yarn.Server.Timeline.Security.TestTimelineAuthenticationFilter
                                                   ).FullName);
                entityToStore.SetEntityId("entity1");
                entityToStore.SetStartTime(0L);
                TimelinePutResponse putResponse = client.PutEntities(entityToStore);

                NUnit.Framework.Assert.AreEqual(0, putResponse.GetErrors().Count);
                TimelineEntity entityToRead = Org.Apache.Hadoop.Yarn.Server.Timeline.Security.TestTimelineAuthenticationFilter
                                              .testTimelineServer.GetTimelineStore().GetEntity("entity1", typeof(Org.Apache.Hadoop.Yarn.Server.Timeline.Security.TestTimelineAuthenticationFilter
                                                                                                                 ).FullName, null);

                NUnit.Framework.Assert.IsNotNull(entityToRead);
                return(null);
            }
Пример #27
0
        private void PublishContainerFinishedEvent(ContainerFinishedEvent @event)
        {
            TimelineEntity entity = CreateContainerEntity(@event.GetContainerId());
            TimelineEvent  tEvent = new TimelineEvent();

            tEvent.SetEventType(ContainerMetricsConstants.FinishedEventType);
            tEvent.SetTimestamp(@event.GetTimestamp());
            IDictionary <string, object> eventInfo = new Dictionary <string, object>();

            eventInfo[ContainerMetricsConstants.DiagnosticsInfoEventInfo] = @event.GetDiagnosticsInfo
                                                                                ();
            eventInfo[ContainerMetricsConstants.ExitStatusEventInfo] = @event.GetContainerExitStatus
                                                                           ();
            eventInfo[ContainerMetricsConstants.StateEventInfo] = @event.GetContainerState().
                                                                  ToString();
            tEvent.SetEventInfo(eventInfo);
            entity.AddEvent(tEvent);
            PutEntity(entity);
        }
Пример #28
0
        public virtual void TestRelatingToOldEntityWithoutDomainId()
        {
            // New entity is put in the default domain
            TimelineEntity entityToStore = new TimelineEntity();

            entityToStore.SetEntityType("NEW_ENTITY_TYPE_1");
            entityToStore.SetEntityId("NEW_ENTITY_ID_1");
            entityToStore.SetDomainId(TimelineDataManager.DefaultDomainId);
            entityToStore.AddRelatedEntity("OLD_ENTITY_TYPE_1", "OLD_ENTITY_ID_1");
            TimelineEntities entities = new TimelineEntities();

            entities.AddEntity(entityToStore);
            store.Put(entities);
            TimelineEntity entityToGet = store.GetEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1"
                                                         , null);

            NUnit.Framework.Assert.IsNotNull(entityToGet);
            NUnit.Framework.Assert.IsNull(entityToGet.GetDomainId());
            NUnit.Framework.Assert.AreEqual("NEW_ENTITY_TYPE_1", entityToGet.GetRelatedEntities
                                                ().Keys.GetEnumerator().Next());
            NUnit.Framework.Assert.AreEqual("NEW_ENTITY_ID_1", entityToGet.GetRelatedEntities
                                                ().Values.GetEnumerator().Next().GetEnumerator().Next());
            // New entity is not put in the default domain
            entityToStore = new TimelineEntity();
            entityToStore.SetEntityType("NEW_ENTITY_TYPE_2");
            entityToStore.SetEntityId("NEW_ENTITY_ID_2");
            entityToStore.SetDomainId("NON_DEFAULT");
            entityToStore.AddRelatedEntity("OLD_ENTITY_TYPE_1", "OLD_ENTITY_ID_1");
            entities = new TimelineEntities();
            entities.AddEntity(entityToStore);
            TimelinePutResponse response = store.Put(entities);

            NUnit.Framework.Assert.AreEqual(1, response.GetErrors().Count);
            NUnit.Framework.Assert.AreEqual(TimelinePutResponse.TimelinePutError.ForbiddenRelation
                                            , response.GetErrors()[0].GetErrorCode());
            entityToGet = store.GetEntity("OLD_ENTITY_ID_1", "OLD_ENTITY_TYPE_1", null);
            NUnit.Framework.Assert.IsNotNull(entityToGet);
            NUnit.Framework.Assert.IsNull(entityToGet.GetDomainId());
            // Still have one related entity
            NUnit.Framework.Assert.AreEqual(1, entityToGet.GetRelatedEntities().Keys.Count);
            NUnit.Framework.Assert.AreEqual(1, entityToGet.GetRelatedEntities().Values.GetEnumerator
                                                ().Next().Count);
        }
Пример #29
0
        /// <summary>Get the events whose entities the given user has access to.</summary>
        /// <remarks>
        /// Get the events whose entities the given user has access to. The meaning of
        /// each argument has been documented with
        /// <see cref="TimelineReader.GetEntityTimelines(string, System.Collections.Generic.ICollection{E}, long, long, long, System.Collections.Generic.ICollection{E})
        ///     "/>
        /// .
        /// </remarks>
        /// <seealso cref="TimelineReader.GetEntityTimelines(string, System.Collections.Generic.ICollection{E}, long, long, long, System.Collections.Generic.ICollection{E})
        ///     "/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual TimelineEvents GetEvents(string entityType, ICollection <string> entityIds
                                                , ICollection <string> eventTypes, long windowStart, long windowEnd, long limit,
                                                UserGroupInformation callerUGI)
        {
            TimelineEvents events = null;

            events = store.GetEntityTimelines(entityType, entityIds, limit, windowStart, windowEnd
                                              , eventTypes);
            if (events != null)
            {
                IEnumerator <TimelineEvents.EventsOfOneEntity> eventsItr = events.GetAllEvents().GetEnumerator
                                                                               ();
                while (eventsItr.HasNext())
                {
                    TimelineEvents.EventsOfOneEntity eventsOfOneEntity = eventsItr.Next();
                    try
                    {
                        TimelineEntity entity = store.GetEntity(eventsOfOneEntity.GetEntityId(), eventsOfOneEntity
                                                                .GetEntityType(), EnumSet.Of(TimelineReader.Field.PrimaryFilters));
                        AddDefaultDomainIdIfAbsent(entity);
                        // check ACLs
                        if (!timelineACLsManager.CheckAccess(callerUGI, ApplicationAccessType.ViewApp, entity
                                                             ))
                        {
                            eventsItr.Remove();
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("Error when verifying access for user " + callerUGI + " on the events of the timeline entity "
                                  + new EntityIdentifier(eventsOfOneEntity.GetEntityId(), eventsOfOneEntity.GetEntityType
                                                             ()), e);
                        eventsItr.Remove();
                    }
                }
            }
            if (events == null)
            {
                return(new TimelineEvents());
            }
            return(events);
        }
Пример #30
0
 public virtual TimelineEntity GetEntity(string entityId, string entityType, EnumSet
                                         <TimelineReader.Field> fieldsToRetrieve)
 {
     lock (this)
     {
         if (fieldsToRetrieve == null)
         {
             fieldsToRetrieve = EnumSet.AllOf <TimelineReader.Field>();
         }
         TimelineEntity entity = entities[new EntityIdentifier(entityId, entityType)];
         if (entity == null)
         {
             return(null);
         }
         else
         {
             return(MaskFields(entity, fieldsToRetrieve));
         }
     }
 }