use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class Namespaces method getPermissions.
@GET
@Path("/{property}/{cluster}/{namespace}/permissions")
@ApiOperation(value = "Retrieve the permissions for a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist"), @ApiResponse(code = 409, message = "Namespace is not empty") })
public Map<String, Set<AuthAction>> getPermissions(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
validateAdminAccessOnProperty(property);
Policies policies = getNamespacePolicies(property, cluster, namespace);
return policies.auth_policies.namespace_auth;
}
use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class Namespaces method getNamespaceMessageTTL.
@GET
@Path("/{property}/{cluster}/{namespace}/messageTTL")
@ApiOperation(value = "Get the message TTL for the namespace")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist") })
public int getNamespaceMessageTTL(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
validateAdminAccessOnProperty(property);
Policies policies = getNamespacePolicies(property, cluster, namespace);
return policies.message_ttl_in_seconds;
}
use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class Namespaces method removeBacklogQuota.
@DELETE
@Path("/{property}/{cluster}/{namespace}/backlogQuota")
@ApiOperation(value = "Remove a backlog quota policy from a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist"), @ApiResponse(code = 409, message = "Concurrent modification") })
public void removeBacklogQuota(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @QueryParam("backlogQuotaType") BacklogQuotaType backlogQuotaType) {
validateAdminAccessOnProperty(property);
validatePoliciesReadOnlyAccess();
if (backlogQuotaType == null) {
backlogQuotaType = BacklogQuotaType.destination_storage;
}
try {
Stat nodeStat = new Stat();
final String path = path("policies", property, cluster, namespace);
byte[] content = globalZk().getData(path, null, nodeStat);
Policies policies = jsonMapper().readValue(content, Policies.class);
policies.backlog_quota_map.remove(backlogQuotaType);
globalZk().setData(path, jsonMapper().writeValueAsBytes(policies), nodeStat.getVersion());
policiesCache().invalidate(path("policies", property, cluster, namespace));
log.info("[{}] Successfully removed backlog namespace={}/{}/{}, quota={}", clientAppId(), property, cluster, namespace, backlogQuotaType);
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to update backlog quota map for namespace {}/{}/{}: does not exist", clientAppId(), property, cluster, namespace);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (KeeperException.BadVersionException e) {
log.warn("[{}] Failed to update backlog quota map for namespace {}/{}/{}: concurrent modification", clientAppId(), property, cluster, namespace);
throw new RestException(Status.CONFLICT, "Concurrent modification");
} catch (Exception e) {
log.error("[{}] Failed to update backlog quota map for namespace {}/{}/{}", clientAppId(), property, cluster, namespace, e);
throw new RestException(e);
}
}
use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class Namespaces method grantPermissionOnNamespace.
@POST
@Path("/{property}/{cluster}/{namespace}/permissions/{role}")
@ApiOperation(value = "Grant a new permission to a role on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist"), @ApiResponse(code = 409, message = "Concurrent modification") })
public void grantPermissionOnNamespace(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("role") String role, Set<AuthAction> actions) {
validateAdminAccessOnProperty(property);
validatePoliciesReadOnlyAccess();
try {
Stat nodeStat = new Stat();
byte[] content = globalZk().getData(path("policies", property, cluster, namespace), null, nodeStat);
Policies policies = jsonMapper().readValue(content, Policies.class);
policies.auth_policies.namespace_auth.put(role, actions);
// Write back the new policies into zookeeper
globalZk().setData(path("policies", property, cluster, namespace), jsonMapper().writeValueAsBytes(policies), nodeStat.getVersion());
policiesCache().invalidate(path("policies", property, cluster, namespace));
log.info("[{}] Successfully granted access for role {}: {} - namespace {}/{}/{}", clientAppId(), role, actions, property, cluster, namespace);
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to set permissions for namespace {}/{}/{}: does not exist", clientAppId(), property, cluster, namespace);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (KeeperException.BadVersionException e) {
log.warn("[{}] Failed to set permissions for namespace {}/{}/{}: concurrent modification", clientAppId(), property, cluster, namespace);
throw new RestException(Status.CONFLICT, "Concurrent modification");
} catch (Exception e) {
log.error("[{}] Failed to get permissions for namespace {}/{}/{}", clientAppId(), property, cluster, namespace, e);
throw new RestException(e);
}
}
use of io.swagger.annotations.ApiResponses in project che by eclipse.
the class WorkspaceService method updateCommand.
@PUT
@Path("/{id}/command/{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace command by replacing the command with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The command successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the workspace"), @ApiResponse(code = 404, message = "The workspace or the command not found"), @ApiResponse(code = 409, message = "The Command with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateCommand(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the command") @PathParam("name") String cmdName, @ApiParam(value = "The command update", required = true) CommandDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
requiredNotNull(update, "Command update");
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
final List<CommandImpl> commands = workspace.getConfig().getCommands();
if (!commands.removeIf(cmd -> cmd.getName().equals(cmdName))) {
throw new NotFoundException(format("Workspace '%s' doesn't contain command '%s'", id, cmdName));
}
commands.add(new CommandImpl(update));
validator.validateConfig(workspace.getConfig());
return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(workspace.getId(), workspace)), getServiceContext());
}
Aggregations