use of com.aphyr.riemann.client.RiemannClient in project nifi by apache.
the class PutRiemann method onScheduled.
@OnScheduled
public void onScheduled(ProcessContext context) throws ProcessException {
if (batchSize == -1) {
batchSize = context.getProperty(BATCH_SIZE).asInteger();
}
if (riemannClient == null || !riemannClient.isConnected()) {
transport = Transport.valueOf(context.getProperty(TRANSPORT_PROTOCOL).getValue());
String host = context.getProperty(RIEMANN_HOST).getValue().trim();
int port = context.getProperty(RIEMANN_PORT).asInteger();
writeTimeout = context.getProperty(TIMEOUT).asLong();
RiemannClient client = null;
try {
switch(transport) {
case TCP:
client = RiemannClient.tcp(host, port);
break;
case UDP:
client = RiemannClient.udp(host, port);
break;
}
client.connect();
riemannClient = client;
} catch (IOException e) {
if (client != null) {
client.close();
}
context.yield();
throw new ProcessException(String.format("Unable to connect to Riemann [%s:%d] (%s)\n%s", host, port, transport, e.getMessage()));
}
}
if (customAttributes.size() == 0) {
for (Map.Entry<PropertyDescriptor, String> property : context.getProperties().entrySet()) {
// only custom defined properties
if (!getSupportedPropertyDescriptors().contains(property.getKey())) {
customAttributes.add(property.getKey());
}
}
}
}
use of com.aphyr.riemann.client.RiemannClient in project nifi by apache.
the class TestPutRiemann method getTestRunner.
private TestRunner getTestRunner(final boolean failOnWrite) {
RiemannClient riemannClient = mock(RiemannClient.class);
when(riemannClient.sendEvents(anyListOf(Proto.Event.class))).thenAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
List<Proto.Event> events = (List<Proto.Event>) invocationOnMock.getArguments()[0];
for (Proto.Event event : events) {
eventStream.add(event);
}
IPromise iPromise = mock(IPromise.class);
if (!failOnWrite) {
when(iPromise.deref(anyInt(), any(TimeUnit.class))).thenReturn(Proto.Msg.getDefaultInstance());
} else {
when(iPromise.deref(anyInt(), any(TimeUnit.class))).thenReturn(null);
}
return iPromise;
}
});
when(riemannClient.isConnected()).thenReturn(true);
PutRiemann riemannProcessor = new PutRiemann();
riemannProcessor.riemannClient = riemannClient;
riemannProcessor.transport = PutRiemann.Transport.TCP;
TestRunner runner = TestRunners.newTestRunner(riemannProcessor);
runner.setProperty(PutRiemann.RIEMANN_HOST, "localhost");
runner.setProperty(PutRiemann.RIEMANN_PORT, "5555");
runner.setProperty(PutRiemann.TRANSPORT_PROTOCOL, "TCP");
runner.setProperty(PutRiemann.BATCH_SIZE, "100");
runner.setProperty(PutRiemann.ATTR_SERVICE, "nifi-test-service");
runner.setProperty(PutRiemann.ATTR_HOST, "${riemann.host}");
runner.setProperty(PutRiemann.ATTR_TTL, "5");
runner.setProperty(PutRiemann.ATTR_DESCRIPTION, "test");
runner.setProperty(PutRiemann.ATTR_TAGS, "tag1, tag2, tag3");
runner.setProperty(PutRiemann.ATTR_METRIC, "${riemann.metric}");
runner.setProperty("custom-attribute-1", "${custom.attribute.1}");
runner.setProperty("custom-attribute-2", "${custom.attribute.2}");
runner.setProperty("custom-attribute-3", "${custom.attribute.3}");
return runner;
}
Aggregations