Example usage for org.apache.commons.configuration BaseConfiguration setProperty

List of usage examples for org.apache.commons.configuration BaseConfiguration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration BaseConfiguration setProperty.

Prototype

public void setProperty(String key, Object value) 

Source Link

Usage

From source file:org.apache.tinkerpop.gremlin.spark.structure.io.gryo.GryoSerializer.java

private static Configuration makeApacheConfiguration(final SparkConf sparkConfiguration) {
    final BaseConfiguration apacheConfiguration = new BaseConfiguration();
    apacheConfiguration.setDelimiterParsingDisabled(true);
    for (final Tuple2<String, String> tuple : sparkConfiguration.getAll()) {
        apacheConfiguration.setProperty(tuple._1(), tuple._2());
    }/*from   w  w w.  j  av a 2  s  .  co  m*/
    return apacheConfiguration;
}

From source file:org.apache.tinkerpop.gremlin.spark.structure.io.InputOutputHelper.java

public static HadoopGraph getOutputGraph(final Configuration configuration,
        final GraphComputer.ResultGraph resultGraph, final GraphComputer.Persist persist) {
    try {/*from www .  j  av a  2s. c  o  m*/
        final HadoopConfiguration hadoopConfiguration = new HadoopConfiguration(configuration);
        final BaseConfiguration newConfiguration = new BaseConfiguration();
        newConfiguration.copy(org.apache.tinkerpop.gremlin.hadoop.structure.io.InputOutputHelper
                .getOutputGraph(configuration, resultGraph, persist).configuration());
        if (resultGraph.equals(GraphComputer.ResultGraph.NEW)
                && hadoopConfiguration.containsKey(Constants.GREMLIN_SPARK_GRAPH_OUTPUT_RDD)) {
            newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_FORMAT,
                    InputRDDFormat.class.getCanonicalName());
            //newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_OUTPUT_FORMAT, OutputRDDFormat.class.getCanonicalName());
            newConfiguration.setProperty(Constants.GREMLIN_SPARK_GRAPH_INPUT_RDD,
                    InputOutputHelper
                            .getInputFormat((Class) Class.forName(
                                    hadoopConfiguration.getString(Constants.GREMLIN_SPARK_GRAPH_OUTPUT_RDD)))
                            .getCanonicalName());
        }
        return HadoopGraph.open(newConfiguration);
    } catch (final ClassNotFoundException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:org.apache.tinkerpop.gremlin.util.SystemUtil.java

/**
 * Generate a {@link Configuration} from the {@link System#getProperties}.
 * Only those properties with specified prefix key are aggregated.
 * If the prefix and a . should be removed, then trim prefix.
 *
 * @param prefix     the prefix of the keys to include in the configuration
 * @param trimPrefix whether to trim the prefix + . from the key
 * @return a configuration generated from the System properties
 *//*from   w  ww . j a va2s  . c o m*/
public static Configuration getSystemPropertiesConfiguration(final String prefix, final boolean trimPrefix) {
    final BaseConfiguration apacheConfiguration = new BaseConfiguration();
    apacheConfiguration.setDelimiterParsingDisabled(true);
    for (final Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
        final String key = entry.getKey().toString();
        final Object value = entry.getValue();
        if (key.startsWith(prefix + "."))
            apacheConfiguration.setProperty(trimPrefix ? key.substring(prefix.length() + 1) : key, value);
    }
    return apacheConfiguration;
}

From source file:org.janusgraph.diskstorage.configuration.CommonConfigTest.java

@Test
public void testDateParsing() {
    BaseConfiguration base = new BaseConfiguration();
    CommonsConfiguration config = new CommonsConfiguration(base);

    for (ChronoUnit unit : Arrays.asList(ChronoUnit.NANOS, ChronoUnit.MICROS, ChronoUnit.MILLIS,
            ChronoUnit.SECONDS, ChronoUnit.MINUTES, ChronoUnit.HOURS, ChronoUnit.DAYS)) {
        base.setProperty("test", "100 " + unit.toString());
        Duration d = config.get("test", Duration.class);
        assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(unit)), d.toNanos());
    }/*  w w w  . j a  v  a2  s .c o m*/

    Map<ChronoUnit, String> mapping = ImmutableMap.of(ChronoUnit.MICROS, "us", ChronoUnit.DAYS, "d");
    for (Map.Entry<ChronoUnit, String> entry : mapping.entrySet()) {
        base.setProperty("test", "100 " + entry.getValue());
        Duration d = config.get("test", Duration.class);
        assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(entry.getKey())), d.toNanos());
    }

}

