Reindex all projects when initializing the site
Bug: Issue 9661 Change-Id: Ic7a82abfab19a3ec05f93a26e2f7cddfe21dacf0
This commit is contained in:
parent
3f53c23e10
commit
c9effe97ee
|
@ -38,7 +38,9 @@ public class ProjectSchemaDefinitions extends SchemaDefinitions<ProjectData> {
|
|||
|
||||
public static final ProjectSchemaDefinitions INSTANCE = new ProjectSchemaDefinitions();
|
||||
|
||||
public static final String NAME = "projects";
|
||||
|
||||
private ProjectSchemaDefinitions() {
|
||||
super("projects", ProjectData.class);
|
||||
super(NAME, ProjectData.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ java_library(
|
|||
"//java/com/google/gerrit/httpd/auth/oauth",
|
||||
"//java/com/google/gerrit/httpd/auth/openid",
|
||||
"//java/com/google/gerrit/index",
|
||||
"//java/com/google/gerrit/index/project",
|
||||
"//java/com/google/gerrit/launcher",
|
||||
"//java/com/google/gerrit/lifecycle",
|
||||
"//java/com/google/gerrit/lucene",
|
||||
|
|
|
@ -14,11 +14,15 @@
|
|||
|
||||
package com.google.gerrit.pgm;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.IoUtil;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.PluginData;
|
||||
import com.google.gerrit.index.project.ProjectSchemaDefinitions;
|
||||
import com.google.gerrit.pgm.init.BaseInit;
|
||||
import com.google.gerrit.pgm.init.Browser;
|
||||
import com.google.gerrit.pgm.init.InitPlugins;
|
||||
|
@ -55,6 +59,9 @@ public class Init extends BaseInit {
|
|||
@Option(name = "--no-auto-start", usage = "Don't automatically start daemon after init")
|
||||
private boolean noAutoStart;
|
||||
|
||||
@Option(name = "--no-reindex", usage = "Don't automatically reindex any entities")
|
||||
private boolean noReindex;
|
||||
|
||||
@Option(name = "--skip-plugins", usage = "Don't install plugins")
|
||||
private boolean skipPlugins;
|
||||
|
||||
|
@ -137,6 +144,7 @@ public class Init extends BaseInit {
|
|||
});
|
||||
modules.add(new GerritServerConfigModule());
|
||||
Guice.createInjector(modules).injectMembers(this);
|
||||
reindexProjects();
|
||||
start(run);
|
||||
}
|
||||
|
||||
|
@ -194,7 +202,6 @@ public class Init extends BaseInit {
|
|||
if (run.flags.autoStart) {
|
||||
if (HostPlatform.isWin32()) {
|
||||
System.err.println("Automatic startup not supported on Win32.");
|
||||
|
||||
} else {
|
||||
startDaemon(run);
|
||||
if (!run.ui.isBatch()) {
|
||||
|
@ -249,6 +256,25 @@ public class Init extends BaseInit {
|
|||
}
|
||||
}
|
||||
|
||||
private void reindexProjects() throws Exception {
|
||||
if (noReindex) {
|
||||
return;
|
||||
}
|
||||
// Reindex all projects, so that we bootstrap the project index for new installations
|
||||
List<String> reindexArgs =
|
||||
ImmutableList.of(
|
||||
"--site-path",
|
||||
getSitePath().toString(),
|
||||
"--threads",
|
||||
Integer.toString(1),
|
||||
"--index",
|
||||
ProjectSchemaDefinitions.NAME);
|
||||
getConsoleUI().message("Init complete, reindexing projects with:");
|
||||
getConsoleUI().message(" reindex " + reindexArgs.stream().collect(joining(" ")));
|
||||
Reindex reindexPgm = new Reindex();
|
||||
reindexPgm.main(reindexArgs.stream().toArray(String[]::new));
|
||||
}
|
||||
|
||||
private static boolean nullOrEmpty(List<?> list) {
|
||||
return list == null || list.isEmpty();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ acceptance_tests(
|
|||
vm_args = ["-Xmx512m"],
|
||||
deps = [
|
||||
":util",
|
||||
"//java/com/google/gerrit/index",
|
||||
"//java/com/google/gerrit/index/project",
|
||||
"//java/com/google/gerrit/server/schema",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
// 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.acceptance.pgm;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.StandaloneSiteTest;
|
||||
import com.google.gerrit.index.IndexConfig;
|
||||
import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gerrit.index.project.ProjectData;
|
||||
import com.google.gerrit.index.project.ProjectIndexCollection;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import java.util.Optional;
|
||||
import org.junit.Test;
|
||||
|
||||
@NoHttpd
|
||||
public class InitIT extends StandaloneSiteTest {
|
||||
|
||||
@Test
|
||||
public void indexesAllProjectsAndAllUsers() throws Exception {
|
||||
runGerrit("init", "-d", sitePaths.site_path.toString(), "--show-stack-trace");
|
||||
try (ServerContext ctx = startServer()) {
|
||||
ProjectIndexCollection projectIndex =
|
||||
ctx.getInjector().getInstance(ProjectIndexCollection.class);
|
||||
Project.NameKey allProjects = ctx.getInjector().getInstance(AllProjectsName.class);
|
||||
Project.NameKey allUsers = ctx.getInjector().getInstance(AllUsersName.class);
|
||||
QueryOptions opts =
|
||||
QueryOptions.create(IndexConfig.createDefault(), 0, 1, ImmutableSet.of("name"));
|
||||
Optional<ProjectData> allProjectsData = projectIndex.getSearchIndex().get(allProjects, opts);
|
||||
assertThat(allProjectsData.isPresent()).isTrue();
|
||||
Optional<ProjectData> allUsersData = projectIndex.getSearchIndex().get(allUsers, opts);
|
||||
assertThat(allUsersData.isPresent()).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue