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

The following examples show how to use org.apache.commons.configuration.HierarchicalConfiguration#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: ScriptSettings.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
@Override
public void load(HierarchicalConfiguration config) 
{
	HierarchicalConfiguration testScriptConfig = config.configurationAt(TESTSCRIPT_KEY);
	
	String scriptNamePar = config.getString("TestScript[@name]");

       if(scriptNamePar == null) {
           throw new ScriptRunException("There is no \"name\" attribute at \"TestScript\" element in the script configuration file");
       }
	
	this.scriptName = scriptNamePar;

       if(!testScriptConfig.configurationsAt(PROPERTIES_KEY).isEmpty()) {
           loadProperties(testScriptConfig.configurationAt(PROPERTIES_KEY));
       }

       if(!testScriptConfig.configurationsAt(LOGGING_KEY).isEmpty()) {
           loadLoggingProperties(testScriptConfig.configurationAt(LOGGING_KEY));
       }

       if(!testScriptConfig.configurationsAt(TESTREPORT_KEY).isEmpty()) {
           loadTestReportProperties(testScriptConfig.configurationAt(TESTREPORT_KEY));
       }
}
 
Example 2
Source File: ConfigurableIngestTopology.java    From cognition with Apache License 2.0 6 votes vote down vote up
void configure(HierarchicalConfiguration conf) throws Exception {

    this.stormConfig = new Config();
    this.builder = new TopologyBuilder();

    SubnodeConfiguration topologyConf = conf.configurationAt(TOPOLOGY);
    this.topologyName = getTopologyName(topologyConf);

    SubnodeConfiguration stormConf = topologyConf.configurationAt(STORM_CONF);
    configureStorm(stormConf, stormConfig);

    SubnodeConfiguration spoutConf = conf.configurationAt(SPOUT);
    String spout = configureSpout(builder, spoutConf);

    SubnodeConfiguration boltConfs = conf.configurationAt(BOLTS);
    configureBolts(builder, boltConfs, spout);
  }
 
Example 3
Source File: JuniperUtils.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the {@literal rt-entry} for static routes.
 *
 * @param rtEntry     rt-entry filtered by {@literal protocol-name} equals to Static
 * @param destination rt-destination
 * @return optional of static route
 */
private static Optional<StaticRoute> parseStaticRoute(HierarchicalConfiguration rtEntry,
                                                      String destination, String metric) {

    Ip4Prefix ipDst = Ip4Prefix.valueOf(destination);

    HierarchicalConfiguration nextHop = rtEntry.configurationAt("nh");
    String to = nextHop.getString("to");
    if (StringUtils.isEmpty(to)) {
        return Optional.empty();
    }
    Ip4Address nextHopIp = Ip4Address.valueOf(to);

    if (metric == null) {
        return Optional.of(new StaticRoute(ipDst, nextHopIp, false));
    } else {
        return Optional.of(new StaticRoute(ipDst, nextHopIp, false,
                toFlowRulePriority(Integer.parseInt(metric))));
    }
}
 
Example 4
Source File: JuniperUtils.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Parses device configuration and returns the device description.
 *
 * @param deviceId    the id of the device
 * @param sysInfoCfg  system configuration
 * @param chassisMacAddresses chassis MAC addresses response. Its format depends on JUNOS version of device.
 * @return device description
 */
public static DeviceDescription parseJuniperDescription(DeviceId deviceId,
                                                        HierarchicalConfiguration sysInfoCfg,
                                                        String chassisMacAddresses) {
    HierarchicalConfiguration info = sysInfoCfg.configurationAt(SYS_INFO);

    String hw = info.getString(HW_MODEL) == null ? UNKNOWN : info.getString(HW_MODEL);
    String sw = UNKNOWN;
    if (info.getString(OS_NAME) != null || info.getString(OS_VER) != null) {
        sw = info.getString(OS_NAME) + " " + info.getString(OS_VER);
    }
    String serial = info.getString(SER_NUM) == null ? UNKNOWN : info.getString(SER_NUM);

    return new DefaultDeviceDescription(deviceId.uri(), ROUTER,
            JUNIPER, hw, sw, serial,
            extractChassisId(chassisMacAddresses),
            DefaultAnnotations.EMPTY);
}
 
