Java Code Examples for org.apache.commons.configuration.XMLConfiguration#configurationAt()

The following examples show how to use org.apache.commons.configuration.XMLConfiguration#configurationAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TerminalDeviceDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        XPathExpressionEngine xpe = new XPathExpressionEngine();
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getDeviceComponentsBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(xpe);

        HierarchicalConfiguration components = xconf.configurationAt("data/components");
        return parsePorts(components);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example 2
Source File: GrooveOpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getTerminalDeviceBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());

        HierarchicalConfiguration logicalChannels = xconf.configurationAt("data/terminal-device/logical-channels");
        return parseLogicalChannels(logicalChannels);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example 3
Source File: CassiniTerminalDevicePowerConfigExt.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * mirror method in the internal class.
 * @param port port
 * @param component component
 * @return target power
 */
Optional<Double> getTargetPower(PortNumber port, Object component) {
    NetconfSession session = cassini.getNetconfSession(cassini.did());
    checkNotNull(session);
    String filter = parsePort(cassini, port, null, null);
    StringBuilder rpcReq = new StringBuilder();
    rpcReq.append(RPC_TAG_NETCONF_BASE)
            .append("<get>")
            .append("<filter type='subtree'>")
            .append(filter)
            .append("</filter>")
            .append("</get>")
            .append(RPC_CLOSE_TAG);
    XMLConfiguration xconf = cassini.executeRpc(session, rpcReq.toString());
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/optical-channel/config");
        double power = Float.valueOf(config.getString("target-output-power")).doubleValue();
        return Optional.of(power);
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example 4
Source File: CassiniTerminalDeviceDiscoveryOld.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getTerminalDeviceBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());

        HierarchicalConfiguration logicalChannels = xconf.configurationAt("data/terminal-device/logical-channels");
        return parseLogicalChannels(logicalChannels);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example 5
Source File: ClientLineTerminalDeviceDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        XPathExpressionEngine xpe = new XPathExpressionEngine();
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getDeviceComponentsBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(xpe);

        log.debug("REPLY {}", rpcReply);
        HierarchicalConfiguration components = xconf.configurationAt("data/components");
        return parsePorts(components);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example 6
Source File: TerminalDevicePowerConfig.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * mirror method in the internal class.
 *
 * @param port      port
 * @param component the component
 * @return current input power
 */
public Optional<Double> currentInputPower(PortNumber port, Object component) {
    Map<String, String> rpcMap = driver.buildRpcString(CURRENT_INPUT_POWER);
    String configString = rpcMap.get("CURRENT_INPUT_POWER_PATH"),
            queryStr = rpcMap.get("CURRENT_INPUT_POWER_ROUTE"),
            paramStr = rpcMap.get("CURRENT_INPUT_POWER_LEAF");
    XMLConfiguration xconf = getOpticalChannelState(
            driver, port, queryStr);
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt(configString);
        if (config == null || config.getString(paramStr) == null) {
            return Optional.empty();
        }
        double currentPower = Float.valueOf(config.getString(paramStr)).doubleValue();
        return Optional.of(currentPower);
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example 7
Source File: GrooveModulationOpenConfig.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Get the Modulation Scheme on the component.
 *
 * @param conf HierarchicalConfiguration for path ../optical-channel/config
 * @return Optional<ModulationScheme>
 **/
public Optional<ModulationScheme> getModulation(XMLConfiguration conf) {
    HierarchicalConfiguration config =
            conf.configurationAt("data/components/component/optical-channel/config");

    String operationalMode = String.valueOf(config.getString("operational-mode"));
    /*Used for Internal Testing */
    //String modulationScheme="DP16QAM";
    ModulationScheme modulation;
    if (operationalMode.equalsIgnoreCase("62") ||
            operationalMode.equalsIgnoreCase("68")) {
        modulation = ModulationScheme.DP_16QAM;
    } else {
        modulation = ModulationScheme.DP_QPSK;
    }
    return Optional.of(modulation);
}
 
Example 8
Source File: OpenconfigBitErrorRateState.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the BER value pre FEC.
 *
 * @param deviceId the device identifier
 * @param port     the port identifier
 * @return the decimal value of BER
 */
@Override
public Optional<Double> getPreFecBer(DeviceId deviceId, PortNumber port) {
    NetconfSession session = NetconfSessionUtility
            .getNetconfSession(deviceId, getController());
    checkNotNull(session);

    String preFecBerFilter = generateBerFilter(deviceId, port, PRE_FEC_BER_TAG);
    String rpcRequest = getConfigOperation(preFecBerFilter);
    log.debug("RPC call for fetching Pre FEC BER : {}", rpcRequest);

    XMLConfiguration xconf = NetconfSessionUtility.executeRpc(session, rpcRequest);

    if (xconf == null) {
        log.error("Error in executing Pre FEC BER RPC");
        return Optional.empty();
    }

    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/transceiver/state/" + PRE_FEC_BER_TAG);
        if (config == null || config.getString("instant") == null) {
            return Optional.empty();
        }
        double ber = Float.valueOf(config.getString("instant")).doubleValue();
        return Optional.of(ber);

    } catch (IllegalArgumentException e) {
        log.error("Error in fetching configuration : {}", e.getMessage());
        return Optional.empty();
    }
}
 
