forked from OpenTSDB/opentsdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
TagNormalizerPlugin/src/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Object> shutdown() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String version() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void collectStats(StatsCollector collector) { | ||
|
||
} | ||
|
||
public Map<String, String> cleanTags(Map<String, String> dirtytags) { | ||
HashMap<String, String> tags = new HashMap<>(dirtytags.size()); | ||
tags.putAll(dirtytags); | ||
|
||
|
||
return tags; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
TagNormalizerPlugin/src/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPluginConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Object> jsonMap = mapper.readValue(orchIs, Map.class); | ||
|
||
this.properties = new Properties(); | ||
properties.putAll(jsonMap); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...lizerPlugin/test/net/nydick/opentsdb/plugin/normalizer/TagNormalizerPluginConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Object> shutdown(); | ||
public abstract String version(); | ||
public abstract void collectStats(final StatsCollector collector); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |