/** * Gets the Configuration with specified constructor from the ServiceBuilder's config. * * @param builderConstructor A Supplier that creates a ConfigBuilder for the desired configuration type. * @param <T> The type of the Configuration to instantiate. */ @Override public <T> T getConfig(Supplier<? extends ConfigBuilder<T>> builderConstructor) { return this.builder.serviceBuilderConfig.getConfig(builderConstructor); }
public ServiceStarter(ServiceBuilderConfig config) { this.builderConfig = config; this.serviceConfig = this.builderConfig.getConfig(ServiceConfig::builder); this.serviceBuilder = createServiceBuilder(); }
protected WriterFactory createWriterFactory() { WriterConfig writerConfig = this.serviceBuilderConfig.getConfig(WriterConfig::builder); return new StorageWriterFactory(writerConfig, this.coreExecutor); }
protected AttributeIndexFactory createAttributeIndexFactory() { CacheFactory cacheFactory = getSingleton(this.cacheFactory, this.cacheFactoryCreator); AttributeIndexConfig config = this.serviceBuilderConfig.getConfig(AttributeIndexConfig::builder); return new ContainerAttributeIndexFactoryImpl(config, cacheFactory, this.cacheManager, this.coreExecutor); }
protected OperationLogFactory createOperationLogFactory() { DurableDataLogFactory dataLogFactory = getSingleton(this.dataLogFactory, this.dataLogFactoryCreator); DurableLogConfig durableLogConfig = this.serviceBuilderConfig.getConfig(DurableLogConfig::builder); return new DurableLogFactory(durableLogConfig, dataLogFactory, this.coreExecutor); }
protected ReadIndexFactory createReadIndexFactory() { CacheFactory cacheFactory = getSingleton(this.cacheFactory, this.cacheFactoryCreator); ReadIndexConfig readIndexConfig = this.serviceBuilderConfig.getConfig(ReadIndexConfig::builder); return new ContainerReadIndexFactory(readIndexConfig, cacheFactory, this.cacheManager, this.coreExecutor); }
private void verifyContents(String message, Properties expected, ServiceBuilderConfig.Builder builder) { AtomicReference<Properties> rawProperties = new AtomicReference<>(); builder.build().getConfig(() -> new TestConfigBuilder<>(s -> s, rawProperties::set)); AssertExtensions.assertContainsSameElements( message, expected.entrySet(), rawProperties.get().entrySet(), (e1, e2) -> { int keyCompare = ((String) e1.getKey()).compareTo((String) e2.getKey()); int valueCompare = ((String) e1.getValue()).compareTo((String) e2.getValue()); return keyCompare * valueCompare + keyCompare + valueCompare; }); }
/** * Creates a new instance of the ServiceConfig class from the shared AdminCommandState passed in via the Constructor. */ protected ServiceConfig getServiceConfig() { return getCommandArgs().getState().getConfigBuilder().build().getConfig(ServiceConfig::builder); }
public void start() throws Exception { Exceptions.checkNotClosed(this.closed, this); log.info("Initializing metrics provider ..."); MetricsProvider.initialize(builderConfig.getConfig(MetricsConfig::builder)); statsProvider = MetricsProvider.getMetricsProvider(); statsProvider.start(); log.info("Initializing ZooKeeper Client ..."); this.zkClient = createZKClient(); log.info("Initializing Service Builder ..."); this.serviceBuilder.initialize(); log.info("Creating StreamSegmentService ..."); StreamSegmentStore service = this.serviceBuilder.createStreamSegmentService(); log.info("Creating TableStoreService ..."); TableStore tableStoreService = this.serviceBuilder.createTableStoreService(); log.info("Creating Segment Stats recorder ..."); segmentStatsFactory = new SegmentStatsFactory(); SegmentStatsRecorder statsRecorder = segmentStatsFactory .createSegmentStatsRecorder(service, builderConfig.getConfig(AutoScalerConfig::builder)); TokenVerifierImpl tokenVerifier = new TokenVerifierImpl(builderConfig.getConfig(AutoScalerConfig::builder)); this.listener = new PravegaConnectionListener(this.serviceConfig.isEnableTls(), this.serviceConfig.getListeningIPAddress(), this.serviceConfig.getListeningPort(), service, tableStoreService, statsRecorder, tokenVerifier, this.serviceConfig.getCertFile(), this.serviceConfig.getKeyFile(), this.serviceConfig.isReplyWithStackTraceOnError()); this.listener.startListening(); log.info("PravegaConnectionListener started successfully."); log.info("StreamSegmentService started."); }
public static void main(String[] args) throws Exception { Properties shortcuts = Shortcuts.extract(System.getProperties()); if (shortcuts.size() == 0 && !System.getProperties().containsKey(TestConfig.CONFIG_FILE_PROPERTY_NAME)) { printUsage(); return; } // Load config & setup logging. ServiceBuilderConfig builderConfig = getConfig(shortcuts); TestConfig testConfig = builderConfig.getConfig(TestConfig::builder); setupLogging(testConfig); // Create a new SelfTest. @Cleanup SelfTest test = new SelfTest(testConfig, builderConfig); // Start the test. test.startAsync().awaitRunning(STARTUP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); // Wait for the test to finish. test.awaitFinished().join(); if (testConfig.isPauseBeforeExit()) { System.out.println("Services are still running. Press any key to exit ..."); System.in.read(); } // Make sure the test is stopped. test.stopAsync().awaitTerminated(); }
protected SegmentContainerFactory createSegmentContainerFactory() { ReadIndexFactory readIndexFactory = getSingleton(this.readIndexFactory, this::createReadIndexFactory); AttributeIndexFactory attributeIndexFactory = getSingleton(this.attributeIndexFactory, this::createAttributeIndexFactory); StorageFactory storageFactory = createStorageFactory(); OperationLogFactory operationLogFactory = getSingleton(this.operationLogFactory, this::createOperationLogFactory); WriterFactory writerFactory = getSingleton(this.writerFactory, this::createWriterFactory); ContainerConfig containerConfig = this.serviceBuilderConfig.getConfig(ContainerConfig::builder); return new StreamSegmentContainerFactory(containerConfig, operationLogFactory, readIndexFactory, attributeIndexFactory, writerFactory, storageFactory, this::createContainerExtensions, this.coreExecutor); }
@Override protected void startUp() throws Exception { if (this.config.isMetricsEnabled()) { MetricsProvider.initialize(this.builderConfig.getConfig(MetricsConfig::builder)); this.statsProvider = MetricsProvider.getMetricsProvider(); this.statsProvider.start(); } if (this.config.getBookieCount() > 0) { this.bookKeeperService = BookKeeperAdapter.startBookKeeperOutOfProcess(this.config, this.logId); } this.serviceBuilder.initialize(); this.streamSegmentStore = this.serviceBuilder.createStreamSegmentService(); }
/** * Creates a new Context to be used by the BookKeeper command. * * @return A new Context. * @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized. */ @Override protected Context createContext() throws DurableDataLogException { val serviceConfig = getServiceConfig(); val containerConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ContainerConfig::builder); val bkConfig = getCommandArgs().getState().getConfigBuilder() .include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())) .build().getConfig(BookKeeperConfig::builder); val zkClient = createZKClient(); val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor()); try { factory.initialize(); } catch (DurableDataLogException ex) { zkClient.close(); throw ex; } val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient()); return new Context(serviceConfig, containerConfig, bkConfig, zkClient, factory, bkAdmin); }
/** * Creates a new Context to be used by the BookKeeper command. * * @return A new Context. * @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized. */ protected Context createContext() throws DurableDataLogException { val serviceConfig = getServiceConfig(); val bkConfig = getCommandArgs().getState().getConfigBuilder() .include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())) .build().getConfig(BookKeeperConfig::builder); val zkClient = createZKClient(); val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor()); try { factory.initialize(); } catch (DurableDataLogException ex) { zkClient.close(); throw ex; } val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient()); return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin); }
/** * Creates a new instance of the ServiceBuilder class which is contained in memory. Any data added to this service will * be lost when the object is garbage collected or the process terminates. * * @param builderConfig The ServiceBuilderConfig to use. * @param executorBuilder A Function that, given a thread count and a pool name, creates a ScheduledExecutorService * with the given number of threads that have the given name as prefix. */ @VisibleForTesting public static ServiceBuilder newInMemoryBuilder(ServiceBuilderConfig builderConfig, ExecutorBuilder executorBuilder) { ServiceConfig serviceConfig = builderConfig.getConfig(ServiceConfig::builder); ServiceBuilder builder; if (serviceConfig.isReadOnlySegmentStore()) { // Only components required for ReadOnly SegmentStore. builder = new ReadOnlyServiceBuilder(builderConfig, serviceConfig, executorBuilder); } else { // Components that are required for general SegmentStore. builder = new ServiceBuilder(builderConfig, serviceConfig, executorBuilder) .withCacheFactory(setup -> new InMemoryCacheFactory()); } // Components that are required for all types of SegmentStore. return builder .withDataLogFactory(setup -> new InMemoryDurableDataLogFactory(setup.getCoreExecutor())) .withContainerManager(setup -> new LocalSegmentContainerManager( setup.getContainerRegistry(), setup.getSegmentToContainerMapper())) .withStorageFactory(setup -> new InMemoryStorageFactory(setup.getStorageExecutor())) .withStreamSegmentStore(setup -> new StreamSegmentService(setup.getContainerRegistry(), setup.getSegmentToContainerMapper())); }
@Cleanup val context = createContext(); val readIndexConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ReadIndexConfig::builder);
@Override protected ServiceBuilder createBuilder(ServiceBuilderConfig.Builder configBuilder, int instanceId) { ServiceBuilderConfig builderConfig = getBuilderConfig(configBuilder, instanceId); return ServiceBuilder .newInMemoryBuilder(builderConfig) .withCacheFactory(setup -> new RocksDBCacheFactory(builderConfig.getConfig(RocksDBConfig::builder))) .withStorageFactory(setup -> new HDFSStorageFactory(setup.getConfig(HDFSStorageConfig::builder), setup.getStorageExecutor())) .withDataLogFactory(setup -> new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), getBookkeeper().getZkClient(), setup.getCoreExecutor())); }
@Override protected ServiceBuilder createBuilder(ServiceBuilderConfig.Builder configBuilder, int instanceId) { ServiceBuilderConfig builderConfig = getBuilderConfig(configBuilder, instanceId); return ServiceBuilder .newInMemoryBuilder(builderConfig) .withCacheFactory(setup -> new RocksDBCacheFactory(builderConfig.getConfig(RocksDBConfig::builder))) .withStorageFactory(setup -> new FileSystemStorageFactory(setup.getConfig(FileSystemStorageConfig::builder), setup.getStorageExecutor())) .withDataLogFactory(setup -> new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), getBookkeeper().getZkClient(), setup.getCoreExecutor())); } }
@Override protected ServiceBuilder createBuilder(ServiceBuilderConfig.Builder configBuilder, int instanceId) { ServiceBuilderConfig builderConfig = getBuilderConfig(configBuilder, instanceId); return ServiceBuilder .newInMemoryBuilder(builderConfig) .withCacheFactory(setup -> new RocksDBCacheFactory(builderConfig.getConfig(RocksDBConfig::builder))) .withStorageFactory(setup -> new LocalExtendedS3StorageFactory(setup.getConfig(ExtendedS3StorageConfig::builder), setup.getStorageExecutor())) .withDataLogFactory(setup -> new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), getBookkeeper().getZkClient(), setup.getCoreExecutor())); }
@Before public void setUp() throws Exception { ServiceBuilderConfig config = ServiceBuilderConfig .builder() .include(System.getProperties()) .build(); SingleNodeConfig conf = config.getConfig(SingleNodeConfig::builder); localPravega = LocalPravegaEmulator.builder() .controllerPort(TestUtils.getAvailableListenPort()) .segmentStorePort(TestUtils.getAvailableListenPort()) .zkPort(TestUtils.getAvailableListenPort()) .restServerPort(TestUtils.getAvailableListenPort()) .enableRestServer(restEnabled) .enableAuth(authEnabled) .enableTls(tlsEnabled) .certFile("../config/cert.pem") .keyFile("../config/key.pem") .jksKeyFile("../config/bookie.keystore.jks") .jksTrustFile("../config/bookie.truststore.jks") .keyPasswordFile("../config/bookie.keystore.jks.passwd") .passwdFile("../config/passwd") .userName("admin") .passwd("1111_aaaa") .build(); localPravega.start(); }