Example 5
Source File: LoadBalancerConfiguration.java    From development with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <E extends VMwareBalancer<?>> E parseBalancer(
        HierarchicalConfiguration parent, Class<E> targetClass,
        Class<? extends E> defaultBalancer,
        VMwareDatacenterInventory inventory) throws Exception {

    String balancerClass = parent.getString("balancer[@class]");
    Class<?> loadedClass = null;
    if (balancerClass != null) {
        loadedClass = this.getClass().getClassLoader()
                .loadClass(balancerClass);
        if (!targetClass.isAssignableFrom(loadedClass)) {
            loadedClass = null;
            logger.warn("The configured balancer '" + balancerClass
                    + "' is not of type " + targetClass.getSimpleName());
        }
    }
    if (loadedClass == null) {
        balancerClass = defaultBalancer.getName();
        parent.addProperty("balancer[@class]", balancerClass);
        loadedClass = defaultBalancer;
    }
    HierarchicalConfiguration balancerConfig = parent
            .configurationAt(ELEMENT_BALANCER);
    E balancer = (E) loadedClass.newInstance();
    balancer.setConfiguration(balancerConfig);
    balancer.setInventory(inventory);
    return balancer;
}
 
Example 6
Source File: XmlConfigParser.java    From onos with Apache License 2.0 5 votes vote down vote up
protected static String parseSwitchId(HierarchicalConfiguration cfg) {
    HierarchicalConfiguration field =
            cfg.configurationAt("data.capable-switch." +
                    "logical-switches." +
                    "switch");
    return field.getProperty("id").toString();
}
 
Example 7
Source File: OplinkNetconfUtility.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves specified node hierarchical configuration from the xml information.
 *
 * @param content the xml information
 * @param key the configuration key node
 * @return the hierarchical configuration, null if exception happens
 */
public static HierarchicalConfiguration configAt(String content, String key) {
    HierarchicalConfiguration info;
    try {
        HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content);
        info = cfg.configurationAt(key);
    } catch (Exception e) {
        // Accept null for information polling
        return null;
    }
    return info;
}
 
Example 8
Source File: OplinkOpticalDeviceDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: JuniperUtils.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: FujitsuT100DeviceDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
private static PortDescription parseT100OduPort(HierarchicalConfiguration cfg, long count) {
    PortNumber portNumber = PortNumber.portNumber(count);
    HierarchicalConfiguration ethernetConfig = cfg.configurationAt("ethernet");
    boolean enabled = "up".equals(ethernetConfig.getString("administrative-state"));
    //Rate is in kbps
    CltSignalType signalType = "100000000".equals(ethernetConfig.getString("rate")) ?
            CltSignalType.CLT_100GBE : null;
    DefaultAnnotations annotations = DefaultAnnotations.builder().
            set(AnnotationKeys.PORT_NAME, cfg.getString("name")).
            build();
    return oduCltPortDescription(portNumber, enabled, signalType, annotations);
}
 
Example 11
Source File: FujitsuT100DeviceDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
private static PortDescription parseT100OchPort(HierarchicalConfiguration cfg, long count) {
    PortNumber portNumber = PortNumber.portNumber(count);
    HierarchicalConfiguration otuConfig = cfg.configurationAt("otu");
    boolean enabled = "up".equals(otuConfig.getString("administrative-state"));
    OduSignalType signalType = "OTU4".equals(otuConfig.getString("rate")) ? OduSignalType.ODU4 : null;
    //Unsure how to retrieve, outside knowledge it is tunable.
    boolean isTunable = true;
    OchSignal lambda = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4);
    DefaultAnnotations annotations = DefaultAnnotations.builder().
            set(AnnotationKeys.PORT_NAME, cfg.getString("name")).
            build();
    return ochPortDescription(portNumber, enabled, signalType, isTunable, lambda, annotations);
}
 
