/// <summary>Get all the domains that belong to the given owner.</summary>
        /// <remarks>
        /// Get all the domains that belong to the given owner. If callerUGI is not
        /// the owner or the admin of the domain, empty list is going to be returned.
        /// </remarks>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual TimelineDomains GetDomains(string owner, UserGroupInformation callerUGI
                                                  )
        {
            TimelineDomains domains   = store.GetDomains(owner);
            bool            hasAccess = true;

            if (domains.GetDomains().Count > 0)
            {
                // The owner for each domain is the same, just need to check one
                hasAccess = timelineACLsManager.CheckAccess(callerUGI, domains.GetDomains()[0]);
            }
            if (hasAccess)
            {
                return(domains);
            }
            else
            {
                return(new TimelineDomains());
            }
        }
Beispiel #2
0
        /// <exception cref="System.IO.IOException"/>
        public virtual TimelineDomains GetDomains(string owner)
        {
            IList <TimelineDomain>       domains           = new AList <TimelineDomain>();
            ICollection <TimelineDomain> domainsOfOneOwner = domainsByOwner[owner];

            if (domainsOfOneOwner == null)
            {
                return(new TimelineDomains());
            }
            foreach (TimelineDomain domain in domainsByOwner[owner])
            {
                TimelineDomain domainToReturn = CreateTimelineDomain(domain.GetId(), domain.GetDescription
                                                                         (), domain.GetOwner(), domain.GetReaders(), domain.GetWriters(), domain.GetCreatedTime
                                                                         (), domain.GetModifiedTime());
                domains.AddItem(domainToReturn);
            }
            domains.Sort(new _IComparer_267());
            TimelineDomains domainsToReturn = new TimelineDomains();

            domainsToReturn.AddDomains(domains);
            return(domainsToReturn);
        }
Beispiel #3
0
        /// <summary>Put timeline data in a JSON file via command line.</summary>
        /// <param name="path">path to the timeline data JSON file</param>
        /// <param name="type">the type of the timeline data in the JSON file</param>
        private static void PutTimelineDataInJSONFile(string path, string type)
        {
            FilePath jsonFile = new FilePath(path);

            if (!jsonFile.Exists())
            {
                Log.Error("File [" + jsonFile.GetAbsolutePath() + "] doesn't exist");
                return;
            }
            ObjectMapper mapper = new ObjectMapper();

            YarnJacksonJaxbJsonProvider.ConfigObjectMapper(mapper);
            TimelineEntities entities = null;
            TimelineDomains  domains  = null;

            try
            {
                if (type.Equals(EntityDataType))
                {
                    entities = mapper.ReadValue <TimelineEntities>(jsonFile);
                }
                else
                {
                    if (type.Equals(DomainDataType))
                    {
                        domains = mapper.ReadValue <TimelineDomains>(jsonFile);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Error when reading  " + e.Message);
                Sharpen.Runtime.PrintStackTrace(e, System.Console.Error);
                return;
            }
            Configuration  conf   = new YarnConfiguration();
            TimelineClient client = TimelineClient.CreateTimelineClient();

            client.Init(conf);
            client.Start();
            try
            {
                if (UserGroupInformation.IsSecurityEnabled() && conf.GetBoolean(YarnConfiguration
                                                                                .TimelineServiceEnabled, false))
                {
                    Org.Apache.Hadoop.Security.Token.Token <TimelineDelegationTokenIdentifier> token =
                        client.GetDelegationToken(UserGroupInformation.GetCurrentUser().GetUserName());
                    UserGroupInformation.GetCurrentUser().AddToken(token);
                }
                if (type.Equals(EntityDataType))
                {
                    TimelinePutResponse response = client.PutEntities(Sharpen.Collections.ToArray(entities
                                                                                                  .GetEntities(), new TimelineEntity[entities.GetEntities().Count]));
                    if (response.GetErrors().Count == 0)
                    {
                        Log.Info("Timeline entities are successfully put");
                    }
                    else
                    {
                        foreach (TimelinePutResponse.TimelinePutError error in response.GetErrors())
                        {
                            Log.Error("TimelineEntity [" + error.GetEntityType() + ":" + error.GetEntityId()
                                      + "] is not successfully put. Error code: " + error.GetErrorCode());
                        }
                    }
                }
                else
                {
                    if (type.Equals(DomainDataType))
                    {
                        bool hasError = false;
                        foreach (TimelineDomain domain in domains.GetDomains())
                        {
                            try
                            {
                                client.PutDomain(domain);
                            }
                            catch (Exception e)
                            {
                                Log.Error("Error when putting domain " + domain.GetId(), e);
                                hasError = true;
                            }
                        }
                        if (!hasError)
                        {
                            Log.Info("Timeline domains are successfully put");
                        }
                    }
                }
            }
            catch (RuntimeException e)
            {
                Log.Error("Error when putting the timeline data", e);
            }
            catch (Exception e)
            {
                Log.Error("Error when putting the timeline data", e);
            }
            finally
            {
                client.Stop();
            }
        }