Java Code Examples for org.apache.commons.configuration.Configuration#getProperty()

The following examples show how to use org.apache.commons.configuration.Configuration#getProperty() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: atlas   File: AdminResource.java    License: Apache License 2.0 6 votes vote down vote up
private String getEditableEntityTypes(Configuration config) {
    String ret = DEFAULT_EDITABLE_ENTITY_TYPES;

    if (config != null && config.containsKey(editableEntityTypes)) {
        Object value = config.getProperty(editableEntityTypes);

        if (value instanceof String) {
            ret = (String) value;
        } else if (value instanceof Collection) {
            StringBuilder sb = new StringBuilder();

            for (Object elem : ((Collection) value)) {
                if (sb.length() > 0) {
                    sb.append(",");
                }

                sb.append(elem.toString());
            }

            ret = sb.toString();
        }
    }

    return ret;
}
 
Example 2
Source Project: atlas   File: GraphSandboxUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean useLocalSolr() {
    boolean ret = false;
    
    try {
        Configuration conf     = ApplicationProperties.get();
        Object        property = conf.getProperty("atlas.graph.index.search.solr.embedded");

        if (property != null && property instanceof String) {
            ret = Boolean.valueOf((String) property);
        }
    } catch (AtlasException ignored) {
        throw new SkipException("useLocalSolr: failed! ", ignored);
    }

    return ret;
}
 
Example 3
Source Project: flux   File: MigrationsRunner.java    License: Apache License 2.0 6 votes vote down vote up
public void migrate(String dbName) {
    try {
        Configuration configuration = yamlConfiguration.subset(dbName + ".Hibernate");
        Properties properties = new Properties();
        properties.put("user", configuration.getProperty("hibernate.connection.username"));
        properties.put("password", configuration.getProperty("hibernate.connection.password"));
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        String url = (String) configuration.getProperty("hibernate.connection.url");
        java.sql.Connection connection = DriverManager.getConnection(url, properties);
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource(dbName +  "/migrations.xml").getFile());
        Liquibase liquibase = new Liquibase(file.getCanonicalPath(), new FileSystemResourceAccessor(), database);
        liquibase.update(new Contexts());
    } catch (Exception e) {
        System.err.println("Unable to perform database migration.");
        e.printStackTrace();
    }
}
 
Example 4
private ZooKeeperCache getAndSetZkCache(Configuration conf) {
    ZooKeeperCache zkCache = null;
    if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
        zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
    } else {
        int zkTimeout;
        String zkServers;
        if (conf instanceof ClientConfiguration) {
            zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
            zkServers = ((ClientConfiguration) conf).getZkServers();
            try {
                ZooKeeper zkClient = ZooKeeperClient.newBuilder().connectString(zkServers)
                        .sessionTimeoutMs(zkTimeout).build();
                zkCache = new ZooKeeperCache("bookies-isolation", zkClient,
                        (int) TimeUnit.MILLISECONDS.toSeconds(zkTimeout)) {
                };
                conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
            } catch (Exception e) {
                LOG.error("Error creating zookeeper client", e);
            }
        } else {
            LOG.error("No zk configurations available");
        }
    }
    return zkCache;
}
 
Example 5
Source Project: incubator-atlas   File: AdminResource.java    License: Apache License 2.0 6 votes vote down vote up
private String getEditableEntityTypes(Configuration config) {
    String ret = DEFAULT_EDITABLE_ENTITY_TYPES;

    if (config != null && config.containsKey(editableEntityTypes)) {
        Object value = config.getProperty(editableEntityTypes);

        if (value instanceof String) {
            ret = (String) value;
        } else if (value instanceof Collection) {
            StringBuilder sb = new StringBuilder();

            for (Object elem : ((Collection) value)) {
                if (sb.length() > 0) {
                    sb.append(",");
                }

                sb.append(elem.toString());
            }

            ret = sb.toString();
        }
    }

    return ret;
}
 
Example 6
@SuppressWarnings({ "rawtypes", "unchecked" })
public static JSONObject getJSON(Configuration config) {

	JSONObject output = new JSONObject();

	if (!config.isEmpty()) {
		Iterator it = config.getKeys();
		while (it.hasNext()) {
			String k = (String) it.next();
			// noinspection unchecked
			String v = (String) config.getProperty(k);
			output.put(k, v);
		}
	}
	return output;
}
 
