@Test public void testOverwriteSameTimeSeriesDBMappingViaMapServiceToClusterInNamespace() throws Exception { Long testNamespaceId = 1L; Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB); Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId); new Expectations() {{ environmentService.getNamespace(testNamespaceId); result = testNamespace; environmentService.listServiceClusterMapping(testNamespaceId); result = existingMappings; }}; NamespaceServiceClusterMap existingTimeSeriesDBMapping = existingMappings.stream() .filter(m -> m.getServiceName().equals(TEST_TIME_SERIES_DB)).findAny().get(); namespaceCatalogResource.mapServiceToClusterInNamespace(testNamespaceId, existingTimeSeriesDBMapping, securityContext); new Verifications() {{ environmentService.addOrUpdateServiceClusterMapping(withAny(new NamespaceServiceClusterMap())); times = 1; }}; }
@POST @Path("/namespaces/{id}/mapping") @Timed public Response mapServiceToClusterInNamespace(@PathParam("id") Long namespaceId, NamespaceServiceClusterMap mapping, @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()); } Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId); if (!existingMappings.contains(mapping)) { existingMappings.add(mapping); } String streamingEngine = namespace.getStreamingEngine(); String timeSeriesDB = namespace.getTimeSeriesDB(); assertServiceIsUnique(existingMappings, streamingEngine); assertServiceIsUnique(existingMappings, timeSeriesDB); NamespaceServiceClusterMap newMapping = environmentService.addOrUpdateServiceClusterMapping(mapping); return WSUtils.respondEntity(newMapping, CREATED); }
NamespaceCatalogResource { @POST @Path("/namespaces/{id}/mapping") @Timed public Response mapServiceToClusterInNamespace(@PathParam("id") Long namespaceId, NamespaceServiceClusterMap mapping, @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()); } Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId); if (!existingMappings.contains(mapping)) { existingMappings.add(mapping); } String streamingEngine = namespace.getStreamingEngine(); String timeSeriesDB = namespace.getTimeSeriesDB(); assertServiceIsUnique(existingMappings, streamingEngine); assertServiceIsUnique(existingMappings, timeSeriesDB); NamespaceServiceClusterMap newMapping = environmentService.addOrUpdateServiceClusterMapping(mapping); return WSUtils.respondEntity(newMapping, CREATED); } }
NamespaceCatalogResource { @POST @Path("/namespaces/{id}/mapping") @Timed public Response mapServiceToClusterInNamespace(@PathParam("id") Long namespaceId, NamespaceServiceClusterMap mapping, @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()); } Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId); if (!existingMappings.contains(mapping)) { existingMappings.add(mapping); } String streamingEngine = namespace.getStreamingEngine(); String timeSeriesDB = namespace.getTimeSeriesDB(); assertServiceIsUnique(existingMappings, streamingEngine); assertServiceIsUnique(existingMappings, timeSeriesDB); NamespaceServiceClusterMap newMapping = environmentService.addOrUpdateServiceClusterMapping(mapping); return WSUtils.respondEntity(newMapping, CREATED); } NamespaceCatalogResource(StreamlineAuthorizer authorizer, StreamCatalogService catalogService,
                                  TopologyActionsService topologyActionsService, EnvironmentService environmentService); }
NamespaceCatalogResource { @POST @Path("/namespaces/{id}/mapping") @Timed public Response mapServiceToClusterInNamespace(@PathParam("id") Long namespaceId, NamespaceServiceClusterMap mapping, @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()); } Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId); if (!existingMappings.contains(mapping)) { existingMappings.add(mapping); } String streamingEngine = namespace.getStreamingEngine(); String timeSeriesDB = namespace.getTimeSeriesDB(); assertServiceIsUnique(existingMappings, streamingEngine); assertServiceIsUnique(existingMappings, timeSeriesDB); NamespaceServiceClusterMap newMapping = environmentService.addOrUpdateServiceClusterMapping(mapping); return WSUtils.respondEntity(newMapping, CREATED); } 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 { @POST @Path("/namespaces/{id}/mapping") @Timed public Response mapServiceToClusterInNamespace(@PathParam("id") Long namespaceId, NamespaceServiceClusterMap mapping, @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()); } Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId); if (!existingMappings.contains(mapping)) { existingMappings.add(mapping); } String streamingEngine = namespace.getStreamingEngine(); String timeSeriesDB = namespace.getTimeSeriesDB(); assertServiceIsUnique(existingMappings, streamingEngine); assertServiceIsUnique(existingMappings, timeSeriesDB); NamespaceServiceClusterMap newMapping = environmentService.addOrUpdateServiceClusterMapping(mapping); return WSUtils.respondEntity(newMapping, CREATED); } 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);  }