예제 #1
0
        /// <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());
            }
        }
예제 #2
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();
            }
        }