Search in sources :

Example 16 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class ServerBootstrap method startCommand.

@Override
protected void startCommand() {
    final AuditEventSender auditEventSender = injector.getInstance(AuditEventSender.class);
    final NodeId nodeId = injector.getInstance(NodeId.class);
    final String systemInformation = Tools.getSystemInformation();
    final Map<String, Object> auditEventContext = ImmutableMap.of("version", version.toString(), "java", systemInformation, "node_id", nodeId.toString());
    auditEventSender.success(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
    final OS os = OS.getOs();
    LOG.info("Graylog {} {} starting up", commandName, version);
    LOG.info("JRE: {}", systemInformation);
    LOG.info("Deployment: {}", configuration.getInstallationSource());
    LOG.info("OS: {}", os.getPlatformName());
    LOG.info("Arch: {}", os.getArch());
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    serverStatus.initialize();
    startNodeRegistration(injector);
    final ActivityWriter activityWriter;
    final ServiceManager serviceManager;
    try {
        activityWriter = injector.getInstance(ActivityWriter.class);
        serviceManager = injector.getInstance(ServiceManager.class);
    } catch (ProvisionException e) {
        LOG.error("Guice error", e);
        annotateProvisionException(e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
        return;
    } catch (Exception e) {
        LOG.error("Unexpected exception", e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
        return;
    }
    Runtime.getRuntime().addShutdownHook(new Thread(injector.getInstance(shutdownHook())));
    // propagate default size to input plugins
    MessageInput.setDefaultRecvBufferSize(configuration.getUdpRecvBufferSizes());
    // Start services.
    final ServiceManagerListener serviceManagerListener = injector.getInstance(ServiceManagerListener.class);
    serviceManager.addListener(serviceManagerListener);
    try {
        serviceManager.startAsync().awaitHealthy();
    } catch (Exception e) {
        try {
            serviceManager.stopAsync().awaitStopped(configuration.getShutdownTimeout(), TimeUnit.MILLISECONDS);
        } catch (TimeoutException timeoutException) {
            LOG.error("Unable to shutdown properly on time. {}", serviceManager.servicesByState());
        }
        LOG.error("Graylog startup failed. Exiting. Exception was:", e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
    }
    LOG.info("Services started, startup times in ms: {}", serviceManager.startupTimes());
    activityWriter.write(new Activity("Started up.", Main.class));
    LOG.info("Graylog " + commandName + " up and running.");
    auditEventSender.success(AuditActor.system(nodeId), NODE_STARTUP_COMPLETE, auditEventContext);
    // Block forever.
    try {
        Thread.currentThread().join();
    } catch (InterruptedException e) {
        return;
    }
}
Also used : OS(org.jsoftbiz.utils.OS) Activity(org.graylog2.shared.system.activities.Activity) TimeoutException(java.util.concurrent.TimeoutException) ProvisionException(com.google.inject.ProvisionException) ProvisionException(com.google.inject.ProvisionException) AuditEventSender(org.graylog2.audit.AuditEventSender) ServiceManager(com.google.common.util.concurrent.ServiceManager) ServerStatus(org.graylog2.plugin.ServerStatus) NodeId(org.graylog2.plugin.system.NodeId) ServiceManagerListener(org.graylog2.shared.initializers.ServiceManagerListener) ActivityWriter(org.graylog2.shared.system.activities.ActivityWriter) TimeoutException(java.util.concurrent.TimeoutException)

Example 17 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class EsNodeProviderTest method noEsFileValuesFromGraylog2Config.

@Test
public void noEsFileValuesFromGraylog2Config() {
    // checks that all values in the node settings are from the graylog2 conf and that no extra settings remain untested
    Map<String, String> settings = Maps.newHashMap();
    Map<String, String> esPropNames = Maps.newHashMap();
    // add all ES settings here that are configurable via graylog.conf
    addEsConfig(esPropNames, settings, "cluster.name", "elasticsearch_cluster_name", "garylog5");
    addEsConfig(esPropNames, settings, "node.name", "elasticsearch_node_name_prefix", "garylord-");
    addEsConfig(esPropNames, settings, "node.master", "elasticsearch_node_master", "true");
    addEsConfig(esPropNames, settings, "node.data", "elasticsearch_node_data", "true");
    addEsConfig(esPropNames, settings, "path.home", "elasticsearch_path_home", "data/elasticsearch");
    addEsConfig(esPropNames, settings, "path.data", "elasticsearch_path_data", "data/elasticsearch");
    addEsConfig(esPropNames, settings, "transport.tcp.port", "elasticsearch_transport_tcp_port", "9999");
    addEsConfig(esPropNames, settings, "http.enabled", "elasticsearch_http_enabled", "true");
    addEsConfig(esPropNames, settings, "discovery.zen.ping.unicast.hosts.0", "elasticsearch_discovery_zen_ping_unicast_hosts", "example.net");
    addEsConfig(esPropNames, settings, "discovery.initial_state_timeout", "elasticsearch_discovery_initial_state_timeout", "5s");
    esPropNames.put("action.auto_create_index", "false");
    esPropNames.put("node.client", "true");
    ElasticsearchConfiguration config = setupConfig(settings);
    Settings nodeSettings = EsNodeProvider.readNodeSettings(config, nodeId);
    assertThat(Sets.symmetricDifference(esPropNames.keySet(), nodeSettings.getAsMap().keySet())).isEmpty();
    assertThat(nodeSettings.get("node.name")).isEqualTo(settings.get("elasticsearch_node_name_prefix") + nodeId);
    for (Map.Entry<String, String> property : esPropNames.entrySet()) {
        final String key = property.getKey();
        // The node name is being constructed and not used verbatim.
        if ("node.name".equals(key)) {
            continue;
        }
        final String settingValue = nodeSettings.get(key);
        // the node setting value should be whatever we have put in.
        assertThat(settingValue).isEqualTo(property.getValue());
    }
}
Also used : ElasticsearchConfiguration(org.graylog2.configuration.ElasticsearchConfiguration) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 18 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class EsNodeProviderTest method testEsConfFileOverride.

@Test
public void testEsConfFileOverride() throws IOException, URISyntaxException {
    final Map<String, String> settings = Maps.newHashMap();
    final String esConfigFilePath = new File(Resources.getResource("org/graylog2/bindings/providers/elasticsearch.yml").toURI()).getAbsolutePath();
    settings.put("elasticsearch_config_file", esConfigFilePath);
    ElasticsearchConfiguration config = setupConfig(settings);
    final Settings nodeSettings = EsNodeProvider.readNodeSettings(config, nodeId);
    assertNotEquals("cluster.name", config.getClusterName(), nodeSettings.get("cluster.name"));
    assertEquals("cluster.name", "fromfile", nodeSettings.get("cluster.name"));
    assertNotEquals("node.name", config.getNodeNamePrefix(), nodeSettings.get("node.name"));
    assertEquals("node.name", "filenode", nodeSettings.get("node.name"));
    assertNotEquals("node.master", config.isMasterNode(), nodeSettings.get("node.master"));
    assertNotEquals("node.data", config.isDataNode(), nodeSettings.get("node.data"));
    assertNotEquals("http.enabled", config.isHttpEnabled(), nodeSettings.get("http.enabled"));
    assertNotEquals("transport.tcp.port", config.getTransportTcpPort(), nodeSettings.get("transport.tcp.port"));
    assertNotEquals("discovery.initial_state_timeout", config.getInitialStateTimeout(), nodeSettings.get("discovery.initial_state_timeout"));
    assertNotEquals("discovery.zen.ping.unicast.hosts", config.getUnicastHosts(), Lists.newArrayList(nodeSettings.getAsArray("discovery.zen.ping.unicast.hosts")));
}
Also used : ElasticsearchConfiguration(org.graylog2.configuration.ElasticsearchConfiguration) File(java.io.File) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 19 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class EsNodeProviderTest method zenUnicastHostsAreTrimmed.

@Test
public void zenUnicastHostsAreTrimmed() throws IOException, ValidationException, RepositoryException {
    Map<String, String> settings = ImmutableMap.of("password_secret", "thisisatest", "retention_strategy", "delete", "root_password_sha2", "thisisatest", "elasticsearch_discovery_zen_ping_unicast_hosts", " example.com,   example.net ");
    final ElasticsearchConfiguration config = new ElasticsearchConfiguration();
    new JadConfig(new InMemoryRepository(settings), config).process();
    final Settings nodeSettings = EsNodeProvider.readNodeSettings(config, nodeId);
    assertThat(nodeSettings.getAsArray("discovery.zen.ping.unicast.hosts")).contains("example.com", "example.net");
}
Also used : JadConfig(com.github.joschi.jadconfig.JadConfig) InMemoryRepository(com.github.joschi.jadconfig.repositories.InMemoryRepository) ElasticsearchConfiguration(org.graylog2.configuration.ElasticsearchConfiguration) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 20 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class EsNodeProviderTest method defaultConfigNoEsFile.

@Test
public void defaultConfigNoEsFile() {
    // check that all ES settings will be taken from the default values in Configuration.java if nothing is specified.
    Map<String, String> minimalSettings = Maps.newHashMap();
    ElasticsearchConfiguration defaultConfig = setupConfig(minimalSettings);
    Map<String, String> settings = Maps.newHashMap();
    ElasticsearchConfiguration config = setupConfig(settings);
    Settings nodeSettings = EsNodeProvider.readNodeSettings(config, nodeId);
    assertEquals(defaultConfig.getClusterName(), nodeSettings.get("cluster.name"));
    assertEquals(defaultConfig.getNodeNamePrefix() + nodeId, nodeSettings.get("node.name"));
    assertEquals(defaultConfig.isMasterNode(), nodeSettings.getAsBoolean("node.master", false));
    assertEquals(defaultConfig.isDataNode(), nodeSettings.getAsBoolean("node.data", false));
    assertEquals(defaultConfig.isHttpEnabled(), nodeSettings.getAsBoolean("http.enabled", false));
    assertEquals(defaultConfig.getTransportTcpPort(), nodeSettings.getAsInt("transport.tcp.port", 0).intValue());
    assertEquals(defaultConfig.getInitialStateTimeout(), nodeSettings.get("discovery.initial_state_timeout"));
    assertEquals(false, nodeSettings.getAsBoolean("action.auto_create_index", true));
}
Also used : ElasticsearchConfiguration(org.graylog2.configuration.ElasticsearchConfiguration) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 Timed (com.codahale.metrics.annotation.Timed)7 ApiOperation (io.swagger.annotations.ApiOperation)7 Node (org.graylog2.cluster.Node)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 Before (org.junit.Before)6 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)5 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Settings (org.elasticsearch.common.settings.Settings)4 ElasticsearchConfiguration (org.graylog2.configuration.ElasticsearchConfiguration)4 File (java.io.File)3 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)3 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)3 JadConfig (com.github.joschi.jadconfig.JadConfig)2 InMemoryRepository (com.github.joschi.jadconfig.repositories.InMemoryRepository)2 BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 Map (java.util.Map)2 PUT (javax.ws.rs.PUT)2