use of com.hortonworks.streamline.streams.cluster.catalog.Namespace 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);
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResource method unmapAllServicesToClusterInNamespace.
@DELETE
@Path("/namespaces/{id}/mapping")
@Timed
public Response unmapAllServicesToClusterInNamespace(@PathParam("id") Long namespaceId, @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));
if (containsStreamingEngine) {
assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
}
List<NamespaceServiceClusterMap> removed = mappings.stream().map((x) -> environmentService.removeServiceClusterMapping(x.getNamespaceId(), x.getServiceName(), x.getClusterId())).collect(toList());
return WSUtils.respondEntities(removed, OK);
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResourceTest method createTestNamespace.
private Namespace createTestNamespace(Long namespaceId, String streamingEngine, String timeSeriesDB) {
Namespace testNamespace = new Namespace();
testNamespace.setId(namespaceId);
testNamespace.setName("test-namespace");
testNamespace.setStreamingEngine(streamingEngine);
testNamespace.setTimeSeriesDB(timeSeriesDB);
return testNamespace;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResourceTest method testOverwriteExistingStreamingEngineMappingViaSetServicesToClusterInNamespace.
@Test
public void testOverwriteExistingStreamingEngineMappingViaSetServicesToClusterInNamespace() 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;
}
};
namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, new ArrayList<>(existingMappings), securityContext);
new Verifications() {
{
catalogService.listTopologies();
times = 0;
topologyActionsService.getRuntimeTopologyId(withAny(new Topology()), anyString);
times = 0;
environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
times = existingMappings.size();
environmentService.addOrUpdateServiceClusterMapping(withAny(new NamespaceServiceClusterMap()));
times = existingMappings.size();
}
};
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResourceTest method testChangeMappingOfStreamingEngineViaSetServicesToClusterInNamespace.
@Test
public void testChangeMappingOfStreamingEngineViaSetServicesToClusterInNamespace() throws Exception {
Long testNamespaceId = 1L;
Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
setupExpectationForSimulatingTopologyIsRunning(testNamespaceId, testNamespace, existingMappings);
List<NamespaceServiceClusterMap> mappingsToApply = existingMappings.stream().filter(m -> !m.getServiceName().equals(TEST_STREAMING_ENGINE)).collect(toList());
// change the mapping of streaming engine to cluster id 2
mappingsToApply.add(new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 2L));
try {
namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
Assert.fail("Should throw BadRequestException");
} catch (BadRequestException e) {
// passed
}
new Verifications() {
{
// request fails before removing existing mappings
environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
times = 0;
}
};
}
Aggregations