Java源码示例:org.apache.commons.configuration.Configuration

示例1
/**
 * @param config configuration for initializing resource manager
 */
public ResourceManager(Configuration config) {
  numQueryRunnerThreads = config.getInt(QUERY_RUNNER_CONFIG_KEY, DEFAULT_QUERY_RUNNER_THREADS);
  numQueryWorkerThreads = config.getInt(QUERY_WORKER_CONFIG_KEY, DEFAULT_QUERY_WORKER_THREADS);

  LOGGER.info("Initializing with {} query runner threads and {} worker threads", numQueryRunnerThreads,
      numQueryWorkerThreads);
  // pqr -> pinot query runner (to give short names)
  ThreadFactory queryRunnerFactory =
      new ThreadFactoryBuilder().setDaemon(false).setPriority(QUERY_RUNNER_THREAD_PRIORITY).setNameFormat("pqr-%d")
          .build();
  queryRunners =
      MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryRunnerThreads, queryRunnerFactory));

  // pqw -> pinot query workers
  ThreadFactory queryWorkersFactory =
      new ThreadFactoryBuilder().setDaemon(false).setPriority(Thread.NORM_PRIORITY).setNameFormat("pqw-%d").build();
  queryWorkers =
      MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryWorkerThreads, queryWorkersFactory));
}
 
示例2
public void validateBindingTemplates(EntityManager em, org.uddi.api_v3.BindingTemplates bindingTemplates,
        org.uddi.api_v3.BusinessService parent, Configuration config, UddiEntityPublisher publisher)
        throws DispositionReportFaultMessage {
        // Binding templates is optional
        if (bindingTemplates == null) {
                return;
        }

        List<org.uddi.api_v3.BindingTemplate> bindingTemplateList = bindingTemplates.getBindingTemplate();
        if (bindingTemplateList == null || bindingTemplateList.size() == 0) {
                throw new ValueNotAllowedException(new ErrorMessage("errors.bindingtemplates.NoInput"));
        }

        for (org.uddi.api_v3.BindingTemplate bindingTemplate : bindingTemplateList) {
                validateBindingTemplate(em, bindingTemplate, parent, config, publisher);
        }

}
 
示例3
public CustomBenchmark(String type, String platformName,
                       Path baseReportDir, Path baseOutputDir, Path baseValidationDir,
                       Map<String, Graph> foundGraphs, Map<String, Map<Algorithm, AlgorithmParameters>> algorithmParameters) {

    super(platformName, true, true,
            baseReportDir, baseOutputDir, baseValidationDir,
            foundGraphs, algorithmParameters);
    this.baseReportDir = formatReportDirectory(baseReportDir, platformName, type);
    this.type = type;

    Configuration benchmarkConfiguration = ConfigurationUtil.loadConfiguration(BENCHMARK_PROPERTIES_FILE);
    this.timeout = ConfigurationUtil.getInteger(benchmarkConfiguration, BENCHMARK_RUN_TIMEOUT_KEY);

    this.validationRequired = ConfigurationUtil.getBoolean(benchmarkConfiguration, BENCHMARK_RUN_VALIDATION_REQUIRED_KEY);
    this.outputRequired = ConfigurationUtil.getBoolean(benchmarkConfiguration, BENCHMARK_RUN_OUTPUT_REQUIRED_KEY);
    this.isWriteResultsDirectlyEnabled = ConfigurationUtil.getBooleanIfExists(benchmarkConfiguration, BENCHMARK_WRITE_RESULT_AFTER_EACH_JOB);

    if (this.validationRequired && !this.outputRequired) {
        LOG.warn("Validation can only be enabled if output is generated. "
                + "Please enable the key " + BENCHMARK_RUN_OUTPUT_REQUIRED_KEY + " in your configuration.");
        LOG.info("Validation will be disabled for all benchmarks.");
        this.validationRequired = false;
    }

}
 
