@Override public synchronized void start() throws Exception { switch (state) { case NONE: throw new IllegalStateException("not initialized"); case STARTED: throw new IllegalStateException("started already"); case DESTROYED: throw new IllegalStateException("can't start after destruction"); default: break; } final File configFile = findConfigFile(this.configFile, DEFAULT_CONFIG_FILE); final CentralDogma dogma; if (configFile == null) { dogma = new CentralDogmaBuilder(DEFAULT_DATA_DIR).build(); } else { dogma = CentralDogma.forConfig(configFile); } dogma.start().get(); this.dogma = dogma; state = State.STARTED; }
/** * Stops the server and deletes the temporary files created by the server. Note that you don't usually need * to call this method manually because the server is automatically stopped at the end by JUnit. */ public final CompletableFuture<Void> stopAsync() { final com.linecorp.centraldogma.server.CentralDogma dogma = this.dogma; this.dogma = null; client = null; httpClient = null; if (dogma != null) { return dogma.stop(); } else { return CompletableFuture.completedFuture(null); } } }
/** * Creates a new instance from the given configuration file. * * @throws IOException if failed to load the configuration from the specified file */ public static CentralDogma forConfig(File configFile) throws IOException { requireNonNull(configFile, "configFile"); return new CentralDogma(Jackson.readValue(configFile, CentralDogmaConfig.class)); }
cfg.maxNumFilesPerMirror(), cfg.maxNumBytesPerMirror()); sessionManager = initializeSessionManager(); executor = startCommandExecutor(pm, mirroringService, repositoryWorker, sessionManager); if (executor.isWritable()) { logger.info("Started the command executor."); server = startServer(pm, executor, sessionManager); logger.info("Started the RPC server at: {}", server.activePorts()); logger.info("Started the Central Dogma successfully."); this.sessionManager = sessionManager; } else { doStop(server, executor, mirroringService, pm, repositoryWorker, sessionManager);
executor = startCommandExecutor(pm, mirroringService, repositoryWorker, securityManager); if (executor.isWritable()) { logger.info("Started the command executor"); server = startServer(pm, executor, securityManager); logger.info("Started the RPC server at: {}", server.activePorts()); logger.info("Started the Central Dogma successfully"); this.server = server; } else { doStop(server, executor, mirroringService, pm, repositoryWorker);
final AuthProvider authProvider = createAuthProvider(executor, sessionManager, mds); configureThriftService(sb, pm, executor, watchService, mds); .build()); configureHttpApi(sb, pm, executor, watchService, mds, authProvider, sessionManager);
return dogma.start().thenRun(() -> { final Optional<ServerPort> activePort = dogma.activePort(); if (!activePort.isPresent()) {
final MetadataService mds = new MetadataService(pm, executor); configureThriftService(sb, pm, executor, watchService, mds); .build()); configureHttpApi(sb, pm, executor, watchService, mds, securityManager);
private void configureThriftService(ServerBuilder sb, ProjectManager pm, CommandExecutor executor, WatchService watchService, MetadataService mds) { final CentralDogmaServiceImpl service = new CentralDogmaServiceImpl(pm, executor, watchService, mds); Service<HttpRequest, HttpResponse> thriftService = ThriftCallService.of(service) .decorate(CentralDogmaTimeoutScheduler::new) .decorate(CentralDogmaExceptionTranslator::new) .decorate(THttpService.newDecorator()); if (cfg.isCsrfTokenRequiredForThrift()) { thriftService = thriftService.decorate(HttpAuthService.newDecorator(new CsrfTokenAuthorizer())); } else { thriftService = thriftService.decorate(TokenlessClientLogger::new); } // Enable content compression for API responses. thriftService = thriftService.decorate(contentEncodingDecorator()); sb.service("/cd/thrift/v1", thriftService); }
private void doStop() { if (server == null) { return; } final Server server = this.server; final CommandExecutor executor = this.executor; final DefaultMirroringService mirroringService = this.mirroringService; final ProjectManager pm = this.pm; final ExecutorService repositoryWorker = this.repositoryWorker; this.server = null; this.executor = null; this.mirroringService = null; this.pm = null; this.repositoryWorker = null; logger.info("Stopping the Central Dogma .."); if (!doStop(server, executor, mirroringService, pm, repositoryWorker)) { logger.warn("Stopped the Central Dogma with failure"); } else { logger.info("Stopped the Central Dogma successfully"); } }
switch (replicationMethod) { case ZOOKEEPER: executor = newZooKeeperCommandExecutor(pm, repositoryWorker, sessionManager, onTakeLeadership, onReleaseLeadership); break;
cfg.maxNumFilesPerMirror(), cfg.maxNumBytesPerMirror()); sessionManager = initializeSessionManager(); executor = startCommandExecutor(pm, mirroringService, repositoryWorker, sessionManager); if (executor.isWritable()) { logger.info("Started the command executor."); server = startServer(pm, executor, sessionManager); logger.info("Started the RPC server at: {}", server.activePorts()); logger.info("Started the Central Dogma successfully."); this.sessionManager = sessionManager; } else { doStop(server, executor, mirroringService, pm, repositoryWorker, sessionManager);
final AuthProvider authProvider = createAuthProvider(executor, sessionManager, mds); configureThriftService(sb, pm, executor, watchService, mds); .build()); configureHttpApi(sb, pm, executor, watchService, mds, authProvider, sessionManager);
decorator = decorator.andThen(contentEncodingDecorator());
private void doStop() { if (server == null) { return; } final Server server = this.server; final CommandExecutor executor = this.executor; final DefaultMirroringService mirroringService = this.mirroringService; final ProjectManager pm = this.pm; final ExecutorService repositoryWorker = this.repositoryWorker; final SessionManager sessionManager = this.sessionManager; this.server = null; this.executor = null; this.mirroringService = null; this.pm = null; this.repositoryWorker = null; this.sessionManager = null; logger.info("Stopping the Central Dogma .."); if (!doStop(server, executor, mirroringService, pm, repositoryWorker, sessionManager)) { logger.warn("Stopped the Central Dogma with failure."); } else { logger.info("Stopped the Central Dogma successfully."); } }
switch (replicationMethod) { case ZOOKEEPER: executor = newZooKeeperCommandExecutor(pm, repositoryWorker, sessionManager, onTakeLeadership, onReleaseLeadership); break;
@Override public synchronized void start() throws Exception { switch (state) { case NONE: throw new IllegalStateException("not initialized"); case STARTED: throw new IllegalStateException("started already"); case DESTROYED: throw new IllegalStateException("can't start after destruction"); default: break; } final File configFile = findConfigFile(this.configFile, DEFAULT_CONFIG_FILE); final CentralDogma dogma; if (configFile == null) { dogma = new CentralDogmaBuilder(DEFAULT_DATA_DIR).build(); } else { dogma = CentralDogma.forConfig(configFile); } dogma.start().get(); this.dogma = dogma; state = State.STARTED; }
@Override public synchronized void stop() throws Exception { switch (state) { case NONE: case INITIALIZED: case STOPPED: return; case DESTROYED: throw new IllegalStateException("can't stop after destruction"); } final CentralDogma dogma = this.dogma; assert dogma != null; this.dogma = null; dogma.stop().get(); state = State.STOPPED; }
/** * Creates a new instance from the given configuration file. * * @throws IOException if failed to load the configuration from the specified file */ public static CentralDogma forConfig(File configFile) throws IOException { requireNonNull(configFile, "configFile"); return new CentralDogma(Jackson.readValue(configFile, CentralDogmaConfig.class)); }