Example 12
Source File: PolatisNetconfUtility.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves specified node hierarchical configuration from the xml information.
 *
 * @param content the xml information
 * @param key the configuration key node
 * @return the hierarchical configuration, null if exception happens
 */
public static HierarchicalConfiguration configAt(String content, String key) {
    HierarchicalConfiguration info;
    try {
        HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content);
        info = cfg.configurationAt(key);
    } catch (IllegalArgumentException e) {
        // Accept null for information polling
        return null;
    }
    return info;
}
 
Example 13
Source File: ConfigurableIngestTopologyTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigure(
    @Injectable HierarchicalConfiguration conf,
    @Injectable SubnodeConfiguration topologyConf,
    @Injectable SubnodeConfiguration stormConf,
    @Injectable SubnodeConfiguration spoutConf,
    @Injectable SubnodeConfiguration boltConfs,
    @Injectable String topologyName,
    @Injectable String spout) throws Exception {

  new Expectations(topology) {{
    conf.configurationAt(TOPOLOGY);
    result = topologyConf;
    topology.getTopologyName(topologyConf);
    result = topologyName;

    topologyConf.configurationAt(STORM_CONF);
    result = stormConf;
    topology.configureStorm(stormConf, (Config) any);

    conf.configurationAt(SPOUT);
    result = spoutConf;
    topology.configureSpout((TopologyBuilder) any, spoutConf);
    result = spout;

    conf.configurationAt(BOLTS);
    result = boltConfs;
    topology.configureBolts((TopologyBuilder) any, boltConfs, spout);
  }};
  topology.configure(conf);
}
 
Example 14
Source File: ConfigurableIngestTopology.java    From cognition with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a topology builder and set of storm bolt configurations. Initializes the bolts and sets them with the
 * topology builder.
 *
 * @param builder   storm topology builder
 * @param boltsConf component configurations
 * @param spout     type of storm component being added (spout/bolt)
 * @throws ConfigurationException
 */
void configureBolts(TopologyBuilder builder, SubnodeConfiguration boltsConf, String spout)
    throws ConfigurationException {

  String prevComponent = spout;
  // bolts subscribe to other bolts by number
  HashMap<Integer, String> boltNumberToId = new HashMap<>();

  List<HierarchicalConfiguration> bolts = boltsConf.configurationsAt(BOLT);
  for (HierarchicalConfiguration bolt : bolts) {
    String boltType = bolt.getString(TYPE);
    Configuration boltConf = bolt.configurationAt(CONF);
    int boltNum = bolt.getInt(NUMBER_ATTRIBUTE);

    String boltId = String.format("%02d_%s", boltNum, boltType);
    boltNumberToId.put(boltNum, boltId);
    String subscribingToComponent = getSubscribingToComponent(prevComponent, boltNumberToId, boltConf);
    logger.info("{} subscribing to {}", boltId, subscribingToComponent);

    IComponent baseComponent = buildComponent(boltType, boltConf);

    StormParallelismConfig stormParallelismConfig = getStormParallelismConfig(boltConf);
    BoltDeclarer declarer = buildBoltDeclarer(builder, stormParallelismConfig, boltId, baseComponent);

    configureTickFrequency(boltConf, declarer);

    configureStreamGrouping(subscribingToComponent, boltConf, declarer);

    prevComponent = boltId;

    boltNum++;
  }
}
 
Example 15
Source File: LumentumNetconfRoadmFlowRuleProgrammable.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a flow rule from a connection hierarchy.
 *
 * @param connection the connection hierarchy
 * @return the flow rule
 */
