예제 #1
0
 /// <exception cref="System.Exception"/>
 protected override void ServiceInit(Configuration conf)
 {
     lock (this)
     {
         Configuration config = new YarnConfiguration(conf);
         // create nm-local-dirs and configure them for the nodemanager
         string localDirsString = this.PrepareDirs("local", this._enclosing.numLocalDirs);
         config.Set(YarnConfiguration.NmLocalDirs, localDirsString);
         // create nm-log-dirs and configure them for the nodemanager
         string logDirsString = this.PrepareDirs("log", this._enclosing.numLogDirs);
         config.Set(YarnConfiguration.NmLogDirs, logDirsString);
         config.SetInt(YarnConfiguration.NmPmemMb, config.GetInt(YarnConfiguration.YarnMiniclusterNmPmemMb
                                                                 , YarnConfiguration.DefaultYarnMiniclusterNmPmemMb));
         config.Set(YarnConfiguration.NmAddress, MiniYARNCluster.GetHostname() + ":0");
         config.Set(YarnConfiguration.NmLocalizerAddress, MiniYARNCluster.GetHostname() +
                    ":0");
         WebAppUtils.SetNMWebAppHostNameAndPort(config, MiniYARNCluster.GetHostname(), 0);
         // Disable resource checks by default
         if (!config.GetBoolean(YarnConfiguration.YarnMiniclusterControlResourceMonitoring
                                , YarnConfiguration.DefaultYarnMiniclusterControlResourceMonitoring))
         {
             config.SetBoolean(YarnConfiguration.NmPmemCheckEnabled, false);
             config.SetBoolean(YarnConfiguration.NmVmemCheckEnabled, false);
         }
         MiniYARNCluster.Log.Info("Starting NM: " + this.index);
         this._enclosing.nodeManagers[this.index].Init(config);
         base.ServiceInit(config);
     }
 }
예제 #2
0
        /// <exception cref="System.Exception"/>
        public override int Run(string[] args)
        {
            // -directlyAccessNodeLabelStore is a additional option for node label
            // access, so just search if we have specified this option, and remove it
            IList <string> argsList = new AList <string>();

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Equals("-directlyAccessNodeLabelStore"))
                {
                    directlyAccessNodeLabelStore = true;
                }
                else
                {
                    argsList.AddItem(args[i]);
                }
            }
            args = Sharpen.Collections.ToArray(argsList, new string[0]);
            YarnConfiguration yarnConf = GetConf() == null ? new YarnConfiguration() : new YarnConfiguration
                                             (GetConf());
            bool isHAEnabled = yarnConf.GetBoolean(YarnConfiguration.RmHaEnabled, YarnConfiguration
                                                   .DefaultRmHaEnabled);

            if (args.Length < 1)
            {
                PrintUsage(string.Empty, isHAEnabled);
                return(-1);
            }
            int    exitCode = -1;
            int    i_1      = 0;
            string cmd      = args[i_1++];

            exitCode = 0;
            if ("-help".Equals(cmd))
            {
                if (i_1 < args.Length)
                {
                    PrintUsage(args[i_1], isHAEnabled);
                }
                else
                {
                    PrintHelp(string.Empty, isHAEnabled);
                }
                return(exitCode);
            }
            if (Usage.Contains(cmd))
            {
                if (isHAEnabled)
                {
                    return(base.Run(args));
                }
                System.Console.Out.WriteLine("Cannot run " + cmd + " when ResourceManager HA is not enabled"
                                             );
                return(-1);
            }
            //
            // verify that we have enough command line parameters
            //
            if ("-refreshAdminAcls".Equals(cmd) || "-refreshQueues".Equals(cmd) || "-refreshNodes"
                .Equals(cmd) || "-refreshServiceAcl".Equals(cmd) || "-refreshUserToGroupsMappings"
                .Equals(cmd) || "-refreshSuperUserGroupsConfiguration".Equals(cmd))
            {
                if (args.Length != 1)
                {
                    PrintUsage(cmd, isHAEnabled);
                    return(exitCode);
                }
            }
            try
            {
                if ("-refreshQueues".Equals(cmd))
                {
                    exitCode = RefreshQueues();
                }
                else
                {
                    if ("-refreshNodes".Equals(cmd))
                    {
                        exitCode = RefreshNodes();
                    }
                    else
                    {
                        if ("-refreshUserToGroupsMappings".Equals(cmd))
                        {
                            exitCode = RefreshUserToGroupsMappings();
                        }
                        else
                        {
                            if ("-refreshSuperUserGroupsConfiguration".Equals(cmd))
                            {
                                exitCode = RefreshSuperUserGroupsConfiguration();
                            }
                            else
                            {
                                if ("-refreshAdminAcls".Equals(cmd))
                                {
                                    exitCode = RefreshAdminAcls();
                                }
                                else
                                {
                                    if ("-refreshServiceAcl".Equals(cmd))
                                    {
                                        exitCode = RefreshServiceAcls();
                                    }
                                    else
                                    {
                                        if ("-getGroups".Equals(cmd))
                                        {
                                            string[] usernames = Arrays.CopyOfRange(args, i_1, args.Length);
                                            exitCode = GetGroups(usernames);
                                        }
                                        else
                                        {
                                            if ("-addToClusterNodeLabels".Equals(cmd))
                                            {
                                                if (i_1 >= args.Length)
                                                {
                                                    System.Console.Error.WriteLine(NoLabelErrMsg);
                                                    exitCode = -1;
                                                }
                                                else
                                                {
                                                    exitCode = AddToClusterNodeLabels(args[i_1]);
                                                }
                                            }
                                            else
                                            {
                                                if ("-removeFromClusterNodeLabels".Equals(cmd))
                                                {
                                                    if (i_1 >= args.Length)
                                                    {
                                                        System.Console.Error.WriteLine(NoLabelErrMsg);
                                                        exitCode = -1;
                                                    }
                                                    else
                                                    {
                                                        exitCode = RemoveFromClusterNodeLabels(args[i_1]);
                                                    }
                                                }
                                                else
                                                {
                                                    if ("-replaceLabelsOnNode".Equals(cmd))
                                                    {
                                                        if (i_1 >= args.Length)
                                                        {
                                                            System.Console.Error.WriteLine(NoMappingErrMsg);
                                                            exitCode = -1;
                                                        }
                                                        else
                                                        {
                                                            exitCode = ReplaceLabelsOnNodes(args[i_1]);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        exitCode = -1;
                                                        System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": Unknown command"
                                                                                       );
                                                        PrintUsage(string.Empty, isHAEnabled);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (ArgumentException arge)
            {
                exitCode = -1;
                System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": " + arge.GetLocalizedMessage
                                                   ());
                PrintUsage(cmd, isHAEnabled);
            }
            catch (RemoteException e)
            {
                //
                // This is a error returned by hadoop server. Print
                // out the first line of the error mesage, ignore the stack trace.
                exitCode = -1;
                try
                {
                    string[] content;
                    content = e.GetLocalizedMessage().Split("\n");
                    System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": " + content
                                                   [0]);
                }
                catch (Exception ex)
                {
                    System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": " + ex.GetLocalizedMessage
                                                       ());
                }
            }
            catch (Exception e)
            {
                exitCode = -1;
                System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": " + e.GetLocalizedMessage
                                                   ());
            }
            if (null != localNodeLabelsManager)
            {
                localNodeLabelsManager.Stop();
            }
            return(exitCode);
        }
예제 #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();
            }
        }