use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class CatalogResourceUtil method enrichTopology.
static TopologyDashboardResponse enrichTopology(Topology topology, String asUser, Integer latencyTopN, EnvironmentService environmentService, TopologyActionsService actionsService, TopologyMetricsService metricsService, StreamCatalogService catalogService) {
LOG.debug("[START] enrichTopology - topology id: {}", topology.getId());
Stopwatch stopwatch = Stopwatch.createStarted();
try {
if (latencyTopN == null) {
latencyTopN = DEFAULT_N_OF_TOP_N_LATENCY;
}
TopologyDashboardResponse detailedResponse;
String namespaceName = null;
Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
if (namespace != null) {
namespaceName = namespace.getName();
}
try {
String runtimeTopologyId = actionsService.getRuntimeTopologyId(topology, asUser);
TopologyMetrics.TopologyMetric topologyMetric = metricsService.getTopologyMetric(topology, asUser);
List<Pair<String, Double>> latenciesTopN = metricsService.getTopNAndOtherComponentsLatency(topology, asUser, latencyTopN);
detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.RUNNING, namespaceName);
detailedResponse.setRuntime(new TopologyRuntimeResponse(runtimeTopologyId, topologyMetric, latenciesTopN));
} catch (TopologyNotAliveException e) {
LOG.debug("Topology {} is not alive", topology.getId());
detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.NOT_RUNNING, namespaceName);
catalogService.getTopologyState(topology.getId()).ifPresent(state -> {
if (TopologyStateFactory.getInstance().getTopologyState(state.getName()) == TopologyStates.TOPOLOGY_STATE_DEPLOYED) {
try {
LOG.info("Force killing streamline topology since its not alive in the cluster");
actionsService.killTopology(topology, asUser);
} catch (Exception ex) {
LOG.error("Error trying to kill topology", ex);
}
}
});
} catch (StormNotReachableException | IOException e) {
LOG.error("Storm is not reachable or fail to operate", e);
detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.UNKNOWN, namespaceName);
} catch (Exception e) {
LOG.error("Unhandled exception occurs while operate with Storm", e);
detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.UNKNOWN, namespaceName);
}
LOG.debug("[END] enrichTopology - topology id: {}, elapsed: {} ms", topology.getId(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
return detailedResponse;
} finally {
stopwatch.stop();
}
}
use of com.hortonworks.streamline.streams.catalog.Topology 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.catalog.Topology in project streamline by hortonworks.
the class NamespaceCatalogResourceTest method testMappingMultipleStreamingEngineViaSetServicesToClusterInNamespace.
@Test
public void testMappingMultipleStreamingEngineViaSetServicesToClusterInNamespace() 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_STREAMING_ENGINE, 2L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 1L), 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.catalog.Topology 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.catalog.Topology in project streamline by hortonworks.
the class TopologyCatalogResource method listTopologies.
@GET
@Path("/topologies")
@Timed
public Response listTopologies(@Context SecurityContext securityContext) {
Collection<Topology> topologies = catalogService.listTopologies();
boolean topologyUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER);
if (topologyUser) {
LOG.debug("Returning all topologies since user has role: {}", Roles.ROLE_TOPOLOGY_USER);
} else {
topologies = SecurityUtil.filter(authorizer, securityContext, NAMESPACE, topologies, READ);
}
Response response;
if (topologies != null) {
response = WSUtils.respondEntities(topologies, OK);
} else {
response = WSUtils.respondEntities(Collections.emptyList(), OK);
}
return response;
}
Aggregations