private void validateTopology(Topology topology) { StorageUtils.ensureUnique(topology, this::listTopologies, QueryParam.params(Topology.NAME, topology.getName())); }
public Topology cloneTopology(Long namespaceId, Topology topology) throws Exception { Preconditions.checkNotNull(topology, "Topology does not exist"); TopologyData exported = new TopologyData(doExportTopology(topology)); Optional<String> latest = getLatestCloneName(exported.getTopologyName(), listTopologies()); exported.setTopologyName(getNextCloneName(latest.orElse(topology.getName()))); if (namespaceId == null) { namespaceId = topology.getNamespaceId(); } return importTopology(namespaceId, exported); }
@PUT @Path("/topologies/{topologyId}") @Timed public Response addOrUpdateTopology (@PathParam("topologyId") Long topologyId, Topology topology, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, WRITE); if (StringUtils.isEmpty(topology.getName())) { throw BadRequestException.missingParameter(Topology.NAME); } if (StringUtils.isEmpty(topology.getConfig())) { throw BadRequestException.missingParameter(Topology.CONFIG); } if (topology.getNamespaceId() == null) { throw BadRequestException.missingParameter(Topology.NAMESPACE_ID); } Topology existingTopology = catalogService.getTopology(topologyId); Topology result = catalogService.addOrUpdateTopology(topologyId, topology); if (existingTopology != null) { Long prevNamespaceId = existingTopology.getNamespaceId(); if (!result.getNamespaceId().equals(prevNamespaceId)) { LOG.info("Determined namespace change on topology: " + topologyId); // environment has changed: it should set 'reconfigure' to all components catalogService.setReconfigureOnAllComponentsInTopology(result); } } return WSUtils.respondEntity(result, OK); }
@GET @Path("/topologies/{topologyId}/actions/export") @Produces(MediaType.APPLICATION_OCTET_STREAM) @Timed public Response exportTopology(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, READ, EXECUTE); Topology topology = catalogService.getTopology(topologyId); if (topology != null) { String exportedTopology = catalogService.exportTopology(topology); if (!StringUtils.isEmpty(exportedTopology)) { InputStream is = new ByteArrayInputStream(exportedTopology.getBytes(StandardCharsets.UTF_8)); return Response.status(OK) .entity(is) .header("Content-Disposition", "attachment; filename=\"" + topology.getName() + ".json\"") .build(); } } throw EntityNotFoundException.byId(topologyId.toString()); }
public Topology(Topology other) { if (other != null) { setId(other.getId()); setVersionId(other.getVersionId()); setName(other.getName()); setDescription(other.getDescription()); setConfig(other.getConfig()); setNamespaceId(other.getNamespaceId()); setVersionTimestamp(other.getVersionTimestamp()); } // this will be re-generated during deployment. topologyDag = null; }
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()); } } };
public static TopologyLayout getTopologyLayout(Topology topology) throws IOException { return new TopologyLayout(topology.getId(), topology.getName(), topology.getConfig(), null); }
public static TopologyLayout getTopologyLayout(Topology topology, TopologyDag topologyDag) throws IOException { return new TopologyLayout(topology.getId(), topology.getName(), topology.getConfig(), topologyDag); }
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()); } }
@POST @Path("/topologies") @Timed public Response addTopology(Topology topology, @Context SecurityContext securityContext) { SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_ADMIN); if (StringUtils.isEmpty(topology.getName())) { throw BadRequestException.missingParameter(Topology.NAME); } if (StringUtils.isEmpty(topology.getConfig())) { throw BadRequestException.missingParameter(Topology.CONFIG); } Topology createdTopology = catalogService.addTopology(topology); SecurityUtil.addAcl(authorizer, securityContext, NAMESPACE, createdTopology.getId(), EnumSet.allOf(Permission.class)); return WSUtils.respondEntity(createdTopology, CREATED); }
@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); } }
private TopologyData doExportTopology(Topology topology) throws Exception { TopologyDag dag = topologyDagBuilder.getDag(topology); topology.setTopologyDag(dag); TopologyData topologyData = new TopologyData(); TopologyExportVisitor exportVisitor = new TopologyExportVisitor(topology.getId(), topologyData, this); topologyData.setTopologyName(topology.getName()); topologyData.setConfig(topology.getConfig()); TopologyDag topologyDag = topology.getTopologyDag(); if (topologyDag != null) { topologyDag.traverse(exportVisitor); } topologyData.setMetadata(getTopologyEditorMetadata(topology.getId())); return topologyData; }