private FlowRule buildFlowrule(HierarchicalConfiguration connection) {

    String dn = connection.getString(DN);
    Pair<Short, Short> pair = parseDn(dn);
    short connId = pair.getRight();
    short moduleId = pair.getLeft();

    if (pair == null) {
        log.error("Lumentum NETCONF - device {} error in retrieving DN field", did());
        return null;
    }

    log.debug("Lumentum NETCONF - retrieved FlowRule module {} connection {}", moduleId, connId);

    HierarchicalConfiguration config = connection.configurationAt(CONFIG);
    double startFreq = config.getDouble(START_FREQ);
    double endFreq = config.getDouble(END_FREQ);
    String inputPortReference = config.getString(INPUT_PORT_REFERENCE);
    String outputPortReference = config.getString(OUTPUT_PORT_REFERENCE);

    HierarchicalConfiguration state = connection.configurationAt(STATE);
    double attenuation = state.getDouble(CHANNEL_ATTENUATION);
    double inputPower = state.getDouble(CHANNEL_INPUT_POWER);
    double outputPower = state.getDouble(CHANNEL_OUTPUT_POWER);

    PortNumber portNumber = getPortNumber(moduleId, inputPortReference, outputPortReference);

    //If rule is on module 1 it means input port in the Flow rule is contained in portNumber.
    //Otherwise the input port in the Flow rule must is the line port.
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchInPort(moduleId == 1 ? portNumber : LINE_PORT_NUMBER)
            .add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID))
            .add(Criteria.matchLambda(toOchSignal(startFreq, endFreq)))
            .build();

    log.debug("Lumentum NETCONF - retrieved FlowRule startFreq {} endFreq {}", startFreq, endFreq);

    //Lookup of connection
    //Retrieved rules, cached rules are considered equal if the selector is equal
    FlowRule cacheRule = null;
    if (getConnectionCache().size(did()) != 0) {
        cacheRule = getConnectionCache().get(did()).stream()
                .filter(r -> (r.selector().equals(selector)))
                .findFirst()
                .orElse(null);
    }


    if (cacheRule == null) {
        //TODO consider a way to keep "external" FlowRules
        log.error("Lumentum NETCONF connection not in the cache {}", pair.getRight());
        rpcDeleteExternalConnection(moduleId, connId);
        return null;
    } else {
        //Update monitored values
        log.debug("Attenuation retrieved {} dB for connection {}",
                attenuation, ((LumentumFlowRule) cacheRule).getConnectionId());
        ((LumentumFlowRule) cacheRule).setAttenuation(attenuation);
        ((LumentumFlowRule) cacheRule).setInputPower(inputPower);
        ((LumentumFlowRule) cacheRule).setOutputPower(outputPower);

        return cacheRule;
    }
}
 
Example 16
Source File: ConfigurableIngestTopologyTest.java    From cognition with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigureBolts(
    @Injectable TopologyBuilder builder,
    @Injectable SubnodeConfiguration boltsConf,
    @Injectable HierarchicalConfiguration bolt,
    @Injectable SubnodeConfiguration boltConf,
    @Injectable IComponent baseComponent,
    @Injectable StormParallelismConfig stormParallelismConfig,
    @Injectable BoltDeclarer declarer) throws Exception {

  List<HierarchicalConfiguration> bolts = Arrays.asList(bolt);
  String spout = "spout_id";

  new Expectations(topology) {{
    boltsConf.configurationsAt(BOLT);
    result = bolts;

    bolt.getString(TYPE);
    result = "bolt_type";
    bolt.configurationAt(CONF);
    result = boltConf;
    bolt.getInt(NUMBER_ATTRIBUTE);
    result = 0;
    topology.getSubscribingToComponent(spout, (HashMap<Integer, String>) any, boltConf);
    result = spout;

    topology.buildComponent("bolt_type", boltConf);
    result = baseComponent;

    topology.getStormParallelismConfig(boltConf);
    result = stormParallelismConfig;
    topology.buildBoltDeclarer(builder, stormParallelismConfig, "00_bolt_type", baseComponent);
    result = declarer;

    topology.configureTickFrequency(boltConf, declarer);

    topology.configureStreamGrouping(spout, boltConf, declarer);

  }};

  topology.configureBolts(builder, boltsConf, spout);
}
 
Example 17
Source File: XmlConfigParser.java    From onos with Apache License 2.0 4 votes vote down vote up
public static String parseCapableSwitchId(HierarchicalConfiguration cfg) {
    HierarchicalConfiguration field =
            cfg.configurationAt("data.capable-switch");
    return field.getProperty("id").toString();
}