use of org.apache.heron.spi.metricsmgr.sink.SinkContext 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.");
}
ExecutorLooper sinkExecutorLoop = new ExecutorLooper();
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;
}
use of org.apache.heron.spi.metricsmgr.sink.SinkContext in project heron by twitter.
the class FileSinkTest method before.
@Before
public void before() throws IOException {
fileSink = new FileSink();
Map<String, Object> conf = new HashMap<>();
tmpDir = Files.createTempDirectory("filesink").toFile();
conf.put("filename-output", tmpDir.getAbsolutePath() + "/filesink");
conf.put("file-maximum", 100);
SinkContext context = Mockito.mock(SinkContext.class);
Mockito.when(context.getMetricsMgrId()).thenReturn("test");
fileSink.init(conf, context);
}
use of org.apache.heron.spi.metricsmgr.sink.SinkContext in project heron by twitter.
the class FileSinkTest method testIllegalConf.
/**
* Method: init()
*/
@Test
public void testIllegalConf() throws IOException {
FileSink sink = new FileSink();
Map<String, Object> conf = new HashMap<>();
SinkContext context = Mockito.mock(SinkContext.class);
try {
sink.init(conf, context);
Assert.fail("Expected IllegalArgumentException.");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Require: filename-output", e.getMessage());
}
sink = new FileSink();
conf.put("filename-output", tmpDir.getAbsolutePath() + "/filesink");
try {
sink.init(conf, context);
Assert.fail("Expected IllegalArgumentException.");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Require: file-maximum", e.getMessage());
}
}
use of org.apache.heron.spi.metricsmgr.sink.SinkContext in project heron by twitter.
the class MetricsCacheSinkTest method testHandleMetricsCacheLocation.
/**
* Test whether MetricsCacheSink would handle MetricsCacheLocation in SingletonRegistry automatically
*/
@Test
public void testHandleMetricsCacheLocation() throws Exception {
// create a new MetricsCacheClientService
MetricsCacheSink metricsCacheSink = new MetricsCacheSink();
Map<String, Object> sinkConfig = new HashMap<String, Object>();
// Fill with necessary config
sinkConfig.put("metricscache-location-check-interval-sec", METRICSCACHE_LOCATION_CHECK_INTERVAL.getSeconds());
sinkConfig.put("metricscache-client", buildServiceConfig());
// It is null since we have not set it
Assert.assertNull(metricsCacheSink.getCurrentMetricsCacheLocation());
MultiCountMetric multiCountMetric = new MultiCountMetric();
SinkContext sinkContext = new SinkContextImpl("topology-name", "cluster", "role", "environment", "metricsmgr-id", "sink-id", multiCountMetric);
// Start the MetricsCacheSink
metricsCacheSink.init(sinkConfig, sinkContext);
// Put the MetricsCacheLocation into SingletonRegistry
TopologyManager.MetricsCacheLocation oldLoc = getMetricsCacheLocation(0);
SingletonRegistry.INSTANCE.registerSingleton(METRICSCACHE_LOCATION_BEAN_NAME, oldLoc);
SysUtils.sleep(RESTART_WAIT_INTERVAL);
// The MetricsCacheService should start
assertTrue(metricsCacheSink.getMetricsCacheStartedAttempts() > 0);
assertEquals(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
assertEquals(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
// Update it, the MetricsCacheSink should pick up the new one.
TopologyManager.MetricsCacheLocation newLoc = getMetricsCacheLocation(1);
SingletonRegistry.INSTANCE.updateSingleton(METRICSCACHE_LOCATION_BEAN_NAME, newLoc);
int lastMetricsCacheStartedAttempts = metricsCacheSink.getMetricsCacheStartedAttempts();
SysUtils.sleep(RESTART_WAIT_INTERVAL);
// The MetricsCacheService should use the new MetricsCacheLocation
assertTrue(metricsCacheSink.getMetricsCacheStartedAttempts() > lastMetricsCacheStartedAttempts);
assertNotSame(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
assertNotSame(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
assertEquals(newLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
assertEquals(newLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
metricsCacheSink.close();
}
use of org.apache.heron.spi.metricsmgr.sink.SinkContext in project heron by twitter.
the class TManagerSinkTest method testHandleTManagerLocation.
/**
* Test whether TManagerSink would handle TManagerLocation in SingletonRegistry automatically
*/
@Test
public void testHandleTManagerLocation() throws InterruptedException {
// create a new TManagerClientService
TManagerSink tManagerSink = new TManagerSink();
Map<String, Object> sinkConfig = new HashMap<>();
// Fill with necessary config
sinkConfig.put("tmanager-location-check-interval-sec", TMANAGER_LOCATION_CHECK_INTERVAL.getSeconds());
sinkConfig.put("tmanager-client", buildServiceConfig());
// It is null since we have not set it
Assert.assertNull(tManagerSink.getCurrentTManagerLocation());
MultiCountMetric multiCountMetric = new MultiCountMetric();
SinkContext sinkContext = new SinkContextImpl("topology-name", "cluster", "role", "environment", "metricsmgr-id", "sink-id", multiCountMetric);
// Start the TManagerSink
tManagerSink.init(sinkConfig, sinkContext);
// Put the TManagerLocation into SingletonRegistry
TopologyManager.TManagerLocation oldLoc = getTManagerLocation(0);
SingletonRegistry.INSTANCE.registerSingleton(TMANAGER_LOCATION_BEAN_NAME, oldLoc);
SysUtils.sleep(RESTART_WAIT_INTERVAL);
// The TManagerService should start
assertTrue(tManagerSink.getTManagerStartedAttempts() > 0);
assertEquals(oldLoc, tManagerSink.getCurrentTManagerLocation());
assertEquals(oldLoc, tManagerSink.getCurrentTManagerLocationInService());
// Update it, the TManagerSink should pick up the new one.
TopologyManager.TManagerLocation newLoc = getTManagerLocation(1);
SingletonRegistry.INSTANCE.updateSingleton(TMANAGER_LOCATION_BEAN_NAME, newLoc);
int lastTManagerStartedAttempts = tManagerSink.getTManagerStartedAttempts();
SysUtils.sleep(RESTART_WAIT_INTERVAL);
// The TManagerService should use the new TManagerLocation
assertTrue(tManagerSink.getTManagerStartedAttempts() > lastTManagerStartedAttempts);
assertNotSame(oldLoc, tManagerSink.getCurrentTManagerLocation());
assertNotSame(oldLoc, tManagerSink.getCurrentTManagerLocationInService());
assertEquals(newLoc, tManagerSink.getCurrentTManagerLocation());
assertEquals(newLoc, tManagerSink.getCurrentTManagerLocationInService());
tManagerSink.close();
}
Aggregations