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

The following examples show how to use org.apache.commons.configuration.Configuration#containsKey() . 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: AdminResource.java    From atlas with 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 File: HAConfiguration.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static ZookeeperProperties getZookeeperProperties(Configuration configuration) {
    String[] zkServers;
    if (configuration.containsKey(HA_ZOOKEEPER_CONNECT)) {
        zkServers = configuration.getStringArray(HA_ZOOKEEPER_CONNECT);
    } else {
        zkServers = configuration.getStringArray("atlas.kafka." + ZOOKEEPER_PREFIX + "connect");
    }

    String zkRoot = configuration.getString(ATLAS_SERVER_HA_ZK_ROOT_KEY, ATLAS_SERVER_ZK_ROOT_DEFAULT);
    int retriesSleepTimeMillis = configuration.getInt(HA_ZOOKEEPER_RETRY_SLEEPTIME_MILLIS,
            DEFAULT_ZOOKEEPER_CONNECT_SLEEPTIME_MILLIS);

    int numRetries = configuration.getInt(HA_ZOOKEEPER_NUM_RETRIES, DEFAULT_ZOOKEEPER_CONNECT_NUM_RETRIES);

    int sessionTimeout = configuration.getInt(HA_ZOOKEEPER_SESSION_TIMEOUT_MS,
            DEFAULT_ZOOKEEPER_SESSION_TIMEOUT_MILLIS);

    String acl = configuration.getString(HA_ZOOKEEPER_ACL);
    String auth = configuration.getString(HA_ZOOKEEPER_AUTH);

    return new ZookeeperProperties(StringUtils.join(zkServers, ','),
                                   zkRoot,
                                   retriesSleepTimeMillis, numRetries,
                                   sessionTimeout, acl, auth);
}
 
Example 3
Source File: AdminResource.java    From incubator-atlas with 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 4
Source File: HAConfiguration.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static ZookeeperProperties getZookeeperProperties(Configuration configuration) {
    String zookeeperConnectString = configuration.getString("atlas.kafka." + ZOOKEEPER_PREFIX + "connect");
    if (configuration.containsKey(HA_ZOOKEEPER_CONNECT)) {
        zookeeperConnectString = configuration.getString(HA_ZOOKEEPER_CONNECT);
    }

    String zkRoot = configuration.getString(ATLAS_SERVER_HA_ZK_ROOT_KEY, ATLAS_SERVER_ZK_ROOT_DEFAULT);
    int retriesSleepTimeMillis = configuration.getInt(HA_ZOOKEEPER_RETRY_SLEEPTIME_MILLIS,
            DEFAULT_ZOOKEEPER_CONNECT_SLEEPTIME_MILLIS);

    int numRetries = configuration.getInt(HA_ZOOKEEPER_NUM_RETRIES, DEFAULT_ZOOKEEPER_CONNECT_NUM_RETRIES);

    int sessionTimeout = configuration.getInt(HA_ZOOKEEPER_SESSION_TIMEOUT_MS,
            DEFAULT_ZOOKEEPER_SESSION_TIMEOUT_MILLIS);

    String acl = configuration.getString(HA_ZOOKEEPER_ACL);
    String auth = configuration.getString(HA_ZOOKEEPER_AUTH);
    return new ZookeeperProperties(zookeeperConnectString, zkRoot, retriesSleepTimeMillis, numRetries,
            sessionTimeout, acl, auth);
}
 
Example 5
Source File: HAConfiguration.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Return whether HA is enabled or not.
 * @param configuration underlying configuration instance
 * @return
 */
public static boolean isHAEnabled(Configuration configuration) {
    boolean ret = false;

    if (configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)) {
        ret = configuration.getBoolean(ATLAS_SERVER_HA_ENABLED_KEY);
    } else {
        String[] ids = configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS);

        ret = ids != null && ids.length > 1;
    }

    return ret;
}
 
