Add REST endpoint to reindex a single group
This may become handy to fix single groups that are stale in the index. Change-Id: Iab3711f343fe1da9bba4979792edc83c76d75a09 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -34,6 +34,7 @@ import com.google.gerrit.server.group.GetName;
|
||||
import com.google.gerrit.server.group.GetOptions;
|
||||
import com.google.gerrit.server.group.GetOwner;
|
||||
import com.google.gerrit.server.group.GroupResource;
|
||||
import com.google.gerrit.server.group.Index;
|
||||
import com.google.gerrit.server.group.ListIncludedGroups;
|
||||
import com.google.gerrit.server.group.ListMembers;
|
||||
import com.google.gerrit.server.group.PutDescription;
|
||||
@@ -71,6 +72,7 @@ class GroupApiImpl implements GroupApi {
|
||||
private final DeleteIncludedGroups deleteGroups;
|
||||
private final GetAuditLog getAuditLog;
|
||||
private final GroupResource rsrc;
|
||||
private final Index index;
|
||||
|
||||
@AssistedInject
|
||||
GroupApiImpl(
|
||||
@@ -91,6 +93,7 @@ class GroupApiImpl implements GroupApi {
|
||||
AddIncludedGroups addGroups,
|
||||
DeleteIncludedGroups deleteGroups,
|
||||
GetAuditLog getAuditLog,
|
||||
Index index,
|
||||
@Assisted GroupResource rsrc) {
|
||||
this.getGroup = getGroup;
|
||||
this.getDetail = getDetail;
|
||||
@@ -109,6 +112,7 @@ class GroupApiImpl implements GroupApi {
|
||||
this.addGroups = addGroups;
|
||||
this.deleteGroups = deleteGroups;
|
||||
this.getAuditLog = getAuditLog;
|
||||
this.index = index;
|
||||
this.rsrc = rsrc;
|
||||
}
|
||||
|
||||
@@ -270,4 +274,13 @@ class GroupApiImpl implements GroupApi {
|
||||
throw new RestApiException("Cannot get audit log", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void index() throws RestApiException {
|
||||
try {
|
||||
index.apply(rsrc, new Index.Input());
|
||||
} catch (IOException e) {
|
||||
throw new RestApiException("Cannot index group", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// 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.group;
|
||||
|
||||
import com.google.gerrit.common.data.GroupDescriptions;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.group.Index.Input;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Singleton
|
||||
public class Index implements RestModifyView<GroupResource, Input> {
|
||||
public static class Input {
|
||||
}
|
||||
|
||||
private final GroupCache groupCache;
|
||||
|
||||
@Inject
|
||||
Index(GroupCache groupCache) {
|
||||
this.groupCache = groupCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<?> apply(GroupResource rsrc, Input input)
|
||||
throws IOException, AuthException, UnprocessableEntityException {
|
||||
if (!rsrc.getControl().isOwner()) {
|
||||
throw new AuthException("not allowed to index group");
|
||||
}
|
||||
|
||||
AccountGroup group = GroupDescriptions.toAccountGroup(rsrc.getGroup());
|
||||
if (group == null) {
|
||||
throw new UnprocessableEntityException(String
|
||||
.format("External Group Not Allowed: %s", rsrc.getGroupUUID().get()));
|
||||
}
|
||||
|
||||
// evicting the group from the cache, reindexes the account
|
||||
groupCache.evict(group);
|
||||
return Response.none();
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ public class Module extends RestApiModule {
|
||||
get(GROUP_KIND).to(GetGroup.class);
|
||||
put(GROUP_KIND).to(PutGroup.class);
|
||||
get(GROUP_KIND, "detail").to(GetDetail.class);
|
||||
post(GROUP_KIND, "index").to(Index.class);
|
||||
post(GROUP_KIND, "members").to(AddMembers.class);
|
||||
post(GROUP_KIND, "members.add").to(AddMembers.class);
|
||||
post(GROUP_KIND, "members.delete").to(DeleteMembers.class);
|
||||
|
||||
Reference in New Issue
Block a user