public static void setConfigList(String key, Enumeration<Object> enumeration) { config.clearProperty(key); List<Object> list = new ArrayList<>(); while (enumeration.hasMoreElements()) { list.add(enumeration.nextElement()); } config.addProperty(key, list); }
public static void setConfigList(String key, List<Object> list) { config.clearProperty(key); config.addProperty(key, list); }
/** * Stores the index maps for multiple star-trees into a file. */ public static void storeToFile(List<Map<IndexKey, IndexValue>> indexMaps, File indexMapFile) throws ConfigurationException { Preconditions.checkState(!indexMapFile.exists(), "Star-tree index map file already exists"); PropertiesConfiguration configuration = new PropertiesConfiguration(indexMapFile); int numStarTrees = indexMaps.size(); for (int i = 0; i < numStarTrees; i++) { Map<IndexKey, IndexValue> indexMap = indexMaps.get(i); for (Map.Entry<IndexKey, IndexValue> entry : indexMap.entrySet()) { IndexKey key = entry.getKey(); IndexValue value = entry.getValue(); configuration.addProperty(key.getPropertyName(i, OFFSET_SUFFIX), value._offset); configuration.addProperty(key.getPropertyName(i, SIZE_SUFFIX), value._size); } } configuration.save(); }
/** * Get Java Env info as string */ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN) public String getEnv() throws ConfigurationException, UnsupportedEncodingException { PropertiesConfiguration tempConfig = new PropertiesConfiguration(); OrderedProperties orderedProperties = new OrderedProperties(new TreeMap<String, String>()); // Add Java Env String content = ""; ByteArrayOutputStream baos = new ByteArrayOutputStream(); // env Map<String, String> env = System.getenv(); for (Map.Entry<String, String> entry : env.entrySet()) { orderedProperties.setProperty(entry.getKey(), entry.getValue()); } // properties Properties properties = System.getProperties(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { orderedProperties.setProperty((String) entry.getKey(), (String) entry.getValue()); } for (Map.Entry<String, String> entry : orderedProperties.entrySet()) { tempConfig.addProperty(entry.getKey(), entry.getValue()); } // do save tempConfig.save(baos); content = baos.toString("UTF-8"); return content; }
_indexDir = null; PropertiesConfiguration segmentMetadataPropertiesConfiguration = new PropertiesConfiguration(); segmentMetadataPropertiesConfiguration.addProperty(SEGMENT_CREATOR_VERSION, null); segmentMetadataPropertiesConfiguration .addProperty(SEGMENT_PADDING_CHARACTER, V1Constants.Str.DEFAULT_STRING_PAD_CHAR); segmentMetadataPropertiesConfiguration .addProperty(SEGMENT_START_TIME, Long.toString(segmentMetadata.getStartTime())); segmentMetadataPropertiesConfiguration.addProperty(SEGMENT_END_TIME, Long.toString(segmentMetadata.getEndTime())); segmentMetadataPropertiesConfiguration.addProperty(TABLE_NAME, segmentMetadata.getTableName()); segmentMetadataPropertiesConfiguration.addProperty(TIME_UNIT, timeUnit.toString()); } else { segmentMetadataPropertiesConfiguration.addProperty(TIME_UNIT, null); segmentMetadataPropertiesConfiguration.addProperty(SEGMENT_TOTAL_DOCS, segmentMetadata.getTotalRawDocs());
private void setupSequenceFileReaderConfig() { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.addProperty("secor.file.reader.writer.factory", "com.pinterest.secor.io.impl.SequenceFileReaderWriterFactory"); mConfig = new SecorConfig(properties); }
private void setupDelimitedTextFileWriterConfig() { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.addProperty("secor.file.reader.writer.factory", "com.pinterest.secor.io.impl.DelimitedTextFileReaderWriterFactory"); mConfig = new SecorConfig(properties); }
File starTreeIndexDir = new File(_segmentDirectory, STAR_TREE_TEMP_DIR); FileUtils.forceMkdir(starTreeIndexDir); _metadataProperties.addProperty(MetadataKey.STAR_TREE_COUNT, numStarTrees); List<Map<IndexKey, IndexValue>> indexMaps = new ArrayList<>(numStarTrees);
@Before public void setUp() throws Exception { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.addProperty("message.timestamp.name", ""); properties.addProperty("message.timestamp.name.separator", ""); properties.addProperty("secor.offsets.prefix", "offset="); mSecorConfig = new SecorConfig(properties); mLogFilePath = new LogFilePath("/foo", "/foo/bar/baz/1_1_1"); }
/** * Create a mock ninja properties, with the given args as the properties. * * The arguments must be in key value pairs, every second argument being the * value for the key name in the previous argument. * * @param mode The mode * @param args The key value pairs. * @throws AssertionError If an odd number of arguments is supplied. */ public static MockNinjaProperties createWithMode(String mode, String contextPath, String... args) { assertTrue("You must supply an even number of arguments to form key value pairs", args.length % 2 == 0); PropertiesConfiguration props = new PropertiesConfiguration(); props.setDelimiterParsingDisabled(true); for (int i = 0; i < args.length; i+= 2) { props.addProperty(args[i], args[i + 1]); } return new MockNinjaProperties(mode, contextPath, props); }
@Test public void testConfiguredPinotCrypter() { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.addProperty("class.testpinotcrypter", TestPinotCrypter.class.getName()); propertiesConfiguration.addProperty("testpinotcrypter" + "." + CONFIG_SUBSET_KEY, SAMPLE_KEYMAP_VAL); PinotCrypterFactory.init(propertiesConfiguration); Assert.assertTrue(PinotCrypterFactory.create(NoOpPinotCrypter.class.getSimpleName()) instanceof NoOpPinotCrypter); PinotCrypter testPinotCrypter = PinotCrypterFactory.create(TestPinotCrypter.class.getSimpleName()); Assert.assertTrue(testPinotCrypter instanceof TestPinotCrypter); testPinotCrypter.encrypt(null, null); }
public void setUp() throws Exception { super.setUp(); PropertiesConfiguration properties = new PropertiesConfiguration(); properties.addProperty("secor.file.reader.writer.factory", "com.pinterest.secor.io.impl.SequenceFileReaderWriterFactory"); properties.addProperty("secor.file.age.youngest", true); SecorConfig secorConfig = new SecorConfig(properties); mRegistry = new FileRegistry(secorConfig); mLogFilePath = new LogFilePath("/some_parent_dir", PATH); mTopicPartition = new TopicPartition("some_topic", 0); mLogFilePathGz = new LogFilePath("/some_parent_dir", PATH_GZ); }
throws Exception { PropertiesConfiguration pinotFSConfig = new PropertiesConfiguration(); pinotFSConfig.addProperty(CommonConstants.Controller.PREFIX_OF_CONFIG_OF_PINOT_FS_FACTORY + ".class", LocalPinotFS.class.getName()); PinotFSFactory.init(pinotFSConfig);
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "code runs in same security context as user who providing the file") private void precomputeDefaultValue() { String v; if (isInterpolated()) { PropertiesConfiguration pconf = new PropertiesConfiguration(); Properties systemProperties = System.getProperties(); synchronized (systemProperties) { pconf.append(new MapConfiguration(systemProperties)); } pconf.addProperty("hack_default_value", this.defaultValue); v = pconf.getString("hack_default_value"); } else { v = getRawDefaultValue(); } if (this.type == PropertyType.ABSOLUTEPATH && !(v.trim().equals(""))) v = new File(v).getAbsolutePath(); computedDefaultValue = v; defaultValueComputed = true; }
@Test public void fromShouldThrowIfConfigAboutLoggerIsInvalid() { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.addProperty("cassandra.query.slow.query.latency.threshold.percentile", 90); configuration.addProperty("cassandra.query.logger.constant.threshold", 100); assertThatThrownBy(() -> QueryLoggerConfiguration.from(configuration)) .isInstanceOf(IllegalStateException.class); }
@Test public void getReadAliasMailboxNameShouldReturnConfiguredValue() throws ConfigurationException { PropertiesConfiguration configuration = new PropertiesConfiguration(); String name = "name"; configuration.addProperty("elasticsearch.alias.read.mailbox.name", name); configuration.addProperty("elasticsearch.hosts", "127.0.0.1"); ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration); assertThat(elasticSearchConfiguration.getReadAliasMailboxName()) .isEqualTo(new ReadAliasName(name)); }
@Test public void getReadAliasMailboxNameShouldReturnDefaultValueWhenMissing() throws ConfigurationException { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.addProperty("elasticsearch.hosts", "127.0.0.1"); ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration); assertThat(elasticSearchConfiguration.getReadAliasMailboxName()) .isEqualTo(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS); }
@Test public void getWriteAliasMailboxNameShouldReturnDefaultValueWhenMissing() throws ConfigurationException { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.addProperty("elasticsearch.hosts", "127.0.0.1"); ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration); assertThat(elasticSearchConfiguration.getWriteAliasMailboxName()) .isEqualTo(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS); }
@Test public void fromShouldNotThrowWithMinimalConfigAboutAConstantThresholdSlowQueryLogger() { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.addProperty("cassandra.query.logger.constant.threshold", 100); assertThatCode(() -> QueryLoggerConfiguration.from(configuration)) .doesNotThrowAnyException(); }
@Test public void getHostsShouldReturnConfiguredHostsWhenListIsUsed() throws ConfigurationException { String hostname = "myHost"; String hostname2 = "myOtherHost"; int port = 2154; PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.addProperty("elasticsearch.hosts", hostname + "," + hostname2 + ":" + port); ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration); assertThat(elasticSearchConfiguration.getHosts()) .containsOnly(Host.from(hostname, ElasticSearchConfiguration.DEFAULT_PORT), Host.from(hostname2, port)); }