@JsonCreator private GangliaHosts(String fileName) { this.gangliaHosts = new GmondConfigParser().getGmondSendChannels(fileName); }
public List<HostPort> getGmondSendChannelsFromConf(String conf) { String cleanConf = removeEmptyLines(stripComments(conf)); List<String> blobs = findSendChannels(cleanConf); log.debug("Found {} channels", blobs.size()); List<HostPort> hosts = new ArrayList<HostPort>(); for (String blob : blobs) { Map<String,String> chanMap = mapifyChannelString(blob); log.debug("Parsed channel from config {}", chanMap); HostPort hp = makeHostPort(chanMap); if (hp != null) { hosts.add(hp); } else { log.warn("Failure to create HostPort from {}", blob); } } return hosts; }
public void print() throws Exception { GmondConfigParser g = new GmondConfigParser(); String conf = g.readFile("src/test/resources/gmond/comments.conf"); System.out.println(conf); }
public List<HostPort> getGmondSendChannels(String fileName) { try { String conf = readFile(fileName); return getGmondSendChannelsFromConf(conf); } catch (IOException ioe) { log.error("Unable to read gmond config from:" + fileName, ioe); return null; } catch (Exception e) { log.error("Error searching for unicast udp_send_channels. It is possible none are defined in " + fileName, e); return null; } }
@Test public void emptyLines() throws Exception { GmondConfigParser g = new GmondConfigParser(); String conf = g.readFile("src/test/resources/gmond/empty-lines.conf"); String expt_conf = g.readFile("src/test/resources/gmond/empty-lines-expt.conf"); String clean = g.removeEmptyLines(conf); assertEquals(expt_conf, clean); }
@Test public void stripAllComments() throws Exception { GmondConfigParser g = new GmondConfigParser(); String conf = g.readFile("src/test/resources/gmond/ctest.conf"); String expt_conf = g.readFile("src/test/resources/gmond/ctest-expt.conf"); String clean = g.stripComments(conf); assertEquals(expt_conf, clean); }
@Test public void extractChannel() throws Exception { GmondConfigParser g = new GmondConfigParser(); String conf = g.readFile("src/test/resources/gmond/udp-send.conf"); List<String> blobs = g.findSendChannels(conf); //System.out.println(blobs); // two channels, each with 4 config lines assertEquals(2, blobs.size()); assertEquals(4, blobs.get(0).split("\n").length); assertEquals(4, blobs.get(1).split("\n").length); }
@Test public void stringMapIfy() throws Exception { String sc = " bind_hostname = no \n host = \"bar.local\"\n port = 8649\n ttl = 1"; Map<String,String> expt = ImmutableMap.of("bind_hostname", "no", "host", "bar.local", "port", "8649", "ttl", "1"); GmondConfigParser g = new GmondConfigParser(); Map<String, String> chan = g.mapifyChannelString(sc); assertEquals(expt, chan); }
@Test public void hostPort() throws Exception { Map<String,String> chan = ImmutableMap.of("bind_hostname", "no", "host", "bar.local", "port", "8649", "ttl", "1"); GmondConfigParser g = new GmondConfigParser(); HostPort hp = g.makeHostPort(chan); assertEquals("bar.local", hp.getHost()); assertEquals(8649, hp.getPort()); }
@Test public void emptyLines() throws Exception { GmondConfigParser g = new GmondConfigParser(); String conf = g.readFile("src/test/resources/gmond/empty-lines.conf"); String expt_conf = g.readFile("src/test/resources/gmond/empty-lines-expt.conf"); String clean = g.removeEmptyLines(conf); assertEquals(expt_conf, clean); }
@Test public void stripAllComments() throws Exception { GmondConfigParser g = new GmondConfigParser(); String conf = g.readFile("src/test/resources/gmond/ctest.conf"); String expt_conf = g.readFile("src/test/resources/gmond/ctest-expt.conf"); String clean = g.stripComments(conf); assertEquals(expt_conf, clean); }
@Test public void extractChannel() throws Exception { GmondConfigParser g = new GmondConfigParser(); String conf = g.readFile("src/test/resources/gmond/udp-send.conf"); List<String> blobs = g.findSendChannels(conf); //System.out.println(blobs); // two channels, each with 4 config lines assertEquals(2, blobs.size()); assertEquals(4, blobs.get(0).split("\n").length); assertEquals(4, blobs.get(1).split("\n").length); }
@Test public void stringMapIfy() throws Exception { String sc = " bind_hostname = no \n host = \"bar.local\"\n port = 8649\n ttl = 1"; Map<String,String> expt = ImmutableMap.of("bind_hostname", "no", "host", "bar.local", "port", "8649", "ttl", "1"); GmondConfigParser g = new GmondConfigParser(); Map<String, String> chan = g.mapifyChannelString(sc); assertEquals(expt, chan); }
@Test public void hostPort() throws Exception { Map<String,String> chan = ImmutableMap.of("bind_hostname", "no", "host", "bar.local", "port", "8649", "ttl", "1"); GmondConfigParser g = new GmondConfigParser(); HostPort hp = g.makeHostPort(chan); assertEquals("bar.local", hp.getHost()); assertEquals(8649, hp.getPort()); }
public List<HostPort> getGmondSendChannels(String fileName) { try { String conf = readFile(fileName); return getGmondSendChannelsFromConf(conf); } catch (IOException ioe) { log.error("Unable to read gmond config from:" + fileName, ioe); return null; } catch (Exception e) { log.error("Error searching for unicast udp_send_channels. It is possible none are defined in " + fileName, e); return null; } }
public List<HostPort> getGmondSendChannelsFromConf(String conf) { String cleanConf = removeEmptyLines(stripComments(conf)); List<String> blobs = findSendChannels(cleanConf); log.debug("Found {} channels", blobs.size()); List<HostPort> hosts = new ArrayList<HostPort>(); for (String blob : blobs) { Map<String,String> chanMap = mapifyChannelString(blob); log.debug("Parsed channel from config {}", chanMap); HostPort hp = makeHostPort(chanMap); if (hp != null) { hosts.add(hp); } else { log.warn("Failure to create HostPort from {}", blob); } } return hosts; }
@Override public List<HostPort> getFullHostList() { if (gmondConf != null) { GmondConfigParser gcp = new GmondConfigParser(); List<HostPort> confHosts = gcp.getGmondSendChannels(gmondConf); if (confHosts == null || confHosts.isEmpty()) { log.warn("No send channels found after reading {}", gmondConf); } return confHosts; } else { return getHostListAndStringList(); } }
public void print() throws Exception { GmondConfigParser g = new GmondConfigParser(); String conf = g.readFile("src/test/resources/gmond/comments.conf"); System.out.println(conf); }
@Override public List<HostPort> getFullHostList() { if (gmondConf != null) { GmondConfigParser gcp = new GmondConfigParser(); List<HostPort> confHosts = gcp.getGmondSendChannels(gmondConf); if (confHosts == null || confHosts.isEmpty()) { log.warn("No send channels found after reading {}", gmondConf); } return confHosts; } else { return getHostListAndStringList(); } }
@Test public void noChannelFoundHandling() throws Exception { System.out.println("Stack trace expected below"); GmondConfigParser g = new GmondConfigParser(); List<HostPort> hosts = g. getGmondSendChannels("src/test/resources/gmond/upstream-default.conf"); assertNull(hosts); } }