use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.
the class NamespaceCatalogResourceTest method testMappingMultipleTimeSeriesDBViaSetServicesToClusterInNamespace.
@Test
public void testMappingMultipleTimeSeriesDBViaSetServicesToClusterInNamespace() throws Exception {
Long testNamespaceId = 1L;
Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
new Expectations() {
{
environmentService.getNamespace(testNamespaceId);
result = testNamespace;
environmentService.listServiceClusterMapping(testNamespaceId);
result = existingMappings;
}
};
List<NamespaceServiceClusterMap> mappingsToApply = Lists.newArrayList(new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 1L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 1L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 2L), new NamespaceServiceClusterMap(testNamespaceId, "KAFKA", 1L));
try {
namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
Assert.fail("Should throw BadRequestException");
} catch (BadRequestException e) {
// passed
}
new Verifications() {
{
catalogService.listTopologies();
times = 0;
topologyActionsService.getRuntimeTopologyId(withAny(new Topology()), anyString);
times = 0;
// request fails before removing existing mappings
environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
times = 0;
}
};
}
use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap in project streamline by hortonworks.
the class EnvironmentServiceTest method invalidateContainersWhenImportingClusterServices.
@Test
public void invalidateContainersWhenImportingClusterServices() throws Exception {
Deencapsulation.setField(environmentService, "clusterImporter", clusterImporter);
long clusterId = 1L;
Cluster testCluster = new Cluster();
testCluster.setId(clusterId);
ArrayList<Long> namespaceIds = Lists.newArrayList(1L, 2L, 3L);
List<NamespaceServiceClusterMap> mappings = new ArrayList<>();
mappings.add(new NamespaceServiceClusterMap(1L, "STORM", clusterId));
mappings.add(new NamespaceServiceClusterMap(2L, "KAFKA", clusterId));
mappings.add(new NamespaceServiceClusterMap(3L, "HADOOP", clusterId));
MockedNamespaceAwareContainer container1 = new MockedNamespaceAwareContainer();
MockedNamespaceAwareContainer container2 = new MockedNamespaceAwareContainer();
environmentService.addNamespaceAwareContainer(container1);
environmentService.addNamespaceAwareContainer(container2);
new Expectations() {
{
clusterImporter.importCluster(discoverer, testCluster);
result = testCluster;
dao.find(NAMESPACE_SERVICE_CLUSTER_MAP, Collections.singletonList(new QueryParam("clusterId", String.valueOf(clusterId))));
result = mappings;
}
};
// we're just checking whether it calls invalidation to associated containers properly
environmentService.importClusterServices(discoverer, testCluster);
assertEquals(3, container1.getInvalidatedNamespaceIds().size());
assertTrue(container1.getInvalidatedNamespaceIds().containsAll(namespaceIds));
assertEquals(3, container2.getInvalidatedNamespaceIds().size());
assertTrue(container2.getInvalidatedNamespaceIds().containsAll(namespaceIds));
}
use of com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap 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.NamespaceServiceClusterMap 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.NamespaceServiceClusterMap 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