Search in sources :

Example 1 with AlreadyExistsException

use of com.hortonworks.registries.storage.exception.AlreadyExistsException in project streamline by hortonworks.

the class NamespaceCatalogResource method addNamespace.

@Timed
@POST
@Path("/namespaces")
public Response addNamespace(Namespace namespace, @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_ADMIN);
    try {
        String namespaceName = namespace.getName();
        Namespace result = environmentService.getNamespaceByName(namespaceName);
        if (result != null) {
            throw new AlreadyExistsException("Namespace entity already exists with name " + namespaceName);
        }
        Namespace created = environmentService.addNamespace(namespace);
        SecurityUtil.addAcl(authorizer, securityContext, Namespace.NAMESPACE, created.getId(), EnumSet.allOf(Permission.class));
        return WSUtils.respondEntity(created, CREATED);
    } catch (ProcessingException ex) {
        throw BadRequestException.of();
    }
}
Also used : AlreadyExistsException(com.hortonworks.registries.storage.exception.AlreadyExistsException) Permission(com.hortonworks.streamline.streams.security.Permission) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) ProcessingException(javax.ws.rs.ProcessingException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with AlreadyExistsException

use of com.hortonworks.registries.storage.exception.AlreadyExistsException in project streamline by hortonworks.

the class ServiceBundleResource method addServiceBundle.

/**
 * Add a new service bundle.
 */
@POST
@Path("/servicebundles")
@Timed
public Response addServiceBundle(ServiceBundle serviceBundle) throws IOException, ComponentConfigException {
    try {
        String serviceName = serviceBundle.getName();
        ServiceBundle result = environmentService.getServiceBundleByName(serviceName);
        if (result != null) {
            throw new AlreadyExistsException("Service bundle for " + serviceName + " is already registered.");
        }
        ServiceBundle created = environmentService.addServiceBundle(serviceBundle);
        return WSUtils.respondEntity(created, CREATED);
    } catch (ProcessingException ex) {
        throw BadRequestException.of();
    }
}
Also used : AlreadyExistsException(com.hortonworks.registries.storage.exception.AlreadyExistsException) ServiceBundle(com.hortonworks.streamline.streams.cluster.catalog.ServiceBundle) ProcessingException(javax.ws.rs.ProcessingException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)2 AlreadyExistsException (com.hortonworks.registries.storage.exception.AlreadyExistsException)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 ProcessingException (javax.ws.rs.ProcessingException)2 Namespace (com.hortonworks.streamline.streams.cluster.catalog.Namespace)1 ServiceBundle (com.hortonworks.streamline.streams.cluster.catalog.ServiceBundle)1 Permission (com.hortonworks.streamline.streams.security.Permission)1