Example usage for org.apache.commons.configuration HierarchicalConfiguration configurationsAt

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration configurationsAt

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration configurationsAt.

Prototype

public List configurationsAt(String key) 

Source Link

Document

Returns a list of sub configurations for all configuration nodes selected by the given key.

Usage

From source file:org.onosproject.drivers.fujitsu.FujitsuVoltControllerConfig.java

/**
 * Parses XML string to get controller information.
 *
 * @param cfg a hierarchical configuration
 * @return a list of controllers//from  w w  w  .  ja v  a2s . co m
 */
private List<ControllerInfo> parseStreamVoltControllers(HierarchicalConfiguration cfg) {
    List<ControllerInfo> controllers = new ArrayList<>();
    List<HierarchicalConfiguration> fields = cfg.configurationsAt(VOLT_DATACONFIG);

    for (HierarchicalConfiguration sub : fields) {
        List<HierarchicalConfiguration> childFields = sub.configurationsAt(CONTROLLER_INFO);

        for (HierarchicalConfiguration child : childFields) {
            Annotations annotations = DefaultAnnotations.builder().set(OFCONFIG_ID, sub.getString(OFCONFIG_ID))
                    .build();
            ControllerInfo controller = new ControllerInfo(IpAddress.valueOf(child.getString(IP_ADDRESS)),
                    Integer.parseInt(child.getString(PORT)), child.getString(PROTOCOL), annotations);

            log.debug("VOLT: OFCONTROLLER: PROTOCOL={}, IP={}, PORT={}, ID={} ", controller.type(),
                    controller.ip(), controller.port(), controller.annotations().value(OFCONFIG_ID));
            controllers.add(controller);
        }
    }
    return controllers;
}

From source file:org.onosproject.drivers.juniper.JuniperUtils.java

/**
 * Parses device ports configuration and returns a list of
 * port description.// w w w. j  a  v a  2  s.co m
 *
 * @param cfg interface configuration
 * @return list of interface descriptions of the device
 */
public static List<PortDescription> parseJuniperPorts(HierarchicalConfiguration cfg) {
    //This methods ignores some internal ports

    List<PortDescription> portDescriptions = Lists.newArrayList();
    List<HierarchicalConfiguration> subtrees = cfg.configurationsAt(IF_INFO);
    for (HierarchicalConfiguration interfInfo : subtrees) {
        List<HierarchicalConfiguration> interfaceTree = interfInfo.configurationsAt(IF_PHY);
        for (HierarchicalConfiguration interf : interfaceTree) {
            if (interf != null) {
                if (interf.getString(IF_TYPE) != null && interf.getString(SPEED) != null) {
                    if (interf.getString(IF_TYPE).contains(ETH) && interf.getString(SPEED).contains(MBPS)) {
                        portDescriptions.add(parseDefaultPort(interf));
                    }
                } else if (interf.getString(IF_LO_ENCAP) != null && !interf.getString(NAME).contains("pfe")
                        && interf.getString(IF_LO_ENCAP).contains("ENET2")) {
                    portDescriptions.add(parseLogicalPort(interf));
                } else if (interf.getString(NAME).contains("lo")) {
                    portDescriptions.add(parseLoopback(interf));
                }
            }
        }
    }
    return portDescriptions;
}

From source file:org.onosproject.drivers.juniper.JuniperUtils.java

/**
 * Parses neighbours discovery information and returns a list of
 * link abstractions.//from   w  ww  .j  a  va2s. c  o  m
 *
 * @param info interface configuration
 * @return set of link abstractions
 */
public static Set<LinkAbstraction> parseJuniperLldp(HierarchicalConfiguration info) {
    Set<LinkAbstraction> neighbour = new HashSet<>();
    List<HierarchicalConfiguration> subtrees = info.configurationsAt(LLDP_NBR_INFO);
    for (HierarchicalConfiguration neighborsInfo : subtrees) {
        List<HierarchicalConfiguration> neighbors = neighborsInfo.configurationsAt(LLDP_NBR_INFO);
        for (HierarchicalConfiguration neighbor : neighbors) {
            String localPortName = neighbor.getString(LLDP_LO_PORT);
            MacAddress mac = MacAddress.valueOf(neighbor.getString(LLDP_REM_CHASS));
            int remotePortIndex = neighbor.getInt(LLDP_REM_PORT);
            LinkAbstraction link = new LinkAbstraction(localPortName, mac.toLong(), remotePortIndex);
            neighbour.add(link);
        }
    }
    return neighbour;
}