Example 7
Source Project: hugegraph   File: TestGraphProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Watched
@Override
public void clear(Graph graph, Configuration config) throws Exception {
    TestGraph testGraph = (TestGraph) graph;
    if (testGraph == null) {
        return;
    }
    String graphName = config.getString(CoreOptions.STORE.name());
    if (!testGraph.initedBackend()) {
        testGraph.close();
    }
    if (testGraph.closed()) {
        if (this.graphs.get(graphName) == testGraph) {
            this.graphs.remove(graphName);
        }
        return;
    }

    // Reset consumers
    graph.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.AUTO);
    graph.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK);

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

    // Clear all data
    Class<?> testClass = (Class<?>) config.getProperty(TEST_CLASS);
    testGraph.clearAll(testClass.getCanonicalName());

    LOG.debug("Clear graph '{}'", graphName);
}
 
Example 8
Source Project: atlas   File: AtlasJanusGraphDatabase.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isEmbeddedSolr() {
    boolean ret = false;

    try {
        Configuration conf     = ApplicationProperties.get();
        Object        property = conf.getProperty("atlas.graph.index.search.solr.embedded");

        if (property != null && property instanceof String) {
            ret = Boolean.valueOf((String) property);
        }
    } catch (AtlasException ignored) { }

    return ret;
}
 
Example 9
@Override
public boolean isValidSource(Configuration localConfiguration) {
  if (localConfiguration.getProperty(APOLLO_CONFIG_URL_KEY) == null) {
    LOGGER.warn("Apollo configuration source is not configured!");
    return false;
  }
  return true;
}
 
Example 10
@Override
public boolean isValidSource(Configuration localConfiguration) {
  if (localConfiguration.getProperty(KIE_CONFIG_URL_KEY) == null) {
    LOGGER.warn("Kie configuration source is not configured!");
    return false;
  }
  return true;
}
 
Example 11
@Override
public boolean isValidSource(Configuration localConfiguration) {
  if (localConfiguration.getProperty(SERVER_ADDR) == null) {
    LOGGER.warn("Nacos configuration source is not configured!");
    return false;
  }
  return true;
}
 
Example 12
public static Object getProperty(Object config, String key) {
  if (null != config && Configuration.class.isInstance(config)) {
    Configuration configuration = (Configuration) config;
    return configuration.getProperty(key);
  }
  return null;
}
 
Example 13
@Override
public boolean isValidSource(Configuration localConfiguration) {
  if (localConfiguration.getProperty("cse.config.client.serverUri") == null) {
    return false;
  }
  return true;
}
 
Example 14
private ZooKeeperDataCache<BookiesRackConfiguration> getAndSetZkCache(Configuration conf) {
    ZooKeeperCache zkCache = null;
    if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
        zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
    } else {
        int zkTimeout;
        String zkServers;
        if (conf instanceof ClientConfiguration) {
            zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
            zkServers = ((ClientConfiguration) conf).getZkServers();
            try {
                ZooKeeper zkClient = ZooKeeperClient.newBuilder().connectString(zkServers)
                        .sessionTimeoutMs(zkTimeout).build();
                zkCache = new ZooKeeperCache("bookies-racks", zkClient,
                        (int) TimeUnit.MILLISECONDS.toSeconds(zkTimeout)) {
                };
                conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
            } catch (Exception e) {
                LOG.error("Error creating zookeeper client", e);
            }
        } else {
            LOG.error("No zk configurations available");
        }
    }
    ZooKeeperDataCache<BookiesRackConfiguration> zkDataCache = getZkBookieRackMappingCache(
            zkCache);
    zkDataCache.registerListener(this);
    return zkDataCache;
}
 
Example 15
Source Project: incubator-pinot   File: PinotFSFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static void init(Configuration fsConfig) {
  // Get schemes and their respective classes
  Iterator<String> keys = fsConfig.subset(CLASS).getKeys();
  if (!keys.hasNext()) {
    LOGGER.info("Did not find any fs classes in the configuration");
  }
  while (keys.hasNext()) {
    String key = keys.next();
    String fsClassName = (String) fsConfig.getProperty(CLASS + "." + key);
    LOGGER.info("Got scheme {}, classname {}, starting to initialize", key, fsClassName);
    register(key, fsClassName, fsConfig.subset(key));
  }
}
 
