private static Broker startDefaultBrokerInTempDirectory() { Loggers.SYSTEM_LOGGER.info("No configuration file specified. Using default configuration."); try { tempFolder = Files.createTempDirectory("zeebe").toAbsolutePath().normalize().toString(); final BrokerCfg cfg = new BrokerCfg(); return new Broker(cfg, tempFolder, null); } catch (final IOException e) { throw new RuntimeException("Could not start broker", e); } }
@Override public void start(ServiceStartContext startContext) { final DataCfg dataConfiguration = configuration.getData(); for (String directory : dataConfiguration.getDirectories()) { final File configDirectory = new File(directory); if (!configDirectory.exists()) { try { configDirectory.getParentFile().mkdirs(); Files.createDirectory(configDirectory.toPath()); } catch (final IOException e) { throw new RuntimeException("Unable to create directory " + configDirectory, e); } } } service = new RaftPersistentConfigurationManager(configuration.getData()); startContext.async(startContext.getScheduler().submitActor(service)); }
private ExporterIntegrationRule configure(List<ExporterCfg> exporters) { getBrokerConfig().getExporters().addAll(exporters); return this; }
@Override public void start(final ServiceStartContext startContext) { final BufferingServerTransport serverTransport = bufferingServerTransportInjector.getValue(); final ClientTransport clientTransport = clientTransportInjector.getValue(); final GossipConfiguration gossipConfiguration = configuration.getGossip(); gossip = new Gossip( configuration.getCluster().getNodeId(), serverTransport, clientTransport, gossipConfiguration); startContext.async(startContext.getScheduler().submitActor(gossip)); }
private void initSystemContext(final ActorClock clock, final String basePath) { LOG.debug("Initializing configuration with base path {}", basePath); brokerCfg.init(basePath); validateConfiguration(); final SocketBindingCfg clientApiCfg = brokerCfg.getNetwork().getClient(); final String brokerId = String.format("%s:%d", clientApiCfg.getHost(), clientApiCfg.getPort()); this.diagnosticContext = Collections.singletonMap(BROKER_ID_LOG_PROPERTY, brokerId); // TODO: submit diagnosticContext to actor scheduler once supported this.metricsManager = initMetricsManager(brokerId); this.scheduler = initScheduler(clock, brokerId); this.serviceContainer = new ServiceContainerImpl(this.scheduler); this.scheduler.start(); initBrokerInfoMetric(); setCloseTimeout(CLOSE_TIMEOUT); }
@Test public void shouldThrowExceptionIfPartitionsCountIsNegative() { // given final BrokerCfg brokerCfg = new BrokerCfg(); brokerCfg.getCluster().setPartitionsCount(-1); // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Partition count must not be smaller then 1."); initSystemContext(brokerCfg); }
public SocketAddress getClientAddress() { return brokerCfg.getNetwork().getClient().toSocketAddress(); }
public SocketAddress getGatewayAddress() { return brokerCfg.getGateway().getNetwork().toSocketAddress(); }
private void assertHost( final String configFileName, final String host, final String gateway, final String client, final String management, final String replication, final String subscription) { final BrokerCfg brokerCfg = readConfig(configFileName); final NetworkCfg networkCfg = brokerCfg.getNetwork(); assertThat(networkCfg.getHost()).isEqualTo(host); assertThat(brokerCfg.getGateway().getNetwork().getHost()).isEqualTo(gateway); assertThat(networkCfg.getClient().getHost()).isEqualTo(client); assertThat(networkCfg.getManagement().getHost()).isEqualTo(management); assertThat(networkCfg.getReplication().getHost()).isEqualTo(replication); assertThat(networkCfg.getSubscription().getHost()).isEqualTo(subscription); }
private void installPartition(final int partitionId, final List<Integer> members) { final RaftPersistentConfiguration configuration = configurationManager .createConfiguration( partitionId, brokerCfg.getCluster().getReplicationFactor(), members) .join(); installPartition(startContext, configuration); }
@Test public void shouldExpandExporterJarPathRelativeToBrokerBaseIffPresent() { // given final InputStream input = new ByteArrayInputStream( ("[[exporters]]\n" + "id=\"external\"\n" + "jarPath=\"exporters/exporter.jar\"\n" + "[[exporters]]\n" + "id=\"internal-1\"\n" + "jarPath=\"\"\n" + "[[exporters]]\n" + "id=\"internal-2\"") .getBytes()); final BrokerCfg config = TomlConfigurationReader.read(input, BrokerCfg.class); final String base = temporaryFolder.getRoot().getAbsolutePath(); final String jarFile = Paths.get(base, "exporters", "exporter.jar").toAbsolutePath().toString(); // when config.init(base); // then assertThat(config.getExporters()).hasSize(3); assertThat(config.getExporters().get(0)) .hasFieldOrPropertyWithValue("jarPath", jarFile) .is(new Condition<>(ExporterCfg::isExternal, "is external")); assertThat(config.getExporters().get(1).isExternal()).isFalse(); assertThat(config.getExporters().get(2).isExternal()).isFalse(); }
DurationUtil.parse(brokerConfiguration.getData().getSnapshotPeriod()); final StreamProcessorServiceFactory streamProcessorFactory = new StreamProcessorServiceFactory(serviceContainer, snapshotPeriod); new ZbStreamProcessorService(brokerConfiguration.getCluster()); serviceContainer .createService(ZB_STREAM_PROCESSOR_SERVICE_NAME, streamProcessorService)
public void init(final String brokerBase) { init(brokerBase, new Environment()); }
@Override public void init(final SystemContext context) { final ServiceContainer serviceContainer = context.getServiceContainer(); final MetricsFileWriterService metricsFileWriterService = new MetricsFileWriterService(context.getBrokerConfiguration().getMetrics()); serviceContainer.createService(METRICS_FILE_WRITER, metricsFileWriterService).install(); final LeaderManagementRequestHandler requestHandlerService = new LeaderManagementRequestHandler(); serviceContainer .createService(LEADER_MANAGEMENT_REQUEST_HANDLER, requestHandlerService) .dependency( bufferingServerTransport(MANAGEMENT_API_SERVER_NAME), requestHandlerService.getManagementApiServerTransportInjector()) .groupReference( LEADER_PARTITION_GROUP_NAME, requestHandlerService.getLeaderPartitionsGroupReference()) .install(); } }
@Test public void shouldThrowExceptionIfReplicationFactorIsLargerThenClusterSize() { // given final BrokerCfg brokerCfg = new BrokerCfg(); brokerCfg.getCluster().setReplicationFactor(2); // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Replication factor 2 needs to be larger then zero and not larger then cluster size 1."); initSystemContext(brokerCfg); }
public SocketAddress getManagementAddress() { return brokerCfg.getNetwork().getManagement().toSocketAddress(); }
public SocketAddress getGatewayAddress() { return brokerCfg.getGateway().getNetwork().toSocketAddress(); }
private void assertHost( final String configFileName, final String host, final String gateway, final String client, final String management, final String replication, final String subscription) { final BrokerCfg brokerCfg = readConfig(configFileName); final NetworkCfg networkCfg = brokerCfg.getNetwork(); assertThat(networkCfg.getHost()).isEqualTo(host); assertThat(brokerCfg.getGateway().getNetwork().getHost()).isEqualTo(gateway); assertThat(networkCfg.getClient().getHost()).isEqualTo(client); assertThat(networkCfg.getManagement().getHost()).isEqualTo(management); assertThat(networkCfg.getReplication().getHost()).isEqualTo(replication); assertThat(networkCfg.getSubscription().getHost()).isEqualTo(subscription); }