Search in sources :

Example 16 with NamespaceServiceClusterMap

use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap 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 17 with NamespaceServiceClusterMap

use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap 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 18 with NamespaceServiceClusterMap

use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.

the class EnvironmentService method importClusterServices.

public Cluster importClusterServices(ServiceNodeDiscoverer serviceNodeDiscoverer, Cluster cluster) throws Exception {
    Cluster newCluster = clusterImporter.importCluster(serviceNodeDiscoverer, cluster);
    // invalidate all containers' elements which is associated to the cluster
    Long clusterId = newCluster.getId();
    List<QueryParam> queryParams = Collections.singletonList(new QueryParam("clusterId", String.valueOf(clusterId)));
    Set<Long> namespaceIdSet = new HashSet<>();
    for (NamespaceServiceClusterMap namespaceServiceClusterMapping : listServiceClusterMapping(queryParams)) {
        Long namespaceId = namespaceServiceClusterMapping.getNamespaceId();
        namespaceIdSet.add(namespaceId);
    }
    containers.forEach(container -> {
        namespaceIdSet.forEach(container::invalidateInstance);
    });
    return newCluster;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) HashSet(java.util.HashSet)

Example 19 with NamespaceServiceClusterMap

use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.

the class EnvironmentService method removeServiceClusterMapping.

public NamespaceServiceClusterMap removeServiceClusterMapping(Long namespaceId, String serviceName, Long clusterId) {
    assertEnvironmentIsNotInternal(namespaceId);
    StorableKey key = getStorableKeyForNamespaceServiceClusterMapping(namespaceId, serviceName, clusterId);
    NamespaceServiceClusterMap ret = this.dao.remove(key);
    invalidateTopologyActionsMetricsInstances(namespaceId);
    return ret;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 20 with NamespaceServiceClusterMap

use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.

the class EnvironmentService method getStorableKeyForNamespaceServiceClusterMapping.

private StorableKey getStorableKeyForNamespaceServiceClusterMapping(Long namespaceId, String serviceName, Long clusterId) {
    NamespaceServiceClusterMap mapping = new NamespaceServiceClusterMap();
    mapping.setNamespaceId(namespaceId);
    mapping.setServiceName(serviceName);
    mapping.setClusterId(clusterId);
    return new StorableKey(NAMESPACE_SERVICE_CLUSTER_MAPPING_NAMESPACE, mapping.getPrimaryKey());
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Aggregations

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