Search in sources :

Example 21 with Namespace

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

Example 22 with Namespace

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);
}
Also used : NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 23 with Namespace

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());
}
Also used : 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 24 with Namespace

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());
}
Also used : Expectations(mockit.Expectations) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 25 with Namespace

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;
}
Also used : TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Aggregations

Namespace (com.hortonworks.streamline.streams.cluster.catalog.Namespace)34 NamespaceServiceClusterMap (com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)22 Test (org.junit.Test)12 Verifications (mockit.Verifications)11 Timed (com.codahale.metrics.annotation.Timed)10 BadRequestException (com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException)10 Path (javax.ws.rs.Path)10 Expectations (mockit.Expectations)10 Topology (com.hortonworks.streamline.streams.catalog.Topology)8 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)8 IOException (java.io.IOException)7 Collection (java.util.Collection)7 List (java.util.List)7 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)6 GET (javax.ws.rs.GET)6 TopologyActionsService (com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService)5 TopologyNotAliveException (com.hortonworks.streamline.streams.exception.TopologyNotAliveException)5 ArrayList (java.util.ArrayList)5 DELETE (com.hortonworks.streamline.streams.security.Permission.DELETE)4 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)4