From source file:org.onosproject.drivers.odtn.openconfig.TerminalDeviceDiscovery.java

/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param components the XML document with components root.
 * @return List of ports// w  w w .  j av  a 2s .  c om
 *
 * //CHECKSTYLE:OFF
 * <pre>{@code
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * }</pre>
 * //CHECKSTYLE:ON
 */
protected List<PortDescription> parsePorts(HierarchicalConfiguration components) {
    return components.configurationsAt("component").stream().filter(component -> {
        return !component.getString("name", "unknown").equals("unknown")
                && component.getString("state/type", "unknown").equals(OC_PLATFORM_TYPES_PORT);
    }).map(component -> {
        try {
            // Pass the root document for cross-reference
            return parsePortComponent(component, components);
        } catch (Exception e) {
            return null;
        }
    }).filter(Objects::nonNull).collect(Collectors.toList());
}

From source file:org.onosproject.drivers.odtn.openconfig.TerminalDeviceDiscovery.java

/**
 * Checks if a given component has a subcomponent of a given type.
 *
 * @param component subtree to parse looking for subcomponents.
 * @param components the full components tree, to cross-ref in
 *  case we need to check (sub)components' types.
 *
 * @return true or false/* w  w  w . ja va2s . c  om*/
 */
private boolean hasSubComponentOfType(HierarchicalConfiguration component, HierarchicalConfiguration components,
        String type) {
    long count = component.configurationsAt("subcomponents/subcomponent").stream().filter(subcomponent -> {
        String scName = subcomponent.getString("name");
        StringBuilder sb = new StringBuilder("component[name='");
        sb.append(scName);
        sb.append("']/state/type");
        String scType = components.getString(sb.toString(), "unknown");
        return scType.equals(type);
    }).count();
    return (count > 0);
}

From source file:org.onosproject.drivers.odtn.openconfig.TerminalDeviceDiscovery.java

/**
 * Parses a component XML doc into a PortDescription.
 *
 * @param component subtree to parse. It must be a component ot type PORT.
 * @param components the full components tree, to cross-ref in
 *  case we need to check transceivers or optical channels.
 *
 * @return PortDescription or null if component does not have onos-index
 */// ww  w .j  a  va 2 s  .com
private PortDescription parsePortComponent(HierarchicalConfiguration component,
        HierarchicalConfiguration components) {
    Map<String, String> annotations = new HashMap<>();
    String name = component.getString("name");
    String type = component.getString("state/type");
    log.info("Parsing Component {} type {}", name, type);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);

    // Store all properties as port properties
    component.configurationsAt("properties/property").forEach(property -> {
        String pn = property.getString("name");
        String pv = property.getString("state/value");
        annotations.put(pn, pv);
    });

    if (!annotations.containsKey(ONOS_PORT_INDEX)) {
        log.warn("DEBUG: PORT {} does not include onos-index, skipping", name);
        return null;
    }

    // The heuristic to know if it is client or line side
    if (!annotations.containsKey(PORT_TYPE)) {
        if (hasTransceiverSubComponent(component, components)) {
            annotations.put(PORT_TYPE, OdtnPortType.CLIENT.value());
        } else if (hasOpticalChannelSubComponent(component, components)) {
            annotations.put(PORT_TYPE, OdtnPortType.LINE.value());
        }
    }

    // Build the port
    Builder builder = DefaultPortDescription.builder();
    builder.withPortNumber(PortNumber.portNumber(Long.parseLong(annotations.get(ONOS_PORT_INDEX)), name));
    if (annotations.get(PORT_TYPE).equals(OdtnPortType.CLIENT.value())) {
        log.info("Adding CLIENT port");
        builder.type(Type.PACKET);
    } else if (annotations.get(PORT_TYPE).equals(OdtnPortType.LINE.value())) {
        log.info("Adding LINE port");
        builder.type(Type.OCH);
    } else {
        log.info("Unknown port added as CLIENT port");
    }
    builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
    return builder.build();
}

From source file:org.onosproject.drivers.odtn.OpenConfigDeviceDiscovery.java

