diff --git a/TagNormalizerPlugin/src/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPlugin.java b/TagNormalizerPlugin/src/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPlugin.java new file mode 100644 index 0000000000..bb5d8784a9 --- /dev/null +++ b/TagNormalizerPlugin/src/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPlugin.java @@ -0,0 +1,47 @@ +package net.nydick.opentsdb.plugin.normalizer; + +import net.opentsdb.core.TSDB; +import net.opentsdb.normalize.NormalizePlugin; +import net.opentsdb.stats.StatsCollector; +import net.opentsdb.utils.PluginConfig; + +import java.util.HashMap; +import java.util.Map; + +public class TagNormalizerPlugin extends NormalizePlugin { + + + public TagNormalizerPlugin(PluginConfig pluginConfig) { + super(pluginConfig); + } + + + @Override + public void initialize(TSDB tsdb) { + + } + + @Override + public com.stumbleupon.async.Deferred shutdown() { + return null; + } + + @Override + public String version() { + return null; + } + + @Override + public void collectStats(StatsCollector collector) { + + } + + public Map cleanTags(Map dirtytags) { + HashMap tags = new HashMap<>(dirtytags.size()); + tags.putAll(dirtytags); + + + return tags; + } + +} diff --git a/TagNormalizerPlugin/src/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPluginConfig.java b/TagNormalizerPlugin/src/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPluginConfig.java new file mode 100644 index 0000000000..d363a23621 --- /dev/null +++ b/TagNormalizerPlugin/src/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPluginConfig.java @@ -0,0 +1,40 @@ +package net.nydick.opentsdb.plugin.normalizer; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sun.deploy.net.BasicHttpRequest; +import com.sun.deploy.net.HttpResponse; +import net.opentsdb.utils.PluginConfig; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Map; +import java.util.Properties; + +public class TagNormalizerPluginConfig extends PluginConfig { + + public TagNormalizerPluginConfig(String configUrl) { + super(configUrl); + try { + this.loadFromOrch(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + private void loadFromOrch() throws IOException { + + URL orchUrl = new URL("http", "orch", 80, "/api/rest/v1/config/dev:infra:observ:opentsdb:default:normalizer_plugin:tag:default"); + + BasicHttpRequest orchReq = new BasicHttpRequest(); + HttpResponse response = orchReq.doGetRequest(orchUrl); + InputStream orchIs = response.getInputStream(); + ObjectMapper mapper = new ObjectMapper(); + Map jsonMap = mapper.readValue(orchIs, Map.class); + + this.properties = new Properties(); + properties.putAll(jsonMap); + } + +} diff --git a/TagNormalizerPlugin/test/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPluginConfigTest.java b/TagNormalizerPlugin/test/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPluginConfigTest.java new file mode 100644 index 0000000000..1b3b68282f --- /dev/null +++ b/TagNormalizerPlugin/test/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPluginConfigTest.java @@ -0,0 +1,18 @@ +package net.nydick.opentsdb.plugin.normalizer; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Properties; + +import static org.junit.Assert.*; + +public class TagNormalizerPluginConfigTest { + + + @org.junit.Test + public void getConfig() { + TagNormalizerPluginConfig tnpc = new TagNormalizerPluginConfig("foo"); + Properties foo = tnpc.getConfig(); + + } +} diff --git a/src/normalize/NormalizePlugin.java b/src/normalize/NormalizePlugin.java new file mode 100644 index 0000000000..50091b1d1e --- /dev/null +++ b/src/normalize/NormalizePlugin.java @@ -0,0 +1,23 @@ +package net.opentsdb.normalize; + +import com.stumbleupon.async.Deferred; +import net.opentsdb.core.TSDB; +import net.opentsdb.stats.StatsCollector; +import net.opentsdb.utils.PluginConfig; + +public abstract class NormalizePlugin { + + private PluginConfig pluginConfig; + + public NormalizePlugin(PluginConfig pluginConfig){ + this.pluginConfig = pluginConfig; + }; + + private NormalizePlugin() {} + public abstract void initialize(final TSDB tsdb); + public abstract Deferred shutdown(); + public abstract String version(); + public abstract void collectStats(final StatsCollector collector); + + +} diff --git a/src/utils/PluginConfig.java b/src/utils/PluginConfig.java new file mode 100644 index 0000000000..a7ad8d9230 --- /dev/null +++ b/src/utils/PluginConfig.java @@ -0,0 +1,19 @@ +package net.opentsdb.utils; + +import java.util.Properties; + +public abstract class PluginConfig { + + protected String configUrl; + private PluginConfig(){} + protected Properties properties; + + public PluginConfig(String configUrl){ + this.configUrl = configUrl; + } + + public Properties getConfig() { + return properties; + } + +}