use of com.twitter.heron.common.basics.Communicator in project heron by twitter.
the class MetricsManager method initSinkExecutor.
private SinkExecutor initSinkExecutor(String sinkId) {
IMetricsSink sink;
String classname = (String) config.getConfigForSink(sinkId).get(MetricsSinksConfig.CONFIG_KEY_CLASSNAME);
try {
sink = (IMetricsSink) Class.forName(classname).newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e + " IMetricsSink class must have a no-arg constructor.");
} catch (IllegalAccessException e) {
throw new RuntimeException(e + " IMetricsSink class must be concrete.");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e + " IMetricsSink class must be a class path.");
}
SlaveLooper sinkExecutorLoop = new SlaveLooper();
Communicator<MetricsRecord> executorInMetricsQueue = new Communicator<MetricsRecord>(null, sinkExecutorLoop);
// Since MetricsCollector is not thread-safe,
// we need to specify individual MetricsCollector and MultiCountMetric
// for different SinkExecutor
MetricsCollector sinkMetricsCollector = new MetricsCollector(sinkExecutorLoop, metricsQueue);
MultiCountMetric internalCounters = new MultiCountMetric();
sinkMetricsCollector.registerMetric(sinkId, internalCounters, heronMetricsExportIntervalSec);
// Set up the SinkContext
SinkContext sinkContext = new SinkContextImpl(topologyName, metricsmgrId, sinkId, internalCounters);
SinkExecutor sinkExecutor = new SinkExecutor(sinkId, sink, sinkExecutorLoop, executorInMetricsQueue, sinkContext);
sinkExecutor.setPropertyMap(config.getConfigForSink(sinkId));
return sinkExecutor;
}
use of com.twitter.heron.common.basics.Communicator in project heron by twitter.
the class MetricsManagerServerTest method testMetricsManagerServer.
/**
* Method: addSinkCommunicator(Communicator<MetricsRecord> communicator)
*/
@Test
public void testMetricsManagerServer() throws Exception {
final Communicator<MetricsRecord> sinkCommunicator = new Communicator<MetricsRecord>();
metricsManagerServer.addSinkCommunicator(sinkCommunicator);
// First run Server
runServer();
// Wait a while for server fully starting
Thread.sleep(3 * 1000);
// Then run Client
runClient();
// Wait some while to let message fully send out
Thread.sleep(10 * 1000);
int messages = 0;
while (!sinkCommunicator.isEmpty()) {
int exceptions = 0;
int metrics = 0;
MetricsRecord record = sinkCommunicator.poll();
Assert.assertEquals("hostname:0/component/instance-id", record.getSource());
Assert.assertEquals("default", record.getContext());
for (MetricsInfo info : record.getMetrics()) {
Assert.assertEquals(METRIC_NAME, info.getName());
Assert.assertEquals(METRIC_VALUE, info.getValue());
metrics++;
}
Assert.assertEquals(N, metrics);
for (ExceptionInfo info : record.getExceptions()) {
Assert.assertEquals(STACK_TRACE, info.getStackTrace());
Assert.assertEquals(LAST_TIME, info.getLastTime());
Assert.assertEquals(FIRST_TIME, info.getFirstTime());
Assert.assertEquals(LOGGING, info.getLogging());
Assert.assertEquals(EXCEPTION_COUNT, info.getCount());
exceptions++;
}
Assert.assertEquals(N, exceptions);
messages++;
}
Assert.assertEquals(MESSAGE_SIZE, messages);
}
use of com.twitter.heron.common.basics.Communicator in project incubator-heron by apache.
the class MetricsManager method initSinkExecutor.
private SinkExecutor initSinkExecutor(String sinkId) {
IMetricsSink sink;
String classname = (String) config.getConfigForSink(sinkId).get(MetricsSinksConfig.CONFIG_KEY_CLASSNAME);
try {
sink = (IMetricsSink) Class.forName(classname).newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e + " IMetricsSink class must have a no-arg constructor.");
} catch (IllegalAccessException e) {
throw new RuntimeException(e + " IMetricsSink class must be concrete.");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e + " IMetricsSink class must be a class path.");
}
SlaveLooper sinkExecutorLoop = new SlaveLooper();
Communicator<MetricsRecord> executorInMetricsQueue = new Communicator<MetricsRecord>(null, sinkExecutorLoop);
// Since MetricsCollector is not thread-safe,
// we need to specify individual MetricsCollector and MultiCountMetric
// for different SinkExecutor
MetricsCollector sinkMetricsCollector = new MetricsCollector(sinkExecutorLoop, metricsQueue);
MultiCountMetric internalCounters = new MultiCountMetric();
sinkMetricsCollector.registerMetric(sinkId, internalCounters, (int) heronMetricsExportInterval.getSeconds());
// Set up the SinkContext
SinkContext sinkContext = new SinkContextImpl(topologyName, cluster, role, environment, metricsmgrId, sinkId, internalCounters);
SinkExecutor sinkExecutor = new SinkExecutor(sinkId, sink, sinkExecutorLoop, executorInMetricsQueue, sinkContext);
sinkExecutor.setPropertyMap(config.getConfigForSink(sinkId));
return sinkExecutor;
}
Aggregations