Example 6
Source File: Constants.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static String getEncodedTypePropertyKey(String defaultKey) {
    try {
        Configuration configuration = ApplicationProperties.get();

        if (configuration.containsKey("atlas.graph.index.search.backend") &&
            configuration.getString("atlas.graph.index.search.backend").equals("elasticsearch")) {

            return defaultKey.replaceAll("\\.", "_");
        }

        return encodePropertyKey(defaultKey);
    } catch (AtlasException e) {
        return encodePropertyKey(defaultKey);
    }
}
 
Example 7
Source File: HAConfiguration.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Return whether HA is enabled or not.
 * @param configuration underlying configuration instance
 * @return
 */
public static boolean isHAEnabled(Configuration configuration) {
    boolean ret = false;

    if (configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)) {
        ret = configuration.getBoolean(ATLAS_SERVER_HA_ENABLED_KEY);
    } else {
        String[] ids = configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS);

        ret = ids != null && ids.length > 1;
    }

    return ret;
}
 
Example 8
Source File: ImportProfile.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
public Configuration getThumbnailProcessor() {
    String processor = config.getString(THUMBNAIL_PROCESSOR, "-");
    String confId = PROCESSOR + "." + processor;
    Configuration subset = config.subset(confId);
    if (!subset.isEmpty() && !subset.containsKey("id")) {
        subset.addProperty("id", confId);
    }
    return subset;
}
 
Example 9
Source File: StatsSender.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
public void maybeSendStats(Window parent, Configuration configuration, Services services, String olvVersion) {
  if (configuration.getBoolean(SEND_STATS, false)) {
    final long now = System.currentTimeMillis();
    final long interval = 10L * 24 * 60 * 60 * 1000;

    if (!configuration.containsKey(NEXT_STATS_SEND_DATE)) {
      configuration.setProperty(NEXT_STATS_SEND_DATE, now + interval);
    }

    final long nextSendDate = configuration.getLong(NEXT_STATS_SEND_DATE);
    LOGGER.info("Next stats send will occur in: " + new Date(nextSendDate));

    if (now > nextSendDate) {
      configuration.setProperty(NEXT_STATS_SEND_DATE, (now + interval));
      final boolean notifyAboutStats = configuration.getBoolean(ConfKeys.SEND_STATS_NOTIFY, false);
      final Map<String, Long> stats = services.getStatsService().getStats();
      final String uuid = configuration.getString(UUID, "");
      final String javaVersion = System.getProperty("java.version", "");

      if (notifyAboutStats) {
        showDialog(parent,
          stats,
          () -> scheduleSend(services, olvVersion, stats, uuid, javaVersion),
          () -> configuration.setProperty(ConfKeys.SEND_STATS_NOTIFY, false));
      } else {
        scheduleSend(services, olvVersion, stats, uuid, javaVersion);
      }
    }
  }
}
 
Example 10
Source File: RootConfig.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ExperimentType[] getAvailableExperimentTypes() {
    Configuration config = GerbilConfiguration.getInstance();
    Set<ExperimentType> types = new HashSet<ExperimentType>();
    if (config.containsKey(AVAILABLE_EXPERIMENT_TYPES_KEY)) {
        String typeNames[] = config.getStringArray(AVAILABLE_EXPERIMENT_TYPES_KEY);
        ExperimentType type = null;
        for (int i = 0; i < typeNames.length; ++i) {
            try {
                type = ExperimentType.valueOf(typeNames[i]);
                types.add(type);
            } catch (IllegalArgumentException e) {
                LOGGER.warn(
                        "Couldn't find the experiment type \"{}\" defined in the properties file. It will be ignored.",
                        typeNames[i]);
            }
        }
    }
    if (types.size() == 0) {
        LOGGER.error(
                "Couldn't load the list of available experiment types. This GERBIL instance won't work as expected. Please define a list of experiment types using the {} key in the configuration file.",
                AVAILABLE_EXPERIMENT_TYPES_KEY);
        return new ExperimentType[0];
    } else {
        ExperimentType typesArray[] = types.toArray(new ExperimentType[types.size()]);
        Arrays.sort(typesArray);
        return typesArray;
    }
}
 
