org.apache.commons.configuration.XMLConfiguration Java Examples

The following examples show how to use org.apache.commons.configuration.XMLConfiguration. 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: LServerClientTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void getConfiguration() throws Exception {
    // given
    LPlatformClient lplatformClient = prepareLPlatformClient();
    HashMap<String, String> request = prepareRequest("GetLServerConfiguration");
    XMLConfiguration xMLConfiguration = mock(XMLConfiguration.class);
    SubnodeConfiguration config = mock(SubnodeConfiguration.class);
    when(config.getString(eq(VMTYPE))).thenReturn(VMTYPE);
    when(xMLConfiguration.configurationAt(eq("lserver")))
            .thenReturn(config);
    when(vdcClient.execute(eq(request))).thenReturn(xMLConfiguration);

    // when
    prepareLServerClient(lplatformClient);
    LServerConfiguration result = lServerClient.getConfiguration();

    // then
    assertEquals(result.getVmType(), VMTYPE);
}
 
Example #2
Source File: CassiniTerminalDevicePowerConfigExt.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Execute RPC request.
 * @param session Netconf session
 * @param message Netconf message in XML format
 * @return XMLConfiguration object
 */
private XMLConfiguration executeRpc(NetconfSession session, String message) {
    try {
        CompletableFuture<String> fut = session.rpc(message);
        String rpcReply = fut.get();
        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());
        return xconf;
    } catch (NetconfException ne) {
        log.error("Exception on Netconf protocol: {}.", ne);
    } catch (InterruptedException ie) {
        log.error("Interrupted Exception: {}.", ie);
    } catch (ExecutionException ee) {
        log.error("Concurrent Exception while executing Netconf operation: {}.", ee);
    }
    return null;
}
 
Example #3
Source File: ConfigurableIngestTopology.java    From cognition with Apache License 2.0 6 votes vote down vote up
/**
 * This class takes an XML configuration and builds and submits a storm topology.
 *
 * @throws org.apache.commons.configuration.ConfigurationException
 * @throws ConfigurationException
 */
public static void main(String[] args) throws Exception {
  // using config file
  if (args.length != 1) {
    System.err.println("usage: xmlConfigFile");
    System.exit(1);
  }
  XMLConfiguration conf = new XMLConfiguration(args[0]);

  ConfigurableIngestTopology topology = new ConfigurableIngestTopology();
  topology.configure(conf);

  boolean doLocalSubmit = conf.getBoolean(DO_LOCAL_SUBMIT, DO_LOCAL_SUBMIT_DEFAULT);
  if (doLocalSubmit)
    topology.submitLocal(new LocalCluster());
  else
    topology.submit();
}
 
Example #4
Source File: AdvaTerminalDeviceDiscovery.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: InternalMetaAnalysisSettings.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
public void parse(String settings, String texttoreplace, String replacetextwith) {
    try {
        config = new XMLConfiguration(settings);

        nrPermutations = config.getInt("defaults.permutations", 0);
        startPermutations = config.getInt("defaults.startpermutation", 0);
        output = config.getString("defaults.output");
        probeToFeature = config.getString("defaults.probeToFeature");
        datasetname = config.getString("defaults.dataset.name");  // see if a dataset is defined
        datasetPrefix = config.getString("defaults.dataset.prefix");  // see if a dataset is defined
        zScoreMergeOption = config.getString("defaults.zScoreMerge").toLowerCase();
        if (datasetPrefix == null) {
            datasetPrefix = "Dataset";
        }
        String datasetloc = config.getString("defaults.dataset.location");  // see if a dataset is defined
        if (texttoreplace != null && replacetextwith != null && datasetloc.contains(texttoreplace)) {
            datasetloc = datasetloc.replace(texttoreplace, replacetextwith);
        }
        datasetlocation = datasetloc;
        
        // parse datasets
    } catch (ConfigurationException e) {
    
    }
}
 
Example #6
Source File: IdentityApplicationManagementServiceClient.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
private String getIdToken(String compositeAppId, String consumerKey, String consumerSecret) throws OAuthSystemException, OAuthProblemException {
    XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
    String hostname = conf.getString("autoscaler.identity.hostname", "localhost");
    int port = conf.getInt("autoscaler.cloudController.port", AutoscalerConstants.IS_DEFAULT_PORT);
    String tokenEndpoint = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.TOKEN_ENDPOINT_SFX;
    OAuthClientRequest accessRequest = OAuthClientRequest.tokenLocation(tokenEndpoint)
            .setGrantType(GrantType.CLIENT_CREDENTIALS)
            .setClientId(consumerKey)
            .setClientSecret(consumerSecret)
            .setScope(compositeAppId)
            .buildBodyMessage();
    OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

    OAuthClientResponse oAuthResponse = oAuthClient.accessToken(accessRequest);
    return oAuthResponse.getParam(ID_TOKEN);
}
 
