@Test public void testUnmapStreamingEngineWhenTopologyIsRunningViaUnmapServiceToClusterInNamespace() throws Exception { Long testNamespaceId = 1L; Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB); Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId); setupExpectationForSimulatingTopologyIsRunning(testNamespaceId, testNamespace, existingMappings); try { namespaceCatalogResource.unmapServiceToClusterInNamespace(testNamespaceId, TEST_STREAMING_ENGINE, 1L, securityContext); Assert.fail("Should throw BadRequestException"); } catch (BadRequestException e) { } new Verifications() {{ environmentService.removeServiceClusterMapping(testNamespaceId, TEST_STREAMING_ENGINE, 1L); times = 0; }}; }
@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)); 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)); }
NamespaceCatalogResource { @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)); 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)); } }
NamespaceCatalogResource { @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)); 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)); } NamespaceCatalogResource(StreamlineAuthorizer authorizer, StreamCatalogService catalogService,
                                  TopologyActionsService topologyActionsService, EnvironmentService environmentService); }
NamespaceCatalogResource { @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)); 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)); } NamespaceCatalogResource(StreamlineAuthorizer authorizer, StreamCatalogService catalogService,
                                  TopologyActionsService topologyActionsService, EnvironmentService environmentService); @GET @Path("/namespaces") @Timed Response listNamespaces(@Context UriInfo uriInfo,
                                 @Context SecurityContext securityContext); @GET @Path("/namespaces/{id}") @Timed Response getNamespaceById(@PathParam("id") Long namespaceId,
                                   @javax.ws.rs.QueryParam("detail") Boolean detail,
                                   @Context SecurityContext securityContext); @GET @Path("/namespaces/name/{namespaceName}") @Timed Response getNamespaceByName(@PathParam("namespaceName") String namespaceName,
                                     @javax.ws.rs.QueryParam("detail") Boolean detail,
                                     @Context SecurityContext securityContext); @Timed @POST @Path("/namespaces") Response addNamespace(Namespace namespace, @Context SecurityContext securityContext); @DELETE @Path("/namespaces/{id}") @Timed Response removeNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext); @PUT @Path("/namespaces/{id}") @Timed Response addOrUpdateNamespace(@PathParam("id") Long namespaceId,
      Namespace namespace, @Context SecurityContext securityContext); @GET @Path("/namespaces/{id}/mapping") @Timed Response listServiceToClusterMappingInNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext); @GET @Path("/namespaces/{id}/mapping/{serviceName}") @Timed Response findServicesToClusterMappingInNamespace(@PathParam("id") Long namespaceId,
                                                          @PathParam("serviceName") String serviceName,
                                                          @Context SecurityContext securityContext); @POST @Path("/namespaces/{id}/mapping/bulk") @Timed Response setServicesToClusterInNamespace(@PathParam("id") Long namespaceId,
                                                  List<NamespaceServiceClusterMap> mappings,
                                                  @Context SecurityContext securityContext); @POST @Path("/namespaces/{id}/mapping") @Timed Response mapServiceToClusterInNamespace(@PathParam("id") Long namespaceId,
                                                 NamespaceServiceClusterMap mapping, @Context SecurityContext securityContext); @DELETE @Path("/namespaces/{id}/mapping/{serviceName}/cluster/{clusterId}") @Timed Response unmapServiceToClusterInNamespace(@PathParam("id") Long namespaceId,
                                                   @PathParam("serviceName") String serviceName,
                                                   @PathParam("clusterId") Long clusterId,
                                                   @Context SecurityContext securityContext); @DELETE @Path("/namespaces/{id}/mapping") @Timed Response unmapAllServicesToClusterInNamespace(@PathParam("id") Long namespaceId,
                                                       @Context SecurityContext securityContext); }
NamespaceCatalogResource { @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)); 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)); } NamespaceCatalogResource(StreamlineAuthorizer authorizer, StreamCatalogService catalogService,
                                  TopologyActionsService topologyActionsService, EnvironmentService environmentService); @GET @Path("/namespaces") @Timed Response listNamespaces(@Context UriInfo uriInfo,
                                 @Context SecurityContext securityContext); @GET @Path("/namespaces/{id}") @Timed Response getNamespaceById(@PathParam("id") Long namespaceId,
                                   @javax.ws.rs.QueryParam("detail") Boolean detail,
                                   @Context SecurityContext securityContext); @GET @Path("/namespaces/name/{namespaceName}") @Timed Response getNamespaceByName(@PathParam("namespaceName") String namespaceName,
                                     @javax.ws.rs.QueryParam("detail") Boolean detail,
                                     @Context SecurityContext securityContext); @Timed @POST @Path("/namespaces") Response addNamespace(Namespace namespace, @Context SecurityContext securityContext); @DELETE @Path("/namespaces/{id}") @Timed Response removeNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext); @PUT @Path("/namespaces/{id}") @Timed Response addOrUpdateNamespace(@PathParam("id") Long namespaceId,
      Namespace namespace, @Context SecurityContext securityContext); @GET @Path("/namespaces/{id}/mapping") @Timed Response listServiceToClusterMappingInNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext); @GET @Path("/namespaces/{id}/mapping/{serviceName}") @Timed Response findServicesToClusterMappingInNamespace(@PathParam("id") Long namespaceId,
                                                          @PathParam("serviceName") String serviceName,
                                                          @Context SecurityContext securityContext); @POST @Path("/namespaces/{id}/mapping/bulk") @Timed Response setServicesToClusterInNamespace(@PathParam("id") Long namespaceId,
                                                  List<NamespaceServiceClusterMap> mappings,
                                                  @Context SecurityContext securityContext); @POST @Path("/namespaces/{id}/mapping") @Timed Response mapServiceToClusterInNamespace(@PathParam("id") Long namespaceId,
                                                 NamespaceServiceClusterMap mapping, @Context SecurityContext securityContext); @DELETE @Path("/namespaces/{id}/mapping/{serviceName}/cluster/{clusterId}") @Timed Response unmapServiceToClusterInNamespace(@PathParam("id") Long namespaceId,
                                                   @PathParam("serviceName") String serviceName,
                                                   @PathParam("clusterId") Long clusterId,
                                                   @Context SecurityContext securityContext); @DELETE @Path("/namespaces/{id}/mapping") @Timed Response unmapAllServicesToClusterInNamespace(@PathParam("id") Long namespaceId,
                                                       @Context SecurityContext securityContext);  }