use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResourceTest method testOverwriteSameTimeSeriesDBMappingViaMapServiceToClusterInNamespace.
@Test
public void testOverwriteSameTimeSeriesDBMappingViaMapServiceToClusterInNamespace() 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;
}
};
NamespaceServiceClusterMap existingTimeSeriesDBMapping = existingMappings.stream().filter(m -> m.getServiceName().equals(TEST_TIME_SERIES_DB)).findAny().get();
namespaceCatalogResource.mapServiceToClusterInNamespace(testNamespaceId, existingTimeSeriesDBMapping, securityContext);
new Verifications() {
{
environmentService.addOrUpdateServiceClusterMapping(withAny(new NamespaceServiceClusterMap()));
times = 1;
}
};
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResourceTest method testUnmapStreamingEngineWhenTopologyIsRunningViaUnmapServiceToClusterInNamespace.
@Test
public void testUnmapStreamingEngineWhenTopologyIsRunningViaUnmapServiceToClusterInNamespace() 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);
try {
namespaceCatalogResource.unmapServiceToClusterInNamespace(testNamespaceId, TEST_STREAMING_ENGINE, 1L, securityContext);
Assert.fail("Should throw BadRequestException");
} catch (BadRequestException e) {
// passed
}
new Verifications() {
{
environmentService.removeServiceClusterMapping(testNamespaceId, TEST_STREAMING_ENGINE, 1L);
times = 0;
}
};
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class StreamsModule method setupPlaceholderTestNamespace.
private void setupPlaceholderTestNamespace(EnvironmentService environmentService) {
if (transactionManager == null) {
throw new RuntimeException("TransactionManager is not initialized");
}
// it's one time setup hence just use it as local variable
ManagedTransaction mt = new ManagedTransaction(transactionManager, TransactionIsolation.DEFAULT);
try {
mt.executeConsumer(() -> {
Namespace testNamespace = environmentService.getNamespace(EnvironmentService.PLACEHOLDER_ID);
if (testNamespace == null) {
testNamespace = new Namespace();
testNamespace.setId(EnvironmentService.PLACEHOLDER_ID);
testNamespace.setName("Test Environment");
testNamespace.setStreamingEngine(MappedTopologyActionsImpl.STORM.name());
// no metric service, no log search service
testNamespace.setDescription("Empty environment to test the topology which doesn't require external service.");
testNamespace.setInternal(true);
testNamespace.setTimestamp(System.currentTimeMillis());
environmentService.addOrUpdateNamespace(EnvironmentService.PLACEHOLDER_ID, testNamespace);
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class TopologyComponentBundleResource method getFieldHints.
@GET
@Path("/componentbundles/{component}/{id}/hints/namespaces/{namespaceId}")
@Timed
public Response getFieldHints(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("id") Long id, @PathParam("namespaceId") Long namespaceId, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_USER);
TopologyComponentBundle bundle = catalogService.getTopologyComponentBundle(id);
if (bundle == null || !bundle.getType().equals(componentType)) {
throw EntityNotFoundException.byId("component bundle id: " + id + " with type: " + componentType);
}
String providerClass = bundle.getFieldHintProviderClass();
if (StringUtils.isNotEmpty(providerClass)) {
ComponentBundleHintProvider provider;
if (bundle.getBuiltin()) {
Class<ComponentBundleHintProvider> clazz = (Class<ComponentBundleHintProvider>) Class.forName(providerClass);
provider = clazz.newInstance();
} else {
provider = hintProviderProxyUtil.loadClassFromJar(bundle.getBundleJar(), providerClass);
}
provider.init(environmentService);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId("namespace id: " + namespaceId);
}
Map<Long, ComponentBundleHintProvider.BundleHintsResponse> hints = provider.provide(namespace, securityContext, subject);
return WSUtils.respondEntity(hints, OK);
} else {
return WSUtils.respondEntity(Collections.emptyMap(), OK);
}
}
Aggregations