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;
}
}
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());
}
}
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")));
}
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");
}
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));
}
Aggregations