void save(SimpleConfiguration appConfig) { appConfig.setProperty(PREFIX + mapId + ".combiner", combinerType + ""); if (updateObserverType != null) { appConfig.setProperty(PREFIX + mapId + ".updateObserver", updateObserverType + ""); } } }
static String getKeyType(String cqId, SimpleConfiguration appConfig) { return appConfig.getString(PREFIX + cqId + ".key"); }
/** * @param className The name of a class that implements {@link Observer} * @param observerConfig Per observer configuration that's specific to this observer. For * configuration that's the same across multiple observers, consider using * {@link FluoConfiguration#getAppConfiguration()} */ public ObserverSpecification(String className, SimpleConfiguration observerConfig) { this.className = className; this.configMap = observerConfig.toMap(); }
Options(String mapId, SimpleConfiguration appConfig) { this.mapId = mapId; this.numBuckets = appConfig.getInt(PREFIX + mapId + ".buckets"); this.combinerType = appConfig.getString(PREFIX + mapId + ".combiner"); this.keyType = appConfig.getString(PREFIX + mapId + ".key"); this.valueType = appConfig.getString(PREFIX + mapId + ".val"); this.updateObserverType = appConfig.getString(PREFIX + mapId + ".updateObserver", null); this.bufferSize = appConfig.getLong(PREFIX + mapId + ".bufferSize", DEFAULT_BUFFER_SIZE); this.bucketsPerTablet = appConfig.getInt(PREFIX + mapId + ".bucketsPerTablet", DEFAULT_BUCKETS_PER_TABLET); }
void save(SimpleConfiguration appConfig) { fluentCfg.save(appConfig); if (exporterConfig != null) { Iterator<String> keys = exporterConfig.getKeys(); while (keys.hasNext()) { String key = keys.next(); appConfig.setProperty(PREFIX + fluentCfg.queueId + ".exporterCfg." + key, exporterConfig.getRawString(key)); } } } }
/** * @param fallback SimpleConfiguration to join together * @return a new simple configuration that contains all of the current properties from this plus * the properties from fallback that are not present in this. * * @since 1.2.0 */ public SimpleConfiguration orElse(SimpleConfiguration fallback) { SimpleConfiguration copy = new SimpleConfiguration(this); for (Map.Entry<String, String> entry : fallback.toMap().entrySet()) { if (!copy.containsKey(entry.getKey())) { copy.setProperty(entry.getKey(), entry.getValue()); } } return copy; }
@Override public List<AutoCloseable> start(Params params) { SimpleConfiguration config = new FluoConfiguration(params.getConfiguration()).getReporterConfiguration("csv"); String dir = config.getString("dir", ""); if (!config.getBoolean("enable", false) || dir.isEmpty()) { return Collections.emptyList(); } TimeUnit rateUnit = TimeUnit.valueOf(config.getString("rateUnit", "seconds").toUpperCase()); TimeUnit durationUnit = TimeUnit.valueOf(config.getString("durationUnit", "milliseconds").toUpperCase()); CsvReporter reporter = CsvReporter.forRegistry(params.getMetricRegistry()) .convertDurationsTo(durationUnit).convertRatesTo(rateUnit).build(new File(dir)); reporter.start(config.getInt("frequency", 60), TimeUnit.SECONDS); log.info("Reporting metrics as csv to directory {}", dir); return Collections.singletonList((AutoCloseable) reporter); }
/** * Returns a SimpleConfiguration clientConfig with properties set from this configuration * * @return SimpleConfiguration */ public SimpleConfiguration getClientConfiguration() { SimpleConfiguration clientConfig = new SimpleConfiguration(); Iterator<String> iter = getKeys(); while (iter.hasNext()) { String key = iter.next(); if (key.startsWith(CONNECTION_PREFIX) || key.startsWith(ACCUMULO_PREFIX) || key.startsWith(CLIENT_PREFIX)) { clientConfig.setProperty(key, getRawString(key)); } } return clientConfig; }
@Test public void testBasic() { SimpleConfiguration uc = client.getAppConfiguration(); Assert.assertEquals(50000, uc.getInt("myapp.sizeLimit")); uc.setProperty("myapp.sizeLimit", 3); uc = client.getAppConfiguration(); Assert.assertEquals(50000, uc.getInt("myapp.sizeLimit")); // update shared config SimpleConfiguration appConfig = config.getAppConfiguration(); appConfig.clear(); appConfig.setProperty("myapp.sizeLimit", 40000); appConfig.setProperty("myapp.timeLimit", 30000); try (FluoAdmin admin = FluoFactory.newAdmin(config)) { miniFluo.close(); admin.updateSharedConfig(); } // set app config that differs from what was just put in zk appConfig.setProperty("myapp.sizeLimit", 6); appConfig.setProperty("myapp.timeLimit", 7); try (FluoClient client2 = FluoFactory.newClient(config)) { uc = client2.getAppConfiguration(); Assert.assertEquals(40000, uc.getInt("myapp.sizeLimit")); Assert.assertEquals(30000, uc.getInt("myapp.timeLimit")); } }
public SimpleConfiguration getConfiguration() { if (config == null) { config = new SimpleConfiguration(configMap); } return config; }
/** * A utility method to get all registered table optimizations. Many recipes will automatically * register table optimizations when configured. */ public static TableOptimizations getConfiguredOptimizations(FluoConfiguration fluoConfig) { try (FluoClient client = FluoFactory.newClient(fluoConfig)) { SimpleConfiguration appConfig = client.getAppConfiguration(); TableOptimizations tableOptim = new TableOptimizations(); SimpleConfiguration subset = appConfig.subset(PREFIX.substring(0, PREFIX.length() - 1)); Iterator<String> keys = subset.getKeys(); while (keys.hasNext()) { String key = keys.next(); String clazz = subset.getString(key); try { TableOptimizationsFactory factory = Class.forName(clazz).asSubclass(TableOptimizationsFactory.class).newInstance(); tableOptim.merge(factory.getTableOptimizations(key, appConfig)); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException(e); } } return tableOptim; } } }
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); save(baos); byte[] data = baos.toByteArray(); out.writeInt(data.length); out.write(data); }
/** * This method is expected to be called after Fluo is initialized to get the ranges that were * registered before initialization. */ public List<RowRange> getTransientRanges() { List<RowRange> ranges = new ArrayList<>(); Iterator<String> keys = appConfig.getKeys(PREFIX.substring(0, PREFIX.length() - 1)); while (keys.hasNext()) { String key = keys.next(); String val = appConfig.getString(key); String[] sa = val.split(":"); RowRange rowRange = new RowRange(Bytes.of(DatatypeConverter.parseHexBinary(sa[0])), Bytes.of(DatatypeConverter.parseHexBinary(sa[1]))); ranges.add(rowRange); } return ranges; } }
@Override public List<AutoCloseable> start(Params params) { SimpleConfiguration config = new FluoConfiguration(params.getConfiguration()).getReporterConfiguration("jmx"); if (!config.getBoolean("enable", false)) { return Collections.emptyList(); } TimeUnit rateUnit = TimeUnit.valueOf(config.getString("rateUnit", "seconds").toUpperCase()); TimeUnit durationUnit = TimeUnit.valueOf(config.getString("durationUnit", "milliseconds").toUpperCase()); JmxReporter reporter = JmxReporter.forRegistry(params.getMetricRegistry()).convertDurationsTo(durationUnit) .convertRatesTo(rateUnit).inDomain(params.getDomain()).build(); reporter.start(); log.info("Reporting metrics to JMX"); return Collections.singletonList((AutoCloseable) reporter); } }
static int getNumBucket(String cqId, SimpleConfiguration appConfig) { return appConfig.getInt(PREFIX + cqId + ".buckets"); } }
/** * @return An immutable copy of this configurations as a map. Changes to this after toMap() is * called will not be reflected in the map. */ public Map<String, String> toMap() { Builder<String, String> builder = ImmutableMap.builder(); Iterator<String> ki = getKeys(); while (ki.hasNext()) { String k = ki.next(); builder.put(k, getRawString(k)); } return builder.build(); }
@Override public List<AutoCloseable> start(Params params) { SimpleConfiguration config = new FluoConfiguration(params.getConfiguration()).getReporterConfiguration("slf4j"); if (!config.getBoolean("enable", false)) { return Collections.emptyList(); } TimeUnit rateUnit = TimeUnit.valueOf(config.getString("rateUnit", "seconds").toUpperCase()); TimeUnit durationUnit = TimeUnit.valueOf(config.getString("durationUnit", "milliseconds").toUpperCase()); Logger logger = LoggerFactory.getLogger(config.getString("logger", "metrics")); Slf4jReporter reporter = Slf4jReporter.forRegistry(params.getMetricRegistry()) .convertDurationsTo(durationUnit).convertRatesTo(rateUnit).outputTo(logger).build(); reporter.start(config.getInt("frequency", 60), TimeUnit.SECONDS); log.info("Reporting metrics using slf4j"); return Collections.singletonList((AutoCloseable) reporter); }
/** * @param fallback SimpleConfiguration to join together * @return a new simple configuration that contains all of the current properties from this plus * the properties from fallback that are not present in this. * * @since 1.2.0 */ public SimpleConfiguration orElse(SimpleConfiguration fallback) { SimpleConfiguration copy = new SimpleConfiguration(this); for (Map.Entry<String, String> entry : fallback.toMap().entrySet()) { if (!copy.containsKey(entry.getKey())) { copy.setProperty(entry.getKey(), entry.getValue()); } } return copy; }
/** * Returns a SimpleConfiguration clientConfig with properties set from this configuration * * @return SimpleConfiguration */ public SimpleConfiguration getClientConfiguration() { SimpleConfiguration clientConfig = new SimpleConfiguration(); Iterator<String> iter = getKeys(); while (iter.hasNext()) { String key = iter.next(); if (key.startsWith(CONNECTION_PREFIX) || key.startsWith(ACCUMULO_PREFIX) || key.startsWith(CLIENT_PREFIX)) { clientConfig.setProperty(key, getRawString(key)); } } return clientConfig; }
static FluentConfigurator load(String queueId, SimpleConfiguration appConfig) { FluentConfigurator fc = new FluentConfigurator(queueId); fc.buckets = appConfig.getInt(PREFIX + queueId + ".buckets"); fc.keyType = appConfig.getString(PREFIX + queueId + ".key"); fc.valueType = appConfig.getString(PREFIX + queueId + ".val"); fc.bufferSize = appConfig.getLong(PREFIX + queueId + ".bufferSize", DEFAULT_BUFFER_SIZE); fc.bucketsPerTablet = appConfig.getInt(PREFIX + queueId + ".bucketsPerTablet", DEFAULT_BUCKETS_PER_TABLET); fc.exporterType = appConfig.getString(PREFIX + queueId + ".exporter", null); return fc; }