Java Code Examples for org.apache.commons.configuration.HierarchicalConfiguration#configurationsAt()
The following examples show how to use
org.apache.commons.configuration.HierarchicalConfiguration#configurationsAt() .
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: Configuration.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
/** * Loads and parse CME MDP Configuration. * * @param uri URI to CME MDP Configuration (config.xml, usually available on CME FTP) * @throws ConfigurationException if failed to parse configuration file * @throws MalformedURLException if URI to Configuration is malformed */ private void load(final URI uri) throws ConfigurationException, MalformedURLException { // todo: if to implement the same via standard JAXB then dep to apache commons configuration will be not required final XMLConfiguration configuration = new XMLConfiguration(); configuration.setDelimiterParsingDisabled(true); configuration.load(uri.toURL()); for (final HierarchicalConfiguration channelCfg : configuration.configurationsAt("channel")) { final ChannelCfg channel = new ChannelCfg(channelCfg.getString("[@id]"), channelCfg.getString("[@label]")); for (final HierarchicalConfiguration connCfg : channelCfg.configurationsAt("connections.connection")) { final String id = connCfg.getString("[@id]"); final FeedType type = FeedType.valueOf(connCfg.getString("type[@feed-type]")); final TransportProtocol protocol = TransportProtocol.valueOf(connCfg.getString("protocol").substring(0, 3)); final Feed feed = Feed.valueOf(connCfg.getString("feed")); final String ip = connCfg.getString("ip"); final int port = connCfg.getInt("port"); final List<String> hostIPs = Arrays.asList(connCfg.getStringArray("host-ip")); final ConnectionCfg connection = new ConnectionCfg(feed, id, type, protocol, ip, hostIPs, port); channel.addConnection(connection); connCfgs.put(connection.getId(), connection); } channelCfgs.put(channel.getId(), channel); } }
Example 2
Source File: JuniperUtils.java From onos with Apache License 2.0 | 6 votes |
/** * Parses device ports configuration and returns a list of * port description. * * @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 = new ArrayList<>(); List<HierarchicalConfiguration> subtrees = cfg.configurationsAt(IF_INFO); for (HierarchicalConfiguration interfInfo : subtrees) { List<HierarchicalConfiguration> interfaceTree = interfInfo.configurationsAt(IF_PHY); for (HierarchicalConfiguration phyIntf : interfaceTree) { if (phyIntf == null) { continue; } // parse physical Interface parsePhysicalInterface(portDescriptions, phyIntf); } } return portDescriptions; }
Example 3
Source File: FujitsuVoltControllerConfig.java From onos with Apache License 2.0 | 6 votes |
/** * Parses XML string to get controller information. * * @param cfg a hierarchical configuration * @return a list of controllers */ 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; }
Example 4
Source File: OpenRoadmFlowRuleProgrammable.java From onos with Apache License 2.0 | 6 votes |
/** * Fetches list of connections from device. * * @return list of connections as XML hierarchy */ private List<HierarchicalConfiguration> getDeviceConnections() { NetconfSession session = getNetconfSession(); if (session == null) { log.error("OPENROADM {}: session not found", did()); return ImmutableList.of(); } try { StringBuilder rb = new StringBuilder(); rb.append(ORG_OPENROADM_DEVICE_OPEN_TAG); rb.append(" <roadm-connections/>"); rb.append(ORG_OPENROADM_DEVICE_CLOSE_TAG); String reply = session.getConfig(DatastoreId.RUNNING, rb.toString()); log.debug("REPLY to getDeviceConnections {}", reply); HierarchicalConfiguration cfg = XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())); return cfg.configurationsAt("data.org-openroadm-device.roadm-connections"); } catch (NetconfException e) { return ImmutableList.of(); } }
Example 5
Source File: CustomPayloadsParam.java From zap-extensions with Apache License 2.0 | 6 votes |
private void loadPayloadsFromConfig(HierarchicalConfiguration rootConfig) { List<HierarchicalConfiguration> categories = rootConfig.configurationsAt(ALL_CATEGORIES_KEY); payloadCategories = new HashMap<>(); for (HierarchicalConfiguration category : categories) { List<HierarchicalConfiguration> fields = category.configurationsAt("payloads.payload"); String cat = category.getString(CATEGORY_NAME_KEY); List<CustomPayload> payloads = new ArrayList<>(); for (HierarchicalConfiguration sub : fields) { int id = sub.getInt(PAYLOAD_ID_KEY); boolean isEnabled = sub.getBoolean(PAYLOAD_ENABLED_KEY); String payload = sub.getString(PAYLOAD_KEY, ""); payloads.add(new CustomPayload(id, isEnabled, cat, payload)); } payloadCategories.put(cat, new PayloadCategory(cat, Collections.emptyList(), payloads)); } }
Example 6
Source File: OpenRoadmDeviceDescription.java From onos with Apache License 2.0 | 5 votes |
/** * Given a device port (external), return its patner/reverse port. * * @param thisPort the port for which we are looking for the reverse port. * @param circuitPacks all the circuit packs (to correlate data). * @return the port number for the reverse port. * @throws NetconfException . */ protected PortNumber findReversePort(HierarchicalConfiguration thisPort, List<HierarchicalConfiguration> circuitPacks) throws NetconfException { String partnerCircuitPackName = checkNotNull(thisPort.getString("partner-port/circuit-pack-name")); String partnerPortName = checkNotNull(thisPort.getString("partner-port/port-name")); for (HierarchicalConfiguration c : circuitPacks) { if (!partnerCircuitPackName.equals( c.getString("circuit-pack-name"))) { continue; } for (HierarchicalConfiguration thatPort : c.configurationsAt("ports[port-qual='roadm-external']")) { String thatPortName = thatPort.getString("port-name"); if (partnerPortName.equals(thatPortName)) { long thatPortNum = Long.parseLong(thatPort.getString("label")); return PortNumber.portNumber(thatPortNum); } } } // We should not reach here throw new NetconfException("missing partner/reverse port info"); }
Example 7
Source File: CassiniTerminalDeviceDiscovery.java From onos with Apache License 2.0 | 5 votes |
/** * Parses port information from OpenConfig XML configuration. * * @param cfg tree where the root node is {@literal <data>} * @return List of ports */ @VisibleForTesting private List<PortDescription> discoverPorts(HierarchicalConfiguration cfg) { // If we want to use XPath cfg.setExpressionEngine(new XPathExpressionEngine()); // converting components into PortDescription. List<HierarchicalConfiguration> components = cfg.configurationsAt("component"); return components.stream() .map(this::toPortDescriptionInternal) .filter(Objects::nonNull) .collect(Collectors.toList()); }
Example 8
Source File: PolatisNetconfUtility.java From onos with Apache License 2.0 | 5 votes |
/** * Retrieves specified node hierarchical configurations from the xml information. * * @param content the xml information * @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; }
Example 9
Source File: XmlConfigParser.java From onos with Apache License 2.0 | 5 votes |
public static List<ControllerInfo> parseStreamControllers(HierarchicalConfiguration cfg) { List<ControllerInfo> controllers = new ArrayList<>(); List<HierarchicalConfiguration> fields = cfg.configurationsAt("data.capable-switch." + "logical-switches." + "switch.controllers.controller"); for (HierarchicalConfiguration sub : fields) { controllers.add(new ControllerInfo( IpAddress.valueOf(sub.getString("ip-address")), Integer.parseInt(sub.getString("port")), sub.getString("protocol"))); } return controllers; }
Example 10
Source File: XmlDriverLoader.java From onos with Apache License 2.0 | 5 votes |
private Map<Class<? extends Behaviour>, Class<? extends Behaviour>> parseBehaviours(HierarchicalConfiguration driverCfg) { ImmutableMap.Builder<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = ImmutableMap.builder(); for (HierarchicalConfiguration b : driverCfg.configurationsAt(BEHAVIOUR)) { behaviours.put(getClass(b.getString(API)), getClass(b.getString(IMPL))); } return behaviours.build(); }
Example 11
Source File: FujitsuVoltAlarmConsumer.java From onos with Apache License 2.0 | 5 votes |
/** * Converts time and date information from device. * @param cfg a hierarchical configuration * @return converted time from device or system time */ private long getTimeRaised(HierarchicalConfiguration cfg) { String strDate; String strTime; long timeRaised; List<HierarchicalConfiguration> timeFields = cfg.configurationsAt(ALERT_TIME); if (timeFields.isEmpty()) { log.debug("{} does not exist", ALERT_TIME); } else { for (HierarchicalConfiguration child : timeFields) { strDate = child.getString(DATE); strTime = child.getString(TIME); if ((strDate != null) && (strTime != null)) { try { Date date = dateFormat.parse(strDate + SPACE + strTime); timeRaised = date.getTime(); log.debug("{} {} converted to {}", strDate, strTime, timeRaised); return timeRaised; } catch (ParseException e) { log.error("Cannot parse exception {} {} {}", strDate, strTime, e); } } else { log.error("{} or {} does not exist", DATE, TIME); } } } // Use the system's time instead. return System.currentTimeMillis(); }
Example 12
Source File: XmlDriverLoader.java From onos with Apache License 2.0 | 5 votes |
/** * Loads a driver provider from the supplied hierarchical configuration. * * @param driversCfg hierarchical configuration containing the drivers definitions * @param resolver driver resolver * @return driver provider */ public DefaultDriverProvider loadDrivers(HierarchicalConfiguration driversCfg, DriverResolver resolver) { DefaultDriverProvider provider = new DefaultDriverProvider(); for (HierarchicalConfiguration cfg : driversCfg.configurationsAt(DRIVER)) { DefaultDriver driver = loadDriver(cfg, resolver); drivers.put(driver.name(), driver); provider.addDriver(driver); } drivers.clear(); return provider; }
Example 13
Source File: JuniperUtils.java From onos with Apache License 2.0 | 5 votes |
/** * Parses neighbours discovery information and returns a list of * link abstractions. * * @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_LIST_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)); String remotePortId = null; long remotePortIndex = -1; String remotePortIdSubtype = neighbor.getString(LLDP_REM_PORT_SUBTYPE, null); if (remotePortIdSubtype != null) { if (remotePortIdSubtype.equals(LLDP_SUBTYPE_MAC) || remotePortIdSubtype.equals(LLDP_SUBTYPE_INTERFACE_NAME)) { remotePortId = neighbor.getString(LLDP_REM_PORT, null); } else { remotePortIndex = neighbor.getLong(LLDP_REM_PORT, -1); } } String remotePortDescription = neighbor.getString(LLDP_REM_PORT_DES, null); LinkAbstraction link = new LinkAbstraction( localPortName, mac.toLong(), remotePortIndex, remotePortId, remotePortDescription); neighbour.add(link); } } return neighbour; }
Example 14
Source File: JuniperUtils.java From onos with Apache License 2.0 | 5 votes |
/** * Parses {@literal route-information} tree. * This implementation supports only static routes. * * @param cfg route-information * @return a collection of static routes */ public static Collection<StaticRoute> parseRoutingTable(HierarchicalConfiguration cfg) { Collection<StaticRoute> staticRoutes = new HashSet<>(); HierarchicalConfiguration routeInfo = cfg.configurationAt("route-information"); List<HierarchicalConfiguration> routeTables = routeInfo.configurationsAt("route-table"); for (HierarchicalConfiguration routeTable : routeTables) { List<HierarchicalConfiguration> routes = routeTable.configurationsAt("rt"); for (HierarchicalConfiguration route : routes) { if (route != null) { List<HierarchicalConfiguration> rtEntries = route.configurationsAt("rt-entry"); rtEntries.forEach(rtEntry -> { if (rtEntry.getString(PROTOCOL_NAME) != null && rtEntry.getString(PROTOCOL_NAME).contains("Static")) { parseStaticRoute(rtEntry, route.getString("rt-destination"), rtEntry.getString("metric")) .ifPresent(staticRoutes::add); } }); } } } return staticRoutes; }
Example 15
Source File: XmlDriverLoader.java From onos with Apache License 2.0 | 5 votes |
private Map<String, String> parseProperties(HierarchicalConfiguration driverCfg) { ImmutableMap.Builder<String, String> properties = ImmutableMap.builder(); for (HierarchicalConfiguration b : driverCfg.configurationsAt(PROPERTY)) { properties.put(b.getString(NAME), (String) b.getRootNode().getValue()); } return properties.build(); }
Example 16
Source File: CienaWaveserverDeviceDescription.java From onos with Apache License 2.0 | 4 votes |
public static List<HierarchicalConfiguration> parseWaveServerCienaPorts(HierarchicalConfiguration cfg) { return cfg.configurationsAt(PORTS); }
Example 17
Source File: DellRestPortDiscovery.java From onos with Apache License 2.0 | 4 votes |
public static List<HierarchicalConfiguration> parseDellPorts(HierarchicalConfiguration cfg) { return cfg.configurationsAt(INTERFACES); }
Example 18
Source File: CzechLightFlowRuleProgrammable.java From onos with Apache License 2.0 | 4 votes |
@Override public Collection<FlowEntry> getFlowEntries() { if (deviceType() == CzechLightDiscovery.DeviceType.INLINE_AMP || deviceType() == CzechLightDiscovery.DeviceType.COHERENT_ADD_DROP) { final var data = getConnectionCache().get(data().deviceId()); if (data == null) { return new ArrayList<>(); } return data.stream() .map(rule -> new DefaultFlowEntry(rule)) .collect(Collectors.toList()); } HierarchicalConfiguration xml; try { xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER); } catch (NetconfException e) { log.error("Cannot read data from NETCONF: {}", e); return new ArrayList<>(); } final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml); Collection<FlowEntry> list = new ArrayList<>(); final var allMCs = xml.configurationsAt("data.media-channels"); allMCs.stream() .map(cfg -> confToMCRouting(ELEMENT_ADD, allChannels, cfg)) .filter(Objects::nonNull) .forEach(flow -> { log.debug("{}: found ADD: {}", data().deviceId(), flow.toString()); list.add(new DefaultFlowEntry(asFlowRule(Direction.ADD, flow), FlowEntry.FlowEntryState.ADDED)); }); allMCs.stream() .map(cfg -> confToMCRouting(ELEMENT_DROP, allChannels, cfg)) .filter(Objects::nonNull) .forEach(flow -> { log.debug("{}: found DROP: {}", data().deviceId(), flow.toString()); list.add(new DefaultFlowEntry(asFlowRule(Direction.DROP, flow), FlowEntry.FlowEntryState.ADDED)); }); return list; }
Example 19
Source File: JuniperUtils.java From onos with Apache License 2.0 | 4 votes |
/** * Parses {@literal physical-interface} tree. * * @param portDescriptions list to populate Ports found parsing configuration * @param phyIntf physical-interface */ private static void parsePhysicalInterface(List<PortDescription> portDescriptions, HierarchicalConfiguration phyIntf) { Builder annotations = DefaultAnnotations.builder(); PortNumber portNumber = portNumber(phyIntf.getString(SNMP_INDEX)); String phyPortName = phyIntf.getString(NAME); if (portNumber == null) { log.debug("Skipping physical-interface {}, no PortNumer", phyPortName); log.trace(" {}", phyIntf); return; } setIfNonNull(annotations, AnnotationKeys.PORT_NAME, phyPortName); setIfNonNull(annotations, AnnotationKeys.PORT_MAC, phyIntf.getString("current-physical-address")); setIfNonNull(annotations, AK_IF_TYPE, phyIntf.getString(IF_TYPE)); setIfNonNull(annotations, AK_DESCRIPTION, phyIntf.getString("description")); boolean opUp = phyIntf.getString("oper-status", "down").equals("up"); annotations.set(AK_OPER_STATUS, toUpDown(opUp)); boolean admUp = phyIntf.getString("admin-status", "down").equals("up"); annotations.set(AK_ADMIN_STATUS, toUpDown(admUp)); long portSpeed = toMbps(phyIntf.getString(SPEED)); Type portType = phyIntf.getString(IF_MEDIA_TYPE, COPPER).equalsIgnoreCase(FIBER) ? Type.FIBER : Type.COPPER; portDescriptions.add(DefaultPortDescription.builder() .withPortNumber(portNumber) .isEnabled(admUp && opUp) .type(portType) .portSpeed(portSpeed) .annotations(annotations.build()).build()); // parse each logical Interface for (HierarchicalConfiguration logIntf : phyIntf.configurationsAt("logical-interface")) { if (logIntf == null) { continue; } PortNumber lPortNumber = safePortNumber(logIntf.getString(SNMP_INDEX)); if (lPortNumber == null) { log.debug("Skipping logical-interface {} under {}, no PortNumer", logIntf.getString(NAME), phyPortName); log.trace(" {}", logIntf); continue; } Builder lannotations = DefaultAnnotations.builder(); setIfNonNull(lannotations, AnnotationKeys.PORT_NAME, logIntf.getString(NAME)); setIfNonNull(lannotations, AK_PHYSICAL_PORT_NAME, phyPortName); String afName = logIntf.getString("address-family.address-family-name"); String address = logIntf.getString("address-family.interface-address.ifa-local"); if (afName != null && address != null) { // e.g., inet : IPV4, inet6 : IPV6 setIfNonNull(lannotations, afName, address); } // preserving former behavior setIfNonNull(lannotations, AK_IP, logIntf.getString("address-family.interface-address.ifa-local")); setIfNonNull(lannotations, AK_ENCAPSULATION, logIntf.getString("encapsulation")); // TODO confirm if this is correct. // Looking at sample data, // it seemed all logical loop-back interfaces were down boolean lEnabled = logIntf.getString("if-config-flags.iff-up") != null; portDescriptions.add(DefaultPortDescription.builder() .withPortNumber(lPortNumber) .isEnabled(admUp && opUp && lEnabled) .type(portType) .portSpeed(portSpeed).annotations(lannotations.build()) .build()); } }
Example 20
Source File: JuniperUtils.java From onos with Apache License 2.0 | 4 votes |
public static List<ControllerInfo> getOpenFlowControllersFromConfig(HierarchicalConfiguration cfg) { List<ControllerInfo> controllers = new ArrayList<>(); String ipKey = "configuration.protocols.openflow.mode.ofagent-mode.controller.ip"; if (!cfg.configurationsAt(ipKey).isEmpty()) { List<HierarchicalConfiguration> ipNodes = cfg.configurationsAt(ipKey); ipNodes.forEach(ipNode -> { int port = 0; String proto = UNKNOWN; HierarchicalConfiguration protocolNode = ipNode.configurationAt(PROTOCOL); HierarchicalConfiguration tcpNode = protocolNode.configurationAt(TCP); if (!tcpNode.isEmpty()) { String portString = tcpNode.getString(PORT); if (portString != null && !portString.isEmpty()) { port = Integer.parseInt(portString); } proto = TCP; } String ipaddress = ipNode.getString(NAME); if (ipaddress == null) { ipaddress = UNKNOWN; } if (ipaddress.equals(UNKNOWN) || proto.equals(UNKNOWN) || port == 0) { log.error("Controller infomation is invalid. Skip this controller node." + " ipaddress: {}, proto: {}, port: {}", ipaddress, proto, port); return; } controllers.add(new ControllerInfo(IpAddress.valueOf(ipaddress), port, proto)); }); } else { log.error("Controller not present"); } return controllers; }