From source file:org.janusgraph.diskstorage.configuration.converter.ReadConfigurationConverter.java

public BaseConfiguration convert(ReadConfiguration readConfiguration) {
    BaseConfiguration result = new BaseConfiguration();
    for (String k : readConfiguration.getKeys("")) {
        result.setProperty(k, readConfiguration.get(k, Object.class));
    }//from  w ww. j  a v  a 2 s  .c o m
    return result;
}

From source file:org.janusgraph.hadoop.serialize.JanusGraphKryoShimService.java

public JanusGraphKryoShimService() {
    final BaseConfiguration c = new BaseConfiguration();
    c.setProperty(IoRegistry.IO_REGISTRY, ImmutableList.of(JanusGraphIoRegistry.class.getCanonicalName()));
    HadoopPools.initialize(c);// w  w  w  .  j av a  2 s  .  c om
}

From source file:org.openecomp.sdc.asdctool.impl.GraphMLConverter.java

public String findErrorInJsonGraph(TitanGraph graph, String outputDirectory) {

    boolean runVertexScan = false;
    boolean runEdgeScan = false;

    String result = null;/*  www  .j av a 2  s  .c  o  m*/

    // GraphMLWriter graphMLWriter = new GraphMLWriter(graph);

    String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis()
            + ".json";

    OutputStream out = null;
    try {
        out = new BufferedOutputStream(new FileOutputStream(outputFile));

        if (runEdgeScan) {

            Vertex vertexFrom = null;
            Vertex vertexTo = null;
            Edge edge = null;

            // Iterable<Edge> edges = graph.getEdges();
            // Iterable<Edge> edges = graph.query().edges();
            Iterable<TitanEdge> edges = graph.query().edges();
            // Iterator<Edge> iterator = edges.iterator();
            Iterator<TitanEdge> iterator = edges.iterator();
            while (iterator.hasNext()) {

                try {

                    edge = iterator.next();

                    // vertexFrom = edge.getVertex(Direction.OUT);
                    // vertexTo = edge.getVertex(Direction.IN);
                    vertexFrom = edge.outVertex();
                    vertexTo = edge.inVertex();

                    BaseConfiguration conf = new BaseConfiguration();
                    conf.setProperty("storage.backend", "inmemory");
                    TitanGraph openGraph = Utils.openGraph(conf);

                    TitanVertex addVertexFrom = openGraph.addVertex();
                    // ElementHelper.setProperties(addVertexFrom,
                    // ElementHelper.getProperties(vertexFrom));
                    Utils.setProperties(addVertexFrom, Utils.getProperties(vertexFrom));

                    TitanVertex addVertexTo = openGraph.addVertex();
                    // ElementHelper.setProperties(addVertexTo,
                    // ElementHelper.getProperties(vertexTo));
                    Utils.setProperties(addVertexTo, Utils.getProperties(vertexTo));

                    // Edge addEdge = openGraph.addEdge(null, addVertexFrom,
                    // addVertexTo, edge.getLabel());

                    // Edge edge = tGraph.addEdge(null,
                    // fromV.left().value(), toV.left().value(), type);

                    Edge addEdge = addVertexFrom.addEdge(edge.label(), addVertexTo);
                    // ElementHelper.setProperties(addEdge,
                    // ElementHelper.getProperties(edge));
                    Utils.setProperties(addEdge, Utils.getProperties(edge));

                    // log.info("fromVertex=" +
                    // ElementHelper.getProperties(vertexFrom));
                    log.info("fromVertex=" + Utils.getProperties(vertexFrom));
                    // log.info("toVertex=" +
                    // ElementHelper.getProperties(vertexTo));
                    log.info("toVertex=" + Utils.getProperties(vertexTo));
                    // log.info("edge=" + edge.getLabel() + " " +
                    // ElementHelper.getProperties(edge));
                    log.info("edge=" + edge.label() + " " + Utils.getProperties(edge));

                    // GraphSONWriter.outputGraph(openGraph, outputFile);
                    GraphSONWriter create = GraphSONWriter.build().create();
                    create.writeGraph(out, openGraph);

                    // openGraph.rollback();
                    openGraph.tx().rollback();

                } catch (Exception e) {
                    e.printStackTrace();

                    // log.error("fromVertex=" +
                    // ElementHelper.getProperties(vertexFrom));
                    log.error("fromVertex=" + Utils.getProperties(vertexFrom));
                    // log.error("toVertex=" +
                    // ElementHelper.getProperties(vertexTo));
                    log.error("toVertex=" + Utils.getProperties(vertexTo));
                    // log.error("edge=" + edge.getLabel() + " " +
                    // ElementHelper.getProperties(edge));
                    log.error("edge=" + edge.label() + " " + Utils.getProperties(edge));

                    break;

                }
            }

            // graph.rollback();
            graph.tx().rollback();

        }

        if (runVertexScan) {

            Vertex vertex = null;
            // Iterable<Vertex> vertices = graph.getVertices();

            // Iterator<Vertex> iteratorVertex = vertices.iterator();
            Iterator<Vertex> iteratorVertex = graph.vertices();
            while (iteratorVertex.hasNext()) {

                try {

                    vertex = iteratorVertex.next();

                    // Iterable<Edge> edges2 =
                    // vertex.getEdges(Direction.BOTH);

                    // Iterator<Edge> iterator2 = edges2.iterator();
                    Iterator<Edge> iterator2 = vertex.edges(Direction.BOTH);
                    if (false == iterator2.hasNext()) {

                        BaseConfiguration conf = new BaseConfiguration();
                        conf.setProperty("storage.backend", "inmemory");
                        TitanGraph openGraph = Utils.openGraph(conf);

                        TitanVertex addVertexFrom = openGraph.addVertex();
                        // ElementHelper.setProperties(addVertexFrom,
                        // ElementHelper.getProperties(vertex));
                        Utils.setProperties(addVertexFrom, Utils.getProperties(vertex));

                        // log.info("fromVertex=" +
                        // ElementHelper.getProperties(addVertexFrom));
                        log.info("fromVertex=" + Utils.getProperties(addVertexFrom));

                        // GraphSONWriter.outputGraph(openGraph,
                        // outputFile);
                        GraphSONWriter create = GraphSONWriter.build().create();
                        create.writeGraph(out, openGraph);

                        // openGraph.rollback();
                        openGraph.tx().rollback();

                    }

                } catch (Exception e) {
                    e.printStackTrace();

                    // log.error("vertex=" +
                    // ElementHelper.getProperties(vertex));

                    GraphPropertiesDictionary[] values = GraphPropertiesDictionary.values();

                    // Object property1 =
                    // vertex.getProperty(GraphPropertiesDictionary.HEALTH_CHECK.getProperty());
                    Object property1 = vertex.value(GraphPropertiesDictionary.HEALTH_CHECK.getProperty());
                    System.out.println(property1);

                    // Object property2 = vertex.getProperty("healthcheck");
                    Object property2 = vertex.value("healthcheck");
                    System.out.println(property2);

                    // for (GraphPropertiesDictionary value : values) {
                    //
                    // System.out.println(property);
                    // }

                    break;

                }
            }

            // graph.rollback();
            graph.tx().rollback();

        }

        // Iterable<Vertex> vertices2 =
        // graph.getVertices(GraphPropertiesDictionary.HEALTH_CHECK.getProperty(),
        // "GOOD");
        Iterable<TitanVertex> vertices2 = graph.query()
                .has(GraphPropertiesDictionary.HEALTH_CHECK.getProperty(), "GOOD").vertices();
        ;
        Vertex next = vertices2.iterator().next();

        BaseConfiguration conf = new BaseConfiguration();
        conf.setProperty("storage.backend", "inmemory");
        TitanGraph openGraph = Utils.openGraph(conf);

        // TitanVertex addVertexFrom = openGraph.addVertex();
        //
        // addVertexFrom.setProperty(GraphPropertiesDictionary.HEALTH_CHECK.getProperty(),
        // "GOOD");
        // addVertexFrom.setProperty("healthcheck",
        // next.getProperty("healthcheck"));
        //
        // //next.remove();
        //
        // next.removeProperty("healthcheck");
        // next.removeProperty("healthcheckis");
        //
        // next.remove();

        // GraphSONWriter.outputGraph(openGraph, outputFile);

        for (NodeTypeEnum nodeTypeEnum : NodeTypeEnum.values()) {
            removeNodesByLabel(graph, nodeTypeEnum.getName());
        }

        // GraphSONWriter.outputGraph(graph, outputFile);

        GraphSONWriter create = GraphSONWriter.build().create();
        create.writeGraph(out, graph);

        // graph.rollback();
        graph.tx().rollback();

    } catch (Exception e) {
        e.printStackTrace();
        // graph.rollback();
        graph.tx().rollback();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return result;

}

From source file:org.openecomp.sdc.be.dao.titan.TitanGraphClient.java

@PostConstruct
public TitanOperationStatus createGraph() {

    logger.info("** createGraph started **");

    if (ConfigurationManager.getConfigurationManager().getConfiguration().getTitanInMemoryGraph()) {
        BaseConfiguration conf = new BaseConfiguration();
        conf.setProperty("storage.backend", "inmemory");
        graph = TitanFactory.open(conf);

        createIndexesAndDefaults();//from w  ww. j  a  v  a 2s . co  m

        logger.info("** in memory graph created");
        return TitanOperationStatus.OK;
    } else {
        this.titanCfgFile = ConfigurationManager.getConfigurationManager().getConfiguration().getTitanCfgFile();
        if (titanCfgFile == null || titanCfgFile.isEmpty()) {
            titanCfgFile = "config/titan.properties";
        }

        // yavivi
        // In case connection failed on init time, schedule a reconnect task
        // in the BG
        TitanOperationStatus status = createGraph(titanCfgFile);
        logger.debug("Create Titan graph status {}", status);
        if (status != TitanOperationStatus.OK) {
            this.startReconnectTask();
        }

        return status;
    }
}

From source file:org.openecomp.sdc.be.resources.TitanGenericDaoTest.java

public void testStringSearch() {
    TitanGraph graph;/*from  w ww .  ja v a  2 s .  c  o m*/

    BaseConfiguration conf = new BaseConfiguration();
    conf.setProperty("storage.backend", "inmemory");
    graph = TitanFactory.open(conf);

    // TitanManagement graphMgt = graph.getManagementSystem();
    TitanManagement graphMgt = graph.openManagement();
    PropertyKey propKey = graphMgt.makePropertyKey("string1").dataType(String.class).make();
    graphMgt.buildIndex("string1", Vertex.class).addKey(propKey).unique().buildCompositeIndex();

    propKey = graphMgt.makePropertyKey("string2").dataType(String.class).make();

    // graphMgt.buildIndex("string2", Vertex.class).addKey(propKey,
    // Mapping.TEXT.getParameter()).buildMixedIndex("search");
    graphMgt.buildIndex("string2", Vertex.class).addKey(propKey).unique().buildCompositeIndex();
    graphMgt.commit();

    // TitanVertex v = graph.addVertex();
    // v.addProperty("string1", "My new String 1");
    // v.addProperty("string2", "String11");
    // graph.commit();
    //
    // v = graph.addVertex();
    // v.addProperty("string1", "my new string 1");
    // v.addProperty("string2", "string11");
    // graph.commit();
    //
    // System.out.println("First index search - case");
    //
    // Iterable<Vertex> vertices = graph.getVertices("string1", "My new
    // String 1");
    // Iterator<Vertex> iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("First index search non case");
    //
    // vertices = graph.getVertices("string1", "my new string 1");
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("Second index search case");
    //
    // vertices = graph.getVertices("string2", "String11");
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("second index search non case");
    //
    // vertices = graph.getVertices("string2", "string11");
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("Query index search case");
    // vertices = graph.query().has("string1", "My new String
    // 1").vertices();
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("Query index search non case");
    // vertices = graph.query().has("string1", "my new string
    // 1").vertices();
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }

    log.debug("**** predicat index search non case");
    Iterable<TitanVertex> vertices = graph.query().has("string1", Text.REGEX, "my new string 1").vertices();
    Iterator<TitanVertex> iter = vertices.iterator();
    while (iter.hasNext()) {
        Vertex ver = iter.next();
        // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
        log.debug("{}", titanDao.getProperties(ver));
    }

}

From source file:org.sonar.java.api.JavaUtilsTest.java

@Test
public void shouldReturnSpecifiedJavaVersion() {
    BaseConfiguration configuration = new BaseConfiguration();
    Project project = new Project("").setConfiguration(configuration);
    configuration.setProperty(JavaUtils.JAVA_SOURCE_PROPERTY, "1.4");
    configuration.setProperty(JavaUtils.JAVA_TARGET_PROPERTY, "1.6");

    assertThat(JavaUtils.getSourceVersion(project), is("1.4"));
    assertThat(JavaUtils.getTargetVersion(project), is("1.6"));
}