You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@omid.apache.org by ik...@apache.org on 2016/04/21 02:02:59 UTC
[42/52] [abbrv] incubator-omid git commit: Move com.yahoo ->
org.apache
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/codahale-metrics/src/main/java/com/yahoo/omid/metrics/CodahaleMetricsProvider.java
----------------------------------------------------------------------
diff --git a/codahale-metrics/src/main/java/com/yahoo/omid/metrics/CodahaleMetricsProvider.java b/codahale-metrics/src/main/java/com/yahoo/omid/metrics/CodahaleMetricsProvider.java
deleted file mode 100644
index 751ce34..0000000
--- a/codahale-metrics/src/main/java/com/yahoo/omid/metrics/CodahaleMetricsProvider.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid.metrics;
-
-import com.codahale.metrics.ConsoleReporter;
-import com.codahale.metrics.CsvReporter;
-import com.codahale.metrics.MetricFilter;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.ScheduledReporter;
-import com.codahale.metrics.Slf4jReporter;
-import com.codahale.metrics.Timer.Context;
-import com.codahale.metrics.graphite.Graphite;
-import com.codahale.metrics.graphite.GraphiteReporter;
-import com.google.common.base.Strings;
-import com.google.common.net.HostAndPort;
-import com.yahoo.omid.metrics.CodahaleMetricsConfig.Reporter;
-import org.apache.commons.io.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class CodahaleMetricsProvider implements MetricsProvider, MetricsRegistry {
-
- private static final Logger LOG = LoggerFactory.getLogger(CodahaleMetricsProvider.class);
-
- public static final Pattern CODAHALE_METRICS_CONFIG_PATTERN = Pattern
- .compile("(csv|slf4j|console|graphite):(.+):(\\d+):(DAYS|HOURS|MICROSECONDS|MILLISECONDS|MINUTES|NANOSECONDS|SECONDS)");
-
- private MetricRegistry metrics = new MetricRegistry();
- private List<ScheduledReporter> reporters = new ArrayList<>();
-
- private final int metricsOutputFrequencyInSecs;
-
- public static CodahaleMetricsProvider createCodahaleMetricsProvider(
- List<String> metricsConfigs) throws IOException {
-
- CodahaleMetricsConfig codahaleConfig = new CodahaleMetricsConfig();
-
- for (String metricConfig : metricsConfigs) {
- Matcher matcher = CODAHALE_METRICS_CONFIG_PATTERN.matcher(metricConfig);
- if (matcher.matches()) {
-
- String reporter = matcher.group(1);
- String reporterConfig = matcher.group(2);
- codahaleConfig.setOutputFreqInSecs(Integer.valueOf(matcher.group(3)));
-
- switch (reporter) {
- case "csv":
- codahaleConfig.addReporter(Reporter.CSV);
- codahaleConfig.setCsvDir(reporterConfig);
- break;
- case "slf4j":
- codahaleConfig.addReporter(Reporter.SLF4J);
- codahaleConfig.setSlf4jLogger(reporterConfig);
- break;
- case "graphite":
- codahaleConfig.addReporter(Reporter.GRAPHITE);
- codahaleConfig.setGraphiteHostConfig(reporterConfig);
- break;
- case "console":
- codahaleConfig.addReporter(Reporter.CONSOLE);
- break;
- default:
- LOG.warn("Reporter {} unknown", reporter);
- break;
- }
- } else {
- LOG.error("Pattern {} not recognized", metricConfig);
- }
- }
- CodahaleMetricsProvider provider = new CodahaleMetricsProvider(codahaleConfig);
- provider.startMetrics();
- return provider;
- }
-
- public CodahaleMetricsProvider(CodahaleMetricsConfig conf) throws IOException {
- metricsOutputFrequencyInSecs = conf.getOutputFreqInSecs();
- int reporterCount = 0;
- for (Reporter reporter : conf.getReporters()) {
- ScheduledReporter codahaleReporter = null;
- switch (reporter) {
- case CONSOLE:
- codahaleReporter = createAndGetConfiguredConsoleReporter();
- break;
- case GRAPHITE:
- codahaleReporter = createAndGetConfiguredGraphiteReporter(conf.getPrefix(),
- conf.getGraphiteHostConfig());
- break;
- case CSV:
- codahaleReporter = createAndGetConfiguredCSVReporter(conf.getPrefix(),
- conf.getCsvDir());
- break;
- case SLF4J:
- codahaleReporter = createAndGetConfiguredSlf4jReporter(conf.getSlf4jLogger());
- break;
- }
- if (codahaleReporter != null) {
- reporters.add(codahaleReporter);
- reporterCount++;
- }
- }
- if (reporterCount == 0) {
- LOG.warn("No metric reporters found, so metrics won't be available");
- }
- startMetrics();
- }
-
- @Override
- public void startMetrics() {
- for (ScheduledReporter r : reporters) {
- LOG.info("Starting metrics reporter {} reporting every {} Secs",
- r.getClass().getCanonicalName(), metricsOutputFrequencyInSecs);
- r.start(metricsOutputFrequencyInSecs, TimeUnit.SECONDS);
- }
- }
-
- @Override
- public void stopMetrics() {
- for (ScheduledReporter r : reporters) {
- r.report();
- LOG.info("Stopping reporter {}", r.toString());
- r.stop();
- }
- }
-
- @Override
- public <T extends Number> void gauge(String name, Gauge<T> appGauge) {
- metrics.register(name, new CodahaleGauge<>(appGauge));
- }
-
- @Override
- public Counter counter(String name) {
- com.codahale.metrics.Counter counter = metrics.counter(name);
- return new CodahaleCounterWrapper(counter);
- }
-
-
- @Override
- public Timer timer(String name) {
- com.codahale.metrics.Timer timer = metrics.timer(name);
- return new CodahaleTimerWrapper(timer);
- }
-
- @Override
- public Meter meter(String name) {
- com.codahale.metrics.Meter meter = metrics.meter(name);
- return new CodahaleMeterWrapper(meter);
- }
-
- @Override
- public Histogram histogram(String name) {
- com.codahale.metrics.Histogram histogram = metrics.histogram(name);
- return new CodahaleHistogramWrapper(histogram);
- }
-
- private ScheduledReporter createAndGetConfiguredConsoleReporter() {
- return ConsoleReporter.forRegistry(metrics)
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .build();
- }
-
- private ScheduledReporter createAndGetConfiguredGraphiteReporter(String prefix, String graphiteHost) {
- LOG.info("Configuring Graphite reporter. Sendig data to host:port {}", graphiteHost);
- HostAndPort addr = HostAndPort.fromString(graphiteHost);
-
- final Graphite graphite = new Graphite(
- new InetSocketAddress(addr.getHostText(), addr.getPort()));
-
- return GraphiteReporter.forRegistry(metrics)
- .prefixedWith(prefix)
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .filter(MetricFilter.ALL)
- .build(graphite);
- }
-
- private ScheduledReporter createAndGetConfiguredCSVReporter(String prefix, String csvDir) throws IOException {
- // NOTE:
- // 1) metrics output files are exclusive to a given process
- // 2) the output directory must exist
- // 3) if output files already exist they are not overwritten and there is no metrics output
- File outputDir;
- if (Strings.isNullOrEmpty(prefix)) {
- outputDir = new File(csvDir, prefix);
- } else {
- outputDir = new File(csvDir);
- }
- FileUtils.forceMkdir(outputDir);
- LOG.info("Configuring stats with csv output to directory [{}]", outputDir.getAbsolutePath());
- return CsvReporter.forRegistry(metrics)
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .build(outputDir);
- }
-
-
- private ScheduledReporter createAndGetConfiguredSlf4jReporter(String slf4jLogger) {
- LOG.info("Configuring stats with SLF4J with logger {}", slf4jLogger);
- return Slf4jReporter.forRegistry(metrics)
- .outputTo(LoggerFactory.getLogger(slf4jLogger))
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .build();
- }
-
- /**
- * Metrics wrapper implementations
- */
-
- private class CodahaleGauge<T extends Number> implements com.codahale.metrics.Gauge<T> {
-
- private final Gauge<T> omidGauge;
-
- CodahaleGauge(Gauge<T> omidGauge) {
- this.omidGauge = omidGauge;
- }
-
- @Override
- public T getValue() {
- return omidGauge.getValue();
- }
-
- }
-
- private class CodahaleCounterWrapper implements Counter {
-
- private final com.codahale.metrics.Counter counter;
-
- CodahaleCounterWrapper(com.codahale.metrics.Counter counter) {
- this.counter = counter;
- }
-
- @Override
- public void inc() {
- counter.inc();
- }
-
- @Override
- public void inc(long n) {
- counter.inc(n);
- }
-
- @Override
- public void dec() {
- counter.dec();
- }
-
- @Override
- public void dec(long n) {
- counter.dec(n);
- }
-
- }
-
- private class CodahaleTimerWrapper implements Timer {
-
- private final com.codahale.metrics.Timer timer;
-
- private Context context;
-
- CodahaleTimerWrapper(com.codahale.metrics.Timer timer) {
- this.timer = timer;
- }
-
- @Override
- public void start() {
- context = timer.time();
- }
-
- @Override
- public void stop() {
- context.stop();
- }
-
- @Override
- public void update(long durationInNs) {
- timer.update(durationInNs, TimeUnit.NANOSECONDS);
- }
-
- }
-
- private class CodahaleMeterWrapper implements Meter {
-
- private com.codahale.metrics.Meter meter;
-
- CodahaleMeterWrapper(com.codahale.metrics.Meter meter) {
- this.meter = meter;
- }
-
- @Override
- public void mark() {
- meter.mark();
- }
-
- @Override
- public void mark(long n) {
- meter.mark(n);
- }
-
- }
-
- private class CodahaleHistogramWrapper implements Histogram {
-
- private com.codahale.metrics.Histogram histogram;
-
- CodahaleHistogramWrapper(com.codahale.metrics.Histogram histogram) {
- this.histogram = histogram;
- }
-
- @Override
- public void update(int value) {
- histogram.update(value);
- }
-
- @Override
- public void update(long value) {
- histogram.update(value);
- }
-
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/codahale-metrics/src/main/java/org/apache/omid/metrics/CodahaleMetricsConfig.java
----------------------------------------------------------------------
diff --git a/codahale-metrics/src/main/java/org/apache/omid/metrics/CodahaleMetricsConfig.java b/codahale-metrics/src/main/java/org/apache/omid/metrics/CodahaleMetricsConfig.java
new file mode 100644
index 0000000..cc43de9
--- /dev/null
+++ b/codahale-metrics/src/main/java/org/apache/omid/metrics/CodahaleMetricsConfig.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid.metrics;
+
+import com.google.inject.Inject;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashSet;
+import java.util.Set;
+
+@Singleton
+public class CodahaleMetricsConfig extends AbstractMetricsConfig {
+
+ public enum Reporter {
+ CSV, SLF4J, GRAPHITE, CONSOLE
+ }
+
+ private static final String DEFAULT_PREFIX = "omid";
+ private static final String DEFAULT_GRAPHITE_HOST = "localhost:2003";
+ private static final String DEFAULT_CSV_DIR = ".";
+ private static final String DEFAULT_SLF4J_LOGGER = "metrics";
+
+ private static final String METRICS_CODAHALE_PREFIX_KEY = "metrics.codahale.prefix";
+ private static final String METRICS_CODAHALE_REPORTERS_KEY = "metrics.codahale.reporters";
+ private static final String METRICS_CODAHALE_GRAPHITE_HOST_CONFIG = "metrics.codahale.graphite.host.config";
+ private static final String METRICS_CODAHALE_CSV_DIR = "metrics.codahale.cvs.dir";
+ private static final String METRICS_CODAHALE_SLF4J_LOGGER = "metrics.codahale.slf4j.logger";
+
+ private String prefix = DEFAULT_PREFIX;
+ private Set<Reporter> reporters = new HashSet<Reporter>();
+ private String graphiteHostConfig = DEFAULT_GRAPHITE_HOST;
+ private String csvDir = DEFAULT_CSV_DIR;
+ private String slf4jLogger = DEFAULT_SLF4J_LOGGER;
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ @Inject(optional = true)
+ public void setPrefix(@Named(METRICS_CODAHALE_PREFIX_KEY) String prefix) {
+ this.prefix = prefix;
+ }
+
+ public Set<Reporter> getReporters() {
+ return reporters;
+ }
+
+ @Inject(optional = true)
+ public void setReporters(@Named(METRICS_CODAHALE_REPORTERS_KEY) Set<Reporter> reporters) {
+ this.reporters = reporters;
+ }
+
+ public void addReporter(Reporter reporter) {
+ reporters.add(reporter);
+ }
+
+ public String getGraphiteHostConfig() {
+ return graphiteHostConfig;
+ }
+
+ @Inject(optional = true)
+ public void setGraphiteHostConfig(@Named(METRICS_CODAHALE_GRAPHITE_HOST_CONFIG) String graphiteHostConfig) {
+ this.graphiteHostConfig = graphiteHostConfig;
+ }
+
+ public String getCsvDir() {
+ return csvDir;
+ }
+
+ @Inject(optional = true)
+ public void setCsvDir(@Named(METRICS_CODAHALE_CSV_DIR) String csvDir) {
+ this.csvDir = csvDir;
+ }
+
+ public String getSlf4jLogger() {
+ return slf4jLogger;
+ }
+
+ @Inject(optional = true)
+ public void setSlf4jLogger(@Named(METRICS_CODAHALE_SLF4J_LOGGER) String slf4jLogger) {
+ this.slf4jLogger = slf4jLogger;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/codahale-metrics/src/main/java/org/apache/omid/metrics/CodahaleMetricsProvider.java
----------------------------------------------------------------------
diff --git a/codahale-metrics/src/main/java/org/apache/omid/metrics/CodahaleMetricsProvider.java b/codahale-metrics/src/main/java/org/apache/omid/metrics/CodahaleMetricsProvider.java
new file mode 100644
index 0000000..89cc49b
--- /dev/null
+++ b/codahale-metrics/src/main/java/org/apache/omid/metrics/CodahaleMetricsProvider.java
@@ -0,0 +1,346 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid.metrics;
+
+import com.codahale.metrics.ConsoleReporter;
+import com.codahale.metrics.CsvReporter;
+import com.codahale.metrics.MetricFilter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.ScheduledReporter;
+import com.codahale.metrics.Slf4jReporter;
+import com.codahale.metrics.Timer.Context;
+import com.codahale.metrics.graphite.Graphite;
+import com.codahale.metrics.graphite.GraphiteReporter;
+import com.google.common.base.Strings;
+import com.google.common.net.HostAndPort;
+import org.apache.omid.metrics.CodahaleMetricsConfig.Reporter;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class CodahaleMetricsProvider implements MetricsProvider, MetricsRegistry {
+
+ private static final Logger LOG = LoggerFactory.getLogger(CodahaleMetricsProvider.class);
+
+ public static final Pattern CODAHALE_METRICS_CONFIG_PATTERN = Pattern
+ .compile("(csv|slf4j|console|graphite):(.+):(\\d+):(DAYS|HOURS|MICROSECONDS|MILLISECONDS|MINUTES|NANOSECONDS|SECONDS)");
+
+ private MetricRegistry metrics = new MetricRegistry();
+ private List<ScheduledReporter> reporters = new ArrayList<>();
+
+ private final int metricsOutputFrequencyInSecs;
+
+ public static CodahaleMetricsProvider createCodahaleMetricsProvider(
+ List<String> metricsConfigs) throws IOException {
+
+ CodahaleMetricsConfig codahaleConfig = new CodahaleMetricsConfig();
+
+ for (String metricConfig : metricsConfigs) {
+ Matcher matcher = CODAHALE_METRICS_CONFIG_PATTERN.matcher(metricConfig);
+ if (matcher.matches()) {
+
+ String reporter = matcher.group(1);
+ String reporterConfig = matcher.group(2);
+ codahaleConfig.setOutputFreqInSecs(Integer.valueOf(matcher.group(3)));
+
+ switch (reporter) {
+ case "csv":
+ codahaleConfig.addReporter(Reporter.CSV);
+ codahaleConfig.setCsvDir(reporterConfig);
+ break;
+ case "slf4j":
+ codahaleConfig.addReporter(Reporter.SLF4J);
+ codahaleConfig.setSlf4jLogger(reporterConfig);
+ break;
+ case "graphite":
+ codahaleConfig.addReporter(Reporter.GRAPHITE);
+ codahaleConfig.setGraphiteHostConfig(reporterConfig);
+ break;
+ case "console":
+ codahaleConfig.addReporter(Reporter.CONSOLE);
+ break;
+ default:
+ LOG.warn("Reporter {} unknown", reporter);
+ break;
+ }
+ } else {
+ LOG.error("Pattern {} not recognized", metricConfig);
+ }
+ }
+ CodahaleMetricsProvider provider = new CodahaleMetricsProvider(codahaleConfig);
+ provider.startMetrics();
+ return provider;
+ }
+
+ public CodahaleMetricsProvider(CodahaleMetricsConfig conf) throws IOException {
+ metricsOutputFrequencyInSecs = conf.getOutputFreqInSecs();
+ int reporterCount = 0;
+ for (Reporter reporter : conf.getReporters()) {
+ ScheduledReporter codahaleReporter = null;
+ switch (reporter) {
+ case CONSOLE:
+ codahaleReporter = createAndGetConfiguredConsoleReporter();
+ break;
+ case GRAPHITE:
+ codahaleReporter = createAndGetConfiguredGraphiteReporter(conf.getPrefix(),
+ conf.getGraphiteHostConfig());
+ break;
+ case CSV:
+ codahaleReporter = createAndGetConfiguredCSVReporter(conf.getPrefix(),
+ conf.getCsvDir());
+ break;
+ case SLF4J:
+ codahaleReporter = createAndGetConfiguredSlf4jReporter(conf.getSlf4jLogger());
+ break;
+ }
+ if (codahaleReporter != null) {
+ reporters.add(codahaleReporter);
+ reporterCount++;
+ }
+ }
+ if (reporterCount == 0) {
+ LOG.warn("No metric reporters found, so metrics won't be available");
+ }
+ startMetrics();
+ }
+
+ @Override
+ public void startMetrics() {
+ for (ScheduledReporter r : reporters) {
+ LOG.info("Starting metrics reporter {} reporting every {} Secs",
+ r.getClass().getCanonicalName(), metricsOutputFrequencyInSecs);
+ r.start(metricsOutputFrequencyInSecs, TimeUnit.SECONDS);
+ }
+ }
+
+ @Override
+ public void stopMetrics() {
+ for (ScheduledReporter r : reporters) {
+ r.report();
+ LOG.info("Stopping reporter {}", r.toString());
+ r.stop();
+ }
+ }
+
+ @Override
+ public <T extends Number> void gauge(String name, Gauge<T> appGauge) {
+ metrics.register(name, new CodahaleGauge<>(appGauge));
+ }
+
+ @Override
+ public Counter counter(String name) {
+ com.codahale.metrics.Counter counter = metrics.counter(name);
+ return new CodahaleCounterWrapper(counter);
+ }
+
+
+ @Override
+ public Timer timer(String name) {
+ com.codahale.metrics.Timer timer = metrics.timer(name);
+ return new CodahaleTimerWrapper(timer);
+ }
+
+ @Override
+ public Meter meter(String name) {
+ com.codahale.metrics.Meter meter = metrics.meter(name);
+ return new CodahaleMeterWrapper(meter);
+ }
+
+ @Override
+ public Histogram histogram(String name) {
+ com.codahale.metrics.Histogram histogram = metrics.histogram(name);
+ return new CodahaleHistogramWrapper(histogram);
+ }
+
+ private ScheduledReporter createAndGetConfiguredConsoleReporter() {
+ return ConsoleReporter.forRegistry(metrics)
+ .convertRatesTo(TimeUnit.SECONDS)
+ .convertDurationsTo(TimeUnit.MILLISECONDS)
+ .build();
+ }
+
+ private ScheduledReporter createAndGetConfiguredGraphiteReporter(String prefix, String graphiteHost) {
+ LOG.info("Configuring Graphite reporter. Sendig data to host:port {}", graphiteHost);
+ HostAndPort addr = HostAndPort.fromString(graphiteHost);
+
+ final Graphite graphite = new Graphite(
+ new InetSocketAddress(addr.getHostText(), addr.getPort()));
+
+ return GraphiteReporter.forRegistry(metrics)
+ .prefixedWith(prefix)
+ .convertRatesTo(TimeUnit.SECONDS)
+ .convertDurationsTo(TimeUnit.MILLISECONDS)
+ .filter(MetricFilter.ALL)
+ .build(graphite);
+ }
+
+ private ScheduledReporter createAndGetConfiguredCSVReporter(String prefix, String csvDir) throws IOException {
+ // NOTE:
+ // 1) metrics output files are exclusive to a given process
+ // 2) the output directory must exist
+ // 3) if output files already exist they are not overwritten and there is no metrics output
+ File outputDir;
+ if (Strings.isNullOrEmpty(prefix)) {
+ outputDir = new File(csvDir, prefix);
+ } else {
+ outputDir = new File(csvDir);
+ }
+ FileUtils.forceMkdir(outputDir);
+ LOG.info("Configuring stats with csv output to directory [{}]", outputDir.getAbsolutePath());
+ return CsvReporter.forRegistry(metrics)
+ .convertRatesTo(TimeUnit.SECONDS)
+ .convertDurationsTo(TimeUnit.MILLISECONDS)
+ .build(outputDir);
+ }
+
+
+ private ScheduledReporter createAndGetConfiguredSlf4jReporter(String slf4jLogger) {
+ LOG.info("Configuring stats with SLF4J with logger {}", slf4jLogger);
+ return Slf4jReporter.forRegistry(metrics)
+ .outputTo(LoggerFactory.getLogger(slf4jLogger))
+ .convertRatesTo(TimeUnit.SECONDS)
+ .convertDurationsTo(TimeUnit.MILLISECONDS)
+ .build();
+ }
+
+ /**
+ * Metrics wrapper implementations
+ */
+
+ private class CodahaleGauge<T extends Number> implements com.codahale.metrics.Gauge<T> {
+
+ private final Gauge<T> omidGauge;
+
+ CodahaleGauge(Gauge<T> omidGauge) {
+ this.omidGauge = omidGauge;
+ }
+
+ @Override
+ public T getValue() {
+ return omidGauge.getValue();
+ }
+
+ }
+
+ private class CodahaleCounterWrapper implements Counter {
+
+ private final com.codahale.metrics.Counter counter;
+
+ CodahaleCounterWrapper(com.codahale.metrics.Counter counter) {
+ this.counter = counter;
+ }
+
+ @Override
+ public void inc() {
+ counter.inc();
+ }
+
+ @Override
+ public void inc(long n) {
+ counter.inc(n);
+ }
+
+ @Override
+ public void dec() {
+ counter.dec();
+ }
+
+ @Override
+ public void dec(long n) {
+ counter.dec(n);
+ }
+
+ }
+
+ private class CodahaleTimerWrapper implements Timer {
+
+ private final com.codahale.metrics.Timer timer;
+
+ private Context context;
+
+ CodahaleTimerWrapper(com.codahale.metrics.Timer timer) {
+ this.timer = timer;
+ }
+
+ @Override
+ public void start() {
+ context = timer.time();
+ }
+
+ @Override
+ public void stop() {
+ context.stop();
+ }
+
+ @Override
+ public void update(long durationInNs) {
+ timer.update(durationInNs, TimeUnit.NANOSECONDS);
+ }
+
+ }
+
+ private class CodahaleMeterWrapper implements Meter {
+
+ private com.codahale.metrics.Meter meter;
+
+ CodahaleMeterWrapper(com.codahale.metrics.Meter meter) {
+ this.meter = meter;
+ }
+
+ @Override
+ public void mark() {
+ meter.mark();
+ }
+
+ @Override
+ public void mark(long n) {
+ meter.mark(n);
+ }
+
+ }
+
+ private class CodahaleHistogramWrapper implements Histogram {
+
+ private com.codahale.metrics.Histogram histogram;
+
+ CodahaleHistogramWrapper(com.codahale.metrics.Histogram histogram) {
+ this.histogram = histogram;
+ }
+
+ @Override
+ public void update(int value) {
+ histogram.update(value);
+ }
+
+ @Override
+ public void update(long value) {
+ histogram.update(value);
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/pom.xml
----------------------------------------------------------------------
diff --git a/commit-table/pom.xml b/commit-table/pom.xml
index 4ad3c4d..ad5c100 100644
--- a/commit-table/pom.xml
+++ b/commit-table/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>com.yahoo.omid</groupId>
+ <groupId>org.apache.omid</groupId>
<artifactId>omid</artifactId>
<version>0.8.1.37-SNAPSHOT</version>
</parent>
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/src/main/java/com/yahoo/omid/committable/CommitTable.java
----------------------------------------------------------------------
diff --git a/commit-table/src/main/java/com/yahoo/omid/committable/CommitTable.java b/commit-table/src/main/java/com/yahoo/omid/committable/CommitTable.java
deleted file mode 100644
index 78ae44b..0000000
--- a/commit-table/src/main/java/com/yahoo/omid/committable/CommitTable.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid.committable;
-
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
-
-import java.io.Closeable;
-import java.io.IOException;
-
-public interface CommitTable {
-
- long INVALID_TRANSACTION_MARKER = -1L;
-
- Writer getWriter() throws IOException;
-
- Client getClient() throws IOException;
-
- interface Writer extends Closeable {
-
- void addCommittedTransaction(long startTimestamp, long commitTimestamp) throws IOException;
-
- void updateLowWatermark(long lowWatermark) throws IOException;
-
- /**
- * Flushes all the buffered events to the underlying datastore
- */
- void flush() throws IOException;
-
- /**
- * Allows to clean the write's current buffer. It is required for HA
- */
- void clearWriteBuffer();
- }
-
- interface Client extends Closeable {
-
- /**
- * Checks whether a transaction commit data is inside the commit table The function also checks whether the
- * transaction was invalidated and returns a commit timestamp type accordingly.
- *
- * @param startTimestamp the transaction start timestamp
- * @return Optional<CommitTimestamp> that represents a valid, invalid, or no timestamp.
- */
- ListenableFuture<Optional<CommitTimestamp>> getCommitTimestamp(long startTimestamp);
-
- ListenableFuture<Long> readLowWatermark();
-
- ListenableFuture<Void> completeTransaction(long startTimestamp);
-
- /**
- * Atomically tries to invalidate a non-committed transaction launched by a previous TSO server.
- *
- * @param startTimeStamp the transaction to invalidate
- * @return true on success and false on failure
- */
- ListenableFuture<Boolean> tryInvalidateTransaction(long startTimeStamp);
- }
-
- // ----------------------------------------------------------------------------------------------------------------
- // Helper classes
- // ----------------------------------------------------------------------------------------------------------------
- class CommitTimestamp {
-
- public enum Location {
- NOT_PRESENT, CACHE, COMMIT_TABLE, SHADOW_CELL
- }
-
- private final Location location;
- private final long value;
- private final boolean isValid;
-
- public CommitTimestamp(Location location, long value, boolean isValid) {
- this.location = location;
- this.value = value;
- this.isValid = isValid;
- }
-
- public Location getLocation() {
- return location;
- }
-
- public long getValue() {
- return value;
- }
-
- public boolean isValid() {
- return isValid;
- }
-
- @Override
- public String toString() {
- return String.format("Is valid=%s, Location=%s, Value=%d)", isValid, location, value);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/src/main/java/com/yahoo/omid/committable/InMemoryCommitTable.java
----------------------------------------------------------------------
diff --git a/commit-table/src/main/java/com/yahoo/omid/committable/InMemoryCommitTable.java b/commit-table/src/main/java/com/yahoo/omid/committable/InMemoryCommitTable.java
deleted file mode 100644
index 181e7aa..0000000
--- a/commit-table/src/main/java/com/yahoo/omid/committable/InMemoryCommitTable.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid.committable;
-
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-import com.yahoo.omid.committable.CommitTable.CommitTimestamp.Location;
-
-import java.io.IOException;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class InMemoryCommitTable implements CommitTable {
-
- final ConcurrentHashMap<Long, Long> table = new ConcurrentHashMap<>();
-
- long lowWatermark;
-
- @Override
- public CommitTable.Writer getWriter() {
- return new Writer();
- }
-
- @Override
- public CommitTable.Client getClient() {
- return new Client();
- }
-
- public class Writer implements CommitTable.Writer {
- @Override
- public void addCommittedTransaction(long startTimestamp, long commitTimestamp) {
- // In this implementation, we use only one location that represents
- // both the value and the invalidation. Therefore, putIfAbsent is
- // required to make sure the entry was not invalidated.
- table.putIfAbsent(startTimestamp, commitTimestamp);
- }
-
- @Override
- public void updateLowWatermark(long lowWatermark) throws IOException {
- InMemoryCommitTable.this.lowWatermark = lowWatermark;
- }
-
- @Override
- public void flush() throws IOException {
- // noop
- }
-
- @Override
- public void clearWriteBuffer() {
- table.clear();
- }
-
- @Override
- public void close() {
- }
- }
-
- public class Client implements CommitTable.Client {
- @Override
- public ListenableFuture<Optional<CommitTimestamp>> getCommitTimestamp(long startTimestamp) {
- SettableFuture<Optional<CommitTimestamp>> f = SettableFuture.create();
- Long result = table.get(startTimestamp);
- if (result == null) {
- f.set(Optional.<CommitTimestamp>absent());
- } else {
- if (result == INVALID_TRANSACTION_MARKER) {
- f.set(Optional.of(new CommitTimestamp(Location.COMMIT_TABLE, INVALID_TRANSACTION_MARKER, false)));
- } else {
- f.set(Optional.of(new CommitTimestamp(Location.COMMIT_TABLE, result, true)));
- }
- }
- return f;
- }
-
- @Override
- public ListenableFuture<Long> readLowWatermark() {
- SettableFuture<Long> f = SettableFuture.create();
- f.set(lowWatermark);
- return f;
- }
-
- @Override
- public ListenableFuture<Void> completeTransaction(long startTimestamp) {
- SettableFuture<Void> f = SettableFuture.create();
- table.remove(startTimestamp);
- f.set(null);
- return f;
- }
-
- @Override
- public ListenableFuture<Boolean> tryInvalidateTransaction(long startTimestamp) {
-
- SettableFuture<Boolean> f = SettableFuture.create();
- Long old = table.get(startTimestamp);
-
- // If the transaction represented by startTimestamp is not in the map
- if (old == null) {
- // Try to invalidate the transaction
- old = table.putIfAbsent(startTimestamp, INVALID_TRANSACTION_MARKER);
- // If we were able to invalidate or someone else invalidate before us
- if (old == null || old == INVALID_TRANSACTION_MARKER) {
- f.set(true);
- return f;
- }
- } else {
- // Check if the value we read marked the transaction as invalid
- if (old == INVALID_TRANSACTION_MARKER) {
- f.set(true);
- return f;
- }
- }
-
- // At this point the transaction was already in the map at the beginning
- // of the method or was added right before we tried to invalidate.
- f.set(false);
- return f;
- }
-
- @Override
- public void close() {
- }
- }
-
- public int countElements() {
- return table.size();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/src/main/java/com/yahoo/omid/committable/NullCommitTable.java
----------------------------------------------------------------------
diff --git a/commit-table/src/main/java/com/yahoo/omid/committable/NullCommitTable.java b/commit-table/src/main/java/com/yahoo/omid/committable/NullCommitTable.java
deleted file mode 100644
index 26aac54..0000000
--- a/commit-table/src/main/java/com/yahoo/omid/committable/NullCommitTable.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid.committable;
-
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-
-import java.io.IOException;
-
-public class NullCommitTable implements CommitTable {
- @Override
- public CommitTable.Writer getWriter() {
- return new Writer();
- }
-
- @Override
- public CommitTable.Client getClient() {
- return new Client();
- }
-
- public class Writer implements CommitTable.Writer {
- @Override
- public void addCommittedTransaction(long startTimestamp, long commitTimestamp) {
- // noop
- }
-
- @Override
- public void updateLowWatermark(long lowWatermark) throws IOException {
- // noop
- }
-
- @Override
- public void clearWriteBuffer() {
- // noop
- }
-
- @Override
- public void flush() throws IOException {
- // noop
- }
-
- @Override
- public void close() {
- }
-
- }
-
- public static class Client implements CommitTable.Client {
- @Override
- public ListenableFuture<Optional<CommitTimestamp>> getCommitTimestamp(long startTimestamp) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ListenableFuture<Long> readLowWatermark() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ListenableFuture<Void> completeTransaction(long startTimestamp) {
- SettableFuture<Void> f = SettableFuture.create();
- f.set(null);
- return f;
- }
-
- @Override
- public ListenableFuture<Boolean> tryInvalidateTransaction(long startTimestamp) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void close() {
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/src/main/java/org/apache/omid/committable/CommitTable.java
----------------------------------------------------------------------
diff --git a/commit-table/src/main/java/org/apache/omid/committable/CommitTable.java b/commit-table/src/main/java/org/apache/omid/committable/CommitTable.java
new file mode 100644
index 0000000..d47822b
--- /dev/null
+++ b/commit-table/src/main/java/org/apache/omid/committable/CommitTable.java
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid.committable;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+public interface CommitTable {
+
+ long INVALID_TRANSACTION_MARKER = -1L;
+
+ Writer getWriter() throws IOException;
+
+ Client getClient() throws IOException;
+
+ interface Writer extends Closeable {
+
+ void addCommittedTransaction(long startTimestamp, long commitTimestamp) throws IOException;
+
+ void updateLowWatermark(long lowWatermark) throws IOException;
+
+ /**
+ * Flushes all the buffered events to the underlying datastore
+ */
+ void flush() throws IOException;
+
+ /**
+ * Allows to clean the write's current buffer. It is required for HA
+ */
+ void clearWriteBuffer();
+ }
+
+ interface Client extends Closeable {
+
+ /**
+ * Checks whether a transaction commit data is inside the commit table The function also checks whether the
+ * transaction was invalidated and returns a commit timestamp type accordingly.
+ *
+ * @param startTimestamp the transaction start timestamp
+ * @return Optional<CommitTimestamp> that represents a valid, invalid, or no timestamp.
+ */
+ ListenableFuture<Optional<CommitTimestamp>> getCommitTimestamp(long startTimestamp);
+
+ ListenableFuture<Long> readLowWatermark();
+
+ ListenableFuture<Void> completeTransaction(long startTimestamp);
+
+ /**
+ * Atomically tries to invalidate a non-committed transaction launched by a previous TSO server.
+ *
+ * @param startTimeStamp the transaction to invalidate
+ * @return true on success and false on failure
+ */
+ ListenableFuture<Boolean> tryInvalidateTransaction(long startTimeStamp);
+ }
+
+ // ----------------------------------------------------------------------------------------------------------------
+ // Helper classes
+ // ----------------------------------------------------------------------------------------------------------------
+ class CommitTimestamp {
+
+ public enum Location {
+ NOT_PRESENT, CACHE, COMMIT_TABLE, SHADOW_CELL
+ }
+
+ private final Location location;
+ private final long value;
+ private final boolean isValid;
+
+ public CommitTimestamp(Location location, long value, boolean isValid) {
+ this.location = location;
+ this.value = value;
+ this.isValid = isValid;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public long getValue() {
+ return value;
+ }
+
+ public boolean isValid() {
+ return isValid;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("Is valid=%s, Location=%s, Value=%d)", isValid, location, value);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/src/main/java/org/apache/omid/committable/InMemoryCommitTable.java
----------------------------------------------------------------------
diff --git a/commit-table/src/main/java/org/apache/omid/committable/InMemoryCommitTable.java b/commit-table/src/main/java/org/apache/omid/committable/InMemoryCommitTable.java
new file mode 100644
index 0000000..ceaec48
--- /dev/null
+++ b/commit-table/src/main/java/org/apache/omid/committable/InMemoryCommitTable.java
@@ -0,0 +1,143 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid.committable;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.apache.omid.committable.CommitTable.CommitTimestamp.Location;
+
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class InMemoryCommitTable implements CommitTable {
+
+ final ConcurrentHashMap<Long, Long> table = new ConcurrentHashMap<>();
+
+ long lowWatermark;
+
+ @Override
+ public CommitTable.Writer getWriter() {
+ return new Writer();
+ }
+
+ @Override
+ public CommitTable.Client getClient() {
+ return new Client();
+ }
+
+ public class Writer implements CommitTable.Writer {
+ @Override
+ public void addCommittedTransaction(long startTimestamp, long commitTimestamp) {
+ // In this implementation, we use only one location that represents
+ // both the value and the invalidation. Therefore, putIfAbsent is
+ // required to make sure the entry was not invalidated.
+ table.putIfAbsent(startTimestamp, commitTimestamp);
+ }
+
+ @Override
+ public void updateLowWatermark(long lowWatermark) throws IOException {
+ InMemoryCommitTable.this.lowWatermark = lowWatermark;
+ }
+
+ @Override
+ public void flush() throws IOException {
+ // noop
+ }
+
+ @Override
+ public void clearWriteBuffer() {
+ table.clear();
+ }
+
+ @Override
+ public void close() {
+ }
+ }
+
+ public class Client implements CommitTable.Client {
+ @Override
+ public ListenableFuture<Optional<CommitTimestamp>> getCommitTimestamp(long startTimestamp) {
+ SettableFuture<Optional<CommitTimestamp>> f = SettableFuture.create();
+ Long result = table.get(startTimestamp);
+ if (result == null) {
+ f.set(Optional.<CommitTimestamp>absent());
+ } else {
+ if (result == INVALID_TRANSACTION_MARKER) {
+ f.set(Optional.of(new CommitTimestamp(Location.COMMIT_TABLE, INVALID_TRANSACTION_MARKER, false)));
+ } else {
+ f.set(Optional.of(new CommitTimestamp(Location.COMMIT_TABLE, result, true)));
+ }
+ }
+ return f;
+ }
+
+ @Override
+ public ListenableFuture<Long> readLowWatermark() {
+ SettableFuture<Long> f = SettableFuture.create();
+ f.set(lowWatermark);
+ return f;
+ }
+
+ @Override
+ public ListenableFuture<Void> completeTransaction(long startTimestamp) {
+ SettableFuture<Void> f = SettableFuture.create();
+ table.remove(startTimestamp);
+ f.set(null);
+ return f;
+ }
+
+ @Override
+ public ListenableFuture<Boolean> tryInvalidateTransaction(long startTimestamp) {
+
+ SettableFuture<Boolean> f = SettableFuture.create();
+ Long old = table.get(startTimestamp);
+
+ // If the transaction represented by startTimestamp is not in the map
+ if (old == null) {
+ // Try to invalidate the transaction
+ old = table.putIfAbsent(startTimestamp, INVALID_TRANSACTION_MARKER);
+ // If we were able to invalidate or someone else invalidate before us
+ if (old == null || old == INVALID_TRANSACTION_MARKER) {
+ f.set(true);
+ return f;
+ }
+ } else {
+ // Check if the value we read marked the transaction as invalid
+ if (old == INVALID_TRANSACTION_MARKER) {
+ f.set(true);
+ return f;
+ }
+ }
+
+ // At this point the transaction was already in the map at the beginning
+ // of the method or was added right before we tried to invalidate.
+ f.set(false);
+ return f;
+ }
+
+ @Override
+ public void close() {
+ }
+ }
+
+ public int countElements() {
+ return table.size();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/src/main/java/org/apache/omid/committable/NullCommitTable.java
----------------------------------------------------------------------
diff --git a/commit-table/src/main/java/org/apache/omid/committable/NullCommitTable.java b/commit-table/src/main/java/org/apache/omid/committable/NullCommitTable.java
new file mode 100644
index 0000000..89e29eb
--- /dev/null
+++ b/commit-table/src/main/java/org/apache/omid/committable/NullCommitTable.java
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid.committable;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+
+import java.io.IOException;
+
+public class NullCommitTable implements CommitTable {
+ @Override
+ public CommitTable.Writer getWriter() {
+ return new Writer();
+ }
+
+ @Override
+ public CommitTable.Client getClient() {
+ return new Client();
+ }
+
+ public class Writer implements CommitTable.Writer {
+ @Override
+ public void addCommittedTransaction(long startTimestamp, long commitTimestamp) {
+ // noop
+ }
+
+ @Override
+ public void updateLowWatermark(long lowWatermark) throws IOException {
+ // noop
+ }
+
+ @Override
+ public void clearWriteBuffer() {
+ // noop
+ }
+
+ @Override
+ public void flush() throws IOException {
+ // noop
+ }
+
+ @Override
+ public void close() {
+ }
+
+ }
+
+ public static class Client implements CommitTable.Client {
+ @Override
+ public ListenableFuture<Optional<CommitTimestamp>> getCommitTimestamp(long startTimestamp) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ListenableFuture<Long> readLowWatermark() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ListenableFuture<Void> completeTransaction(long startTimestamp) {
+ SettableFuture<Void> f = SettableFuture.create();
+ f.set(null);
+ return f;
+ }
+
+ @Override
+ public ListenableFuture<Boolean> tryInvalidateTransaction(long startTimestamp) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void close() {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/src/test/java/com/yahoo/omid/committable/NullCommitTableTest.java
----------------------------------------------------------------------
diff --git a/commit-table/src/test/java/com/yahoo/omid/committable/NullCommitTableTest.java b/commit-table/src/test/java/com/yahoo/omid/committable/NullCommitTableTest.java
deleted file mode 100644
index 92cd248..0000000
--- a/commit-table/src/test/java/com/yahoo/omid/committable/NullCommitTableTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid.committable;
-
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertNull;
-
-/**
- * TODO: Remove this class when removing this class from production code
- */
-public class NullCommitTableTest {
-
- private static final long TEST_ST = 1L;
- private static final long TEST_CT = 2L;
- private static final long TEST_LWM = 1L;
-
- @Test(timeOut = 10_000)
- public void testClientAndWriter() throws Exception {
-
- CommitTable commitTable = new NullCommitTable();
-
- try (CommitTable.Client commitTableClient = commitTable.getClient();
- CommitTable.Writer commitTableWriter = commitTable.getWriter()) {
-
- // Test client
- try {
- commitTableClient.readLowWatermark().get();
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- try {
- commitTableClient.getCommitTimestamp(TEST_ST).get();
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- try {
- commitTableClient.tryInvalidateTransaction(TEST_ST).get();
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- assertNull(commitTableClient.completeTransaction(TEST_ST).get());
-
- // Test writer
- commitTableWriter.updateLowWatermark(TEST_LWM);
- commitTableWriter.addCommittedTransaction(TEST_ST, TEST_CT);
- commitTableWriter.clearWriteBuffer();
- commitTableWriter.flush();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/commit-table/src/test/java/org/apache/omid/committable/NullCommitTableTest.java
----------------------------------------------------------------------
diff --git a/commit-table/src/test/java/org/apache/omid/committable/NullCommitTableTest.java b/commit-table/src/test/java/org/apache/omid/committable/NullCommitTableTest.java
new file mode 100644
index 0000000..612a4ed
--- /dev/null
+++ b/commit-table/src/test/java/org/apache/omid/committable/NullCommitTableTest.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid.committable;
+
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertNull;
+
+/**
+ * TODO: Remove this class when removing this class from production code
+ */
+public class NullCommitTableTest {
+
+ private static final long TEST_ST = 1L;
+ private static final long TEST_CT = 2L;
+ private static final long TEST_LWM = 1L;
+
+ @Test(timeOut = 10_000)
+ public void testClientAndWriter() throws Exception {
+
+ CommitTable commitTable = new NullCommitTable();
+
+ try (CommitTable.Client commitTableClient = commitTable.getClient();
+ CommitTable.Writer commitTableWriter = commitTable.getWriter()) {
+
+ // Test client
+ try {
+ commitTableClient.readLowWatermark().get();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ commitTableClient.getCommitTimestamp(TEST_ST).get();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ commitTableClient.tryInvalidateTransaction(TEST_ST).get();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ assertNull(commitTableClient.completeTransaction(TEST_ST).get());
+
+ // Test writer
+ commitTableWriter.updateLowWatermark(TEST_LWM);
+ commitTableWriter.addCommittedTransaction(TEST_ST, TEST_CT);
+ commitTableWriter.clearWriteBuffer();
+ commitTableWriter.flush();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/common/pom.xml
----------------------------------------------------------------------
diff --git a/common/pom.xml b/common/pom.xml
index 5a84a35..d776e2b 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>com.yahoo.omid</groupId>
+ <groupId>org.apache.omid</groupId>
<artifactId>omid</artifactId>
<version>0.8.1.37-SNAPSHOT</version>
</parent>
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/common/src/main/java/com/yahoo/omid/YAMLUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/com/yahoo/omid/YAMLUtils.java b/common/src/main/java/com/yahoo/omid/YAMLUtils.java
deleted file mode 100644
index 6edd71d..0000000
--- a/common/src/main/java/com/yahoo/omid/YAMLUtils.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid;
-
-import com.google.common.base.Preconditions;
-import com.google.common.io.Resources;
-import org.apache.commons.beanutils.BeanUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.Yaml;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.nio.charset.Charset;
-import java.util.HashMap;
-import java.util.Map;
-
-public class YAMLUtils {
-
- private static final Logger LOG = LoggerFactory.getLogger(YAMLUtils.class);
-
- public void loadSettings(String resourcePath, String defaultResourcePath, Object bean) {
- try {
- Map properties = loadSettings(resourcePath, defaultResourcePath);
- BeanUtils.populate(bean, properties);
- } catch (IllegalAccessException | InvocationTargetException | IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public void loadSettings(String resourcePath, Object bean) {
- try {
- Map properties = loadSettings(null, resourcePath);
- BeanUtils.populate(bean, properties);
- } catch (IllegalAccessException | InvocationTargetException | IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- private Map loadSettings(String resourcePath, String defaultResourcePath) throws IOException {
- Map defaultSetting = loadAsMap(defaultResourcePath);
- Preconditions.checkState(defaultSetting.size() > 0, String.format("Failed to load file '%s' from classpath", defaultResourcePath));
- if (resourcePath != null) {
- Map userSetting = loadAsMap(resourcePath);
- defaultSetting.putAll(userSetting);
- }
- return defaultSetting;
- }
-
- @SuppressWarnings("unchecked")
- private Map loadAsMap(String path) throws IOException {
- try {
- String content = Resources.toString(Resources.getResource(path), Charset.forName("UTF-8"));
- LOG.debug("Loaded resource file '{}'\n{}", path, content);
- Map settings = new Yaml().loadAs(content, Map.class);
- if (settings == null) {
- settings = new HashMap(0);
- }
- return settings;
- } catch (IllegalArgumentException e) {
- return new HashMap();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/common/src/main/java/com/yahoo/omid/zk/ZKUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/com/yahoo/omid/zk/ZKUtils.java b/common/src/main/java/com/yahoo/omid/zk/ZKUtils.java
deleted file mode 100644
index 10e3df1..0000000
--- a/common/src/main/java/com/yahoo/omid/zk/ZKUtils.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid.zk;
-
-import org.apache.curator.RetryPolicy;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
-public class ZKUtils {
-
- private static final Logger LOG = LoggerFactory.getLogger(ZKUtils.class);
-
- public static CuratorFramework initZKClient(String zkCluster, String namespace, int zkConnectionTimeoutInSec)
- throws IOException, InterruptedException {
-
- LOG.info("Creating Zookeeper Client connecting to {}", zkCluster);
-
- RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
- CuratorFramework zkClient = CuratorFrameworkFactory.builder()
- .namespace(namespace)
- .connectString(zkCluster)
- .retryPolicy(retryPolicy)
- .build();
-
- zkClient.start();
- if (zkClient.blockUntilConnected(zkConnectionTimeoutInSec, TimeUnit.SECONDS)) {
- LOG.info("Connected to ZK cluster '{}', client in state: [{}]", zkCluster, zkClient.getState());
- } else {
- throw new IOException(String.format("Can't contact ZK cluster '%s' after 10 seconds", zkCluster));
- }
-
- return zkClient;
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/common/src/main/java/org/apache/omid/YAMLUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/omid/YAMLUtils.java b/common/src/main/java/org/apache/omid/YAMLUtils.java
new file mode 100644
index 0000000..156d033
--- /dev/null
+++ b/common/src/main/java/org/apache/omid/YAMLUtils.java
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid;
+
+import com.google.common.base.Preconditions;
+import com.google.common.io.Resources;
+import org.apache.commons.beanutils.BeanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+
+public class YAMLUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(YAMLUtils.class);
+
+ public void loadSettings(String resourcePath, String defaultResourcePath, Object bean) {
+ try {
+ Map properties = loadSettings(resourcePath, defaultResourcePath);
+ BeanUtils.populate(bean, properties);
+ } catch (IllegalAccessException | InvocationTargetException | IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public void loadSettings(String resourcePath, Object bean) {
+ try {
+ Map properties = loadSettings(null, resourcePath);
+ BeanUtils.populate(bean, properties);
+ } catch (IllegalAccessException | InvocationTargetException | IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map loadSettings(String resourcePath, String defaultResourcePath) throws IOException {
+ Map defaultSetting = loadAsMap(defaultResourcePath);
+ Preconditions.checkState(defaultSetting.size() > 0, String.format("Failed to load file '%s' from classpath", defaultResourcePath));
+ if (resourcePath != null) {
+ Map userSetting = loadAsMap(resourcePath);
+ defaultSetting.putAll(userSetting);
+ }
+ return defaultSetting;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map loadAsMap(String path) throws IOException {
+ try {
+ String content = Resources.toString(Resources.getResource(path), Charset.forName("UTF-8"));
+ LOG.debug("Loaded resource file '{}'\n{}", path, content);
+ Map settings = new Yaml().loadAs(content, Map.class);
+ if (settings == null) {
+ settings = new HashMap(0);
+ }
+ return settings;
+ } catch (IllegalArgumentException e) {
+ return new HashMap();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/common/src/main/java/org/apache/omid/zk/ZKUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/omid/zk/ZKUtils.java b/common/src/main/java/org/apache/omid/zk/ZKUtils.java
new file mode 100644
index 0000000..24c0ee1
--- /dev/null
+++ b/common/src/main/java/org/apache/omid/zk/ZKUtils.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid.zk;
+
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public class ZKUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ZKUtils.class);
+
+ public static CuratorFramework initZKClient(String zkCluster, String namespace, int zkConnectionTimeoutInSec)
+ throws IOException, InterruptedException {
+
+ LOG.info("Creating Zookeeper Client connecting to {}", zkCluster);
+
+ RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
+ CuratorFramework zkClient = CuratorFrameworkFactory.builder()
+ .namespace(namespace)
+ .connectString(zkCluster)
+ .retryPolicy(retryPolicy)
+ .build();
+
+ zkClient.start();
+ if (zkClient.blockUntilConnected(zkConnectionTimeoutInSec, TimeUnit.SECONDS)) {
+ LOG.info("Connected to ZK cluster '{}', client in state: [{}]", zkCluster, zkClient.getState());
+ } else {
+ throw new IOException(String.format("Can't contact ZK cluster '%s' after 10 seconds", zkCluster));
+ }
+
+ return zkClient;
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/common/src/main/proto/TSOProto.proto
----------------------------------------------------------------------
diff --git a/common/src/main/proto/TSOProto.proto b/common/src/main/proto/TSOProto.proto
index 23762c5..43987d8 100644
--- a/common/src/main/proto/TSOProto.proto
+++ b/common/src/main/proto/TSOProto.proto
@@ -16,7 +16,7 @@
// limitations under the License.
//
-option java_package = "com.yahoo.omid.proto";
+option java_package = "org.apache.omid.proto";
option optimize_for = SPEED;
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/common/src/test/java/com/yahoo/omid/YAMLUtilsTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/com/yahoo/omid/YAMLUtilsTest.java b/common/src/test/java/com/yahoo/omid/YAMLUtilsTest.java
deleted file mode 100644
index 172e898..0000000
--- a/common/src/test/java/com/yahoo/omid/YAMLUtilsTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid;
-
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-public class YAMLUtilsTest {
-
- @Test
- public void testLoadDefaultSettings_setToBean() throws Exception {
- Map map = new HashMap();
- new YAMLUtils().loadSettings("test.yml", "default-test.yml", map);
- Assert.assertNotNull(map);
- Assert.assertEquals(map.get("prop1"), 11);
- Assert.assertEquals(map.get("prop2"), "22");
- Assert.assertEquals(map.get("prop3"), 3);
- }
-
- @Test
- public void testLoadDefaultSettings_setToBean2() throws Exception {
- Map map = new HashMap();
- new YAMLUtils().loadSettings("test.yml", map);
- Assert.assertNotNull(map);
- Assert.assertEquals(map.get("prop1"), 11);
- Assert.assertEquals(map.get("prop2"), "22");
- Assert.assertEquals(map.size(), 2);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/common/src/test/java/org/apache/omid/YAMLUtilsTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/omid/YAMLUtilsTest.java b/common/src/test/java/org/apache/omid/YAMLUtilsTest.java
new file mode 100644
index 0000000..b296922
--- /dev/null
+++ b/common/src/test/java/org/apache/omid/YAMLUtilsTest.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.omid;
+
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class YAMLUtilsTest {
+
+ @Test
+ public void testLoadDefaultSettings_setToBean() throws Exception {
+ Map map = new HashMap();
+ new YAMLUtils().loadSettings("test.yml", "default-test.yml", map);
+ Assert.assertNotNull(map);
+ Assert.assertEquals(map.get("prop1"), 11);
+ Assert.assertEquals(map.get("prop2"), "22");
+ Assert.assertEquals(map.get("prop3"), 3);
+ }
+
+ @Test
+ public void testLoadDefaultSettings_setToBean2() throws Exception {
+ Map map = new HashMap();
+ new YAMLUtils().loadSettings("test.yml", map);
+ Assert.assertNotNull(map);
+ Assert.assertEquals(map.get("prop1"), 11);
+ Assert.assertEquals(map.get("prop2"), "22");
+ Assert.assertEquals(map.size(), 2);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 592fe28..192f414 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>omid</artifactId>
- <groupId>com.yahoo.omid</groupId>
+ <groupId>org.apache.omid</groupId>
<version>0.8.1.37-SNAPSHOT</version>
</parent>
@@ -18,13 +18,13 @@
<!-- Dependencies on Omid modules -->
<dependency>
- <groupId>com.yahoo.omid</groupId>
+ <groupId>org.apache.omid</groupId>
<artifactId>hbase-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>com.yahoo.omid</groupId>
+ <groupId>org.apache.omid</groupId>
<artifactId>codahale-metrics</artifactId>
<version>${project.version}</version>
</dependency>
@@ -112,7 +112,7 @@
</activation>
<dependencies>
<dependency>
- <groupId>com.yahoo.omid</groupId>
+ <groupId>org.apache.omid</groupId>
<artifactId>hbase0-shims</artifactId>
<version>${project.version}</version>
</dependency>
@@ -123,7 +123,7 @@
<id>hbase-1</id>
<dependencies>
<dependency>
- <groupId>com.yahoo.omid</groupId>
+ <groupId>org.apache.omid</groupId>
<artifactId>hbase1-shims</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/examples/run.sh
----------------------------------------------------------------------
diff --git a/examples/run.sh b/examples/run.sh
index c3ea2e9..6785919 100755
--- a/examples/run.sh
+++ b/examples/run.sh
@@ -84,13 +84,13 @@ USER_OPTION=$1
shift
case ${USER_OPTION} in
basic)
- java -cp $KLASSPATH com.yahoo.omid.examples.BasicExample "$@"
+ java -cp $KLASSPATH org.apache.omid.examples.BasicExample "$@"
;;
si)
- java -cp $KLASSPATH com.yahoo.omid.examples.SnapshotIsolationExample "$@"
+ java -cp $KLASSPATH org.apache.omid.examples.SnapshotIsolationExample "$@"
;;
conf)
- java -cp $KLASSPATH com.yahoo.omid.examples.ConfigurationExample "$@"
+ java -cp $KLASSPATH org.apache.omid.examples.ConfigurationExample "$@"
;;
*)
show_help
http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/9cd856c6/examples/src/main/java/com/yahoo/omid/examples/BasicExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/com/yahoo/omid/examples/BasicExample.java b/examples/src/main/java/com/yahoo/omid/examples/BasicExample.java
deleted file mode 100644
index 44d9646..0000000
--- a/examples/src/main/java/com/yahoo/omid/examples/BasicExample.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.yahoo.omid.examples;
-
-import com.yahoo.omid.transaction.HBaseTransactionManager;
-import com.yahoo.omid.transaction.TTable;
-import com.yahoo.omid.transaction.Transaction;
-import com.yahoo.omid.transaction.TransactionManager;
-import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * ****************************************************************************************************
- *
- * Example code which demonstrates an atomic write into two different rows in HBase
- *
- * ****************************************************************************************************
- *
- * After building the package with 'mvn clean package' find the resulting examples-<version>-bin.tar.gz file in the
- * 'examples/target' folder. Copy it to the target host and expand with 'tar -zxvf examples-<version>-bin.tar.gz'.
- *
- * Make sure that 'hbase-site.xml' and 'core-site.xml' are either in classpath (see run.sh) or explicitly referenced in
- * configuration file. If a secure HBase deployment is needed, make sure to specify the principal (user) and keytab file.
- *
- * The example requires a user table to perform transactional read/write operations. A table is already specified in
- * the default configuration, and can be created with the following command using the 'hbase shell':
- *
- * <pre>
- * create 'MY_TX_TABLE', {NAME => 'MY_CF', VERSIONS => '2147483647', TTL => '2147483647'}
- * </pre>
- *
- * Make sure that the principal/user has RW permissions for the given table using also the 'hbase shell':
- * <pre>
- * grant '<principal/user>', 'RW', 'MY_TX_TABLE'
- * </pre>
- *
- * Alternatively, a table with a column family already created can be used by specifying the table name and column
- * family identifiers using the command line arguments (see details also in 'run.sh') If a table namespace is required,
- * specify it like this: 'namespace:table_name'
- *
- * Finally, run the example using the 'run.sh' script without arguments or specifying the necessary configuration
- * parameters.
- */
-public class BasicExample {
-
- private static final Logger LOG = LoggerFactory.getLogger(BasicExample.class);
-
- public static void main(String[] args) throws Exception {
-
- LOG.info("Parsing command line arguments");
- String userTableName = "MY_TX_TABLE";
- if (args != null && args.length > 0 && StringUtils.isNotEmpty(args[0])) {
- userTableName = args[0];
- }
- byte[] family = Bytes.toBytes("MY_CF");
- if (args != null && args.length > 1 && StringUtils.isNotEmpty(args[1])) {
- family = Bytes.toBytes(args[1]);
- }
- LOG.info("Table '{}', column family '{}'", userTableName, Bytes.toString(family));
-
- byte[] exampleRow1 = Bytes.toBytes("EXAMPLE_ROW1");
- byte[] exampleRow2 = Bytes.toBytes("EXAMPLE_ROW2");
- byte[] qualifier = Bytes.toBytes("MY_Q");
- byte[] dataValue1 = Bytes.toBytes("val1");
- byte[] dataValue2 = Bytes.toBytes("val2");
-
- LOG.info("Creating access to Omid Transaction Manager & Transactional Table '{}'", userTableName);
- try (TransactionManager tm = HBaseTransactionManager.newInstance();
- TTable txTable = new TTable(userTableName))
- {
- Transaction tx = tm.begin();
- LOG.info("Transaction {} STARTED", tx);
-
- Put row1 = new Put(exampleRow1);
- row1.add(family, qualifier, dataValue1);
- txTable.put(tx, row1);
- LOG.info("Transaction {} trying to write a new value in [TABLE:ROW/CF/Q] => {}:{}/{}/{} = {} ",
- tx, userTableName, Bytes.toString(exampleRow1), Bytes.toString(family),
- Bytes.toString(qualifier), Bytes.toString(dataValue1));
-
- Put row2 = new Put(exampleRow2);
- row2.add(family, qualifier, dataValue2);
- txTable.put(tx, row2);
- LOG.info("Transaction {} trying to write a new value in [TABLE:ROW/CF/Q] => {}:{}/{}/{} = {} ",
- tx, userTableName, Bytes.toString(exampleRow2), Bytes.toString(family),
- Bytes.toString(qualifier), Bytes.toString(dataValue2));
-
- tm.commit(tx);
- LOG.info("Transaction {} COMMITTED", tx);
- }
-
- }
-
-}