use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestRocksDbKeyValueStoreJava method testIterate.
@Test
public void testIterate() throws Exception {
Config config = new MapConfig();
Options options = new Options();
options.setCreateIfMissing(true);
File dbDir = new File(System.getProperty("java.io.tmpdir") + "/dbStore" + System.currentTimeMillis());
RocksDbKeyValueStore store = new RocksDbKeyValueStore(dbDir, options, config, false, "dbStore", new WriteOptions(), new FlushOptions(), new KeyValueStoreMetrics("dbStore", new MetricsRegistryMap()));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String prefix = "prefix";
for (int i = 0; i < 100; i++) {
store.put(genKey(outputStream, prefix, i), genValue());
}
byte[] firstKey = genKey(outputStream, prefix, 0);
byte[] lastKey = genKey(outputStream, prefix, 1000);
KeyValueSnapshot<byte[], byte[]> snapshot = store.snapshot(firstKey, lastKey);
// Make sure the cached Iterable won't change when new elements are added
store.put(genKey(outputStream, prefix, 200), genValue());
KeyValueIterator<byte[], byte[]> iterator = snapshot.iterator();
assertTrue(Iterators.size(iterator) == 100);
iterator.close();
List<Integer> keys = new ArrayList<>();
KeyValueIterator<byte[], byte[]> iterator2 = snapshot.iterator();
while (iterator2.hasNext()) {
Entry<byte[], byte[]> entry = iterator2.next();
int key = Ints.fromByteArray(Arrays.copyOfRange(entry.getKey(), prefix.getBytes().length, entry.getKey().length));
keys.add(key);
}
assertEquals(keys, IntStream.rangeClosed(0, 99).boxed().collect(Collectors.toList()));
iterator2.close();
outputStream.close();
snapshot.close();
store.close();
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class YarnJobValidationTool method validateJmxMetrics.
public void validateJmxMetrics() throws Exception {
MetricsRegistry metricsRegistry = new MetricsRegistryMap();
CoordinatorStreamStore coordinatorStreamStore = new CoordinatorStreamStore(config, metricsRegistry);
coordinatorStreamStore.init();
try {
LocalityManager localityManager = new LocalityManager(new NamespaceAwareCoordinatorStreamStore(coordinatorStreamStore, SetConfig.TYPE));
validator.init(config);
LocalityModel localityModel = localityManager.readLocality();
for (ProcessorLocality processorLocality : localityModel.getProcessorLocalities().values()) {
String containerId = processorLocality.id();
String jmxUrl = processorLocality.jmxTunnelingUrl();
if (StringUtils.isNotBlank(jmxUrl)) {
log.info("validate container " + containerId + " metrics with JMX: " + jmxUrl);
JmxMetricsAccessor jmxMetrics = new JmxMetricsAccessor(jmxUrl);
jmxMetrics.connect();
validator.validate(jmxMetrics);
jmxMetrics.close();
log.info("validate container " + containerId + " successfully");
}
}
validator.complete();
} finally {
coordinatorStreamStore.close();
}
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestZkLocalApplicationRunner method getConfigFromCoordinatorStream.
private MapConfig getConfigFromCoordinatorStream(Config config) {
MetadataStoreFactory metadataStoreFactory = ReflectionUtil.getObj(new JobConfig(config).getMetadataStoreFactory(), MetadataStoreFactory.class);
MetadataStore metadataStore = metadataStoreFactory.getMetadataStore("set-config", config, new MetricsRegistryMap());
metadataStore.init();
Map<String, String> configMap = new HashMap<>();
CoordinatorStreamValueSerde jsonSerde = new CoordinatorStreamValueSerde("set-config");
metadataStore.all().forEach((key, value) -> {
CoordinatorStreamStore.CoordinatorMessageKey coordinatorMessageKey = CoordinatorStreamStore.deserializeCoordinatorMessageKeyFromJson(key);
String deserializedValue = jsonSerde.fromBytes(value);
configMap.put(coordinatorMessageKey.getKey(), deserializedValue);
});
return new MapConfig(configMap);
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class RemoteJobPlanner method getConfigFromPrevRun.
private Config getConfigFromPrevRun() {
CoordinatorStreamSystemConsumer consumer = new CoordinatorStreamSystemConsumer(userConfig, new MetricsRegistryMap());
consumer.register();
consumer.start();
consumer.bootstrap();
consumer.stop();
Config cfg = consumer.getConfig();
LOG.info("Previous config is: " + cfg.toString());
return cfg;
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class LocalJobPlanner method getMetadataStore.
private MetadataStore getMetadataStore() {
String metadataStoreFactoryClass = appDesc.getConfig().get(METADATA_STORE_FACTORY_CONFIG);
if (metadataStoreFactoryClass == null) {
metadataStoreFactoryClass = DEFAULT_METADATA_STORE_FACTORY;
}
MetadataStoreFactory metadataStoreFactory = ReflectionUtil.getObj(metadataStoreFactoryClass, MetadataStoreFactory.class);
return metadataStoreFactory.getMetadataStore(STREAM_CREATION_METADATA_STORE, appDesc.getConfig(), new MetricsRegistryMap());
}
Aggregations