Add GerritRuntime enum to describe the current running environment
Gerrit can run in different conditions: as a Daemon server, in batch mode... Gerrit's behaviour should be adjusted accordingly, and with this new enum it is possible to do it. It is bound in the configuration injector, so the sys modules can depend on it to enable (or not) different modules. Change-Id: Id811f1447a8078afccc96bbfbc707a761aa103a1
This commit is contained in:
@@ -29,6 +29,7 @@ import com.google.gerrit.extensions.config.FactoryModule;
|
||||
import com.google.gerrit.lucene.LuceneIndexModule;
|
||||
import com.google.gerrit.pgm.Daemon;
|
||||
import com.google.gerrit.pgm.Init;
|
||||
import com.google.gerrit.server.config.GerritRuntime;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gerrit.server.git.receive.AsyncReceiveCommits;
|
||||
@@ -44,6 +45,7 @@ import com.google.gerrit.testing.NoteDbChecker;
|
||||
import com.google.gerrit.testing.NoteDbMode;
|
||||
import com.google.gerrit.testing.SshMode;
|
||||
import com.google.gerrit.testing.TempFileUtil;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
@@ -352,7 +354,13 @@ public class GerritServer implements AutoCloseable {
|
||||
daemon.setDatabaseForTesting(
|
||||
ImmutableList.<Module>of(
|
||||
new InMemoryTestingDatabaseModule(
|
||||
cfg, site, inMemoryRepoManager, inMemoryDatabaseInstance)));
|
||||
cfg, site, inMemoryRepoManager, inMemoryDatabaseInstance),
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritRuntime.class).toInstance(GerritRuntime.DAEMON);
|
||||
}
|
||||
}));
|
||||
daemon.start();
|
||||
return new GerritServer(desc, null, createTestInjector(daemon), daemon, null);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ import com.google.gerrit.server.config.DownloadConfig;
|
||||
import com.google.gerrit.server.config.GerritGlobalModule;
|
||||
import com.google.gerrit.server.config.GerritInstanceNameModule;
|
||||
import com.google.gerrit.server.config.GerritOptions;
|
||||
import com.google.gerrit.server.config.GerritRuntime;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SysExecutorModule;
|
||||
import com.google.gerrit.server.events.EventBroker;
|
||||
@@ -371,6 +372,11 @@ public class Daemon extends SiteProgram {
|
||||
manager.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GerritRuntime getGerritRuntime() {
|
||||
return GerritRuntime.DAEMON;
|
||||
}
|
||||
|
||||
private boolean sshdOff() {
|
||||
return new SshAddressesModule().getListenAddresses(config).isEmpty();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.metrics.DisabledMetricMaker;
|
||||
import com.google.gerrit.metrics.MetricMaker;
|
||||
import com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker;
|
||||
import com.google.gerrit.server.config.GerritRuntime;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.GerritServerConfigModule;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
@@ -155,6 +156,13 @@ public abstract class SiteProgram extends AbstractProgram {
|
||||
});
|
||||
Module configModule = new GerritServerConfigModule();
|
||||
modules.add(configModule);
|
||||
modules.add(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritRuntime.class).toInstance(getGerritRuntime());
|
||||
}
|
||||
});
|
||||
Injector cfgInjector = Guice.createInjector(sitePathModule, configModule);
|
||||
Config cfg = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
|
||||
String dbType;
|
||||
@@ -219,6 +227,11 @@ public abstract class SiteProgram extends AbstractProgram {
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current runtime used by this Gerrit program. */
|
||||
protected GerritRuntime getGerritRuntime() {
|
||||
return GerritRuntime.BATCH;
|
||||
}
|
||||
|
||||
protected final String getConfiguredSecureStoreClass() {
|
||||
return getSecureStoreClassName(sitePath);
|
||||
}
|
||||
|
||||
24
java/com/google/gerrit/server/config/GerritRuntime.java
Normal file
24
java/com/google/gerrit/server/config/GerritRuntime.java
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
/** Represents the current runtime environment in which Gerrit is running. */
|
||||
public enum GerritRuntime {
|
||||
/** Gerrit is running as a server, with all its features. */
|
||||
DAEMON,
|
||||
|
||||
/** Gerrit is running from the command line, in batch mode (reindex, ...). */
|
||||
BATCH
|
||||
}
|
||||
@@ -17,10 +17,13 @@ package com.google.gerrit.server.plugins;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.extensions.systemstatus.ServerInformation;
|
||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.server.config.GerritRuntime;
|
||||
|
||||
public class PluginModule extends LifecycleModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
requireBinding(GerritRuntime.class);
|
||||
|
||||
bind(ServerInformationImpl.class);
|
||||
bind(ServerInformation.class).to(ServerInformationImpl.class);
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.google.gerrit.server.config.ChangeUpdateExecutor;
|
||||
import com.google.gerrit.server.config.GerritGlobalModule;
|
||||
import com.google.gerrit.server.config.GerritInstanceNameModule;
|
||||
import com.google.gerrit.server.config.GerritOptions;
|
||||
import com.google.gerrit.server.config.GerritRuntime;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.GerritServerId;
|
||||
import com.google.gerrit.server.config.GerritServerIdProvider;
|
||||
@@ -168,6 +169,7 @@ public class InMemoryModule extends FactoryModule {
|
||||
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
|
||||
}
|
||||
});
|
||||
bind(GerritRuntime.class).toInstance(GerritRuntime.DAEMON);
|
||||
bind(MetricMaker.class).to(DisabledMetricMaker.class);
|
||||
install(cfgInjector.getInstance(GerritGlobalModule.class));
|
||||
install(new GerritApiModule());
|
||||
|
||||
Reference in New Issue
Block a user