Example 9
Source File: TerminalDevicePowerConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
public Optional<Range<Double>> getTargetPowerRange(PortNumber port, Object component) {
    XMLConfiguration xconf = getOpticalChannelState(
            driver, port, "<target-power-range/>");
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/optical-channel/state/target-power-range");
        double targetMin = Float.valueOf(config.getString("min")).doubleValue();
        double targetMax = Float.valueOf(config.getString("max")).doubleValue();
        return Optional.of(Range.open(targetMin, targetMax));
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example 10
Source File: TerminalDevicePowerConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
public Optional<Range<Double>> getInputPowerRange(PortNumber port, Object component) {
    XMLConfiguration xconf = getOpticalChannelState(
            driver, port, "<input-power-range/>");
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/optical-channel/state/input-power-range");
        double inputMin = Float.valueOf(config.getString("min")).doubleValue();
        double inputMax = Float.valueOf(config.getString("max")).doubleValue();
        return Optional.of(Range.open(inputMin, inputMax));
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example 11
Source File: OpenconfigBitErrorRateState.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the BER value post FEC.
 *
 * @param deviceId the device identifier
 * @param port     the port identifier
 * @return the decimal value of BER
 */
@Override
public Optional<Double> getPostFecBer(DeviceId deviceId, PortNumber port) {
    NetconfSession session = NetconfSessionUtility
            .getNetconfSession(deviceId, getController());
    checkNotNull(session);

    String postFecBerFilter = generateBerFilter(deviceId, port, POST_FEC_BER_TAG);
    String rpcRequest = getConfigOperation(postFecBerFilter);
    log.debug("RPC call for fetching Post FEC BER : {}", rpcRequest);

    XMLConfiguration xconf = NetconfSessionUtility.executeRpc(session, rpcRequest);

    if (xconf == null) {
        log.error("Error in executing Post FEC BER RPC");
        return Optional.empty();
    }

    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/transceiver/state/" + POST_FEC_BER_TAG);
        if (config == null || config.getString("instant") == null) {
            return Optional.empty();
        }
        double ber = Float.valueOf(config.getString("instant")).doubleValue();
        return Optional.of(ber);

    } catch (IllegalArgumentException e) {
        log.error("Error in fetching configuration : {}", e.getMessage());
        return Optional.empty();
    }
}
 
Example 12
Source File: TerminalDeviceModulationConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the Modulation Scheme on the component.
 *
 * @param conf HierarchicalConfiguration for path ../optical-channel/config
 * @return Optional<ModulationScheme>
 **/
public Optional<ModulationScheme> getModulation(XMLConfiguration conf) {
    HierarchicalConfiguration config =
                    conf.configurationAt("components/component/optical-channel/config");

            String modulationScheme = String.valueOf(config.getString("modulation"));

    return Optional.of(modulationSchemeType(modulationScheme));
}
 
Example 13
Source File: TerminalDeviceModulationConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
private double fetchDeviceSnr(TerminalDeviceModulationConfig modulationConfig, PortNumber portNumber) {
    double osnr = 0.0;
    XMLConfiguration xconf = getTerminalDeviceSnr(terminalDevice, portNumber);
    if (xconf == null) {
        return osnr;
    }
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/optical-channel/state/osnr");
        osnr = Float.valueOf(config.getString("snr")).doubleValue();
        return osnr;
    } catch (IllegalArgumentException e) {
        return osnr;
    }
}
 
