Beispiel #1
0
  @Override
  @RequiredPermission(Permission.MANAGE_SETTINGS)
  public ServerDetails getServerDetails(Subject subject) {
    CoreServerMBean coreServerMBean = LookupUtil.getCoreServer();

    ServerDetails serverDetails = new ServerDetails();

    serverDetails.setProductInfo(getProductInfo(subject));

    HashMap<Detail, String> details = serverDetails.getDetails();

    DateFormat localTimeFormatter =
        DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL);
    details.put(ServerDetails.Detail.SERVER_LOCAL_TIME, localTimeFormatter.format(new Date()));
    details.put(ServerDetails.Detail.SERVER_TIMEZONE, TimeZone.getDefault().getDisplayName());
    details.put(
        ServerDetails.Detail.SERVER_HOME_DIR,
        coreServerMBean.getJBossServerHomeDir().getAbsolutePath());
    details.put(
        ServerDetails.Detail.SERVER_INSTALL_DIR, coreServerMBean.getInstallDir().getAbsolutePath());

    SystemDatabaseInformation dbInfo = SystemDatabaseInformation.getInstance();
    details.put(ServerDetails.Detail.DATABASE_CONNECTION_URL, dbInfo.getDatabaseConnectionURL());
    details.put(ServerDetails.Detail.DATABASE_DRIVER_NAME, dbInfo.getDatabaseDriverName());
    details.put(ServerDetails.Detail.DATABASE_DRIVER_VERSION, dbInfo.getDatabaseDriverVersion());
    details.put(ServerDetails.Detail.DATABASE_PRODUCT_NAME, dbInfo.getDatabaseProductName());
    details.put(ServerDetails.Detail.DATABASE_PRODUCT_VERSION, dbInfo.getDatabaseProductVersion());

    details.put(ServerDetails.Detail.SERVER_IDENTITY, serverManager.getServer().getName());

    return serverDetails;
  }
Beispiel #2
0
  private void initializeServer() {
    // Ensure the class is loaded and the dbType is set for our current db
    Connection conn = null;
    try {
      conn = dataSource.getConnection();
      DatabaseTypeFactory.setDefaultDatabaseType(DatabaseTypeFactory.getDatabaseType(conn));
    } catch (Exception e) {
      log.error("Could not initialize server.", e);
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (Exception e) {
          log.error("Failed to close temporary connection used for server initialization.", e);
        }
      }
    }

    // Ensure that this server is registered in the database.
    createDefaultServerIfNecessary();

    // immediately put the server into MM if configured to do so
    if (ServerCommunicationsServiceUtil.getService().getMaintenanceModeAtStartup()) {
      log.info("Server is configured to start up in MAINTENANCE mode.");
      Server server = serverManager.getServer();
      Integer[] serverId = new Integer[] {server.getId()};
      topologyManager.updateServerMode(
          LookupUtil.getSubjectManager().getOverlord(), serverId, OperationMode.MAINTENANCE);
    }

    // Establish the current server mode for the server. This will move the server to NORMAL
    // mode from DOWN if necessary.  This can also affect comm layer behavior.
    serverManager.establishCurrentServerMode();
    if ("true".equals(System.getProperty("rhq.sync.endpoint-address", "false"))) {
      try {
        serverManager.syncEndpointAddress();
      } catch (SyncEndpointAddressException e) {
        log.error("Failed to sync server endpoint address.", e);
      }
    }
  }
