private void killTopologyIfRunning(TopologyContext context, TopologyLayout layout) { try { TopologyActions.Status engineStatus = context.getTopologyActions().status(layout, context.getAsUser()); if (!engineStatus.getStatus().equals(TopologyActions.Status.STATUS_UNKNOWN)) { invokeKill(context); } } catch (Exception e) { LOG.debug("Not able to get running status of topology '{}'", context.getTopology().getName()); } } };
private static void invokeKill(TopologyContext context) throws Exception { Topology topology = context.getTopology(); TopologyActions topologyActions = context.getTopologyActions(); topologyActions.kill(CatalogToLayoutConverter.getTopologyLayout(topology), context.getAsUser()); LOG.debug("Killed topology '{}'", topology.getName()); } }
@Override public void suspend(TopologyContext context) throws Exception { try { context.setCurrentAction("Suspending topology"); Topology topology = context.getTopology(); TopologyActions topologyActions = context.getTopologyActions(); topologyActions.suspend(CatalogToLayoutConverter.getTopologyLayout(topology), context.getAsUser()); context.setState(TOPOLOGY_STATE_SUSPENDED); context.setCurrentAction("Topology suspended"); } catch (Exception ex) { LOG.error("Error while trying to suspend the topology", ex); context.setCurrentAction("Suspending the topology failed due to: " + ex); throw new IgnoreTransactionRollbackException(ex); } } };
@Override public void resume(TopologyContext context) throws Exception { try { context.setCurrentAction("Resuming topology"); Topology topology = context.getTopology(); TopologyActions topologyActions = context.getTopologyActions(); topologyActions.resume(CatalogToLayoutConverter.getTopologyLayout(topology), context.getAsUser()); context.setState(TOPOLOGY_STATE_DEPLOYED); context.setCurrentAction("Topology resumed"); } catch (Exception ex) { LOG.error("Error while trying to resume the topology", ex); context.setCurrentAction("Resuming the topology failed due to: " + ex); throw new IgnoreTransactionRollbackException(ex); } } };
@Override public void deploy(TopologyContext context) throws Exception { TopologyActions topologyActions = context.getTopologyActions(); Topology topology = context.getTopology(); TopologyDag dag = topology.getTopologyDag(); TopologyLayout layout = CatalogToLayoutConverter.getTopologyLayout(topology, dag); if (dag == null) { throw new IllegalStateException("Topology dag not set up"); } try { context.setCurrentAction("Submitting topology to streaming engine"); String mavenArtifacts = context.getMavenArtifacts(); topologyActions.deploy(layout, mavenArtifacts, context, context.getAsUser()); context.setState(TOPOLOGY_STATE_DEPLOYED); context.setCurrentAction("Topology deployed"); } catch (Exception ex) { LOG.error("Error while trying to deploy the topology in the streaming engine", ex); LOG.error("Trying to kill any running instance of topology '{}'", context.getTopology().getName()); killTopologyIfRunning(context, layout); context.setState(TOPOLOGY_STATE_DEPLOYMENT_FAILED); context.setCurrentAction("Topology submission failed due to: " + ex); throw new IgnoreTransactionRollbackException(ex); } }