use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestTaskCallbackManager method setup.
@Before
public void setup() {
TaskInstanceMetrics metrics = new TaskInstanceMetrics("Partition 0", new MetricsRegistryMap());
listener = new TaskCallbackListener() {
@Override
public void onComplete(TaskCallback callback) {
}
@Override
public void onFailure(TaskCallback callback, Throwable t) {
}
};
callbackManager = new TaskCallbackManager(listener, null, -1, 2, () -> System.nanoTime());
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestKafkaSystemProducerJava method testInstantiateProducer.
@Test
public void testInstantiateProducer() {
KafkaSystemProducer ksp = new KafkaSystemProducer("SysName", new ExponentialSleepStrategy(2.0, 200, 10000), new AbstractFunction0<Producer<byte[], byte[]>>() {
@Override
public Producer<byte[], byte[]> apply() {
return new KafkaProducer<>(new HashMap<String, Object>());
}
}, new KafkaSystemProducerMetrics("SysName", new MetricsRegistryMap()), new AbstractFunction0<Object>() {
@Override
public Object apply() {
return System.currentTimeMillis();
}
});
long now = System.currentTimeMillis();
assertTrue((Long) ksp.clock().apply() >= now);
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class StreamAppender method setupSystem.
protected void setupSystem() {
config = getConfig();
SystemFactory systemFactory = null;
Log4jSystemConfig log4jSystemConfig = new Log4jSystemConfig(config);
if (streamName == null) {
streamName = getStreamName(log4jSystemConfig.getJobName(), log4jSystemConfig.getJobId());
}
String systemName = log4jSystemConfig.getSystemName();
String systemFactoryName = log4jSystemConfig.getSystemFactory(systemName);
if (systemFactoryName != null) {
systemFactory = Util.<SystemFactory>getObj(systemFactoryName);
} else {
throw new SamzaException("Could not figure out \"" + systemName + "\" system factory for log4j StreamAppender to use");
}
setSerde(log4jSystemConfig, systemName, streamName);
systemProducer = systemFactory.getProducer(systemName, config, new MetricsRegistryMap());
systemStream = new SystemStream(systemName, streamName);
systemProducer.register(SOURCE);
systemProducer.start();
log.info(SOURCE + " has been registered in " + systemName + ". So all the logs will be sent to " + streamName + " in " + systemName + ". Logs are partitioned by " + key);
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class SamzaRestService method main.
/**
* Command line interface to run the server.
*
* @param args arguments supported by {@link org.apache.samza.util.CommandLine}.
* In particular, --config-path and --config-factory are used to read the Samza REST config file.
* @throws Exception if the server could not be successfully started.
*/
public static void main(String[] args) throws Exception {
try {
SamzaRestConfig config = parseConfig(args);
ReadableMetricsRegistry metricsRegistry = new MetricsRegistryMap();
log.info("Creating new SamzaRestService with config: {}", config);
MetricsConfig metricsConfig = new MetricsConfig(config);
Map<String, MetricsReporter> metricsReporters = MetricsReporterLoader.getMetricsReporters(metricsConfig, Util.getLocalHost().getHostName());
SamzaRestService restService = new SamzaRestService(new Server(config.getPort()), metricsRegistry, metricsReporters, new ServletContextHandler(ServletContextHandler.SESSIONS));
// Add applications
SamzaRestApplication samzaRestApplication = new SamzaRestApplication(config);
ServletContainer container = new ServletContainer(samzaRestApplication);
restService.addServlet(container, "/*");
// Schedule monitors to run
ScheduledExecutorService schedulingService = Executors.newScheduledThreadPool(1);
ScheduledExecutorSchedulingProvider schedulingProvider = new ScheduledExecutorSchedulingProvider(schedulingService);
SamzaMonitorService monitorService = new SamzaMonitorService(config, metricsRegistry, schedulingProvider);
monitorService.start();
restService.runBlocking();
monitorService.stop();
} catch (Throwable t) {
log.error("Exception in main.", t);
}
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestOperatorImpls method testBroadcastChain.
@Test
public void testBroadcastChain() throws IllegalAccessException, InvocationTargetException {
// test creation of broadcast chain
StreamGraphImpl mockGraph = mock(StreamGraphImpl.class);
MessageStreamImpl<TestMessageEnvelope> testInput = TestMessageStreamImplUtil.getMessageStreamImpl(mockGraph);
TaskContext mockContext = mock(TaskContext.class);
when(mockContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
Config mockConfig = mock(Config.class);
testInput.filter(m -> m.getMessage().getEventTime() > 123456L).flatMap(m -> new ArrayList() {
{
this.add(m);
this.add(m);
}
});
testInput.filter(m -> m.getMessage().getEventTime() < 123456L).map(m -> m);
OperatorImplGraph opGraph = new OperatorImplGraph();
RootOperatorImpl operatorChain = (RootOperatorImpl) createOpsMethod.invoke(opGraph, testInput, mockConfig, mockContext);
Set<OperatorImpl> subsSet = (Set<OperatorImpl>) nextOperatorsField.get(operatorChain);
assertEquals(subsSet.size(), 2);
Iterator<OperatorImpl> iter = subsSet.iterator();
// check the first branch w/ flatMap
OperatorImpl<TestMessageEnvelope, TestMessageEnvelope> opImpl = iter.next();
Set<OperatorImpl> subsOps = (Set<OperatorImpl>) nextOperatorsField.get(opImpl);
assertEquals(subsOps.size(), 1);
OperatorImpl flatMapImpl = subsOps.iterator().next();
subsOps = (Set<OperatorImpl>) nextOperatorsField.get(flatMapImpl);
assertEquals(subsOps.size(), 0);
// check the second branch w/ map
opImpl = iter.next();
subsOps = (Set<OperatorImpl>) nextOperatorsField.get(opImpl);
assertEquals(subsOps.size(), 1);
OperatorImpl mapImpl = subsOps.iterator().next();
subsOps = (Set<OperatorImpl>) nextOperatorsField.get(mapImpl);
assertEquals(subsOps.size(), 0);
}
Aggregations