Only bind index ssh commands when the index type is Lucene
In the current implementation these commands are coupled with the Lucene index. Since at this point Lucene is the only supported secondary index, this is not a problem. However, if we add support for a new index type, for example Elasticsearch, this will cause dependency issues. A long term solution for this would be to refactor the commands out of the Lucene implementation into the abstract index API, so that they can also be used by other index implementations. For now, as a short term solution, only bind the commands when the index type is Lucene. Change-Id: If1e20e656f03ed3cb82a146c669a4105af12c762
This commit is contained in:
parent
27c7f6ceb8
commit
9dc12ef0fb
@ -80,6 +80,7 @@ import com.google.gerrit.sshd.SshHostKeyModule;
|
||||
import com.google.gerrit.sshd.SshKeyCacheImpl;
|
||||
import com.google.gerrit.sshd.SshModule;
|
||||
import com.google.gerrit.sshd.commands.DefaultCommandModule;
|
||||
import com.google.gerrit.sshd.commands.IndexCommandsModule;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
@ -155,6 +156,7 @@ public class Daemon extends SiteProgram {
|
||||
private Module emailModule;
|
||||
|
||||
private Runnable serverStarted;
|
||||
private IndexType indexType;
|
||||
|
||||
public Daemon() {
|
||||
}
|
||||
@ -276,6 +278,7 @@ public class Daemon extends SiteProgram {
|
||||
cfgInjector = createCfgInjector();
|
||||
config = cfgInjector.getInstance(
|
||||
Key.get(Config.class, GerritServerConfig.class));
|
||||
initIndexType();
|
||||
sysInjector = createSysInjector();
|
||||
sysInjector.getInstance(PluginGuiceEnvironment.class)
|
||||
.setDbCfgInjector(dbInjector, cfgInjector);
|
||||
@ -379,7 +382,6 @@ public class Daemon extends SiteProgram {
|
||||
if (slave) {
|
||||
return new DummyIndexModule();
|
||||
}
|
||||
IndexType indexType = IndexModule.getIndexType(cfgInjector);
|
||||
switch (indexType) {
|
||||
case LUCENE:
|
||||
return luceneModule != null ? luceneModule : new LuceneIndexModule();
|
||||
@ -388,6 +390,16 @@ public class Daemon extends SiteProgram {
|
||||
}
|
||||
}
|
||||
|
||||
private void initIndexType() {
|
||||
indexType = IndexModule.getIndexType(cfgInjector);
|
||||
switch (indexType) {
|
||||
case LUCENE:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("unsupported index.type = " + indexType);
|
||||
}
|
||||
}
|
||||
|
||||
private void initSshd() {
|
||||
sshInjector = createSshInjector();
|
||||
sysInjector.getInstance(PluginGuiceEnvironment.class)
|
||||
@ -403,6 +415,9 @@ public class Daemon extends SiteProgram {
|
||||
}
|
||||
modules.add(new DefaultCommandModule(slave,
|
||||
sysInjector.getInstance(DownloadConfig.class)));
|
||||
if (indexType == IndexType.LUCENE) {
|
||||
modules.add(new IndexCommandsModule());
|
||||
}
|
||||
return sysInjector.createChildInjector(modules);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@ public class DefaultCommandModule extends CommandModule {
|
||||
protected void configure() {
|
||||
CommandName git = Commands.named("git");
|
||||
CommandName gerrit = Commands.named("gerrit");
|
||||
CommandName index = Commands.named(gerrit, "index");
|
||||
CommandName logging = Commands.named(gerrit, "logging");
|
||||
CommandName plugin = Commands.named(gerrit, "plugin");
|
||||
CommandName testSubmit = Commands.named(gerrit, "test-submit");
|
||||
@ -58,10 +57,6 @@ public class DefaultCommandModule extends CommandModule {
|
||||
command(gerrit, VersionCommand.class);
|
||||
command(gerrit, GarbageCollectionCommand.class);
|
||||
|
||||
command(index).toProvider(new DispatchCommandProvider(index));
|
||||
command(index, IndexActivateCommand.class);
|
||||
command(index, IndexStartCommand.class);
|
||||
|
||||
command(gerrit, "plugin").toProvider(new DispatchCommandProvider(plugin));
|
||||
command(plugin, PluginLsCommand.class);
|
||||
command(plugin, PluginEnableCommand.class);
|
||||
|
@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2015 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.sshd.commands;
|
||||
|
||||
import com.google.gerrit.sshd.CommandModule;
|
||||
import com.google.gerrit.sshd.CommandName;
|
||||
import com.google.gerrit.sshd.Commands;
|
||||
import com.google.gerrit.sshd.DispatchCommandProvider;
|
||||
|
||||
public class IndexCommandsModule extends CommandModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
CommandName gerrit = Commands.named("gerrit");
|
||||
CommandName index = Commands.named(gerrit, "index");
|
||||
command(index).toProvider(new DispatchCommandProvider(index));
|
||||
command(index, IndexActivateCommand.class);
|
||||
command(index, IndexStartCommand.class);
|
||||
}
|
||||
}
|
@ -65,6 +65,7 @@ import com.google.gerrit.sshd.SshHostKeyModule;
|
||||
import com.google.gerrit.sshd.SshKeyCacheImpl;
|
||||
import com.google.gerrit.sshd.SshModule;
|
||||
import com.google.gerrit.sshd.commands.DefaultCommandModule;
|
||||
import com.google.gerrit.sshd.commands.IndexCommandsModule;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.CreationException;
|
||||
import com.google.inject.Guice;
|
||||
@ -117,6 +118,7 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
private GuiceFilter filter;
|
||||
|
||||
private ServletContext servletContext;
|
||||
private IndexType indexType;
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse res,
|
||||
@ -166,6 +168,7 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
}
|
||||
|
||||
cfgInjector = createCfgInjector();
|
||||
initIndexType();
|
||||
config = cfgInjector.getInstance(
|
||||
Key.get(Config.class, GerritServerConfig.class));
|
||||
sysInjector = createSysInjector();
|
||||
@ -299,16 +302,13 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
modules.add(new PluginRestApiModule());
|
||||
modules.add(new RestCacheAdminModule());
|
||||
modules.add(new GpgModule(config));
|
||||
AbstractModule changeIndexModule;
|
||||
IndexType indexType = IndexModule.getIndexType(cfgInjector);
|
||||
switch (indexType) {
|
||||
case LUCENE:
|
||||
changeIndexModule = new LuceneIndexModule();
|
||||
modules.add(new LuceneIndexModule());
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("unsupported index.type = " + indexType);
|
||||
}
|
||||
modules.add(changeIndexModule);
|
||||
modules.add(new CanonicalWebUrlModule() {
|
||||
@Override
|
||||
protected Class<? extends Provider<String>> provider() {
|
||||
@ -327,12 +327,19 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
return cfgInjector.createChildInjector(modules);
|
||||
}
|
||||
|
||||
private void initIndexType() {
|
||||
indexType = IndexModule.getIndexType(cfgInjector);
|
||||
}
|
||||
|
||||
private Injector createSshInjector() {
|
||||
final List<Module> modules = new ArrayList<>();
|
||||
modules.add(sysInjector.getInstance(SshModule.class));
|
||||
modules.add(new SshHostKeyModule());
|
||||
modules.add(new DefaultCommandModule(false,
|
||||
sysInjector.getInstance(DownloadConfig.class)));
|
||||
if (indexType == IndexType.LUCENE) {
|
||||
modules.add(new IndexCommandsModule());
|
||||
}
|
||||
return sysInjector.createChildInjector(modules);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user