Beispiel #3
0
  /**
   * Starts the embedded agent, but only if the embedded agent is installed and it is enabled.
   *
   * @throws RuntimeException if the agent is installed and enabled but failed to start
   * @deprecated we don't have an embedded agent anymore, leaving this in case we resurrect it
   */
  private void startEmbeddedAgent() throws RuntimeException {
    // we can't use EmbeddedAgentBootstrapServiceMBean because if the embedded agent
    // isn't installed, that class will not be available; we must use JMX API
    final ObjectName agentBootstrapMBean =
        ObjectNameFactory.create("rhq:service=EmbeddedAgentBootstrap");
    final String agentEnabledAttribute = "AgentEnabled";
    final String startAgentMethod = "startAgent";
    final String configurationOverridesAttribute = "ConfigurationOverrides";
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    try {
      // this will fail if the embedded agent isn't installed
      String enabled = (String) mbs.getAttribute(agentBootstrapMBean, agentEnabledAttribute);

      // if we got this far, the embedded agent is at least installed
      // now check to see if its enabled - if so start it; any startup exceptions now are thrown
      try {
        if (Boolean.valueOf(enabled)) {
          log.info("The embedded Agent is installed and enabled - it will now be started...");

          // NOTE: we cannot directly import AgentConfigurationConstants, so we hardcode the
          // actual constant values here - need to keep an eye on these in the unlikely event
          // the constant values change.
          String AgentConfigurationConstants_SERVER_TRANSPORT = "rhq.agent.server.transport";
          String AgentConfigurationConstants_SERVER_BIND_ADDRESS = "rhq.agent.server.bind-address";
          String AgentConfigurationConstants_SERVER_BIND_PORT = "rhq.agent.server.bind-port";

          // Get the configuration overrides as set in the configuration file.
          // If the agent's bind address isn't overridden with a non-empty value,
          // then we need to get the Server bind address and use it for the agent's bind address.
          // If the agent's server endpoint address/port are empty, we again use the values
          // appropriate for the Server this agent is embedded in.
          // Note that we don't look for the values in persisted preferences - we assume they
          // are always present in the configuration overrides (which they should always be);
          Properties overrides;
          String serverTransport;
          String serverAddress;
          String serverPort;
          String agentAddress;

          overrides =
              (Properties) mbs.getAttribute(agentBootstrapMBean, configurationOverridesAttribute);

          serverTransport = overrides.getProperty(AgentConfigurationConstants_SERVER_TRANSPORT);
          serverAddress = overrides.getProperty(AgentConfigurationConstants_SERVER_BIND_ADDRESS);
          serverPort = overrides.getProperty(AgentConfigurationConstants_SERVER_BIND_PORT);
          agentAddress =
              overrides.getProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_ADDRESS);

          Server server = serverManager.getServer();

          if (agentAddress == null || agentAddress.trim().equals("")) {
            overrides.setProperty(
                ServiceContainerConfigurationConstants.CONNECTOR_BIND_ADDRESS, server.getAddress());
          }
          if (serverAddress == null || serverAddress.trim().equals("")) {
            overrides.setProperty(
                AgentConfigurationConstants_SERVER_BIND_ADDRESS, server.getAddress());
          }
          if (serverPort == null || serverPort.trim().equals("")) {
            if (SecurityUtil.isTransportSecure(serverTransport)) {
              overrides.setProperty(
                  AgentConfigurationConstants_SERVER_BIND_PORT,
                  Integer.toString(server.getSecurePort()));
            } else {
              overrides.setProperty(
                  AgentConfigurationConstants_SERVER_BIND_PORT, Integer.toString(server.getPort()));
            }
          }

          mbs.setAttribute(
              agentBootstrapMBean, new Attribute(configurationOverridesAttribute, overrides));

          // We need to do the agent startup in a separate thread so we do not hang
          // this startup servlet.  JBossAS 4.2 will not begin accepting HTTP requests
          // until this startup servlet has finished (this is different from JBossAS 4.0).
          // The agent needs to submit an HTTP request in order to complete its startup
          // (it needs to register with the server).
          // The side effect of this is the RHQ Server will still start even if the embedded
          // agent fails to start - this may not be a bad thing.  We probably do not want
          // the entire RHQ Server to go down if its agent fails to start.
          Runnable agentStartRunnable =
              new Runnable() {
                public void run() {
                  // this returns only when the agent has started and is registered (sends HTTP
                  // request)
                  try {
                    mbs.invoke(agentBootstrapMBean, startAgentMethod, new Object[0], new String[0]);
                  } catch (Throwable t) {
                    log.error("Failed to start the embedded Agent - it will not be available!", t);
                  }
                }
              };

          Thread agentStartThread = new Thread(agentStartRunnable, "Embedded Agent Startup");
          agentStartThread.setDaemon(true);
          agentStartThread.start();
        } else {
          log.debug("The embedded Agent is not enabled, so it will not be started.");
        }
      } catch (Throwable t) {
        throw new RuntimeException("Failed to start the embedded Agent.", t);
      }
    } catch (RuntimeException se) {
      throw se;
    } catch (Throwable t) {
      log.info("The embedded Agent is not installed, so it will not be started (" + t + ").");
    }

    return;
  }