Allow to index all changes of a project
So far, indexing a series of changes had to be done by listing them one after the other which can be cumbersome when the number of changes to re-index is high. Add the possibility of indexing all the changes belonging to a project. Change-Id: Ib47f6d65ca49c85713d30806d7579f9d2d9cf823
This commit is contained in:
37
Documentation/cmd-index-project.txt
Normal file
37
Documentation/cmd-index-project.txt
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
= gerrit index project
|
||||||
|
|
||||||
|
== NAME
|
||||||
|
gerrit index project - Index all the changes in one or more projects.
|
||||||
|
|
||||||
|
== SYNOPSIS
|
||||||
|
[verse]
|
||||||
|
--
|
||||||
|
_ssh_ -p <port> <host> _gerrit index project_ <PROJECT> [<PROJECT> ...]
|
||||||
|
--
|
||||||
|
|
||||||
|
== DESCRIPTION
|
||||||
|
Index all the changes in one or more projects.
|
||||||
|
|
||||||
|
== ACCESS
|
||||||
|
Caller must have the 'Maintain Server' capability.
|
||||||
|
|
||||||
|
== SCRIPTING
|
||||||
|
This command is intended to be used in scripts.
|
||||||
|
|
||||||
|
== OPTIONS
|
||||||
|
<PROJECT>::
|
||||||
|
Required; name of the project to be indexed.
|
||||||
|
|
||||||
|
== EXAMPLES
|
||||||
|
Index all changes in projects MyProject and NiceProject.
|
||||||
|
|
||||||
|
----
|
||||||
|
$ ssh -p 29418 user@review.example.com gerrit index project MyProject NiceProject
|
||||||
|
----
|
||||||
|
|
||||||
|
GERRIT
|
||||||
|
------
|
||||||
|
Part of link:index.html[Gerrit Code Review]
|
||||||
|
|
||||||
|
SEARCHBOX
|
||||||
|
---------
|
@@ -133,6 +133,9 @@ link:cmd-index-start.html[gerrit index start]::
|
|||||||
link:cmd-index-changes.html[gerrit index changes]::
|
link:cmd-index-changes.html[gerrit index changes]::
|
||||||
Index one or more changes.
|
Index one or more changes.
|
||||||
|
|
||||||
|
link:cmd-index-project.html[gerrit index project]::
|
||||||
|
Index all the changes in one or more projects.
|
||||||
|
|
||||||
link:cmd-logging-ls-level.html[gerrit logging ls-level]::
|
link:cmd-logging-ls-level.html[gerrit logging ls-level]::
|
||||||
List loggers and their logging level.
|
List loggers and their logging level.
|
||||||
|
|
||||||
|
@@ -1066,6 +1066,24 @@ As result a link:#project-access-info[ProjectAccessInfo] entity is returned.
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
[[index]]
|
||||||
|
=== Index all changes in a project
|
||||||
|
|
||||||
|
Adds or updates all the changes belonging to a project in the secondary index.
|
||||||
|
The indexing task is executed asynchronously in background, so this command
|
||||||
|
returns immediately.
|
||||||
|
|
||||||
|
.Request
|
||||||
|
----
|
||||||
|
POST /projects/MyProject/index HTTP/1.0
|
||||||
|
----
|
||||||
|
|
||||||
|
.Response
|
||||||
|
----
|
||||||
|
HTTP/1.1 202 Accepted
|
||||||
|
Content-Disposition: attachment
|
||||||
|
----
|
||||||
|
|
||||||
[[branch-endpoints]]
|
[[branch-endpoints]]
|
||||||
== Branch Endpoints
|
== Branch Endpoints
|
||||||
|
|
||||||
|
@@ -194,7 +194,7 @@ public class AllChangesIndexer extends SiteIndexer<Change.Id, ChangeData, Change
|
|||||||
return new Result(sw, ok.get(), nDone, nFailed);
|
return new Result(sw, ok.get(), nDone, nFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Callable<Void> reindexProject(
|
public Callable<Void> reindexProject(
|
||||||
final ChangeIndexer indexer,
|
final ChangeIndexer indexer,
|
||||||
final Project.NameKey project,
|
final Project.NameKey project,
|
||||||
final Task done,
|
final Task done,
|
||||||
|
@@ -0,0 +1,65 @@
|
|||||||
|
// Copyright (C) 2017 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.project;
|
||||||
|
|
||||||
|
import static com.google.gerrit.server.git.QueueProvider.QueueType.BATCH;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.CharStreams;
|
||||||
|
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||||
|
import com.google.gerrit.common.data.GlobalCapability;
|
||||||
|
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||||
|
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||||
|
import com.google.gerrit.extensions.restapi.Response;
|
||||||
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
|
import com.google.gerrit.server.git.MultiProgressMonitor;
|
||||||
|
import com.google.gerrit.server.git.MultiProgressMonitor.Task;
|
||||||
|
import com.google.gerrit.server.index.IndexExecutor;
|
||||||
|
import com.google.gerrit.server.index.change.AllChangesIndexer;
|
||||||
|
import com.google.gerrit.server.index.change.ChangeIndexer;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
|
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
|
||||||
|
@Singleton
|
||||||
|
public class Index implements RestModifyView<ProjectResource, ProjectInput> {
|
||||||
|
|
||||||
|
private final AllChangesIndexer allChangesIndexer;
|
||||||
|
private final ChangeIndexer indexer;
|
||||||
|
private final ListeningExecutorService executor;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
Index(
|
||||||
|
AllChangesIndexer allChangesIndexer,
|
||||||
|
ChangeIndexer indexer,
|
||||||
|
@IndexExecutor(BATCH) ListeningExecutorService executor) {
|
||||||
|
this.allChangesIndexer = allChangesIndexer;
|
||||||
|
this.indexer = indexer;
|
||||||
|
this.executor = executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response.Accepted apply(ProjectResource resource, ProjectInput input) {
|
||||||
|
Project.NameKey project = resource.getNameKey();
|
||||||
|
Task mpt =
|
||||||
|
new MultiProgressMonitor(ByteStreams.nullOutputStream(), "Reindexing project")
|
||||||
|
.beginSubTask("", MultiProgressMonitor.UNKNOWN);
|
||||||
|
PrintWriter pw = new PrintWriter(CharStreams.nullWriter());
|
||||||
|
executor.submit(allChangesIndexer.reindexProject(indexer, project, mpt, mpt, pw));
|
||||||
|
return Response.accepted("Project " + project + " submitted for reindexing");
|
||||||
|
}
|
||||||
|
}
|
@@ -61,6 +61,7 @@ public class Module extends RestApiModule {
|
|||||||
|
|
||||||
get(PROJECT_KIND, "statistics.git").to(GetStatistics.class);
|
get(PROJECT_KIND, "statistics.git").to(GetStatistics.class);
|
||||||
post(PROJECT_KIND, "gc").to(GarbageCollect.class);
|
post(PROJECT_KIND, "gc").to(GarbageCollect.class);
|
||||||
|
post(PROJECT_KIND, "index").to(Index.class);
|
||||||
|
|
||||||
child(PROJECT_KIND, "branches").to(BranchesCollection.class);
|
child(PROJECT_KIND, "branches").to(BranchesCollection.class);
|
||||||
put(BRANCH_KIND).to(PutBranch.class);
|
put(BRANCH_KIND).to(PutBranch.class);
|
||||||
|
@@ -29,5 +29,6 @@ public class IndexCommandsModule extends CommandModule {
|
|||||||
command(index, IndexActivateCommand.class);
|
command(index, IndexActivateCommand.class);
|
||||||
command(index, IndexStartCommand.class);
|
command(index, IndexStartCommand.class);
|
||||||
command(index, IndexChangesCommand.class);
|
command(index, IndexChangesCommand.class);
|
||||||
|
command(index, IndexProjectCommand.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
// Copyright (C) 2017 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 static com.google.gerrit.common.data.GlobalCapability.MAINTAIN_SERVER;
|
||||||
|
|
||||||
|
import com.google.gerrit.extensions.annotations.RequiresAnyCapability;
|
||||||
|
import com.google.gerrit.server.project.Index;
|
||||||
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
|
import com.google.gerrit.server.project.ProjectResource;
|
||||||
|
import com.google.gerrit.sshd.CommandMetaData;
|
||||||
|
import com.google.gerrit.sshd.SshCommand;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.kohsuke.args4j.Argument;
|
||||||
|
|
||||||
|
@RequiresAnyCapability({MAINTAIN_SERVER})
|
||||||
|
@CommandMetaData(name = "project", description = "Index changes of a project")
|
||||||
|
final class IndexProjectCommand extends SshCommand {
|
||||||
|
|
||||||
|
@Inject private Index index;
|
||||||
|
|
||||||
|
@Argument(
|
||||||
|
index = 0,
|
||||||
|
required = true,
|
||||||
|
multiValued = true,
|
||||||
|
metaVar = "PROJECT",
|
||||||
|
usage = "projects for which the changes should be indexed"
|
||||||
|
)
|
||||||
|
private List<ProjectControl> projects = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void run() throws UnloggedFailure, Failure, Exception {
|
||||||
|
if (projects.isEmpty()) {
|
||||||
|
throw die("needs at least one project as command arguments");
|
||||||
|
}
|
||||||
|
projects.stream().forEach(this::index);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void index(ProjectControl projectControl) {
|
||||||
|
try {
|
||||||
|
index.apply(new ProjectResource(projectControl), null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
writeError(
|
||||||
|
"error",
|
||||||
|
String.format(
|
||||||
|
"Unable to index %s: %s", projectControl.getProject().getName(), e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user