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