Пример #1
0
  // Node DataScopes can be the first element in a path. They must
  // find or make the corresponding HostDS and return that as the
  // preferred parent.
  @Override
  protected ResourceContext preferredParent(RSS root) {

    ServiceBroker sb = (ServiceBroker) root.getProperty("ServiceBroker");
    AgentTopologyService ats = sb.getService(this, AgentTopologyService.class, null);
    String nodename = (String) getSymbolValue(NODENAME);
    String hostname = null;
    if (ats != null) {
      hostname = ats.getNodeHost(MessageAddress.getMessageAddress(nodename));
    } else {
      // AgentTopologyService not loaded. Try a direct WP
      // call, even though it can give an inconsistent picture.
      WhitePagesService svc = sb.getService(this, WhitePagesService.class, null);
      try {
        AddressEntry entry = svc.get(nodename, TOPOLOGY, -1);
        if (entry == null) {
          if (logger.isWarnEnabled()) {
            logger.warn("Can't find host for node " + nodename);
          }
        } else {
          hostname = entry.getURI().getHost();
        }
      } catch (Exception ex) {
        // log this?
      }
    }

    String[] params = {hostname == null ? UNKNOWN_HOST_IP : hostname};
    ResourceNode node = new ResourceNode();
    node.kind = "Host";
    node.parameters = params;
    ResourceNode[] path = {node};
    ResourceContext parent = root.getPathContext(path);
    setParent(parent);
    return parent;
  }
Пример #2
0
    @Override
    protected void initialize(ResourceContext context) {
      super.initialize(context);

      rt = Runtime.getRuntime();
      ResourceNode node = new ResourceNode();
      node.kind = "Alarm";
      node.parameters = new String[0];
      ResourceNode formula = new ResourceNode();
      formula.kind = "FifteenSeconds";
      formula.parameters = new String[0];
      ResourceNode[] path = {node, formula};
      DataFormula alarm = RSS.instance().getPathFormula(path);
      registerDependency(alarm, "Alarm");
    }