use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class AutoCredsServiceConfigurationReader method readAllClusters.
@Override
public Map<Long, Map<String, String>> readAllClusters(String serviceName) {
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw new IllegalArgumentException("Namespace " + namespaceId + " doesn't exist.");
}
Long namespaceId = namespace.getId();
Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId, serviceName);
List<Long> clusters = mappings.stream().map(mapping -> mapping.getClusterId()).collect(Collectors.toList());
Map<Long, Map<String, String>> retMap = new HashMap<>();
clusters.forEach(c -> {
Map<String, String> flattenConfig = read(c, serviceName);
retMap.put(c, flattenConfig);
});
return retMap;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class AutoCredsServiceConfigurationReader method read.
@Override
public Map<String, String> read(Long clusterId, String serviceName) {
Cluster cluster = environmentService.getCluster(clusterId);
if (cluster == null) {
throw new IllegalArgumentException("Cluster with id " + clusterId + " doesn't exist.");
}
Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId, serviceName);
boolean associated = mappings.stream().anyMatch(map -> map.getClusterId().equals(clusterId));
if (!associated) {
return Collections.emptyMap();
}
Long serviceId = environmentService.getServiceIdByName(clusterId, serviceName);
if (serviceId == null) {
throw new IllegalStateException("Cluster " + clusterId + " is associated to the service " + serviceName + " for namespace " + namespaceId + ", but actual service doesn't exist.");
}
Collection<ServiceConfiguration> serviceConfigurations = environmentService.listServiceConfigurations(serviceId);
Map<String, String> flattenConfig = new HashMap<>();
String[] confNames = AutoCredsServiceConfigurations.valueOf(serviceName).getConfNames();
// let's forget about optimization here since two lists will be small enough
Arrays.stream(confNames).forEachOrdered(confName -> {
Optional<ServiceConfiguration> serviceConfigurationOptional = serviceConfigurations.stream().filter(sc -> sc.getName().equals(confName)).findFirst();
if (serviceConfigurationOptional.isPresent()) {
ServiceConfiguration sc = serviceConfigurationOptional.get();
try {
Map<String, String> configurationMap = sc.getConfigurationMap();
flattenConfig.putAll(configurationMap);
} catch (IOException e) {
throw new RuntimeException("Can't read configuration from service configuration - ID: " + sc.getId());
}
}
});
return flattenConfig;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class TopologyLogSearchService method getTopologyLogSearchInstance.
private TopologyLogSearch getTopologyLogSearchInstance(Topology topology) {
Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
if (namespace == null) {
throw new RuntimeException("Corresponding namespace not found: " + topology.getNamespaceId());
}
TopologyLogSearch topologyLogSearch = topologyLogSearchContainer.findInstance(namespace);
if (topologyLogSearch == null) {
throw new RuntimeException("Can't find Topology Log Search for such namespace " + topology.getNamespaceId());
}
return topologyLogSearch;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class TopologyMetricsService method getTopologyMetricsInstance.
private TopologyMetrics getTopologyMetricsInstance(Topology topology) {
Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
if (namespace == null) {
throw new RuntimeException("Corresponding namespace not found: " + topology.getNamespaceId());
}
TopologyMetrics topologyMetrics = topologyMetricsContainer.findInstance(namespace);
if (topologyMetrics == null) {
throw new RuntimeException("Can't find Topology Metrics for such namespace " + topology.getNamespaceId());
}
return topologyMetrics;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResource method findServicesToClusterMappingInNamespace.
@GET
@Path("/namespaces/{id}/mapping/{serviceName}")
@Timed
public Response findServicesToClusterMappingInNamespace(@PathParam("id") Long namespaceId, @PathParam("serviceName") String serviceName, @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("Namespace: " + namespaceId.toString());
}
Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId, serviceName);
if (mappings != null) {
return WSUtils.respondEntities(mappings, OK);
} else {
return WSUtils.respondEntities(Collections.emptyList(), OK);
}
}
Aggregations