Exemple #1
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();
            }
        }
Exemple #2
0
 static TimelineUtils()
 {
     mapper = new ObjectMapper();
     YarnJacksonJaxbJsonProvider.ConfigObjectMapper(mapper);
 }