Example #7
Source File: RORClient.java    From development with Apache License 2.0 6 votes vote down vote up
public List<String> listServerTypes() throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.LIST_SERVER_TYPE);
	XMLConfiguration response = execute(request);
	List<String> result = new LinkedList<String>();
	if (response != null) {
		List<HierarchicalConfiguration> types = response
				.configurationsAt("servertypes.servertype");
		for (HierarchicalConfiguration type : types) {
			String name = type.getString("name");
			if (name != null && name.trim().length() > 0) {
				result.add(name);
			}
		}
	}
	return result;
}
 
Example #8
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 #9
Source File: Configuration.java    From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #10
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 #11
Source File: ElasticSearchJsonBoltTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigureFieldTypeMapping() throws Exception {
    URL resource = getResource("configureFieldTypeMapping.xml");
    XMLConfiguration conf = new XMLConfiguration(resource);
    bolt.configureFieldTypeMapping(conf.subset("fieldTypeMapping"));

    assertThat(bolt.fieldTypeMappings.size(), is(2));
    Map<String, String> geo_coordinates = bolt.fieldTypeMappings.get("geo_coordinates");
    assertThat(geo_coordinates.get(ElasticSearchJsonBolt.FIELD_NAME), is("geo_coordinates"));
    assertThat(geo_coordinates.get(ElasticSearchJsonBolt.FIELD_TYPE), is("array"));
}
 
Example #12
Source File: LPlatformClientTest.java    From development with Apache License 2.0 5 votes vote down vote up
private void PrepareSubnodeConfiguration(HashMap<String, String> request)
        throws Exception {
    XMLConfiguration xMLConfiguration = mock(XMLConfiguration.class);
    SubnodeConfiguration config = mock(SubnodeConfiguration.class);
    when(config.getString(eq(LPLATFORMID))).thenReturn(LPLATFORMID);

    when(xMLConfiguration.configurationAt(eq(LPLATFORM)))
            .thenReturn(config);
    when(rorClient.execute(eq(request))).thenReturn(xMLConfiguration);
}
 
Example #13
Source File: YangXmlUtilsTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    assertTrue("No resource for test", YangXmlUtilsTest.class.
            getResourceAsStream("/of-config/of-config.xml") != null);
    utils = new YangXmlUtilsAdap();

    testCreateConfig = new XMLConfiguration();
}
 
Example #14
Source File: OpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param cfg tree where the root node is {@literal <data>}
 * @return List of ports
 */
@VisibleForTesting
protected List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());

    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
    return components.stream()
        .map(this::toPortDescription)
        .filter(Objects::nonNull)
        .collect(Collectors.toList());
}
 
Example #15
Source File: MonetaConfiguration.java    From moneta with Apache License 2.0 5 votes vote down vote up
protected void gatherKeyFields(XMLConfiguration config, Topic topic) {
	int nbrKeyFields = 0;
	Object temp = config.getList("Topics.Topic.PrimaryKey.Field[@name]");
	if (temp instanceof Collection) {
		nbrKeyFields = ((Collection)temp).size();
	}
	
	String name, typeStr;
	TopicKeyField.DataType dataType;
	TopicKeyField keyField;
	for (int i = 0; i < nbrKeyFields; i++) {
		name=config.getString("Topics.Topic.PrimaryKey.Field(" + i + ")[@name]");
		typeStr=config.getString("Topics.Topic.PrimaryKey.Field(" + i + ")[@type]");
		if (StringUtils.isEmpty(name) || StringUtils.isEmpty(typeStr)) {
			throw new MonetaException("Topic Primary Key Fields fields must have both name and type specified")
				.addContextValue("topic", topic.getTopicName())
				.addContextValue("name", name)
				.addContextValue("type", typeStr);
		}
		try {dataType = TopicKeyField.DataType.valueOf(typeStr.toUpperCase());}
		catch (Exception e) {
			throw new MonetaException("Datatype not supported", e)
				.addContextValue("topic", topic.getTopicName())
				.addContextValue("key field", name)
				.addContextValue("dataType", typeStr);
		}
		
		keyField = new TopicKeyField();
		topic.getKeyFieldList().add(keyField);
		keyField.setColumnName(name);
		keyField.setDataType(dataType);
	}
}
 
Example #16
Source File: ElasticSearchJsonBoltTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigure() throws Exception {
    URL resource = getResource("config.xml");
    
    XMLConfiguration conf = new XMLConfiguration(resource);
    bolt.configure(conf);

    assertNotNull(bolt.timeSeriesIndexFieldName);
    assertThat(bolt.fieldTypeMappings.size(), is(5));
}
 
Example #17
Source File: LogTableFormatConfigView.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
private void exportToFile(File file, List<ColumnLayout> columnLayouts) throws ConfigurationException, FileNotFoundException {
  FileOutputStream out = null;
  try {
    final XMLConfiguration xmlConfiguration = new XMLConfiguration();
    saveColumnLayouts(columnLayouts, xmlConfiguration);
    out = new FileOutputStream(file);
    xmlConfiguration.save(out);
    otrosApplication.getStatusObserver().updateStatus(String.format("Column layouts have been exported to %s", file.getAbsolutePath()));
  } finally {
    IOUtils.closeQuietly(out);
  }
}
 