Example 16
/**
 * Initializes map of crypter classes at startup time. Will initialize map with lower case simple class names.
 * @param config
 * Sample configuration:
 * class.nooppinotcrypter = org.apache.pinot.core.crypt.NoOpPinotCrypter
 * nooppinotcrypter.keyMap = sample_key
 */
public static void init(Configuration config) {
  // Get schemes and their respective classes
  Iterator<String> keys = config.subset(CLASS).getKeys();
  if (!keys.hasNext()) {
    LOGGER.info("Did not find any crypter classes in the configuration");
  }
  while (keys.hasNext()) {
    String key = keys.next();
    String className = (String) config.getProperty(CLASS + "." + key);
    LOGGER.info("Got crypter class name {}, full crypter path {}, starting to initialize", key, className);

    try {
      PinotCrypter pinotCrypter = PluginManager.get().createInstance(className);
      pinotCrypter.init(config.subset(key));
      LOGGER.info("Initializing PinotCrypter for scheme {}, classname {}", key, className);
      _crypterMap.put(key.toLowerCase(), pinotCrypter);
    } catch (Exception e) {
      LOGGER.error("Could not instantiate crypter for class {}", className, e);
      throw new RuntimeException(e);
    }
  }

  if (!_crypterMap.containsKey(NOOP_PINOT_CRYPTER)) {
    LOGGER.info("NoOpPinotCrypter not configured, adding as default");
    _crypterMap.put(NOOP_PINOT_CRYPTER, new NoOpPinotCrypter());
  }
}
 
Example 17
Source Project: jbake   File: DefaultJBakeConfiguration.java    License: MIT License 5 votes vote down vote up
public Object getAsciidoctorOption(String optionKey) {
    Configuration subConfig = compositeConfiguration.subset(JBakeProperty.ASCIIDOCTOR_OPTION);
    Object value = subConfig.getProperty(optionKey);

    if (value == null) {
        logger.warn("Cannot find asciidoctor option '{}.{}'", JBakeProperty.ASCIIDOCTOR_OPTION, optionKey);
        return "";
    }
    return value;
}
 
Example 18
Source Project: hugegraph   File: TestGraphProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Watched
@Override
public Graph openTestGraph(final Configuration config) {
    String graphName = config.getString(CoreOptions.STORE.name());
    Class<?> testClass = (Class<?>) config.getProperty(TEST_CLASS);
    String testMethod = config.getString(TEST_METHOD);

    TestGraph testGraph = this.graphs.get(graphName);
    if (testGraph == null) {
        this.graphs.putIfAbsent(graphName, this.newTestGraph(config));
    } else if (testGraph.closed()) {
        this.graphs.put(graphName, this.newTestGraph(config));
    }
    testGraph = this.graphs.get(graphName);

    // Ensure tx clean
    testGraph.tx().rollback();

    // Define property key 'aKey' based on specified type in test name
    String aKeyType = getAKeyType(testClass, testMethod);
    if (aKeyType != null) {
        testGraph.initPropertyKey("aKey", aKeyType);
    }

    if (testMethod.equals(
        "shouldHaveTruncatedStringRepresentationForEdgeProperty")) {
        testGraph.initPropertyKey("long", "String");
    } else {
        testGraph.initPropertyKey("long", "Long");
    }

    // Basic schema is initiated by default once a graph is open
    testGraph.initBasicSchema(idStrategy(config), TestGraph.DEFAULT_VL);
    if (testClass.getName().equals(
        "org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest$Traversals")) {
        testGraph.initEdgeLabelPersonKnowsPerson();
        testGraph.initEdgeLabelPersonCreatedSoftware();
    } else {
        testGraph.initEdgeLabelDefaultKnowsDefault(TestGraph.DEFAULT_VL);
        testGraph.initEdgeLabelDefaultCreatedDefault(TestGraph.DEFAULT_VL);
    }
    testGraph.tx().commit();

    testGraph.loadedGraph(getIoType(testClass, testMethod));
    testGraph.autoPerson(false);
    testGraph.ioTest(isIoTest(testClass));

    Object loadGraph = config.getProperty(LOAD_GRAPH);
    if (loadGraph != null && !graphName.endsWith(STANDARD)) {
        this.loadGraphData(testGraph, (LoadGraphWith.GraphData) loadGraph);
    }

    // Used for travis ci output log
    if (LOG_RATE_LIMITER.tryAcquire(1)) {
        LOG.info("Open graph '{}' for test '{}'", graphName, testMethod);
    }
    return testGraph;
}