public List<Csar> getTopologiesCsar(Topology... topologies) { Set<String> ids = Sets.newHashSet(); for (Topology topology : topologies) { ids.add(topology.getId()); } return csarDAO.findByIds(Csar.class, ids.toArray(new String[ids.size()])); }
private void ensureUniqueness(Topology topology, String name) { if (topology.getWorkflows().containsKey(name)) { throw new AlreadyExistException(String.format("The workflow '%s' already exists in topology '%s'.", name, topology.getId())); } } }
/** * Get a {@link NodeTemplate} given its name from a topology * * @param topology the topology * @param nodeTemplateId the name of the node template * @return the found node template, throws NotFoundException if not found */ public static NodeTemplate getNodeTemplate(Topology topology, String nodeTemplateId) { Map<String, NodeTemplate> nodeTemplates = getNodeTemplates(topology); return getNodeTemplate(topology.getId(), nodeTemplateId, nodeTemplates); }
/** * Throw an UpdateTopologyException if the topology is released * * @param topology topology to be checked */ public void throwsErrorIfReleased(Topology topology) { if (isReleased(topology)) { throw new UpdateTopologyException("The topology " + topology.getId() + " cannot be updated because it's released"); } }
@Override protected void processInputOperation(Csar csar, Topology topology, AddInputOperation operation, Map<String, PropertyDefinition> inputs) { if (operation.getInputName() == null || operation.getInputName().isEmpty() || !operation.getInputName().matches("\\w+")) { throw new InvalidNameException("newInputName", operation.getInputName(), "\\w+"); } if (inputs.containsKey(operation.getInputName())) { throw new AlreadyExistException("An input with the id " + operation.getInputName() + "already exist in the topology " + topology.getId()); } inputs.put(operation.getInputName(), operation.getPropertyDefinition()); topology.setInputs(inputs); log.debug("Add a new input [ {} ] for the topology [ {} ].", operation.getInputName(), topology.getId()); }
private static String getRelationshipTarget(String source, String relationshipId, TopologyContext topologyContext) { NodeTemplate sourceNode = safe(topologyContext.getTopology().getNodeTemplates()).get(source); if (sourceNode == null) { throw new NotFoundException("Source " + source + " cannot be found in the topology " + topologyContext.getTopology().getId()); } RelationshipTemplate relationshipTemplate = safe(sourceNode.getRelationships()).get(relationshipId); if (relationshipTemplate == null) { throw new NotFoundException( "Source " + source + " does not have the relationship " + relationshipId + " in the topology " + topologyContext.getTopology().getId()); } return relationshipTemplate.getTarget(); }
@Override protected void processWorkflowOperation(Csar csar, Topology topology, ConnectStepFromOperation operation, Workflow workflow) { log.debug("connecting steps [ {} ] to [ {} ] in the workflow [ {} ] from topology [ {} ]", StringUtils.join(operation.getFromStepIds(), ","), operation.getToStepId(), workflow.getName(), topology.getId()); workflowBuilderService.connectStepFrom(topology, csar, workflow.getName(), operation.getToStepId(), operation.getFromStepIds()); } }
@Override protected void processWorkflowOperation(Csar csar, Topology topology, ConnectStepToOperation operation, Workflow workflow) { log.debug("connecting step [ {} ] to [ {} ] in the workflow [ {} ] from topology [ {} ]", operation.getFromStepId(), StringUtils.join(operation.getToStepIds(), ","), workflow.getName(), topology.getId()); workflowBuilderService.connectStepTo(topology, csar, workflow.getName(), operation.getFromStepId(), operation.getToStepIds()); } }
@Override protected void processNodeOperation(Csar csar, Topology topology, UnSetNodePropertyAsOutputOperation operation, NodeTemplate nodeTemplate) { // check if the property exists check(operation, topology, nodeTemplate); Map<String, Set<String>> outputs = topology.getOutputProperties(); removeAndClean(operation, outputs); topology.setOutputProperties(outputs); log.debug("Unset node [ {} ]'s property [ {} ] as output for the topology [ {} ].", operation.getNodeName(), operation.getPropertyName(), topology.getId()); }
@Override protected void processWorkflowOperation(Csar csar, Topology topology, ReinitializeWorkflowOperation operation, Workflow workflow) { ensureStandard(workflow, "Non standard workflow <" + workflow.getName() + "> can not be reinitialized"); log.debug("reinitializing workflow [ {} ] from topology [ {} ]", workflow.getName(), topology.getId()); workflowBuilderService.reinitWorkflow(workflow.getName(), workflowBuilderService.buildTopologyContext(topology, csar), true); }
@Override protected void process(Csar csar, Topology topology, RenamePolicyOperation operation, PolicyTemplate policyTemplate) { NameValidationUtils.validateNodeName(operation.getNewName()); AlienUtils.failIfExists(topology.getPolicies(), operation.getNewName(), "A node template with the given name {} already exists in the topology {}.", operation.getNewName(), topology.getId()); log.debug("Renaming policy template <" + operation.getPolicyName() + "> to <" + operation.getNewName() + "> in the topology <" + topology.getId() + "> ."); policyTemplate.setName(operation.getNewName()); topology.getPolicies().put(operation.getNewName(), policyTemplate); topology.getPolicies().remove(operation.getPolicyName()); } }
@Override protected void processWorkflowOperation(Csar csar, Topology topology, AddActivityOperation operation, Workflow workflow) { log.debug("adding activity [ {} ] to the workflow [ {} ] from topology [ {} ]", operation.getActivity().toString(), workflow.getName(), topology.getId()); workflowBuilderService.addActivity(topology, csar, operation.getWorkflowName(), operation.getRelatedStepId(), operation.isBefore(), operation.getTarget(), operation.getTargetRelationship(), operation.getActivity()); } }
@Override protected void processWorkflowOperation(Csar csar, Topology topology, SwapStepOperation operation, Workflow workflow) { log.debug("swapping step [ {} ] with [ {} ] in workflow [ {} ] from topology [ {} ]", operation.getStepId(), operation.getTargetStepId(), workflow.getName(), topology.getId()); workflowBuilderService.swapSteps(topology, csar, workflow.getName(), operation.getStepId(), operation.getTargetStepId()); } }
@Override protected void processWorkflowOperation(Csar csar, Topology topology, RenameStepOperation operation, Workflow workflow) { log.debug("renaming step [ {} ] to [ {} ] in workflow [ {} ] from topology [ {} ]", operation.getStepId(), operation.getNewName(), workflow.getName(), topology.getId()); workflowBuilderService.renameStep(topology, csar, workflow.getName(), operation.getStepId(), operation.getNewName()); } }
@Override protected void processRelationshipOperation(Csar csar, Topology topology, DeleteRelationshipOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) { log.debug("Removing the Relationship template <" + operation.getRelationshipName() + "> from the Node template <" + operation.getNodeName() + ">, Topology <" + topology.getId() + "> ."); topologyService.unloadType(topology, relationshipTemplate.getType()); workflowBuilderService.removeRelationship(topology, csar, operation.getNodeName(), operation.getRelationshipName(), relationshipTemplate); nodeTemplate.getRelationships().remove(operation.getRelationshipName()); } }
@Override protected void processNodeOperation(Csar csar, Topology topology, T operation, NodeTemplate nodeTemplate) { RelationshipTemplate relationshipTemplate = safe(nodeTemplate.getRelationships()).get(operation.getRelationshipName()); if (relationshipTemplate == null) { throw new NotFoundException("The relationship with name [" + operation.getRelationshipName() + "] do not exist for the node [" + operation.getNodeName() + "] of the topology [" + topology.getId() + "]"); } processRelationshipOperation(csar, topology, operation, nodeTemplate, relationshipTemplate); }
@Override public void process(Csar csar, Topology topology, T operation) { NodeTemplate nodeTemplate = AlienUtils.getOrFail(topology.getNodeTemplates(), operation.getNodeName(), "The node with name [ {} ] cannot be found in the topology [ {} ].", operation.getNodeName(), topology.getId()); processNodeOperation(csar, topology, operation, nodeTemplate); }
@Override public void process(Csar csar, Topology topology, RenameNodeOperation operation) { NameValidationUtils.validateNodeName(operation.getNewName()); AlienUtils.failIfExists(topology.getNodeTemplates(), operation.getNewName(), "A node template with the given name {} already exists in the topology {}.", operation.getNodeName(), topology.getId()); log.debug("Renaming the Node template [ {} ] with [ {} ] in the topology [ {} ] .", operation.getNodeName(), operation.getNewName(), topology.getId()); TopologyUtils.renameNodeTemplate(topology, operation.getNodeName(), operation.getNewName()); workflowBuilderService.renameNode(topology, csar, operation.getNodeName(), operation.getNewName()); } }
@Override protected void processRelationshipOperation(Csar csar, Topology topology, UnsetRelationshipPropertyAsSecretOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) { RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType()); PropertyDefinition relationshipPropertyDefinition = getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property {} do not exist for relationship {} of node {}", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName()); AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(relationshipPropertyDefinition); relationshipTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue); log.debug("Remove secret from property [ {} ] of relationship template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName(), topology.getId()); } }
@Then("^The RestResponse should contain a topology$") public void The_RestResponse_should_contain_a_topology() throws Throwable { String topologyResponseText = Context.getInstance().getRestResponse(); RestResponse<TopologyDTO> topologyResponse = JsonUtil.read(topologyResponseText, TopologyDTO.class, Context.getJsonMapper()); assertNotNull(topologyResponse.getData()); assertNotNull(topologyResponse.getData().getTopology().getId()); }