示例4
@Override
public void init(Configuration config) {
  Preconditions.checkArgument(!isNullOrEmpty(config.getString(REGION)));
  String region = config.getString(REGION);

  AwsCredentialsProvider awsCredentialsProvider;
  try {

    if (!isNullOrEmpty(config.getString(ACCESS_KEY)) && !isNullOrEmpty(config.getString(SECRET_KEY))) {
      String accessKey = config.getString(ACCESS_KEY);
      String secretKey = config.getString(SECRET_KEY);
      AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(accessKey, secretKey);
      awsCredentialsProvider = StaticCredentialsProvider.create(awsBasicCredentials);
    } else {
      awsCredentialsProvider =
          AwsCredentialsProviderChain.builder().addCredentialsProvider(SystemPropertyCredentialsProvider.create())
              .addCredentialsProvider(EnvironmentVariableCredentialsProvider.create()).build();
    }

    _s3Client = S3Client.builder().region(Region.of(region)).credentialsProvider(awsCredentialsProvider).build();
  } catch (S3Exception e) {
    throw new RuntimeException("Could not initialize S3PinotFS", e);
  }
}
 
示例5
public void validateCategoryBag(org.uddi.api_v3.CategoryBag categories, Configuration config, boolean isRoot) throws DispositionReportFaultMessage {

                // Category bag is optional
                if (categories == null) {
                        return;
                }

                // If category bag does exist, it must have at least one element
                List<KeyedReference> elems = categories.getKeyedReference();
                List<KeyedReferenceGroup> groups = categories.getKeyedReferenceGroup();
                if (groups.size() == 0 && elems.size() == 0) {
                        throw new ValueNotAllowedException(new ErrorMessage("errors.categorybag.NoInput"));
                }

                for (KeyedReferenceGroup group : groups) {
                        validateKeyedReferenceGroup(group, config, isRoot);
                }

                for (KeyedReference elem : elems) {
                        validateKeyedReference(elem, config, isRoot);
                }
        }
 
示例6
/**
 * Extracts map entries from configuration.
 *
 * @param conf
 * @param mappingEntry
 * @param fields       first field should be unique and exist in all entries, other fields are optional from map
 * @return
 */
public static Map<String, Map<String, String>> extractMapList(
    final Configuration conf,
    final String mappingEntry,
    final String... fields) {
  String keyField = fields[0];
  List<Object> keys = conf.getList(mappingEntry + "." + keyField);
  Map<String, Map<String, String>> maps = new HashMap<>(keys.size());

  for (int i = 0; i < keys.size(); i++) {
    Map<String, String> map = new HashMap<>();
    Object key = keys.get(i);
    map.put(keyField, key.toString());

    for (int j = 1; j < fields.length; j++) {
      String field = fields[j];
      String fieldPath = String.format("%s(%s).%s", mappingEntry, i, field);
      String value = conf.getString(fieldPath);
      if (value != null)
        map.put(field, value);
    }

    maps.put(key.toString(), map);
  }
  return maps;
}
 
示例7
@Test
public void testGetPropertiesWithPrefix() {
  ClassLoaderScopeContext.clearClassLoaderScopeProperty();
  Configuration configuration = ConfigUtil.createLocalConfig();

  String prefix = "service_description.properties";
  Map<String, String> expectedMap = new HashMap<>();
  expectedMap.put("key1", "value1");
  expectedMap.put("key2", "value2");
  Assert.assertEquals(expectedMap, ConfigurePropertyUtils.getPropertiesWithPrefix(configuration, prefix));

  List<BasePath> paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
  Assert.assertEquals(2, paths.size());
  Assert.assertEquals(paths.get(0).getPath(), "/test1/testpath");
  Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);

  ClassLoaderScopeContext.setClassLoaderScopeProperty(DefinitionConst.URL_PREFIX, "/webroot");
  paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
  Assert.assertEquals(2, paths.size());
  Assert.assertEquals(paths.get(0).getPath(), "/webroot/test1/testpath");
  Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);
  ClassLoaderScopeContext.clearClassLoaderScopeProperty();
}
 
示例8
@VisibleForTesting
protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) {
    int numPartitions = atlasProperties.getInt("atlas.notification.hook.numthreads", 1);
    int numReplicas = atlasProperties.getInt("atlas.notification.replicas", 1);
    AdminUtils.createTopic(zkUtils, topicName,  numPartitions, numReplicas,
            new Properties(), RackAwareMode.Enforced$.MODULE$);
    LOG.warn("Created topic {} with partitions {} and replicas {}", topicName, numPartitions, numReplicas);
}
 
