Search in sources :

Example 1 with SinkContext

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;
}
Also used : IMetricsSink(org.apache.heron.spi.metricsmgr.sink.IMetricsSink) MetricsCollector(org.apache.heron.common.utils.metrics.MetricsCollector) Communicator(org.apache.heron.common.basics.Communicator) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) SinkExecutor(org.apache.heron.metricsmgr.executor.SinkExecutor) MultiCountMetric(org.apache.heron.api.metric.MultiCountMetric) ExecutorLooper(org.apache.heron.common.basics.ExecutorLooper) SinkContextImpl(org.apache.heron.metricsmgr.sink.SinkContextImpl)

Example 2 with SinkContext

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);
}
Also used : HashMap(java.util.HashMap) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) Before(org.junit.Before)

Example 3 with SinkContext

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());
    }
}
Also used : HashMap(java.util.HashMap) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) Test(org.junit.Test)

Example 4 with SinkContext

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();
}
Also used : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) HashMap(java.util.HashMap) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) SinkContextImpl(org.apache.heron.metricsmgr.sink.SinkContextImpl) MultiCountMetric(org.apache.heron.api.metric.MultiCountMetric) Test(org.junit.Test)

Example 5 with SinkContext

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();
}
Also used : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) HashMap(java.util.HashMap) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) SinkContextImpl(org.apache.heron.metricsmgr.sink.SinkContextImpl) MultiCountMetric(org.apache.heron.api.metric.MultiCountMetric) Test(org.junit.Test)

Aggregations

SinkContext (org.apache.heron.spi.metricsmgr.sink.SinkContext)6 HashMap (java.util.HashMap)4 MultiCountMetric (org.apache.heron.api.metric.MultiCountMetric)4 SinkContextImpl (org.apache.heron.metricsmgr.sink.SinkContextImpl)4 Test (org.junit.Test)3 ExecutorLooper (org.apache.heron.common.basics.ExecutorLooper)2 TopologyManager (org.apache.heron.proto.tmanager.TopologyManager)2 Before (org.junit.Before)2 Communicator (org.apache.heron.common.basics.Communicator)1 MetricsCollector (org.apache.heron.common.utils.metrics.MetricsCollector)1 SinkExecutor (org.apache.heron.metricsmgr.executor.SinkExecutor)1 MetricsRecord (org.apache.heron.spi.metricsmgr.metrics.MetricsRecord)1 IMetricsSink (org.apache.heron.spi.metricsmgr.sink.IMetricsSink)1