Example 11
Source File: BaseBenchmark.java    From sqlg with MIT License 5 votes vote down vote up
private Configuration getConfiguration() {
    try {
        URL sqlProperties = Thread.currentThread().getContextClassLoader().getResource("sqlg.properties");
        Configuration configuration = new PropertiesConfiguration(sqlProperties);
        if (!configuration.containsKey("jdbc.url"))
            throw new IllegalArgumentException("SqlGraph configuration requires that the jdbc.url sqlg.property be set");
        return configuration;
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source File: SqlgGraph.java    From sqlg with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <G extends Graph> G open(final Configuration configuration, final SqlgDataSource dataSource) {
    if (null == configuration) throw Graph.Exceptions.argumentCanNotBeNull("configuration");

    if (!configuration.containsKey(JDBC_URL))
        throw new IllegalArgumentException(String.format("SqlgGraph configuration requires that the %s be set", JDBC_URL));

    SqlgGraph sqlgGraph = new SqlgGraph(configuration, dataSource);
    SqlgStartupManager sqlgStartupManager = new SqlgStartupManager(sqlgGraph);
    sqlgStartupManager.loadSqlgSchema();
    sqlgGraph.buildVersion = sqlgStartupManager.getBuildVersion();
    return (G)sqlgGraph;
}
 
Example 13
Source File: ClientConfig.java    From juddi with Apache License 2.0 4 votes vote down vote up
private Map<String, UDDIClerk> readClerkConfig(Configuration config, Map<String, UDDINode> uddiNodes)
     throws ConfigurationException {
        clientName = config.getString("client[@name]");
        clientCallbackUrl = config.getString("client[@callbackUrl]");
        Map<String, UDDIClerk> clerks = new HashMap<String, UDDIClerk>();
        if (config.containsKey("client.clerks.clerk[@name]")) {
                String[] names = config.getStringArray("client.clerks.clerk[@name]");

                log.debug("clerk names=" + names.length);
                for (int i = 0; i < names.length; i++) {
                        UDDIClerk uddiClerk = new UDDIClerk();
                        uddiClerk.setManagerName(clientName);
                        uddiClerk.setName(config.getString("client.clerks.clerk(" + i + ")[@name]"));
                        String nodeRef = config.getString("client.clerks.clerk(" + i + ")[@node]");
                        if (!uddiNodes.containsKey(nodeRef)) {
                                throw new ConfigurationException("Could not find Node with name=" + nodeRef);
                        }
                        UDDINode uddiNode = uddiNodes.get(nodeRef);
                        uddiClerk.setUDDINode(uddiNode);
                        uddiClerk.setPublisher(config.getString("client.clerks.clerk(" + i + ")[@publisher]"));
                        uddiClerk.setPassword(config.getString("client.clerks.clerk(" + i + ")[@password]"));
                        uddiClerk.setIsPasswordEncrypted(config.getBoolean("client.clerks.clerk(" + i + ")[@isPasswordEncrypted]", false));
                        uddiClerk.setCryptoProvider(config.getString("client.clerks.clerk(" + i + ")[@cryptoProvider]"));

                        String clerkBusinessKey = config.getString("client.clerks.clerk(" + i + ")[@businessKey]");
                        String clerkBusinessName = config.getString("client.clerks.clerk(" + i + ")[@businessName]");
                        String clerkKeyDomain = config.getString("client.clerks.clerk(" + i + ")[@keyDomain]");

                        String[] classes = config.getStringArray("client.clerks.clerk(" + i + ").class");
                        uddiClerk.setClassWithAnnotations(classes);

                        int numberOfWslds = config.getStringArray("client.clerks.clerk(" + i + ").wsdl").length;
                        if (numberOfWslds > 0) {
                                UDDIClerk.WSDL[] wsdls = new UDDIClerk.WSDL[numberOfWslds];
                                for (int w = 0; w < wsdls.length; w++) {

                                        UDDIClerk.WSDL wsdl = new UDDIClerk.WSDL();
                                        String fileName = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")");
                                        wsdl.setFileName(fileName);
                                        if (!new File(fileName).exists()) {
                                                log.warn("The wsdl file referenced in the config at '" + fileName + "' doesn't exist!");
                                        }
                                        String businessKey = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessKey]");
                                        String businessName = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessName]");
                                        String keyDomain = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@keyDomain]");
                                        if (businessKey == null) {
                                                businessKey = clerkBusinessKey;
                                        }
                                        if (businessKey == null) {
                                                businessKey = uddiClerk.getUDDINode().getProperties().getProperty("businessKey");
                                        }
                                        if (businessKey == null) {
                                                //use key convention to build the businessKey
                                                if (businessName == null) {
                                                        businessName = clerkBusinessName;
                                                }
                                                if (keyDomain == null) {
                                                        keyDomain = clerkKeyDomain;
                                                }
                                                if (keyDomain == null) {
                                                        keyDomain = uddiClerk.getUDDINode().getProperties().getProperty("keyDomain");
                                                }
                                                if ((businessName == null && !uddiClerk.getUDDINode().getProperties().containsKey("businessName"))
                                                     || keyDomain == null && !uddiClerk.getUDDINode().getProperties().containsKey("keyDomain")) {
                                                        throw new ConfigurationException("Either the wsdl(" + wsdls[w]
                                                             + ") or clerk (" + uddiClerk.name + ") elements require a businessKey, or businessName & keyDomain attributes");
                                                } else {
                                                        Properties properties = new Properties(uddiClerk.getUDDINode().getProperties());
                                                        if (businessName != null) {
                                                                properties.put("businessName", businessName);
                                                        }
                                                        if (keyDomain != null) {
                                                                properties.put("keyDomain", keyDomain);
                                                        }
                                                        businessKey = UDDIKeyConvention.getBusinessKey(properties);
                                                }
                                        }
                                        if (!businessKey.toLowerCase().startsWith("uddi:") || !businessKey.substring(5).contains(":")) {
                                                throw new ConfigurationException("The businessKey '" + businessKey + "' does not implement a valid UDDI v3 key format. See config file at client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessKey]");
                                        }
                                        wsdl.setBusinessKey(businessKey);
                                        if (keyDomain == null) {
                                                keyDomain = businessKey.split(":")[1];
                                        }
                                        wsdl.setKeyDomain(keyDomain);
                                        wsdls[w] = wsdl;
                                }
                                uddiClerk.setWsdls(wsdls);
                        }

                        clerks.put(names[i], uddiClerk);
                }
        }
        return clerks;
}
 