示例9
@VisibleForTesting
protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) {
    int numPartitions = atlasProperties.getInt("atlas.notification.hook.numthreads", 1);
    int numReplicas = atlasProperties.getInt("atlas.notification.replicas", 1);
    AdminUtils.createTopic(zkUtils, topicName,  numPartitions, numReplicas,
            new Properties(), RackAwareMode.Enforced$.MODULE$);
    LOG.warn("Created topic {} with partitions {} and replicas {}", topicName, numPartitions, numReplicas);
}
 
示例10
/** Takes two configuration and returns their union, with the second overriding the first.
 *
 * @param base the base configuration.
 * @param additional the additional set of properties, some of which may override those specified in <code>base</code>.
 * @return the union of the two configurations, as specified above.
 */
private static Configuration append(Configuration base, Configuration additional) {
	final CompositeConfiguration result = new CompositeConfiguration();
	result.addConfiguration(additional);
	result.addConfiguration(base);
	return result;
}
 
示例11
@Override
public void importContextData(Context ctx, Configuration config) throws ConfigurationException {
    List<Object> serializedRules = config.getList(CONTEXT_CONFIG_ACCESS_RULES_RULE);
    if (serializedRules != null) {
        ContextAccessRulesManager contextManager = getContextAccessRulesManager(ctx);
        // Make sure we reload the context tree
        contextManager.reloadContextSiteTree(Model.getSingleton().getSession());
        for (Object serializedRule : serializedRules) {
            contextManager.importSerializedRule(serializedRule.toString());
        }
    }
}
 
示例12
public ControllerConf(Configuration conf) {
  super();
  Iterator<String> keysIterator = conf.getKeys();
  while(keysIterator.hasNext()) {
    String key = keysIterator.next();
    this.setProperty(key, conf.getProperty(key));
  }
}
 
示例13
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;
}
 
示例14
@Test
public void testAllCustomServerConf()
    throws Exception {
  Configuration serverConf = new BaseConfiguration();
  serverConf.addProperty(CONFIG_OF_INSTANCE_ID, CUSTOM_INSTANCE_ID);
  serverConf.addProperty(KEY_OF_SERVER_NETTY_HOST, CUSTOM_HOST);
  serverConf.addProperty(KEY_OF_SERVER_NETTY_PORT, CUSTOM_PORT);
  verifyInstanceConfig(serverConf, CUSTOM_INSTANCE_ID, CUSTOM_HOST, CUSTOM_PORT);
}
 
示例15
/**
 * 获取配置信息
 */
public static Configuration getConfig() {
    try {
        return new PropertiesConfiguration("generator.properties" );
    } catch (ConfigurationException e) {
        throw new BaseException("获取配置文件失败,", e);
    }
}
 
示例16
/**
 * Get the list of operations which are configured to be skipped from auditing
 * Valid format is HttpMethod:URL eg: GET:Version
 * @return list of string
 * @throws AtlasException
 */
public static List<String> getAuditExcludedOperations(Configuration config) throws AtlasException {
    if (config == null) {
        try {
            config = ApplicationProperties.get();
        } catch (AtlasException e) {
            LOG.error(" Error reading operations for auditing ", e);
            throw e;
        }
    }
    if (skippedOperations == null) {
        skippedOperations = new ArrayList<String>();
            String[] skipAuditForOperations = config
                    .getStringArray(AUDIT_EXCLUDED_OPERATIONS);
            if (skipAuditForOperations != null
                    && skipAuditForOperations.length > 0) {
                for (String skippedOperation : skipAuditForOperations) {
                    String[] excludedOperations = skippedOperation.trim().toLowerCase().split(SEPARATOR);
                    if (excludedOperations!= null && excludedOperations.length == 2) {
                        skippedOperations.add(skippedOperation.toLowerCase());
                    } else {
                        LOG.error("Invalid format for skipped operation {}. Valid format is HttpMethod:URL eg: GET:Version", skippedOperation);
                    }
                }
            }
    }
    return skippedOperations;
}
 
