use of org.graylog2.plugin.inputs.MisfireException in project graylog2-server by Graylog2.
the class AmqpTransport method doLaunch.
@Override
public void doLaunch(MessageInput input) throws MisfireException {
int heartbeatTimeout = ConnectionFactory.DEFAULT_HEARTBEAT;
if (configuration.intIsSet(CK_HEARTBEAT_TIMEOUT)) {
heartbeatTimeout = configuration.getInt(CK_HEARTBEAT_TIMEOUT);
if (heartbeatTimeout < 0) {
LOG.warn("AMQP heartbeat interval must not be negative ({}), using default timeout ({}).", heartbeatTimeout, ConnectionFactory.DEFAULT_HEARTBEAT);
heartbeatTimeout = ConnectionFactory.DEFAULT_HEARTBEAT;
}
}
consumer = new AmqpConsumer(configuration.getString(CK_HOSTNAME), configuration.getInt(CK_PORT), configuration.getString(CK_VHOST), configuration.getString(CK_USERNAME), configuration.getString(CK_PASSWORD), configuration.getInt(CK_PREFETCH), configuration.getString(CK_QUEUE), configuration.getString(CK_EXCHANGE), configuration.getBoolean(CK_EXCHANGE_BIND), configuration.getString(CK_ROUTING_KEY), configuration.getInt(CK_PARALLEL_QUEUES), configuration.getBoolean(CK_TLS), configuration.getBoolean(CK_REQUEUE_INVALID_MESSAGES), heartbeatTimeout, input, scheduler, this);
eventBus.register(this);
try {
consumer.run();
} catch (IOException e) {
eventBus.unregister(this);
throw new MisfireException("Could not launch AMQP consumer.", e);
}
}
use of org.graylog2.plugin.inputs.MisfireException in project graylog2-server by Graylog2.
the class HttpPollTransport method doLaunch.
@Override
public void doLaunch(final MessageInput input) throws MisfireException {
serverStatus.awaitRunning(() -> lifecycleStateChange(Lifecycle.RUNNING));
// listen for lifecycle changes
serverEventBus.register(this);
final Map<String, String> headers = parseHeaders(configuration.getString(CK_HEADERS));
// figure out a reasonable remote address
final String url = configuration.getString(CK_URL);
final InetSocketAddress remoteAddress;
InetSocketAddress remoteAddress1;
try {
final URL url1 = new URL(url);
final int port = url1.getPort();
remoteAddress1 = new InetSocketAddress(url1.getHost(), port != -1 ? port : 80);
} catch (MalformedURLException e) {
remoteAddress1 = null;
}
remoteAddress = remoteAddress1;
final Runnable task = () -> {
if (paused) {
LOG.debug("Message processing paused, not polling HTTP resource {}.", url);
return;
}
if (isThrottled()) {
// this transport won't block, but we can simply skip this iteration
LOG.debug("Not polling HTTP resource {} because we are throttled.", url);
}
final Request.Builder requestBuilder = new Request.Builder().get().url(url).headers(Headers.of(headers));
try (final Response r = httpClient.newCall(requestBuilder.build()).execute()) {
if (!r.isSuccessful()) {
throw new RuntimeException("Expected successful HTTP status code [2xx], got " + r.code());
}
input.processRawMessage(new RawMessage(r.body().bytes(), remoteAddress));
} catch (IOException e) {
LOG.error("Could not fetch HTTP resource at " + url, e);
}
};
scheduledFuture = scheduler.scheduleAtFixedRate(task, 0, configuration.getInt(CK_INTERVAL), TimeUnit.valueOf(configuration.getString(CK_TIMEUNIT)));
}
use of org.graylog2.plugin.inputs.MisfireException in project graylog2-server by Graylog2.
the class NettyTransport method launch.
@Override
public void launch(final MessageInput input) throws MisfireException {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = getBaseChannelHandlers(input);
final LinkedHashMap<String, Callable<? extends ChannelHandler>> finalHandlers = getFinalChannelHandlers(input);
handlerList.putAll(finalHandlers);
try {
bootstrap = getBootstrap();
bootstrap.setPipelineFactory(getPipelineFactory(handlerList));
// sigh, bindable bootstraps do not share a common interface
int receiveBufferSize;
if (bootstrap instanceof ConnectionlessBootstrap) {
acceptChannel = ((ConnectionlessBootstrap) bootstrap).bind(socketAddress);
final DefaultDatagramChannelConfig channelConfig = (DefaultDatagramChannelConfig) acceptChannel.getConfig();
receiveBufferSize = channelConfig.getReceiveBufferSize();
} else if (bootstrap instanceof ServerBootstrap) {
acceptChannel = ((ServerBootstrap) bootstrap).bind(socketAddress);
final ServerSocketChannelConfig channelConfig = (ServerSocketChannelConfig) acceptChannel.getConfig();
receiveBufferSize = channelConfig.getReceiveBufferSize();
} else {
log.error("Unknown Netty bootstrap class returned: {}. Cannot safely bind.", bootstrap);
throw new IllegalStateException("Unknown netty bootstrap class returned: " + bootstrap + ". Cannot safely bind.");
}
if (receiveBufferSize != getRecvBufferSize()) {
log.warn("receiveBufferSize (SO_RCVBUF) for input {} should be {} but is {}.", input, getRecvBufferSize(), receiveBufferSize);
}
} catch (Exception e) {
throw new MisfireException(e);
}
}
use of org.graylog2.plugin.inputs.MisfireException in project graylog2-server by Graylog2.
the class GeneratorTransport method doLaunch.
@Override
public void doLaunch(final MessageInput input) throws MisfireException {
generatorService = new AbstractExecutionThreadService() {
@Override
protected void run() throws Exception {
while (isRunning()) {
if (isThrottled()) {
blockUntilUnthrottled();
}
final RawMessage rawMessage = GeneratorTransport.this.produceRawMessage(input);
if (rawMessage != null) {
input.processRawMessage(rawMessage);
}
}
}
};
generatorService.startAsync();
}
use of org.graylog2.plugin.inputs.MisfireException in project graylog2-server by Graylog2.
the class KafkaTransport method doLaunch.
@Override
public void doLaunch(final MessageInput input) throws MisfireException {
serverStatus.awaitRunning(new Runnable() {
@Override
public void run() {
lifecycleStateChange(Lifecycle.RUNNING);
}
});
// listen for lifecycle changes
serverEventBus.register(this);
final Properties props = new Properties();
props.put("group.id", GROUP_ID);
props.put("client.id", "gl2-" + nodeId + "-" + input.getId());
props.put("fetch.min.bytes", String.valueOf(configuration.getInt(CK_FETCH_MIN_BYTES)));
props.put("fetch.wait.max.ms", String.valueOf(configuration.getInt(CK_FETCH_WAIT_MAX)));
props.put("zookeeper.connect", configuration.getString(CK_ZOOKEEPER));
// Default auto commit interval is 60 seconds. Reduce to 1 second to minimize message duplication
// if something breaks.
props.put("auto.commit.interval.ms", "1000");
// Set a consumer timeout to avoid blocking on the consumer iterator.
props.put("consumer.timeout.ms", "1000");
final int numThreads = configuration.getInt(CK_THREADS);
final ConsumerConfig consumerConfig = new ConsumerConfig(props);
cc = Consumer.createJavaConsumerConnector(consumerConfig);
final TopicFilter filter = new Whitelist(configuration.getString(CK_TOPIC_FILTER));
final List<KafkaStream<byte[], byte[]>> streams = cc.createMessageStreamsByFilter(filter, numThreads);
final ExecutorService executor = executorService(numThreads);
// this is being used during shutdown to first stop all submitted jobs before committing the offsets back to zookeeper
// and then shutting down the connection.
// this is to avoid yanking away the connection from the consumer runnables
stopLatch = new CountDownLatch(streams.size());
for (final KafkaStream<byte[], byte[]> stream : streams) {
executor.submit(new Runnable() {
@Override
public void run() {
final ConsumerIterator<byte[], byte[]> consumerIterator = stream.iterator();
boolean retry;
do {
retry = false;
try {
// noinspection WhileLoopReplaceableByForEach
while (consumerIterator.hasNext()) {
if (paused) {
// we try not to spin here, so we wait until the lifecycle goes back to running.
LOG.debug("Message processing is paused, blocking until message processing is turned back on.");
Uninterruptibles.awaitUninterruptibly(pausedLatch);
}
// check for being stopped before actually getting the message, otherwise we could end up losing that message
if (stopped) {
break;
}
if (isThrottled()) {
blockUntilUnthrottled();
}
// process the message, this will immediately mark the message as having been processed. this gets tricky
// if we get an exception about processing it down below.
final MessageAndMetadata<byte[], byte[]> message = consumerIterator.next();
final byte[] bytes = message.message();
// it is possible that the message is null
if (bytes == null) {
continue;
}
totalBytesRead.addAndGet(bytes.length);
lastSecBytesReadTmp.addAndGet(bytes.length);
final RawMessage rawMessage = new RawMessage(bytes);
// TODO implement throttling
input.processRawMessage(rawMessage);
}
} catch (ConsumerTimeoutException e) {
// Happens when there is nothing to consume, retry to check again.
retry = true;
} catch (Exception e) {
LOG.error("Kafka consumer error, stopping consumer thread.", e);
}
} while (retry && !stopped);
// explicitly commit our offsets when stopping.
// this might trigger a couple of times, but it won't hurt
cc.commitOffsets();
stopLatch.countDown();
}
});
}
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
lastSecBytesRead.set(lastSecBytesReadTmp.getAndSet(0));
}
}, 1, 1, TimeUnit.SECONDS);
}
Aggregations