Example 14
Source File: RORClient.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves a list of templates available for the tenant.
 * 
 * @param descriptorId
 * @return the list
 * @throws RORException
 */
public LPlatformDescriptorConfiguration getLPlatformDescriptorConfiguration(
		String descriptorId) throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.GET_LPLATFORM_DESCR_CONFIG);
	request.put(LParameter.LPLATFORM_DESCR_ID, descriptorId);
	XMLConfiguration result = execute(request);
	return new LPlatformDescriptorConfiguration(
			result.configurationAt("lplatformdescriptor"));
}
 
Example 15
Source File: CassiniTerminalDevicePowerConfigExt.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * mirror method in the internal class.
 * @param port port
 * @param component the component
 * @return current input power
 */
Optional<Double> currentInputPower(PortNumber port, Object component) {
    XMLConfiguration xconf = getOpticalChannelState(
            cassini, port, "<input-power><instant/></input-power>");
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/optical-channel/state/input-power");
        double currentPower = Float.valueOf(config.getString("instant")).doubleValue();
        return Optional.of(currentPower);
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example 16
Source File: CassiniTerminalDevicePowerConfigExt.java    From onos with Apache License 2.0 5 votes vote down vote up
Optional<Range<Double>> getTargetPowerRange(PortNumber port, Object component) {
    XMLConfiguration xconf = getOpticalChannelState(
            cassini, port, "<target-power-range/>");
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/optical-channel/state/target-power-range");
        double targetMin = Float.valueOf(config.getString("min")).doubleValue();
        double targetMax = Float.valueOf(config.getString("max")).doubleValue();
        return Optional.of(Range.open(targetMin, targetMax));
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }

}
 
Example 17
Source File: CassiniTerminalDevicePowerConfigExt.java    From onos with Apache License 2.0 5 votes vote down vote up
Optional<Range<Double>> getInputPowerRange(PortNumber port, Object component) {
    XMLConfiguration xconf = getOpticalChannelState(
            cassini, port, "<input-power-range/>");
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/optical-channel/state/input-power-range");
        double inputMin = Float.valueOf(config.getString("min")).doubleValue();
        double inputMax = Float.valueOf(config.getString("max")).doubleValue();
        return Optional.of(Range.open(inputMin, inputMax));
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example 18
Source File: LPlatformClient.java    From development with Apache License 2.0 4 votes vote down vote up
public LPlatformConfiguration getConfiguration() throws IaasException,
        SuspendException {
    XMLConfiguration result = executeLPlatformAction(LOperation.GET_LPLATFORM_CONFIG);
    return new LPlatformConfiguration(result.configurationAt("lplatform"));
}
 
Example 19
Source File: CassiniTerminalDeviceDiscovery.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 * <p>
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }
        CompletableFuture<CharSequence> fut1 = session.asyncGet();
        String rpcReplyTest = fut1.get().toString();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReplyTest);
        xconf.setExpressionEngine(new XPathExpressionEngine());

        HierarchicalConfiguration logicalChannels = xconf.configurationAt("components");
        return discoverPorts(logicalChannels);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example 20
Source File: LServerClient.java    From development with Apache License 2.0 4 votes vote down vote up
/**
 * @return the configuration
 * @throws RORException
 */
public LServerConfiguration getConfiguration() throws IaasException {
    XMLConfiguration result = executeLServerAction(LOperation.GET_LSERVER_CONFIG);
    return new LServerConfiguration(result.configurationAt("lserver"));
}