public static MetricsConfig getMetricsConfig() { val builder = MetricsConfig.builder(); for (Map.Entry<String, ConfigValue> e : CONFIG.entrySet()) { if (e.getKey().startsWith(METRIC_PATH)) { builder.with(Property.named(e.getKey().replaceFirst(METRIC_PATH, "")), e.getValue().unwrapped()); } } return builder.build(); } }
/** * Creates a new ConfigBuilder that can be used to create instances of this class. * * @return A new Builder for this class. */ public static ConfigBuilder<AttributeIndexConfig> builder() { return new ConfigBuilder<>(COMPONENT_CODE, AttributeIndexConfig::new); } //endregion
static Properties extract(Properties source) { Properties result = new Properties(); for (val e : SHORTCUTS.entrySet()) { val builder = e.getKey().get(); boolean any = false; for (val s : e.getValue()) { val value = source.getProperty(s.key, null); if (value != null) { builder.withUnsafe(s.property, value); any = true; } } if (any) { builder.copyTo(result); } } return result; }
/** * Gets a new instance of a Configuration for this builder. * * @param constructor A Supplier for a ConfigBuilder for the given Configuration. * @param <T> The type of the Configuration to instantiate. */ public <T> T getConfig(Supplier<? extends ConfigBuilder<? extends T>> constructor) { return constructor.get() .rebase(this.properties) .build(); }
/** * Generates a new ServiceBuilderConfig.Builder with hardcoded defaults, in case these are not supplied via other means, * such as a config file or System Properties. */ private static ServiceBuilderConfig.Builder getDefaultServiceBuilderConfig() { return ServiceBuilderConfig .builder() .include(ServiceConfig.builder() .with(ServiceConfig.THREAD_POOL_SIZE, 80) .with(ServiceConfig.CACHE_POLICY_MAX_TIME, 600) .with(ServiceConfig.CACHE_POLICY_MAX_SIZE, 4 * 1024 * 1024 * 1024L) .with(ServiceConfig.CERT_FILE, "../config/cert.pem") .with(ServiceConfig.KEY_FILE, "../config/key.pem")) .include(DurableLogConfig.builder() .with(DurableLogConfig.CHECKPOINT_COMMIT_COUNT, 100) .with(DurableLogConfig.CHECKPOINT_MIN_COMMIT_COUNT, 100) .with(DurableLogConfig.CHECKPOINT_TOTAL_COMMIT_LENGTH, 100 * 1024 * 1024L)) .include(ReadIndexConfig.builder() .with(ReadIndexConfig.MEMORY_READ_MIN_LENGTH, 128 * 1024)) .include(ContainerConfig.builder() .with(ContainerConfig.SEGMENT_METADATA_EXPIRATION_SECONDS, ContainerConfig.MINIMUM_SEGMENT_METADATA_EXPIRATION_SECONDS) .with(ContainerConfig.MAX_ACTIVE_SEGMENT_COUNT, 500)) // This is for those tests that use BookKeeper for Tier1. .include(BookKeeperConfig.builder() .with(BookKeeperConfig.BK_LEDGER_MAX_SIZE, Integer.MAX_VALUE) .with(BookKeeperConfig.ZK_METADATA_PATH, "/pravega/selftest/segmentstore/containers") .with(BookKeeperConfig.BK_LEDGER_PATH, TestConfig.BK_LEDGER_PATH)); }
final String namespace = "ns"; final int propertyCount = 10; val builder1 = new ConfigBuilder<TestConfig>(namespace, TestConfig::new); for (int i = 0; i < propertyCount; i++) { builder1.with(Property.named(Integer.toString(i)), i); val builder2 = builder1.rebase(p2); Assert.assertNotEquals("rebase() returned the same instance.", builder1, builder2); Assert.assertEquals("rebase() touched the target Properties object.", 1, p2.size()); builder2.with(Property.named(Integer.toString(i)), i * 10); TestConfig c1 = builder1.build(); TestConfig c2 = builder2.build(); for (int i = 0; i < propertyCount; i++) { val p = Property.<Integer>named(Integer.toString(i));
/** * Tests the with() method. */ @Test public void testWith() { final String namespace = "ns"; final int propertyCount = 10; val builder = new ConfigBuilder<TestConfig>(namespace, TestConfig::new); for (int i = 0; i < propertyCount; i++) { val result = builder.with(Property.named(Integer.toString(i)), i); Assert.assertEquals("with() did not return this instance.", builder, result); } TestConfig c = builder.build(); for (int i = 0; i < propertyCount; i++) { val p = Property.<Integer>named(Integer.toString(i)); val actual = c.getProperties().getInt(p); Assert.assertEquals("Unexpected value in result.", i, actual); } }
/** * Tests the copyTo() method. */ @Test public void testCopyTo() { final String namespace = "ns"; final int propertyCount = 10; val builder = new ConfigBuilder<TestConfig>(namespace, TestConfig::new); for (int i = 0; i < propertyCount; i++) { builder.with(Property.named(Integer.toString(i)), i); } Properties p2 = new Properties(); p2.setProperty(namespace + ".1", "a"); // Decoy - this should be overridden. builder.copyTo(p2); Assert.assertEquals("Unexpected number of properties copied.", propertyCount, p2.size()); for (int i = 0; i < propertyCount; i++) { val actualProp2 = p2.getProperty(namespace + "." + Integer.toString(i)); Assert.assertEquals("CopyTo did not set the correct values.", Integer.toString(i), actualProp2); } }
@Test public void testDefaultValues() { BookKeeperConfig cfg = BookKeeperConfig.builder() .build(); Assert.assertEquals("localhost:2181", cfg.getZkAddress()); Assert.assertEquals(Duration.ofMillis(10000), cfg.getZkSessionTimeout()); Assert.assertEquals(Duration.ofMillis(10000), cfg.getZkConnectionTimeout()); Assert.assertEquals("/segmentstore/containers", cfg.getZkMetadataPath()); Assert.assertEquals(2, cfg.getZkHierarchyDepth()); Assert.assertEquals(5, cfg.getMaxWriteAttempts()); Assert.assertEquals(3, cfg.getBkEnsembleSize()); Assert.assertEquals(2, cfg.getBkAckQuorumSize()); Assert.assertEquals(3, cfg.getBkWriteQuorumSize()); Assert.assertEquals(5000, cfg.getBkWriteTimeoutMillis()); Assert.assertEquals(5000, cfg.getBkReadTimeoutMillis()); Assert.assertEquals(1024 * 1024 * 1024, cfg.getBkLedgerMaxSize()); Assert.assertEquals(0, cfg.getBKPassword().length); Assert.assertEquals("", cfg.getBkLedgerPath()); Assert.assertEquals(false, cfg.isTLSEnabled()); Assert.assertEquals("config/client.truststore.jks", cfg.getTlsTrustStore()); Assert.assertEquals("", cfg.getTlsTrustStorePasswordPath()); }
/** * Includes the given Builder into this Builder. * * @param builder The Builder to include. * @param <T> Type of the Configuration to include. * @return This instance. */ public <T> Builder include(ConfigBuilder<T> builder) { builder.copyTo(this.properties); return this; }
.include(authProps) .include(ServiceConfig.builder() .with(ServiceConfig.CONTAINER_COUNT, containerCount) .with(ServiceConfig.THREAD_POOL_SIZE, THREADPOOL_SIZE) .with(ServiceConfig.ZK_URL, "localhost:" + zkPort) .with(ServiceConfig.SECURE_ZK, this.secureZK) .with(ServiceConfig.ZK_TRUSTSTORE_LOCATION, jksTrustFile) .with(ServiceConfig.ZK_TRUST_STORE_PASSWORD_PATH, keyPasswordFile) .with(ServiceConfig.LISTENING_PORT, this.segmentStorePorts[segmentStoreId]) .with(ServiceConfig.CLUSTER_NAME, this.clusterName) .with(ServiceConfig.ENABLE_TLS, this.enableTls) .with(ServiceConfig.KEY_FILE, this.keyFile) .with(ServiceConfig.CERT_FILE, this.certFile) .with(ServiceConfig.CACHE_POLICY_MAX_TIME, 60) .with(ServiceConfig.CACHE_POLICY_MAX_SIZE, 128 * 1024 * 1024L) .with(ServiceConfig.DATALOG_IMPLEMENTATION, isInMemStorage ? ServiceConfig.DataLogType.INMEMORY : ServiceConfig.DataLogType.BOOKKEEPER) .with(ServiceConfig.STORAGE_IMPLEMENTATION, isInMemStorage ? ServiceConfig.StorageType.INMEMORY : ServiceConfig.StorageType.FILESYSTEM)) .include(DurableLogConfig.builder() .with(DurableLogConfig.CHECKPOINT_COMMIT_COUNT, 100) .with(DurableLogConfig.CHECKPOINT_MIN_COMMIT_COUNT, 100) .with(DurableLogConfig.CHECKPOINT_TOTAL_COMMIT_LENGTH, 100 * 1024 * 1024L)) .include(AutoScalerConfig.builder() .with(AutoScalerConfig.CONTROLLER_URI, (this.enableTls ? "tls" : "tcp") + "://localhost:" + controllerPorts[0]) .with(AutoScalerConfig.TOKEN_SIGNING_KEY, "secret")
static DurableLogConfig createDurableLogConfig(Integer checkpointMinCommitCount, Long checkpointMinTotalCommitLength) { if (checkpointMinCommitCount == null) { checkpointMinCommitCount = Integer.MAX_VALUE; } if (checkpointMinTotalCommitLength == null) { checkpointMinTotalCommitLength = Long.MAX_VALUE; } return DurableLogConfig .builder() .with(DurableLogConfig.CHECKPOINT_MIN_COMMIT_COUNT, CHECKPOINT_MIN_COMMIT_COUNT) .with(DurableLogConfig.CHECKPOINT_COMMIT_COUNT, checkpointMinCommitCount) .with(DurableLogConfig.CHECKPOINT_TOTAL_COMMIT_LENGTH, checkpointMinTotalCommitLength) .with(DurableLogConfig.START_RETRY_DELAY_MILLIS, START_RETRY_DELAY_MILLIS) .build(); } }
int bkWriteQuorum = Math.min(3, testConfig.getBookieCount()); b.include(ServiceConfig.builder() .with(ServiceConfig.CONTAINER_COUNT, testConfig.getContainerCount())); b.include(BookKeeperConfig.builder() .with(BookKeeperConfig.ZK_ADDRESS, TestConfig.LOCALHOST + ":" + testConfig.getZkPort()) .with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, bkWriteQuorum) .with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, bkWriteQuorum) .with(BookKeeperConfig.BK_ENSEMBLE_SIZE, bkWriteQuorum)); if (testConfig.isMetricsEnabled()) { b.include(MetricsConfig.builder() .with(MetricsConfig.ENABLE_STATISTICS, true) .with(MetricsConfig.ENABLE_CSV_REPORTER, true) .with(MetricsConfig.OUTPUT_FREQUENCY, 1) .with(MetricsConfig.CSV_ENDPOINT, testConfig.getComponentMetricsPath("segmentstore", 0)));
/** * Creates a new ConfigBuilder that can be used to create instances of this class. * * @return A new Builder for this class. */ public static ConfigBuilder<ReadIndexConfig> builder() { return new ConfigBuilder<>(COMPONENT_CODE, ReadIndexConfig::new); }
@Before public void setUp() throws Exception { this.baseDir = Files.createTempDirectory("test_nfs").toFile().getAbsoluteFile(); MetricsConfig metricsConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).build(); MetricsProvider.initialize(metricsConfig); this.adapterConfig = FileSystemStorageConfig .builder() .with(FileSystemStorageConfig.ROOT, this.baseDir.getAbsolutePath()) .build(); }
/** * Gets a default set of configuration values, in absence of any real configuration. * These configuration values are the default ones from all component configurations, except that it will * create only one container to host segments. */ public static ServiceBuilderConfig getDefaultConfig() { // All component configs should have defaults built-in, so no need to override them here. return new Builder() .include(ServiceConfig.builder().with(ServiceConfig.CONTAINER_COUNT, 1)) .build(); }
/** * Creates a new ConfigBuilder that can be used to create instances of this class. * * @return A new Builder for this class. */ public static ConfigBuilder<ServiceConfig> builder() { return new ConfigBuilder<>(COMPONENT_CODE, ServiceConfig::new); }
/** * Creates a new ConfigBuilder that can be used to create instances of this class. * * @return A new Builder for this class. */ public static ConfigBuilder<DurableLogConfig> builder() { return new ConfigBuilder<>(COMPONENT_CODE, DurableLogConfig::new); }