Search in sources :

Example 1 with DELETE

use of com.hortonworks.streamline.streams.security.Permission.DELETE in project streamline by hortonworks.

the class UDFCatalogResource method removeUDF.

/**
 * Remove a UDF by ID.
 *
 * <p>
 * DELETE api/v1/catalog/udfs/:ID
 * </p>
 * <pre>
 * {
 *   "responseCode": 1000,
 *   "responseMessage": "Success",
 *   "entity": {
 *     "id": 48,
 *     "name": "SUBSTRING",
 *     "description": "Substring",
 *     "type": "FUNCTION",
 *     "className": "builtin"
 *   }
 * }
 * </pre>
 */
@DELETE
@Path("/udfs/{id}")
@Timed
public Response removeUDF(@PathParam("id") Long id, @Context SecurityContext securityContext) {
    SecurityUtil.checkPermissions(authorizer, securityContext, UDF.NAMESPACE, id, DELETE);
    UDF removedUDF = catalogService.removeUDF(id);
    if (removedUDF != null) {
        SecurityUtil.removeAcl(authorizer, securityContext, UDF.NAMESPACE, id);
        return WSUtils.respondEntity(removedUDF, OK);
    }
    throw EntityNotFoundException.byId(id.toString());
}
Also used : UDF(com.hortonworks.streamline.streams.catalog.UDF) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with DELETE

use of com.hortonworks.streamline.streams.security.Permission.DELETE in project streamline by hortonworks.

the class NamespaceCatalogResource method unmapAllServicesToClusterInNamespace.

@DELETE
@Path("/namespaces/{id}/mapping")
@Timed
public Response unmapAllServicesToClusterInNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext) {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
    Namespace namespace = environmentService.getNamespace(namespaceId);
    if (namespace == null) {
        throw EntityNotFoundException.byId(namespaceId.toString());
    }
    String streamingEngine = namespace.getStreamingEngine();
    Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId);
    boolean containsStreamingEngine = mappings.stream().anyMatch(m -> m.getServiceName().equals(streamingEngine));
    if (containsStreamingEngine) {
        assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
    }
    List<NamespaceServiceClusterMap> removed = mappings.stream().map((x) -> environmentService.removeServiceClusterMapping(x.getNamespaceId(), x.getServiceName(), x.getClusterId())).collect(toList());
    return WSUtils.respondEntities(removed, OK);
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Roles(com.hortonworks.streamline.streams.security.Roles) Produces(javax.ws.rs.Produces) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) QueryParam(com.hortonworks.registries.common.QueryParam) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) StringUtils(org.apache.commons.lang3.StringUtils) BooleanUtils(org.apache.commons.lang.BooleanUtils) MediaType(javax.ws.rs.core.MediaType) WSUtils(com.hortonworks.streamline.common.util.WSUtils) READ(com.hortonworks.streamline.streams.security.Permission.READ) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) EnumSet(java.util.EnumSet) DELETE(javax.ws.rs.DELETE) SecurityUtil(com.hortonworks.streamline.streams.security.SecurityUtil) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Context(javax.ws.rs.core.Context) Permission(com.hortonworks.streamline.streams.security.Permission) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) OK(javax.ws.rs.core.Response.Status.OK) AlreadyExistsException(com.hortonworks.registries.storage.exception.AlreadyExistsException) Collection(java.util.Collection) Objects(java.util.Objects) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Response(javax.ws.rs.core.Response) ProcessingException(javax.ws.rs.ProcessingException) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) CREATED(javax.ws.rs.core.Response.Status.CREATED) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) PathParam(javax.ws.rs.PathParam) EntityNotFoundException(com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException) GET(javax.ws.rs.GET) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) WRITE(com.hortonworks.streamline.streams.security.Permission.WRITE) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) TopologyActionsService(com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService) IOException(java.io.IOException) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Collectors.toList(java.util.stream.Collectors.toList) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with DELETE

use of com.hortonworks.streamline.streams.security.Permission.DELETE in project streamline by hortonworks.

the class NotifierInfoCatalogResource method removeNotifierInfo.

@DELETE
@Path("/notifiers/{id}")
@Timed
public Response removeNotifierInfo(@PathParam("id") Long id, @Context SecurityContext securityContext) {
    SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, DELETE);
    Notifier removedNotifier = catalogService.removeNotifierInfo(id);
    if (removedNotifier != null) {
        SecurityUtil.removeAcl(authorizer, securityContext, Notifier.NAMESPACE, id);
        return WSUtils.respondEntity(removedNotifier, OK);
    }
    throw EntityNotFoundException.byId(id.toString());
}
Also used : Notifier(com.hortonworks.streamline.streams.catalog.Notifier) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 4 with DELETE

