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());
}
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);
}
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());
}
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;
}
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));
}
Aggregations