use of com.hortonworks.streamline.streams.cluster.catalog.Namespace 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));
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResource method mapServiceToClusterInNamespace.
@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);
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResource method removeNamespace.
@DELETE
@Path("/namespaces/{id}")
@Timed
public Response removeNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, DELETE);
assertNoTopologyRefersNamespace(namespaceId);
Namespace removed = environmentService.removeNamespace(namespaceId);
if (removed != null) {
SecurityUtil.removeAcl(authorizer, securityContext, Namespace.NAMESPACE, namespaceId);
return WSUtils.respondEntity(removed, OK);
}
throw EntityNotFoundException.byId(namespaceId.toString());
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class AbstractBundleHintProviderTest method testProvide.
@Test
public void testProvide() throws Exception {
Cluster cluster1 = createDummyCluster(1L, "cluster1");
Cluster cluster2 = createDummyCluster(2L, "cluster2");
Cluster cluster3 = createDummyCluster(3L, "cluster3");
List<NamespaceServiceClusterMap> testServiceClusterMappings = createDummyServiceClusterMappings(Lists.newArrayList(cluster1, cluster2, cluster3));
new Expectations() {
{
environmentService.getCluster(1L);
result = cluster1;
environmentService.getCluster(2L);
result = cluster2;
environmentService.getCluster(3L);
result = cluster3;
environmentService.listServiceClusterMapping(TEST_NAMESPACE_ID, TEST_SERVICE_NAME);
result = testServiceClusterMappings;
}
};
Namespace namespace = new Namespace();
namespace.setId(TEST_NAMESPACE_ID);
Map<Long, ComponentBundleHintProvider.BundleHintsResponse> hints = provider.provide(namespace, null, null);
Assert.assertEquals(3, hints.size());
Assert.assertEquals(cluster1, hints.get(cluster1.getId()).getCluster());
Assert.assertEquals(TEST_HINTS, hints.get(cluster1.getId()).getHints());
Assert.assertEquals(cluster2, hints.get(cluster2.getId()).getCluster());
Assert.assertEquals(TEST_HINTS, hints.get(cluster2.getId()).getHints());
Assert.assertEquals(cluster3, hints.get(cluster3.getId()).getCluster());
Assert.assertEquals(TEST_HINTS, hints.get(cluster3.getId()).getHints());
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class TopologyActionsService method getTopologyActionsInstance.
public TopologyActions getTopologyActionsInstance(Topology ds) {
Namespace namespace = environmentService.getNamespace(ds.getNamespaceId());
if (namespace == null) {
throw new RuntimeException("Corresponding namespace not found: " + ds.getNamespaceId());
}
TopologyActions topologyActions = topologyActionsContainer.findInstance(namespace);
if (topologyActions == null) {
throw new RuntimeException("Can't find Topology Actions for such namespace " + ds.getNamespaceId());
}
return topologyActions;
}
Aggregations