Skip to content

Commit

Permalink
commit just to save changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gnydick committed Jan 17, 2019
1 parent c59776d commit ace409b
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
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;
}

}
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);
}

}
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();

}
}
23 changes: 23 additions & 0 deletions src/normalize/NormalizePlugin.java
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);


}
19 changes: 19 additions & 0 deletions src/utils/PluginConfig.java
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;
}

}

0 comments on commit ace409b

Please sign in to comment.