Пример #1
0
  public HostInfo makeHost(JrdsDocument n)
      throws SecurityException, IllegalArgumentException, NoSuchMethodException,
          IllegalAccessException, InvocationTargetException, ClassNotFoundException {
    JrdsElement hostNode = n.getRootElement();
    String hostName = hostNode.getAttribute("name");
    String dnsHostname = hostNode.getAttribute("dnsName");
    if (hostName == null) {
      return null;
    }

    HostInfo host = null;
    if (dnsHostname != null) {
      host = new HostInfo(hostName, dnsHostname);
    } else {
      host = new HostInfo(hostName);
    }
    host.setHostDir(new File(pm.rrddir, host.getName()));

    String hidden = hostNode.getAttribute("hidden");
    host.setHidden(hidden != null && Boolean.parseBoolean(hidden));

    Map<String, Set<String>> collections = new HashMap<String, Set<String>>();

    parseFragment(hostNode, host, collections, null);

    return host;
  }
Пример #2
0
 public Filter makeFilter(JrdsDocument n)
     throws SecurityException, IllegalArgumentException, NoSuchMethodException,
         IllegalAccessException, InvocationTargetException, InstantiationException {
   JrdsElement root = n.getRootElement();
   JrdsElement name = root.getElementbyName("name");
   if (name == null) return null;
   FilterXml f = new FilterXml(name.getTextContent());
   setMethod(root.getChildElementsByName("path"), f, "addPath", String.class);
   setMethod(root.getChildElementsByName("tag"), f, "addTag", String.class);
   setMethod(root.getChildElementsByName("qualifiedname"), f, "addGraph", String.class);
   doACL(f, n, root);
   logger.trace(Util.delayedFormatString("Filter loaded: %s", f.getName()));
   return f;
 }
Пример #3
0
  @Test
  public void testNewProbe()
      throws InvocationTargetException, IllegalArgumentException, IllegalAccessException,
          IOException {
    PropertiesManager localpm = Tools.makePm();

    HostBuilder hb = new HostBuilder();
    // Generate a probe with a bean hostInfo with a default value of ${host}
    hb.setProbeFactory(
        new MokeProbeFactory() {
          @Override
          public Probe<?, ?> makeProbe(String type) {
            logger.trace(type);
            ProbeDesc pd = generateProbeDesc(type);
            try {
              pd.setProbeClass(MokeProbeBean.class);
            } catch (InvocationTargetException e1) {
              throw new RuntimeException(e1);
            }
            Probe<?, ?> p = new MokeProbeBean(pd);
            try {
              pd.addDefaultArg("hostInfo", "${host}");
            } catch (Exception e) {
              throw new RuntimeException(e.getMessage(), e);
            }
            return p;
          }
        });
    hb.setPm(localpm);
    hb.setTimers(Tools.getSimpleTimerMap());

    HostInfo host = new HostInfo("localhost");
    host.setHostDir(testFolder.getRoot());

    JrdsDocument probeNode = new JrdsDocument(Tools.dbuilder.newDocument());
    probeNode.doRootElement("probe", "type=probetype");

    Probe<?, ?> p = hb.makeProbe(probeNode.getRootElement(), host, null);
    Assert.assertEquals(
        "localhost", p.getPd().getBeanMap().get("hostInfo").getReadMethod().invoke(p));
    logger.trace(p.getName());
  }
Пример #4
0
  @Test
  public void testConnectionInfo() throws Exception {
    PropertiesManager pm = Tools.makePm();

    HostBuilder hb = new HostBuilder();
    hb.setPm(pm);
    hb.setClassLoader(this.getClass().getClassLoader());

    JrdsDocument cnxdoc = new JrdsDocument(Tools.dbuilder.newDocument());
    cnxdoc
        .doRootElement("host")
        .addElement("connection", "type=jrds.probe.JMXConnection")
        .addElement("attr", "name=port")
        .setTextContent("8999");
    for (ConnectionInfo ci : hb.makeConnexion(cnxdoc.getRootElement(), new HostInfo("localhost"))) {
      logger.trace(ci.getName());
      StarterNode sn = new StarterNode() {};
      ci.register(sn);
      JMXConnection cnx = sn.find(JMXConnection.class);
      Assert.assertEquals("Attributed not setted", new Integer(8999), cnx.getPort());
    }
  }