use of com.hortonworks.streamline.streams.exception.TopologyNotAliveException 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.exception.TopologyNotAliveException in project streamline by hortonworks.
the class TopologyCatalogResource method removeTopology.
@DELETE
@Path("/topologies/{topologyId}")
@Timed
public Response removeTopology(@PathParam("topologyId") Long topologyId, @javax.ws.rs.QueryParam("onlyCurrent") boolean onlyCurrent, @javax.ws.rs.QueryParam("force") boolean force, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, DELETE);
if (!force) {
Topology result = catalogService.getTopology(topologyId);
if (result == null) {
throw EntityNotFoundException.byId(topologyId.toString());
}
String asUser = WSUtils.getUserFromSecurityContext(securityContext);
try {
String runtimeTopologyId = actionsService.getRuntimeTopologyId(result, asUser);
if (StringUtils.isNotEmpty(runtimeTopologyId)) {
throw BadRequestException.message("Can't remove topology while Topology is running - topology id: " + topologyId);
}
} catch (TopologyNotAliveException e) {
// OK to continue
} catch (StormNotReachableException | IOException e) {
// users need to make a request with force parameter on
throw new StreamingEngineNotReachableException(e.getMessage(), e);
}
}
Response response;
if (onlyCurrent) {
response = removeCurrentTopologyVersion(topologyId);
} else {
response = removeAllTopologyVersions(topologyId);
}
SecurityUtil.removeAcl(authorizer, securityContext, NAMESPACE, topologyId);
return response;
}
use of com.hortonworks.streamline.streams.exception.TopologyNotAliveException in project streamline by hortonworks.
the class TopologyStates method doKill.
private static void doKill(TopologyContext context) throws Exception {
try {
context.setCurrentAction("Killing topology");
invokeKill(context);
context.setState(TOPOLOGY_STATE_INITIAL);
context.setCurrentAction("Topology killed");
} catch (TopologyNotAliveException ex) {
LOG.warn("Got TopologyNotAliveException while trying to kill topology, " + "probably the topology was killed externally.");
context.setState(TOPOLOGY_STATE_INITIAL);
context.setCurrentAction("Setting topology to initial state since its not alive in the cluster");
} catch (Exception ex) {
LOG.error("Error while trying to kill the topology", ex);
context.setCurrentAction("Killing the topology failed due to: " + ex);
throw new IgnoreTransactionRollbackException(ex);
}
}
use of com.hortonworks.streamline.streams.exception.TopologyNotAliveException in project streamline by hortonworks.
the class NamespaceCatalogResourceTest method setupExpectationForSimulatingTopologyIsRunning.
private void setupExpectationForSimulatingTopologyIsRunning(final Long testNamespaceId, final Namespace testNamespace, final Collection<NamespaceServiceClusterMap> existingMappings) throws IOException {
List<Topology> topologies = createTestTopologies(testNamespaceId);
new Expectations() {
{
environmentService.getNamespace(testNamespaceId);
result = testNamespace;
environmentService.listServiceClusterMapping(testNamespaceId);
result = existingMappings;
catalogService.listTopologies();
result = topologies;
// assuming first topology is not running
topologyActionsService.getRuntimeTopologyId(topologies.get(0), anyString);
result = new TopologyNotAliveException("generated exception for purpose");
// and second topology is running now
topologyActionsService.getRuntimeTopologyId(topologies.get(1), anyString);
result = "dummy-storm-topology-id";
}
};
}
Aggregations