Merge "Fix exception handling when reading value from REST response"
This commit is contained in:
@@ -74,7 +74,7 @@ public abstract class Response<T> {
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static <T> T unwrap(T obj) {
|
||||
public static <T> T unwrap(T obj) throws Exception {
|
||||
while (obj instanceof Response) {
|
||||
obj = (T) ((Response) obj).value();
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public abstract class Response<T> {
|
||||
|
||||
public abstract int statusCode();
|
||||
|
||||
public abstract T value();
|
||||
public abstract T value() throws Exception;
|
||||
|
||||
public abstract CacheControl caching();
|
||||
|
||||
@@ -306,8 +306,8 @@ public abstract class Response<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T value() {
|
||||
throw new UnsupportedOperationException();
|
||||
public T value() throws Exception {
|
||||
throw cause();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,7 @@ java_library(
|
||||
"//java/com/google/gerrit/git",
|
||||
"//java/com/google/gerrit/reviewdb:server",
|
||||
"//java/com/google/gerrit/server",
|
||||
"//java/com/google/gerrit/server/api",
|
||||
"//lib:guava",
|
||||
"//lib/bouncycastle:bcpg-neverlink",
|
||||
"//lib/bouncycastle:bcprov-neverlink",
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.gpg.api;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeysInput;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
@@ -68,6 +70,8 @@ public class GpgApiAdapterImpl implements GpgApiAdapter {
|
||||
return gpgKeys.get().list().apply(account).value();
|
||||
} catch (PGPException | IOException e) {
|
||||
throw new GpgException(e);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list GPG keys", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +86,8 @@ public class GpgApiAdapterImpl implements GpgApiAdapter {
|
||||
return postGpgKeys.get().apply(account, in).value();
|
||||
} catch (PGPException | IOException | ConfigInvalidException e) {
|
||||
throw new GpgException(e);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put GPG keys", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.gpg.api;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
@@ -47,8 +49,8 @@ public class GpgKeyApiImpl implements GpgKeyApi {
|
||||
public GpgKeyInfo get() throws RestApiException {
|
||||
try {
|
||||
return get.apply(rsrc).value();
|
||||
} catch (IOException e) {
|
||||
throw new RestApiException("Cannot get GPG key", e);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get GPG key", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +59,7 @@ public class GpgKeyApiImpl implements GpgKeyApi {
|
||||
try {
|
||||
delete.apply(rsrc, new Input());
|
||||
} catch (PGPException | IOException | ConfigInvalidException e) {
|
||||
throw new RestApiException("Cannot delete GPG key", e);
|
||||
throw asRestApiException("Cannot delete GPG key", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,8 +248,12 @@ public class AccountApiImpl implements AccountApi {
|
||||
|
||||
@Override
|
||||
public boolean getActive() throws RestApiException {
|
||||
Response<String> result = getActive.apply(account);
|
||||
return result.statusCode() == SC_OK && result.value().equals("ok");
|
||||
try {
|
||||
Response<String> result = getActive.apply(account);
|
||||
return result.statusCode() == SC_OK && result.value().equals("ok");
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get active", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -401,7 +401,11 @@ class ChangeApiImpl implements ChangeApi {
|
||||
|
||||
@Override
|
||||
public String topic() throws RestApiException {
|
||||
return getTopic.apply(change).value();
|
||||
try {
|
||||
return getTopic.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get topic", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -624,7 +624,11 @@ class RevisionApiImpl implements RevisionApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(revision).value();
|
||||
try {
|
||||
return getDescription.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get description", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -156,7 +156,11 @@ public class ServerImpl implements Server {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TopMenu.MenuEntry> topMenus() {
|
||||
return listTopMenus.apply(new ConfigResource()).value();
|
||||
public List<TopMenu.MenuEntry> topMenus() throws RestApiException {
|
||||
try {
|
||||
return listTopMenus.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get top menus", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,11 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public String name() throws RestApiException {
|
||||
return getName.apply(rsrc).value();
|
||||
try {
|
||||
return getName.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get group name", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,7 +176,11 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(rsrc).value();
|
||||
try {
|
||||
return getDescription.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get group description", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,7 +196,11 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public GroupOptionsInfo options() throws RestApiException {
|
||||
return getOptions.apply(rsrc).value();
|
||||
try {
|
||||
return getOptions.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get group options", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.api.plugins;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.plugins.PluginApi;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
@@ -53,7 +55,11 @@ public class PluginApiImpl implements PluginApi {
|
||||
|
||||
@Override
|
||||
public PluginInfo get() throws RestApiException {
|
||||
return getStatus.apply(resource).value();
|
||||
try {
|
||||
return getStatus.apply(resource).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get status", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.api.plugins;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.plugins.InstallPluginInput;
|
||||
import com.google.gerrit.extensions.api.plugins.PluginApi;
|
||||
import com.google.gerrit.extensions.api.plugins.Plugins;
|
||||
@@ -27,7 +29,6 @@ import com.google.gerrit.server.plugins.PluginsCollection;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.SortedMap;
|
||||
|
||||
@Singleton
|
||||
@@ -59,7 +60,11 @@ public class PluginsImpl implements Plugins {
|
||||
return new ListRequest() {
|
||||
@Override
|
||||
public SortedMap<String, PluginInfo> getAsMap() throws RestApiException {
|
||||
return listProvider.get().request(this).apply(TopLevelResource.INSTANCE).value();
|
||||
try {
|
||||
return listProvider.get().request(this).apply(TopLevelResource.INSTANCE).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list plugins", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -87,8 +92,8 @@ public class PluginsImpl implements Plugins {
|
||||
Response<PluginInfo> created =
|
||||
installProvider.get().setName(name).apply(TopLevelResource.INSTANCE, input);
|
||||
return pluginApi.create(plugins.parse(created.value().id));
|
||||
} catch (IOException e) {
|
||||
throw new RestApiException("could not install plugin", e);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot install plugin", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +119,8 @@ public class BranchApiImpl implements BranchApi {
|
||||
public List<ReflogEntryInfo> reflog() throws RestApiException {
|
||||
try {
|
||||
return getReflog.apply(resource()).value();
|
||||
} catch (IOException | PermissionBackendException e) {
|
||||
throw new RestApiException("Cannot retrieve reflog", e);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve reflog", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.ChildProjectApi;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@@ -43,7 +45,11 @@ public class ChildProjectApiImpl implements ChildProjectApi {
|
||||
|
||||
@Override
|
||||
public ProjectInfo get(boolean recursive) throws RestApiException {
|
||||
getChildProject.setRecursive(recursive);
|
||||
return getChildProject.apply(rsrc).value();
|
||||
try {
|
||||
getChildProject.setRecursive(recursive);
|
||||
return getChildProject.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot child project", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DashboardApiImpl implements DashboardApi {
|
||||
public DashboardInfo get(boolean inherited) throws RestApiException {
|
||||
try {
|
||||
return get.get().setInherited(inherited).apply(resource()).value();
|
||||
} catch (IOException | PermissionBackendException | ConfigInvalidException e) {
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot read dashboard", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,7 +368,11 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(checkExists()).value();
|
||||
try {
|
||||
return getDescription.apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get description", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -427,7 +431,11 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
|
||||
@Override
|
||||
public ConfigInfo config() throws RestApiException {
|
||||
return getConfig.apply(checkExists()).value();
|
||||
try {
|
||||
return getConfig.apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get config", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,16 +15,12 @@
|
||||
package com.google.gerrit.server.restapi.access;
|
||||
|
||||
import com.google.gerrit.extensions.api.access.ProjectAccessInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.restapi.project.GetAccess;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -49,8 +45,7 @@ public class ListAccess implements RestReadView<TopLevelResource> {
|
||||
|
||||
@Override
|
||||
public Response<Map<String, ProjectAccessInfo>> apply(TopLevelResource resource)
|
||||
throws ResourceNotFoundException, ResourceConflictException, IOException,
|
||||
PermissionBackendException {
|
||||
throws Exception {
|
||||
Map<String, ProjectAccessInfo> access = new TreeMap<>();
|
||||
for (String p : projects) {
|
||||
access.put(p, getAccess.apply(Project.nameKey(p)));
|
||||
|
||||
@@ -98,8 +98,7 @@ public class Stars implements ChildCollection<AccountResource, AccountResource.S
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Response<List<ChangeInfo>> apply(AccountResource rsrc)
|
||||
throws BadRequestException, AuthException, PermissionBackendException {
|
||||
public Response<List<ChangeInfo>> apply(AccountResource rsrc) throws Exception {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
throw new AuthException("not allowed to list stars of another account");
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.server.change.ChangeMessageResource;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
@@ -50,8 +49,7 @@ public class ChangeMessages implements ChildCollection<ChangeResource, ChangeMes
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeMessageResource parse(ChangeResource parent, IdString id)
|
||||
throws ResourceNotFoundException, PermissionBackendException {
|
||||
public ChangeMessageResource parse(ChangeResource parent, IdString id) throws Exception {
|
||||
String uuid = id.get();
|
||||
|
||||
List<ChangeMessageInfo> changeMessages = listChangeMessages.apply(parent).value();
|
||||
|
||||
@@ -275,7 +275,7 @@ public class Rebase extends RetryingRestModifyView<RevisionResource, RebaseInput
|
||||
@Override
|
||||
protected Response<ChangeInfo> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, RebaseInput input)
|
||||
throws UpdateException, RestApiException, IOException, PermissionBackendException {
|
||||
throws Exception {
|
||||
PatchSet ps = psUtil.current(rsrc.getNotes());
|
||||
if (ps == null) {
|
||||
throw new ResourceConflictException("current revision is missing");
|
||||
|
||||
@@ -454,9 +454,7 @@ public class Submit
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ChangeInfo> apply(ChangeResource rsrc, SubmitInput input)
|
||||
throws RestApiException, RepositoryNotFoundException, IOException,
|
||||
PermissionBackendException, UpdateException, ConfigInvalidException {
|
||||
public Response<ChangeInfo> apply(ChangeResource rsrc, SubmitInput input) throws Exception {
|
||||
PatchSet ps = psUtil.current(rsrc.getNotes());
|
||||
if (ps == null) {
|
||||
throw new ResourceConflictException("current revision is missing");
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestCollectionCreateView;
|
||||
@@ -223,8 +222,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
|
||||
@Override
|
||||
public Response<AccountInfo> apply(GroupResource resource, IdString id, Input input)
|
||||
throws AuthException, MethodNotAllowedException, ResourceNotFoundException, IOException,
|
||||
ConfigInvalidException, PermissionBackendException {
|
||||
throws Exception {
|
||||
AddMembers.Input in = new AddMembers.Input();
|
||||
in._oneMember = id.get();
|
||||
try {
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.gerrit.extensions.common.GroupInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestCollectionCreateView;
|
||||
@@ -144,8 +143,7 @@ public class AddSubgroups implements RestModifyView<GroupResource, Input> {
|
||||
|
||||
@Override
|
||||
public Response<GroupInfo> apply(GroupResource resource, IdString id, Input input)
|
||||
throws AuthException, MethodNotAllowedException, ResourceNotFoundException, IOException,
|
||||
ConfigInvalidException, PermissionBackendException {
|
||||
throws Exception {
|
||||
AddSubgroups.Input in = new AddSubgroups.Input();
|
||||
in.groups = ImmutableList.of(id.get());
|
||||
try {
|
||||
|
||||
@@ -248,8 +248,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<SortedMap<String, GroupInfo>> apply(TopLevelResource resource)
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
|
||||
public Response<SortedMap<String, GroupInfo>> apply(TopLevelResource resource) throws Exception {
|
||||
SortedMap<String, GroupInfo> output = new TreeMap<>();
|
||||
for (GroupInfo info : get()) {
|
||||
output.put(MoreObjects.firstNonNull(info.name, "Group " + Url.decode(info.id)), info);
|
||||
@@ -258,8 +257,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
return Response.ok(output);
|
||||
}
|
||||
|
||||
public List<GroupInfo> get()
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
|
||||
public List<GroupInfo> get() throws Exception {
|
||||
if (!Strings.isNullOrEmpty(suggest)) {
|
||||
return suggestGroups();
|
||||
}
|
||||
|
||||
@@ -19,15 +19,12 @@ import com.google.gerrit.extensions.api.projects.SetDashboardInput;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestCollectionCreateView;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.DashboardResource;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
@Singleton
|
||||
@@ -45,7 +42,7 @@ public class CreateDashboard
|
||||
|
||||
@Override
|
||||
public Response<DashboardInfo> apply(ProjectResource parent, IdString id, SetDashboardInput input)
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
throws Exception {
|
||||
parent.getProjectState().checkStatePermitsWrite();
|
||||
if (!DashboardsCollection.isDefaultDashboard(id)) {
|
||||
throw new ResourceNotFoundException(id);
|
||||
|
||||
@@ -18,14 +18,11 @@ import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.api.projects.SetDashboardInput;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.DashboardResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
|
||||
@Singleton
|
||||
public class DeleteDashboard implements RestModifyView<DashboardResource, SetDashboardInput> {
|
||||
@@ -38,7 +35,7 @@ public class DeleteDashboard implements RestModifyView<DashboardResource, SetDas
|
||||
|
||||
@Override
|
||||
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
throws Exception {
|
||||
if (resource.isProjectDefault()) {
|
||||
SetDashboardInput in = new SetDashboardInput();
|
||||
in.commitMessage = input != null ? input.commitMessage : null;
|
||||
|
||||
@@ -117,9 +117,7 @@ public class GetAccess implements RestReadView<ProjectResource> {
|
||||
this.projectConfigFactory = projectConfigFactory;
|
||||
}
|
||||
|
||||
public ProjectAccessInfo apply(Project.NameKey nameKey)
|
||||
throws ResourceNotFoundException, ResourceConflictException, IOException,
|
||||
PermissionBackendException {
|
||||
public ProjectAccessInfo apply(Project.NameKey nameKey) throws Exception {
|
||||
ProjectState state = projectCache.checkedGet(nameKey);
|
||||
if (state == null) {
|
||||
throw new ResourceNotFoundException(nameKey.get());
|
||||
|
||||
@@ -22,17 +22,14 @@ import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.api.projects.IndexProjectInput;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.index.project.ProjectIndexer;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.index.IndexExecutor;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
@RequiresCapability(GlobalCapability.MAINTAIN_SERVER)
|
||||
@@ -53,8 +50,7 @@ public class Index implements RestModifyView<ProjectResource, IndexProjectInput>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response.Accepted apply(ProjectResource rsrc, IndexProjectInput input)
|
||||
throws IOException, PermissionBackendException, RestApiException {
|
||||
public Response.Accepted apply(ProjectResource rsrc, IndexProjectInput input) throws Exception {
|
||||
String response = "Project " + rsrc.getName() + " submitted for reindexing";
|
||||
|
||||
reindex(rsrc.getNameKey(), input.async);
|
||||
|
||||
@@ -20,13 +20,10 @@ import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.exceptions.InvalidNameException;
|
||||
import com.google.gerrit.extensions.api.access.ProjectAccessInfo;
|
||||
import com.google.gerrit.extensions.api.access.ProjectAccessInput;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
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.Project;
|
||||
import com.google.gerrit.server.CreateGroupPermissionSyncer;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -34,7 +31,6 @@ import com.google.gerrit.server.account.GroupBackend;
|
||||
import com.google.gerrit.server.git.meta.MetaDataUpdate;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.permissions.RefPermission;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectConfig;
|
||||
@@ -42,7 +38,6 @@ import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@@ -82,8 +77,7 @@ public class SetAccess implements RestModifyView<ProjectResource, ProjectAccessI
|
||||
|
||||
@Override
|
||||
public Response<ProjectAccessInfo> apply(ProjectResource rsrc, ProjectAccessInput input)
|
||||
throws ResourceNotFoundException, ResourceConflictException, IOException, AuthException,
|
||||
BadRequestException, UnprocessableEntityException, PermissionBackendException {
|
||||
throws Exception {
|
||||
MetaDataUpdate.User metaDataUpdateUser = metaDataUpdateFactory.get();
|
||||
|
||||
ProjectConfig config;
|
||||
|
||||
@@ -18,14 +18,11 @@ import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.api.projects.SetDashboardInput;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.DashboardResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
|
||||
@Singleton
|
||||
public class SetDashboard implements RestModifyView<DashboardResource, SetDashboardInput> {
|
||||
@@ -38,7 +35,7 @@ public class SetDashboard implements RestModifyView<DashboardResource, SetDashbo
|
||||
|
||||
@Override
|
||||
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
throws Exception {
|
||||
if (resource.isProjectDefault()) {
|
||||
return defaultSetter.get().apply(resource, input);
|
||||
}
|
||||
|
||||
@@ -23,12 +23,10 @@ import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.git.meta.MetaDataUpdate;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.permissions.ProjectPermission;
|
||||
import com.google.gerrit.server.project.DashboardResource;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
@@ -36,7 +34,6 @@ import com.google.gerrit.server.project.ProjectConfig;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.io.IOException;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.kohsuke.args4j.Option;
|
||||
@@ -70,7 +67,7 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, SetDashbo
|
||||
|
||||
@Override
|
||||
public Response<DashboardInfo> apply(DashboardResource rsrc, SetDashboardInput input)
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
throws Exception {
|
||||
if (input == null) {
|
||||
input = new SetDashboardInput(); // Delete would set input to null.
|
||||
}
|
||||
|
||||
@@ -114,11 +114,12 @@ final class CreateGroupCommand extends SshCommand {
|
||||
}
|
||||
} catch (RestApiException e) {
|
||||
throw die(e);
|
||||
} catch (Exception e) {
|
||||
throw new Failure(1, "unavailable", e);
|
||||
}
|
||||
}
|
||||
|
||||
private GroupResource createGroup()
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
|
||||
private GroupResource createGroup() throws Exception {
|
||||
GroupInput input = new GroupInput();
|
||||
input.description = groupDescription;
|
||||
input.visibleToAll = visibleToAll;
|
||||
|
||||
@@ -23,7 +23,6 @@ import static com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE;
|
||||
import com.google.gerrit.extensions.annotations.RequiresAnyCapability;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.config.ConfigResource;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.restapi.config.ListCaches;
|
||||
import com.google.gerrit.server.restapi.config.ListCaches.OutputFormat;
|
||||
import com.google.gerrit.server.restapi.config.PostCaches;
|
||||
@@ -81,13 +80,13 @@ final class FlushCaches extends SshCommand {
|
||||
}
|
||||
} catch (RestApiException e) {
|
||||
throw die(e.getMessage());
|
||||
} catch (PermissionBackendException e) {
|
||||
} catch (Exception e) {
|
||||
throw new Failure(1, "unavailable", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void doList() {
|
||||
private void doList() throws Exception {
|
||||
for (String name :
|
||||
(List<String>)
|
||||
listCaches.setFormat(OutputFormat.LIST).apply(new ConfigResource()).value()) {
|
||||
|
||||
@@ -211,8 +211,7 @@ final class SetAccountCommand extends SshCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void setAccount()
|
||||
throws IOException, UnloggedFailure, ConfigInvalidException, PermissionBackendException {
|
||||
private void setAccount() throws Failure {
|
||||
user = genericUserFactory.create(id);
|
||||
rsrc = new AccountResource(user.asIdentifiedUser());
|
||||
try {
|
||||
@@ -267,6 +266,8 @@ final class SetAccountCommand extends SshCommand {
|
||||
}
|
||||
} catch (RestApiException e) {
|
||||
throw die(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
throw new Failure(1, "unavailable", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,9 +280,7 @@ final class SetAccountCommand extends SshCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteSshKeys(List<String> sshKeys)
|
||||
throws RestApiException, RepositoryNotFoundException, IOException, ConfigInvalidException,
|
||||
PermissionBackendException {
|
||||
private void deleteSshKeys(List<String> sshKeys) throws Exception {
|
||||
List<SshKeyInfo> infos = getSshKeys.apply(rsrc).value();
|
||||
if (sshKeys.contains("ALL")) {
|
||||
for (SshKeyInfo i : infos) {
|
||||
@@ -318,8 +317,7 @@ final class SetAccountCommand extends SshCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteEmail(String email)
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
|
||||
private void deleteEmail(String email) throws Exception {
|
||||
if (email.equals("ALL")) {
|
||||
List<EmailInfo> emails = getEmails.apply(rsrc).value();
|
||||
for (EmailInfo e : emails) {
|
||||
@@ -330,8 +328,7 @@ final class SetAccountCommand extends SshCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void putPreferred(String email)
|
||||
throws RestApiException, IOException, PermissionBackendException, ConfigInvalidException {
|
||||
private void putPreferred(String email) throws Exception {
|
||||
for (EmailInfo e : getEmails.apply(rsrc).value()) {
|
||||
if (e.email.equals(email)) {
|
||||
putPreferred.apply(new AccountResource.Email(user.asIdentifiedUser(), email), null);
|
||||
|
||||
@@ -16,14 +16,12 @@ package com.google.gerrit.sshd.commands;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.exceptions.StorageException;
|
||||
import com.google.gerrit.extensions.api.projects.ParentInput;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -112,7 +110,7 @@ final class SetParentCommand extends SshCommand {
|
||||
childProjects.addAll(getChildrenForReparenting(oldParent));
|
||||
} catch (PermissionBackendException e) {
|
||||
throw new Failure(1, "permissions unavailable", e);
|
||||
} catch (StorageException | RestApiException e) {
|
||||
} catch (Exception e) {
|
||||
throw new Failure(1, "failure in request", e);
|
||||
}
|
||||
}
|
||||
@@ -148,8 +146,7 @@ final class SetParentCommand extends SshCommand {
|
||||
* list of child projects does not contain projects that were specified to be excluded from
|
||||
* reparenting.
|
||||
*/
|
||||
private List<Project.NameKey> getChildrenForReparenting(ProjectState parent)
|
||||
throws PermissionBackendException, RestApiException {
|
||||
private List<Project.NameKey> getChildrenForReparenting(ProjectState parent) throws Exception {
|
||||
final List<Project.NameKey> childProjects = new ArrayList<>();
|
||||
final List<Project.NameKey> excluded = new ArrayList<>(excludedChildren.size());
|
||||
for (ProjectState excludedChild : excludedChildren) {
|
||||
|
||||
@@ -110,7 +110,7 @@ final class ShowCaches extends SshCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run() throws UnloggedFailure {
|
||||
protected void run() throws Failure {
|
||||
nw = columns - 50;
|
||||
Date now = new Date();
|
||||
stdout.format(
|
||||
@@ -161,38 +161,42 @@ final class ShowCaches extends SshCommand {
|
||||
}
|
||||
stdout.print("+---------------------+---------+---------+\n");
|
||||
|
||||
Collection<CacheInfo> caches = getCaches();
|
||||
printMemoryCoreCaches(caches);
|
||||
printMemoryPluginCaches(caches);
|
||||
printDiskCaches(caches);
|
||||
stdout.print('\n');
|
||||
|
||||
boolean showJvm;
|
||||
try {
|
||||
permissionBackend.user(self).check(GlobalPermission.MAINTAIN_SERVER);
|
||||
showJvm = true;
|
||||
} catch (AuthException | PermissionBackendException e) {
|
||||
// Silently ignore and do not display detailed JVM information.
|
||||
showJvm = false;
|
||||
}
|
||||
if (showJvm) {
|
||||
sshSummary();
|
||||
Collection<CacheInfo> caches = getCaches();
|
||||
printMemoryCoreCaches(caches);
|
||||
printMemoryPluginCaches(caches);
|
||||
printDiskCaches(caches);
|
||||
stdout.print('\n');
|
||||
|
||||
SummaryInfo summary =
|
||||
getSummary.setGc(gc).setJvm(showJVM).apply(new ConfigResource()).value();
|
||||
taskSummary(summary.taskSummary);
|
||||
memSummary(summary.memSummary);
|
||||
threadSummary(summary.threadSummary);
|
||||
|
||||
if (showJVM && summary.jvmSummary != null) {
|
||||
jvmSummary(summary.jvmSummary);
|
||||
boolean showJvm;
|
||||
try {
|
||||
permissionBackend.user(self).check(GlobalPermission.MAINTAIN_SERVER);
|
||||
showJvm = true;
|
||||
} catch (AuthException | PermissionBackendException e) {
|
||||
// Silently ignore and do not display detailed JVM information.
|
||||
showJvm = false;
|
||||
}
|
||||
if (showJvm) {
|
||||
sshSummary();
|
||||
|
||||
SummaryInfo summary =
|
||||
getSummary.setGc(gc).setJvm(showJVM).apply(new ConfigResource()).value();
|
||||
taskSummary(summary.taskSummary);
|
||||
memSummary(summary.memSummary);
|
||||
threadSummary(summary.threadSummary);
|
||||
|
||||
if (showJVM && summary.jvmSummary != null) {
|
||||
jvmSummary(summary.jvmSummary);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new Failure(1, "unavailable", e);
|
||||
}
|
||||
|
||||
stdout.flush();
|
||||
}
|
||||
|
||||
private Collection<CacheInfo> getCaches() {
|
||||
private Collection<CacheInfo> getCaches() throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, CacheInfo> caches =
|
||||
(Map<String, CacheInfo>) listCaches.apply(new ConfigResource()).value();
|
||||
|
||||
@@ -99,6 +99,8 @@ final class ShowQueue extends SshCommand {
|
||||
throw die(e);
|
||||
} catch (PermissionBackendException e) {
|
||||
throw new Failure(1, "permission backend unavailable", e);
|
||||
} catch (Exception e) {
|
||||
throw new Failure(1, "unavailable", e);
|
||||
}
|
||||
|
||||
boolean viewAll = permissionBackend.user(currentUser).testOrFalse(GlobalPermission.VIEW_QUEUE);
|
||||
|
||||
Submodule plugins/delete-project updated: 3a4b095552...757afad54a
Submodule plugins/plugin-manager updated: 69343c65a6...7dad3163ae
Reference in New Issue
Block a user