Ejemplo n.º 1
0
 /// <summary>Sets a new server status.</summary>
 /// <remarks>
 /// Sets a new server status.
 /// <p>
 /// The status must be settable.
 /// <p>
 /// All services will be notified o the status change via the
 /// <see cref="Service.ServerStatusChange(Status, Status)"/>
 /// method. If a service
 /// throws an exception during the notification, the server will be destroyed.
 /// </remarks>
 /// <param name="status">status to set.</param>
 /// <exception cref="ServerException">
 /// thrown if the service has been destroy because of
 /// a failed notification to a service.
 /// </exception>
 /// <exception cref="Org.Apache.Hadoop.Lib.Server.ServerException"/>
 public virtual void SetStatus(Server.Status status)
 {
     Check.NotNull(status, "status");
     if (status.settable)
     {
         if (status != this.status)
         {
             Server.Status oldStatus = this.status;
             this.status = status;
             foreach (Service service in services.Values)
             {
                 try
                 {
                     service.ServerStatusChange(oldStatus, status);
                 }
                 catch (Exception ex)
                 {
                     log.Error("Service [{}] exception during status change to [{}] -server shutting down-,  {}"
                               , new object[] { service.GetInterface().Name, status, ex.Message, ex });
                     Destroy();
                     throw new ServerException(ServerException.ERROR.S11, service.GetInterface().Name,
                                               status, ex.Message, ex);
                 }
             }
         }
     }
     else
     {
         throw new ArgumentException("Status [" + status + " is not settable");
     }
 }
Ejemplo n.º 2
0
 /// <summary>Destroys the server.</summary>
 /// <remarks>
 /// Destroys the server.
 /// <p>
 /// All services are destroyed in reverse order of initialization, then the
 /// Log4j framework is shutdown.
 /// </remarks>
 public virtual void Destroy()
 {
     EnsureOperational();
     DestroyServices();
     log.Info("Server [{}] shutdown!", name);
     log.Info("======================================================");
     if (!bool.GetBoolean("test.circus"))
     {
         LogManager.Shutdown();
     }
     status = Server.Status.Shutdown;
 }
Ejemplo n.º 3
0
 /// <summary>Creates a server instance.</summary>
 /// <remarks>
 /// Creates a server instance.
 /// <p>
 /// It uses the provided configuration instead loading it from the config dir.
 /// </remarks>
 /// <param name="name">server name.</param>
 /// <param name="homeDir">server home directory.</param>
 /// <param name="configDir">config directory.</param>
 /// <param name="logDir">log directory.</param>
 /// <param name="tempDir">temp directory.</param>
 /// <param name="config">server configuration.</param>
 public Server(string name, string homeDir, string configDir, string logDir, string
               tempDir, Configuration config)
 {
     this.name      = StringUtils.ToLowerCase(Check.NotEmpty(name, "name").Trim());
     this.homeDir   = Check.NotEmpty(homeDir, "homeDir");
     this.configDir = Check.NotEmpty(configDir, "configDir");
     this.logDir    = Check.NotEmpty(logDir, "logDir");
     this.tempDir   = Check.NotEmpty(tempDir, "tempDir");
     CheckAbsolutePath(homeDir, "homeDir");
     CheckAbsolutePath(configDir, "configDir");
     CheckAbsolutePath(logDir, "logDir");
     CheckAbsolutePath(tempDir, "tempDir");
     if (config != null)
     {
         this.config = new Configuration(false);
         ConfigurationUtils.Copy(config, this.config);
     }
     status = Server.Status.Undef;
 }
Ejemplo n.º 4
0
 /// <exception cref="Org.Apache.Hadoop.Lib.Server.ServiceException"/>
 public virtual void ServerStatusChange(Server.Status oldStatus, Server.Status newStatus
                                        )
 {
 }
Ejemplo n.º 5
0
 /// <exception cref="Org.Apache.Hadoop.Lib.Server.ServiceException"/>
 public override void ServerStatusChange(Server.Status oldStatus, Server.Status newStatus
                                         )
 {
     throw new RuntimeException();
 }
Ejemplo n.º 6
0
 /// <exception cref="Org.Apache.Hadoop.Lib.Server.ServiceException"/>
 public virtual void ServerStatusChange(Server.Status oldStatus, Server.Status newStatus
                                        )
 {
     Lifecycle.AddItem("serverStatusChange");
 }
Ejemplo n.º 7
0
        /// <summary>Initializes the Server.</summary>
        /// <remarks>
        /// Initializes the Server.
        /// <p>
        /// The initialization steps are:
        /// <ul>
        /// <li>It verifies the service home and temp directories exist</li>
        /// <li>Loads the Server <code>#SERVER#-default.xml</code>
        /// configuration file from the classpath</li>
        /// <li>Initializes log4j logging. If the
        /// <code>#SERVER#-log4j.properties</code> file does not exist in the config
        /// directory it load <code>default-log4j.properties</code> from the classpath
        /// </li>
        /// <li>Loads the <code>#SERVER#-site.xml</code> file from the server config
        /// directory and merges it with the default configuration.</li>
        /// <li>Loads the services</li>
        /// <li>Initializes the services</li>
        /// <li>Post-initializes the services</li>
        /// <li>Sets the server startup status</li>
        /// </ul>
        /// </remarks>
        /// <exception cref="ServerException">thrown if the server could not be initialized.</exception>
        /// <exception cref="Org.Apache.Hadoop.Lib.Server.ServerException"/>
        public virtual void Init()
        {
            if (status != Server.Status.Undef)
            {
                throw new InvalidOperationException("Server already initialized");
            }
            status = Server.Status.Booting;
            VerifyDir(homeDir);
            VerifyDir(tempDir);
            Properties serverInfo = new Properties();

            try
            {
                InputStream @is = GetResource(name + ".properties");
                serverInfo.Load(@is);
                @is.Close();
            }
            catch (IOException)
            {
                throw new RuntimeException("Could not load server information file: " + name + ".properties"
                                           );
            }
            InitLog();
            log.Info("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            log.Info("Server [{}] starting", name);
            log.Info("  Built information:");
            log.Info("    Version           : {}", serverInfo.GetProperty(name + ".version",
                                                                          "undef"));
            log.Info("    Source Repository : {}", serverInfo.GetProperty(name + ".source.repository"
                                                                          , "undef"));
            log.Info("    Source Revision   : {}", serverInfo.GetProperty(name + ".source.revision"
                                                                          , "undef"));
            log.Info("    Built by          : {}", serverInfo.GetProperty(name + ".build.username"
                                                                          , "undef"));
            log.Info("    Built timestamp   : {}", serverInfo.GetProperty(name + ".build.timestamp"
                                                                          , "undef"));
            log.Info("  Runtime information:");
            log.Info("    Home   dir: {}", homeDir);
            log.Info("    Config dir: {}", (config == null) ? configDir : "-");
            log.Info("    Log    dir: {}", logDir);
            log.Info("    Temp   dir: {}", tempDir);
            InitConfig();
            log.Debug("Loading services");
            IList <Service> list = LoadServices();

            try
            {
                log.Debug("Initializing services");
                InitServices(list);
                log.Info("Services initialized");
            }
            catch (ServerException ex)
            {
                log.Error("Services initialization failure, destroying initialized services");
                DestroyServices();
                throw;
            }
            Server.Status status = Server.Status.ValueOf(GetConfig().Get(GetPrefixedName(ConfStartupStatus
                                                                                         ), Server.Status.Normal.ToString()));
            SetStatus(status);
            log.Info("Server [{}] started!, status [{}]", name, status);
        }