use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getBaseChannelHandlersFailsIfTempDirDoesNotExist.
@Test
public void getBaseChannelHandlersFailsIfTempDirDoesNotExist() throws IOException {
final File tmpDir = temporaryFolder.newFolder();
assumeTrue(tmpDir.delete());
System.setProperty("java.io.tmpdir", tmpDir.getAbsolutePath());
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter) {
@Override
protected Bootstrap getBootstrap() {
return super.getBootstrap();
}
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
return super.getBaseChannelHandlers(input);
}
};
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Couldn't write to temporary directory: " + tmpDir.getAbsolutePath());
transport.getBaseChannelHandlers(input);
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getBaseChannelHandlersFailsIfTempDirIsNotWritable.
@Test
public void getBaseChannelHandlersFailsIfTempDirIsNotWritable() throws IOException {
final File tmpDir = temporaryFolder.newFolder();
assumeTrue(tmpDir.setWritable(false));
assumeFalse(tmpDir.canWrite());
System.setProperty("java.io.tmpdir", tmpDir.getAbsolutePath());
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter) {
@Override
protected Bootstrap getBootstrap() {
return super.getBootstrap();
}
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
return super.getBaseChannelHandlers(input);
}
};
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Couldn't write to temporary directory: " + tmpDir.getAbsolutePath());
transport.getBaseChannelHandlers(input);
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getBaseChannelHandlersGeneratesSelfSignedCertificates.
@Test
public void getBaseChannelHandlersGeneratesSelfSignedCertificates() {
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter) {
@Override
protected Bootstrap getBootstrap() {
return super.getBootstrap();
}
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
return super.getBaseChannelHandlers(input);
}
};
final MessageInput input = mock(MessageInput.class);
assertThat(transport.getBaseChannelHandlers(input)).containsKey("tls");
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getBaseChannelHandlersFailsIfTempDirIsNoDirectory.
@Test
public void getBaseChannelHandlersFailsIfTempDirIsNoDirectory() throws IOException {
final File file = temporaryFolder.newFile();
assumeTrue(file.isFile());
System.setProperty("java.io.tmpdir", file.getAbsolutePath());
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter) {
@Override
protected Bootstrap getBootstrap() {
return super.getBootstrap();
}
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
return super.getBaseChannelHandlers(input);
}
};
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Couldn't write to temporary directory: " + file.getAbsolutePath());
transport.getBaseChannelHandlers(input);
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class BundleImporter method createMessageInput.
private MessageInput createMessageInput(final String bundleId, final Input inputDescription, final String userName) throws NoSuchInputTypeException, ConfigurationException, ValidationException, NotFoundException, org.graylog2.ConfigurationException, ExtractorFactory.NoSuchExtractorException, org.graylog2.plugin.inputs.Extractor.ReservedFieldException {
final Configuration inputConfig = new Configuration(inputDescription.getConfiguration());
final DateTime createdAt = Tools.nowUTC();
final MessageInput messageInput = messageInputFactory.create(inputDescription.getType(), inputConfig);
messageInput.setTitle(inputDescription.getTitle());
messageInput.setGlobal(inputDescription.isGlobal());
messageInput.setCreatorUserId(userName);
messageInput.setCreatedAt(createdAt);
messageInput.setContentPack(bundleId);
messageInput.checkConfiguration();
// Don't run if exclusive and another instance is already running.
if (messageInput.isExclusive() && inputRegistry.hasTypeRunning(messageInput.getClass())) {
LOG.error("Input type <{}> of input <{}> is exclusive and already has input running.", messageInput.getClass(), messageInput.getTitle());
}
final String id = inputDescription.getId();
final org.graylog2.inputs.Input mongoInput;
if (id == null) {
mongoInput = inputService.create(buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
} else {
mongoInput = inputService.create(id, buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
}
// Persist input.
final String persistId = inputService.save(mongoInput);
messageInput.setPersistId(persistId);
messageInput.initialize();
addStaticFields(messageInput, inputDescription.getStaticFields());
addExtractors(messageInput, inputDescription.getExtractors(), userName);
return messageInput;
}
Aggregations