/**
 * Converts Component subtree to PortDescription.
 *
 * @param component subtree to parse//w w w .ja  va  2s .c o  m
 * @return PortDescription or null if component is not an ONOS Port
 */
private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {

    // to access other part of <data> tree:
    //log.warn("parent data Node: {}",
    //       ((SubnodeConfiguration) component).getParent().getRootNode().getName());

    Map<String, String> props = new HashMap<>();

    String name = component.getString("name");
    String type = component.getString("state/type");
    checkNotNull(name, "name not found");
    checkNotNull(type, "state/type not found");
    props.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    props.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);

    component.configurationsAt("properties/property").forEach(prop -> {
        String pName = prop.getString("name");
        String pValue = prop.getString("config/value");
        props.put(pName, pValue);
    });

    if (!props.containsKey(ONOS_PORT_INDEX)) {
        log.info("DEBUG: Component {} does not include onos-index, skipping", name);
        // ODTN: port must have onos-index property
        return null;
    }

    Builder builder = DefaultPortDescription.builder();
    builder.withPortNumber(PortNumber.portNumber(Long.parseLong(props.get(ONOS_PORT_INDEX)), name));

    switch (type) {
    case "oc-platform-types:PORT":
    case "oc-opt-types:OPTICAL_CHANNEL":
        // TODO assign appropriate port type & annotations at some point
        // for now we just need a Port with annotations
        builder.type(Type.OCH);

        props.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());

        // Just a heuristics to deal with simple transponder
        // if the device declare odtn-connection-id, just use them
        // if not assign same value to relevant ports types
        props.putIfAbsent(CONNECTION_ID, "the-only-one");
        break;

    case "oc-platform-types:TRANSCEIVER":
        // TODO assign appropriate port type & annotations at some point
        // for now we just need a Port with annotations
        builder.type(Type.PACKET);

        props.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());

        // Just a heuristics to deal with simple transponder
        // if the device declare odtn-connection-id, just use them
        // if not assign same value to relevant ports types
        props.putIfAbsent(CONNECTION_ID, "the-only-one");
        break;

    default:
        log.info("DEBUG: Unknown component type {}", type);
        return null;
    }

    builder.annotations(DefaultAnnotations.builder().putAll(props).build());

    return builder.build();

}

From source file:org.onosproject.drivers.oplink.OplinkNetconfUtility.java

/**
 * Retrieves specified node hierarchical configurations from the xml information.
 *
 * @param content the xml information// w ww. j  ava 2s. co m
 * @param key the configuration key node
 * @return the hierarchical configurations, empty if exception happens
 */
public static List<HierarchicalConfiguration> configsAt(String content, String key) {
    List<HierarchicalConfiguration> info;
    try {
        HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content);
        info = cfg.configurationsAt(key);
    } catch (Exception e) {
        // Accept empty for information polling
        return ImmutableList.of();
    }
    return info;
}

From source file:org.onosproject.drivers.oplink.OplinkRoadmDeviceDescription.java

/**
 * Parses a configuration and returns a set of ports for Oplink Roadm.
 *
 * @param cfg a hierarchical configuration
 * @return a list of port descriptions/*w ww  .j  a  v a  2  s  .  c om*/
 */
private static List<PortDescription> parseOplinkRoadmPorts(HierarchicalConfiguration cfg) {
    List<PortDescription> portDescriptions = Lists.newArrayList();
    List<HierarchicalConfiguration> subtrees = cfg.configurationsAt("data.open-oplink-device.ports");
    for (HierarchicalConfiguration portConfig : subtrees) {
        portDescriptions.add(parsePort(portConfig));
    }
    return portDescriptions;
}

From source file:org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.java

/**
 * Retrieves specified node hierarchical configurations from the xml information.
 *
 * @param content the xml information//from  ww  w  . j av a  2 s . co  m
 * @param key the configuration key node
 * @return the hierarchical configurations, empty if exception happens
 */
public static List<HierarchicalConfiguration> configsAt(String content, String key) {
    List<HierarchicalConfiguration> info;
    try {
        HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content);
        info = cfg.configurationsAt(key);
    } catch (IllegalArgumentException e) {
        // Accept empty for information polling
        return ImmutableList.of();
    }
    return info;
}