Example 14
Source File: BigdataGraphConfiguration.java    From database with GNU General Public License v2.0 2 votes vote down vote up
protected BigdataGraph configure(final GraphConfigurationContext context)
        throws Exception {
    
    final Configuration config = context.getProperties();
    
    if (!config.containsKey(Options.TYPE)) {
        throw new GraphConfigurationException("missing required parameter: " + Options.TYPE);
    }
    
    final String type = config.getString(Options.TYPE).toLowerCase();
    
    if (Options.TYPE_EMBEDDED.equals(type)) {
        
        if (config.containsKey(Options.FILE)) {
        
            final String journal = config.getString(Options.FILE);
        
            return BigdataGraphFactory.open(journal, true);
            
        } else {
            
            return BigdataGraphFactory.create();
            
        }
        
    } else if (Options.TYPE_REMOTE.equals(type)) {

        if (config.containsKey(Options.SPARQL_ENDPOINT_URL)) {
            
            final String sparqlEndpointURL = config.getString(Options.SPARQL_ENDPOINT_URL);

            return BigdataGraphFactory.connect(sparqlEndpointURL);

        }
        
        if (!config.containsKey(Options.HOST)) {
            throw new GraphConfigurationException("missing required parameter: " + Options.HOST);
        }
        
        if (!config.containsKey(Options.PORT)) {
            throw new GraphConfigurationException("missing required parameter: " + Options.PORT);
        }
        
        final String host = config.getString(Options.HOST);

        final int port = config.getInt(Options.PORT);
        
        return BigdataGraphFactory.connect(host, port);
        
    } else {
        
        throw new GraphConfigurationException("unrecognized value for "
                + Options.TYPE + ": " + type);
        
    }
    
}