use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.
the class AbstractBundleHintProvider method provide.
@Override
public Map<Long, BundleHintsResponse> provide(Namespace namespace, SecurityContext securityContext, Subject subject) {
Map<Long, BundleHintsResponse> hintMap = new HashMap<>();
Collection<NamespaceServiceClusterMap> serviceMappings = environmentService.listServiceClusterMapping(namespace.getId(), getServiceName());
for (NamespaceServiceClusterMap mapping : serviceMappings) {
Long clusterId = mapping.getClusterId();
Cluster cluster = environmentService.getCluster(clusterId);
if (cluster == null) {
throw new RuntimeException(new ClusterNotFoundException(clusterId));
}
BundleHintsResponse response = new BundleHintsResponse(cluster, getHintsOnCluster(cluster, securityContext, subject));
hintMap.put(clusterId, response);
}
return hintMap;
}
use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.
the class AbstractSecureBundleHintProvider method provide.
@Override
public Map<Long, BundleHintsResponse> provide(Namespace namespace, SecurityContext securityContext, Subject subject) {
Map<Long, BundleHintsResponse> hintMap = new HashMap<>();
Collection<NamespaceServiceClusterMap> serviceMappings = environmentService.listServiceClusterMapping(namespace.getId(), getServiceName());
for (NamespaceServiceClusterMap mapping : serviceMappings) {
Long clusterId = mapping.getClusterId();
Cluster cluster = environmentService.getCluster(clusterId);
if (cluster == null) {
throw new RuntimeException(new ClusterNotFoundException(clusterId));
}
BundleHintsResponse response = new SecureBundleHintsResponse(cluster, getSecurity(cluster, securityContext, subject), getHintsOnCluster(cluster, securityContext, subject));
hintMap.put(clusterId, response);
}
return hintMap;
}
use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.
the class NamespaceAwareContainer method getServiceForNamespace.
protected Collection<Service> getServiceForNamespace(Namespace namespace, String serviceName) {
Collection<NamespaceServiceClusterMap> serviceClusterMappings = environmentService.listServiceClusterMapping(namespace.getId(), serviceName);
if (serviceClusterMappings == null) {
throw new RuntimeException("Service name " + serviceName + " is not set in namespace " + namespace.getName() + "(" + namespace.getId() + ")");
}
Collection<Service> services = new ArrayList<>(serviceClusterMappings.size());
for (NamespaceServiceClusterMap mapping : serviceClusterMappings) {
Long clusterId = mapping.getClusterId();
Cluster cluster = environmentService.getCluster(clusterId);
if (cluster == null) {
throw new RuntimeException("Cluster " + clusterId + " is not found");
}
Service service = environmentService.getServiceByName(clusterId, serviceName);
if (service == null) {
throw new RuntimeException("Service name " + serviceName + " is not found in Cluster " + clusterId);
}
services.add(service);
}
return services;
}
use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.
the class NamespaceCatalogResource method setServicesToClusterInNamespace.
@POST
@Path("/namespaces/{id}/mapping/bulk")
@Timed
public Response setServicesToClusterInNamespace(@PathParam("id") Long namespaceId, List<NamespaceServiceClusterMap> mappings, @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();
String timeSeriesDB = namespace.getTimeSeriesDB();
Collection<NamespaceServiceClusterMap> existing = environmentService.listServiceClusterMapping(namespaceId);
Optional<NamespaceServiceClusterMap> existingStreamingEngine = existing.stream().filter(m -> m.getServiceName().equals(streamingEngine)).findFirst();
// indicates that mapping of streaming engine has been changed or removed
if (existingStreamingEngine.isPresent() && !mappings.contains(existingStreamingEngine.get())) {
assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
}
// we're OK to just check with new mappings since we will remove existing mappings
assertServiceIsUnique(mappings, streamingEngine);
assertServiceIsUnique(mappings, timeSeriesDB);
// remove any existing mapping for (namespace, service name) pairs
Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId);
if (existingMappings != null) {
existingMappings.forEach(m -> environmentService.removeServiceClusterMapping(m.getNamespaceId(), m.getServiceName(), m.getClusterId()));
}
List<NamespaceServiceClusterMap> newMappings = mappings.stream().map(environmentService::addOrUpdateServiceClusterMapping).collect(toList());
return WSUtils.respondEntities(newMappings, CREATED);
}
use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.
the class NamespaceCatalogResource method listServiceToClusterMappingInNamespace.
@GET
@Path("/namespaces/{id}/mapping")
@Timed
public Response listServiceToClusterMappingInNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_USER, Namespace.NAMESPACE, namespaceId, READ);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId(namespaceId.toString());
}
Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId);
if (existingMappings != null) {
return WSUtils.respondEntities(existingMappings, OK);
}
return WSUtils.respondEntities(Collections.emptyList(), OK);
}
Aggregations