Example #18
Source File: LogTableFormatConfigView.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
private void exportToClipBoard(List<ColumnLayout> columnLayouts) throws ConfigurationException {
  final XMLConfiguration xmlConfiguration = new XMLConfiguration();
  saveColumnLayouts(columnLayouts, xmlConfiguration);
  final StringWriter writer = new StringWriter();
  xmlConfiguration.save(writer);
  StringSelection stringSelection = new StringSelection(writer.getBuffer().toString());
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  clipboard.setContents(stringSelection, null);
  otrosApplication.getStatusObserver().updateStatus("Column layouts have been exported to clipboard");
}
 
Example #19
Source File: NokiaOpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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(XMLConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());
    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
    return components.stream()
            .map(this::toPortDescriptionInternal)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #20
Source File: LogTableFormatConfigView.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
private void importFromFile(FileObject file) throws ConfigurationException, IOException {
  try (InputStream is = file.getContent().getInputStream()) {
    final XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.load(is);
    final List<ColumnLayout> columnLayouts = loadColumnLayouts(xmlConfiguration);
    importColumnLayouts(columnLayouts);
    otrosApplication.getStatusObserver().updateStatus(String.format("Column layouts have been imported from %s", file.getName().getFriendlyURI()));
  } finally {
    Utils.closeQuietly(file);
  }
}
 
Example #21
Source File: LPlatformClientTest.java    From development with Apache License 2.0 5 votes vote down vote up
private void PrepareXMLConfiguration(HashMap<String, String> request,
        String configString) throws Exception {
    XMLConfiguration xMLConfiguration = mock(XMLConfiguration.class);
    when(xMLConfiguration.getString(eq(configString))).thenReturn(
            configString);
    when(rorClient.execute(eq(request))).thenReturn(xMLConfiguration);
}
 
Example #22
Source File: AutoscalerCloudControllerClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private AutoscalerCloudControllerClient() {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(AS_CC_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(AS_CC_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);

    try {
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
        ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
        int port = conf.getInt("autoscaler.cloudController.port", AutoscalerConstants
                .CLOUD_CONTROLLER_DEFAULT_PORT);
        String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
        String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
        int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000);

        stub = new CloudControllerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,
                cloudControllerClientTimeout);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (Exception e) {
        log.error("Could not initialize cloud controller client", e);
    }
}
 
Example #23
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 #24
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 #25
Source File: OAuthAdminServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public static OAuthAdminServiceClient getServiceClient() throws AxisFault {
    if (serviceClient == null) {
        synchronized (OAuthAdminServiceClient.class) {
            if (serviceClient == null) {
                XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
                String hostname = conf.getString("autoscaler.identity.hostname", "localhost");
                int port = conf.getInt("autoscaler.cloudController.port", AutoscalerConstants.IS_DEFAULT_PORT);
                String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.OAUTH_SERVICE_SFX;
                serviceClient = new OAuthAdminServiceClient(epr);
            }
        }
    }
    return serviceClient;
}
 
Example #26
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 #27
Source File: RORClient.java    From development with Apache License 2.0 5 votes vote down vote up
private void getRespStream(XMLConfiguration result, GetMethod get)
		throws ConfigurationException, IOException {
	InputStream in = null;
	try {
		in = get.getResponseBodyAsStream();
		result.load(in);
	} finally {
		if (in != null) {
			in.close();
		}
	}

}
 
Example #28
Source File: ConfigurableIngestTopologyTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigureTickFrequency(
    @Injectable BoltDeclarer boltDeclarer) throws Exception {
  URL resource = TestResourceUtils.getResource(this.getClass(), "tick-frequency-config.xml");
  XMLConfiguration conf = new XMLConfiguration(resource);
  new Expectations() {{
    boltDeclarer.addConfiguration(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, "30");
  }};
  topology.configureTickFrequency(conf, boltDeclarer);
}
 
Example #29
Source File: ConfigurableIngestTopologyTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTopologyName() throws Exception {
  URL resource = TestResourceUtils.getResource(this.getClass(), "topology-config.xml");
  XMLConfiguration conf = new XMLConfiguration(resource);

  assertThat(topology.getTopologyName(conf), is("TestTopology"));
}
 
Example #30
Source File: ZteDeviceDiscoveryImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId deviceId = handler().data().deviceId();
    log.info("Discovering ZTE device {}", deviceId);

    NetconfController controller = handler().get(NetconfController.class);
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();

    String hwVersion = "ZTE hw";
    String swVersion = "ZTE sw";
    String serialNumber = "000000000000";

    try {
        String reply = session.requestSync(buildDeviceInfoRequest());
        XMLConfiguration cfg = (XMLConfiguration) XmlConfigParser.loadXmlString(getDataOfRpcReply(reply));
        hwVersion = cfg.getString("components.component.state.hardware-version");
        swVersion = cfg.getString("components.component.state.software-version");
        serialNumber = cfg.getString("components.component.state.serial-no");
    } catch (NetconfException e) {
        log.error("ZTE device discovery error.", e);
    }

    return new DefaultDeviceDescription(deviceId.uri(),
            Device.Type.OTN,
            "ZTE",
            hwVersion,
            swVersion,
            serialNumber,
            new ChassisId(1));
}