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

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

Introduction

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

Prototype

public String getString(String key) 

Source Link

Usage

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

private PortDescription toPortDescription(HierarchicalConfiguration component) {
    try {//w  ww .  j av  a 2  s .c  o  m
        return toPortDescriptionInternal(component);
    } catch (Exception e) {
        log.error("Unexpected exception parsing component {} on {}", component.getString("name"),
                data().deviceId(), e);
        return null;
    }
}

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

/**
 * Converts Component subtree to PortDescription.
 *
 * @param component subtree to parse/*from   www. j av  a  2  s.  co 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());

    String name = component.getString("name");
    checkNotNull(name);
    if (!name.contains("GIGECLIENTCTP")) {
        return null;
    }

    Builder builder = DefaultPortDescription.builder();

    Map<String, String> props = new HashMap<>();
    props.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    props.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, name);

    Pattern clientPattern = Pattern.compile("GIGECLIENTCTP.1-A-2-T(\\d+)");
    Pattern linePattern = Pattern.compile("GIGECLIENTCTP.1-L(\\d+)-1-1");
    Matcher clientMatch = clientPattern.matcher(name);
    Matcher lineMatch = linePattern.matcher(name);

    if (clientMatch.find()) {
        String num = clientMatch.group(1);
        Integer connection = (Integer.parseInt(num) + 1) / 2;
        props.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
        props.putIfAbsent(CONNECTION_ID, "connection:" + connection.toString());
        builder.withPortNumber(PortNumber.portNumber(Long.parseLong(num), name));
        builder.type(Type.PACKET);
    } else if (lineMatch.find()) {
        String num = lineMatch.group(1);
        props.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
        props.putIfAbsent(CONNECTION_ID, "connection:" + num);
        builder.withPortNumber(PortNumber.portNumber(100 + Long.parseLong(num), name));
        builder.type(Type.OCH);
    } else {
        return null;
    }

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

}

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
 *//*from ww w  .  j  a  v  a 2s.  c o m*/
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//from   w  w  w .j  av  a 2s  .  co  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.OplinkOpticalDeviceDescription.java

private PortDescription parsePort(HierarchicalConfiguration cfg) {
    PortNumber portNumber = PortNumber.portNumber(cfg.getLong(KEY_PORTID));
    HierarchicalConfiguration portInfo = cfg.configurationAt(KEY_PORT);
    DefaultAnnotations annotations = DefaultAnnotations.builder()
            .set(AnnotationKeys.PORT_NAME, portInfo.getString(KEY_PORTNAME))
            .set(PORT_DIRECTION, portInfo.getString(KEY_PORTDIRECT)).build();
    return omsPortDescription(portNumber, true, START_CENTER_FREQ, STOP_CENTER_FREQ,
            CHANNEL_SPACING.frequency(), annotations);
}

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

private FlowRule parseConnection(HierarchicalConfiguration cfg) {
    return OplinkOpticalUtility.toFlowRule(this, PortNumber.portNumber(cfg.getString(KEY_SRC_PORTID)),
            PortNumber.portNumber(cfg.getString(KEY_DST_PORTID)), cfg.getInt(KEY_SRC_CHID));

}

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

private static PortDescription parsePort(HierarchicalConfiguration cfg) {
    PortNumber portNumber = PortNumber.portNumber(cfg.getLong("port-id"));
    HierarchicalConfiguration portInfo = cfg.configurationAt("port");
    DefaultAnnotations annotations = DefaultAnnotations.builder()
            .set(AnnotationKeys.PORT_NAME, portInfo.getString("port-name"))
            .set("portDirection", portInfo.getString("port-direction")).build();
    return omsPortDescription(portNumber, true, START_CENTER_FREQ, END_CENTER_FREQ, CHANNEL_SPACING.frequency(),
            annotations);//from  w ww .j  a va  2 s.  com
}

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

private Alarm parseAlarm(HierarchicalConfiguration cfg) {
    boolean cleared = false;
    // TODO: Use the type for severity or in the description?
    String alarmType = cfg.getString(ALARM_TYPE);
    String alarmMessage = cfg.getString(ALARM_MESSAGE);
    SeverityLevel alarmLevel = SeverityLevel.INDETERMINATE;
    long timeRaised = getTimeRaised(cfg);
    DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(
            AlarmId.alarmId(deviceId, Long.toString(timeRaised)), deviceId, alarmMessage, alarmLevel,
            timeRaised);//from w w w  .j  av a2  s.  co m
    return alarmBuilder.build();
}

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

private long getTimeRaised(HierarchicalConfiguration cfg) {
    long timeRaised;

    String alarmTime = cfg.getString(ALARM_TIME);
    try {/* w  w w . j a v  a2s  .  com*/
        OffsetDateTime date = OffsetDateTime.parse(alarmTime, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        timeRaised = date.toInstant().toEpochMilli();
        return timeRaised;
    } catch (DateTimeException e) {
        log.error("Cannot parse exception {} {}", alarmTime, e);
    }
    return System.currentTimeMillis();
}

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

private DeviceDescription parseProductInformation() {
    DeviceService devsvc = checkNotNull(handler().get(DeviceService.class));
    DeviceId devid = handler().data().deviceId();
    Device dev = devsvc.getDevice(devid);
    if (dev == null) {
        return new DefaultDeviceDescription(devid.uri(), FIBER_SWITCH, DEFAULT_MANUFACTURER,
                DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA, new ChassisId());
    }//from  w w  w  .j a  v  a 2 s  .  com
    String reply = netconfGet(handler(), getProductInformationFilter());
    HierarchicalConfiguration cfg = configAt(reply, KEY_DATA_PRODINF);
    return new DefaultDeviceDescription(dev.id().uri(), FIBER_SWITCH, cfg.getString(KEY_MANUFACTURER),
            cfg.getString(KEY_HWVERSION), cfg.getString(KEY_SWVERSION), cfg.getString(KEY_SERIALNUMBER),
            dev.chassisId());
}