use of com.hortonworks.streamline.streams.security.Permission.DELETE in project streamline by hortonworks.

the class TopologyCatalogResource method removeTopology.

@DELETE
@Path("/topologies/{topologyId}")
@Timed
public Response removeTopology(@PathParam("topologyId") Long topologyId, @javax.ws.rs.QueryParam("onlyCurrent") boolean onlyCurrent, @javax.ws.rs.QueryParam("force") boolean force, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, DELETE);
    if (!force) {
        Topology result = catalogService.getTopology(topologyId);
        if (result == null) {
            throw EntityNotFoundException.byId(topologyId.toString());
        }
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        try {
            String runtimeTopologyId = actionsService.getRuntimeTopologyId(result, asUser);
            if (StringUtils.isNotEmpty(runtimeTopologyId)) {
                throw BadRequestException.message("Can't remove topology while Topology is running - topology id: " + topologyId);
            }
        } catch (TopologyNotAliveException e) {
        // OK to continue
        } catch (StormNotReachableException | IOException e) {
            // users need to make a request with force parameter on
            throw new StreamingEngineNotReachableException(e.getMessage(), e);
        }
    }
    Response response;
    if (onlyCurrent) {
        response = removeCurrentTopologyVersion(topologyId);
    } else {
        response = removeAllTopologyVersions(topologyId);
    }
    SecurityUtil.removeAcl(authorizer, securityContext, NAMESPACE, topologyId);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) StormNotReachableException(com.hortonworks.streamline.streams.storm.common.StormNotReachableException) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) Topology(com.hortonworks.streamline.streams.catalog.Topology) IOException(java.io.IOException) StreamingEngineNotReachableException(com.hortonworks.streamline.common.exception.service.exception.server.StreamingEngineNotReachableException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 5 with DELETE

use of com.hortonworks.streamline.streams.security.Permission.DELETE in project streamline by hortonworks.

the class NamespaceCatalogResource method unmapServiceToClusterInNamespace.

@DELETE
@Path("/namespaces/{id}/mapping/{serviceName}/cluster/{clusterId}")
@Timed
public Response unmapServiceToClusterInNamespace(@PathParam("id") Long namespaceId, @PathParam("serviceName") String serviceName, @PathParam("clusterId") Long clusterId, @Context SecurityContext securityContext) {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
    Namespace namespace = environmentService.getNamespace(namespaceId);
    if (namespace == null) {
        throw EntityNotFoundException.byId(namespaceId.toString());
    }
    String streamingEngine = namespace.getStreamingEngine();
    Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId);
    boolean containsStreamingEngine = mappings.stream().anyMatch(m -> m.getServiceName().equals(streamingEngine));
    // check topology running only streaming engine exists
    if (serviceName.equals(streamingEngine) && containsStreamingEngine) {
        assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
    }
    NamespaceServiceClusterMap mapping = environmentService.removeServiceClusterMapping(namespaceId, serviceName, clusterId);
    if (mapping != null) {
        return WSUtils.respondEntity(mapping, OK);
    }
    throw EntityNotFoundException.byId(buildMessageForCompositeId(namespaceId, serviceName, clusterId));
}
Also used : NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)8 DELETE (com.hortonworks.streamline.streams.security.Permission.DELETE)8 DELETE (javax.ws.rs.DELETE)8 Path (javax.ws.rs.Path)8 Namespace (com.hortonworks.streamline.streams.cluster.catalog.Namespace)3 IOException (java.io.IOException)3 Topology (com.hortonworks.streamline.streams.catalog.Topology)2 NamespaceServiceClusterMap (com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)2 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)2 TopologyNotAliveException (com.hortonworks.streamline.streams.exception.TopologyNotAliveException)2 Response (javax.ws.rs.core.Response)2 QueryParam (com.hortonworks.registries.common.QueryParam)1 AlreadyExistsException (com.hortonworks.registries.storage.exception.AlreadyExistsException)1 BadRequestException (com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException)1 EntityNotFoundException (com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException)1 StreamingEngineNotReachableException (com.hortonworks.streamline.common.exception.service.exception.server.StreamingEngineNotReachableException)1 WSUtils (com.hortonworks.streamline.common.util.WSUtils)1 TopologyActionsService (com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService)1 File (com.hortonworks.streamline.streams.catalog.File)1 Notifier (com.hortonworks.streamline.streams.catalog.Notifier)1