示例17
public void validateSaveService(EntityManager em, SaveService body, Configuration config, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {

                if (config == null) {
                        try {
                                config = AppConfig.getConfiguration();
                        } catch (ConfigurationException ce) {
                                log.error("Could not optain config. " + ce.getMessage(), ce);
                        }
                }
                // No null input
                if (body == null) {
                        throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
                }

                // No null or empty list
                List<org.uddi.api_v3.BusinessService> entityList = body.getBusinessService();
                if (entityList == null || entityList.size() == 0) {
                        throw new ValueNotAllowedException(new ErrorMessage("errors.saveservice.NoInput"));
                }

                for (org.uddi.api_v3.BusinessService entity : entityList) {
                        // Entity specific data validation
                        validateBusinessService(em, entity, null, config, publisher);

                }
                validateCheckedTModelsBS(entityList, config);
        }
 
示例18
private void validateHostingRedirector(EntityManager em, HostingRedirector hostingRedirector, Configuration config) throws ValueNotAllowedException {
        if (log.isDebugEnabled()) {
                log.debug("validateHostingRedirector");
        }
        if (hostingRedirector == null) {
                return;
        }

        if (hostingRedirector.getBindingKey() == null || hostingRedirector.getBindingKey().length() == 0) {
                throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.noinput"));
        }
        if (hostingRedirector.getBindingKey().length() > ValidationConstants.MAX_Key) {
                throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.TooLong"));
        }
        boolean checkRef = false;
        try {
                checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
        } catch (Exception ex) {
                log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
        }
        if (checkRef) {
                //TODO check the spec to confirm this is logically correct
    /*Object obj = em.find(org.apache.juddi.model.BindingTemplate.class, hostingRedirector.getBindingKey());
                 if (obj == null) {
                 throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.keynotexist"));
                 }*/
        }

}
 
示例19
static void validateIndexBackend(Configuration config) {
    String configuredIndexBackend = config.getString(INDEX_BACKEND_CONF);

    JanusGraphManagement managementSystem = getGraphInstance().openManagement();
    String currentIndexBackend = managementSystem.get(INDEX_BACKEND_CONF);
    managementSystem.commit();

    if (!configuredIndexBackend.equals(currentIndexBackend)) {
        throw new RuntimeException("Configured Index Backend " + configuredIndexBackend
                + " differs from earlier configured Index Backend " + currentIndexBackend + ". Aborting!");
    }

}
 
示例20
/**
 * Asserts that reading list values from a properties file works properly when the default
 * list delimiter is modified.
 */
@Test
public void testFromFile_listValuesWithDefaultDelimiterChanged() throws Exception {
  AbstractConfiguration.setDefaultListDelimiter('|');
  Configuration configuration = configurationHelper.fromFile(
      ConfigurationHelperTest.class.getResource("props/test3.properties"));
  assertPropertiesEquals(test3Properties, configuration);
  String[] stringArray = configuration.getStringArray("i.j.k");
  assertArrayEquals(new String[] {"foo", "bar"}, stringArray);
}
 
示例21
static String toString(Configuration c) {
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  try {
    PrintStream ps = new PrintStream(buffer, false, "UTF-8");
    PropertiesConfiguration tmp = new PropertiesConfiguration();
    tmp.copy(c);
    tmp.save(ps);
    return buffer.toString("UTF-8");
  } catch (Exception e) {
    throw new MetricsConfigException(e);
  }
}
 
示例22
/**
 * This method is for reference purpose only.
 */
@SuppressWarnings("UnusedReturnValue")
public static HelixServerStarter startDefault()
    throws Exception {
  Configuration serverConf = new BaseConfiguration();
  int port = 8003;
  serverConf.addProperty(KEY_OF_SERVER_NETTY_PORT, port);
  serverConf.addProperty(CONFIG_OF_INSTANCE_DATA_DIR, "/tmp/PinotServer/test" + port + "/index");
  serverConf.addProperty(CONFIG_OF_INSTANCE_SEGMENT_TAR_DIR, "/tmp/PinotServer/test" + port + "/segmentTar");
  HelixServerStarter serverStarter = new HelixServerStarter("quickstart", "localhost:2191", serverConf);
  serverStarter.start();
  return serverStarter;
}
 
示例23
public static TestPriorityScheduler create(Configuration config) {
  ResourceManager rm = new PolicyBasedResourceManager(config);
  QueryExecutor qe = new TestQueryExecutor();
  groupFactory = new TestSchedulerGroupFactory();
  MultiLevelPriorityQueue queue =
      new MultiLevelPriorityQueue(config, rm, groupFactory, new TableBasedGroupMapper());
  latestQueryTime = new LongAccumulator(Long::max, 0);
  return new TestPriorityScheduler(config, rm, qe, queue, metrics, latestQueryTime);
}
 
示例24
public static Map<String, String> getPropertiesWithPrefix(Configuration configuration, String prefix) {
  Map<String, String> propertiesMap = new HashMap<>();

  Iterator<String> keysIterator = configuration.getKeys(prefix);
  while (keysIterator.hasNext()) {
    String key = keysIterator.next();
    propertiesMap.put(key.substring(prefix.length() + 1), String.valueOf(configuration.getProperty(key)));
  }
  return propertiesMap;
}
 
示例25
/**
 * The main method.
 * 
 * @param args
 *          the arguments
 */
public static void main(String[] args) {

  List<String> tmpArgs = new ArrayList<String>(Arrays.asList(args));

  int numWorker = StormSamoaUtils.numWorkers(tmpArgs);

  args = tmpArgs.toArray(new String[0]);

  // convert the arguments into Storm topology
  StormTopology stormTopo = StormSamoaUtils.argsToTopology(args);
  String topologyName = stormTopo.getTopologyName();

  Config conf = new Config();
  // conf.putAll(Utils.readStormConfig());
  conf.setDebug(false);

  // local mode
  conf.setMaxTaskParallelism(numWorker);

  backtype.storm.LocalCluster cluster = new backtype.storm.LocalCluster();
  cluster.submitTopology(topologyName, conf, stormTopo.getStormBuilder().createTopology());

  // Read local mode execution duration from property file
  Configuration stormConfig = StormSamoaUtils.getPropertyConfig(LocalStormDoTask.SAMOA_STORM_PROPERTY_FILE_LOC);
  long executionDuration= stormConfig.getLong(LocalStormDoTask.EXECUTION_DURATION_KEY);
  backtype.storm.utils.Utils.sleep(executionDuration * 1000);

  cluster.killTopology(topologyName);
  cluster.shutdown();

}
 
示例26
@Override
protected List<String> buildCmdLine(Configuration conf) {
    String inputFile = input.getAbsolutePath();
    String outputFile = output.getAbsolutePath();
    List<String> cmdLine = super.buildCmdLine(conf);
    //cmdLine.add("-i");
    cmdLine.add(inputFile);
    //cmdLine.add("-o");
    cmdLine.add(outputFile);
    return cmdLine;
}
 
示例27
public static WorkflowOptions getOptions(Configuration config) {
    WorkflowOptions options = new WorkflowOptions();

    String materialFolderRawScan = config.getString(PROP_MATERIAL_FOLDER_RAW_SCAN);
    if (materialFolderRawScan == null) {
        materialFolderRawScan = "";
    }
    options.setRawScan(materialFolderRawScan);

    String materialFolderMasterCopy = config.getString(PROP_MATERIAL_FOLDER_MASTER_COPY);
    if (materialFolderMasterCopy == null) {
        materialFolderMasterCopy = "";
    }
    options.setMasterCopy(materialFolderMasterCopy);

    String materialFolderOcr = config.getString(PROP_MATERIAL_FOLDER_OCR);
    if (materialFolderOcr == null) {
        materialFolderOcr = "";
    }
    options.setOcr(materialFolderOcr);

    String materialFolderOcrProcess = config.getString(PROP_MATERIAL_FOLDER_OCR_IMAGE);
    if (materialFolderOcrProcess == null) {
        materialFolderOcrProcess = "";
    }
    options.setOcrImage(materialFolderOcrProcess);

    return options;
}
 
示例28
/**
 * Never publicly instantiated - only by another {@link BlazeGraphEmbedded} 
 * instance.
 */
BlazeGraphReadOnly(final BigdataSailRepository repo,
        final BigdataSailRepositoryConnection cxn,
        final Configuration config) {
    super(repo, config);
    
    this.cxn = cxn;
}
 
示例29
/**
 * Create the "the crew" graph which is a TinkerPop 3.x toy graph showcasing many 3.x features like meta-properties,
 * multi-properties and graph variables.
 */
public static TinkerGraph createTheCrew() {
    final Configuration conf = getNumberIdManagerConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name());
    final TinkerGraph g = TinkerGraph.open(conf);
    generateTheCrew(g);
    return g;
}
 
示例30
void startInternal(Configuration configuration, ExecutorService executorService) {
    if (consumers == null) {
        consumers = new ArrayList<>();
    }
    if (executorService != null) {
        executors = executorService;
    }
    if (!HAConfiguration.isHAEnabled(configuration)) {
        LOG.info("HA is disabled, starting consumers inline.");
        startConsumers(executorService);
    }
}