private SubstitutionTarget parseSubstitutionTarget(Node valueNode, ParsingContextExecution context) { List<String> values = (List<String>) stringListParser.parse(valueNode, context); if (values.size() == 3 && (ParsingContextExecution.get().getDefinitionVersion() != null && ALIEN_DSL_140.equals(ParsingContextExecution.get().getDefinitionVersion()))) { // DSL 1.4.0 allows to specify services relationship types return new SubstitutionTarget(values.get(0), values.get(1), values.get(2)); } if (values.size() != 2) { context.getParsingErrors().add(new ParsingError(ErrorCode.SYNTAX_ERROR, null, valueNode.getStartMark(), "Substitution mapping for capabilities and requirements requires 2 arguments.", valueNode.getEndMark(), null)); return null; } return new SubstitutionTarget(values.get(0), values.get(1)); } }
@Override public void process(Csar csar, Topology topology, AddCapabilitySubstitutionTypeOperation operation) { if (topology.getNodeTemplates() == null || !topology.getNodeTemplates().containsKey(operation.getNodeTemplateName())) { throw new NotFoundException("Node " + operation.getNodeTemplateName() + " do not exist"); } NodeTemplate nodeTemplate = topology.getNodeTemplates().get(operation.getNodeTemplateName()); if (nodeTemplate.getCapabilities() == null || !nodeTemplate.getCapabilities().containsKey(operation.getCapabilityId())) { throw new NotFoundException("Capability " + operation.getCapabilityId() + " do not exist for node " + operation.getNodeTemplateName()); } if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) { throw new NotFoundException("No substitution type has been found"); } Map<String, SubstitutionTarget> substitutionCapabilities = topology.getSubstitutionMapping().getCapabilities(); if (substitutionCapabilities == null) { substitutionCapabilities = Maps.newHashMap(); topology.getSubstitutionMapping().setCapabilities(substitutionCapabilities); } else if (substitutionCapabilities.containsKey(operation.getSubstitutionCapabilityId())) { // ensure name unicity throw new AlreadyExistException(String.format("A substitution with capability id <%s> already exists", operation.getSubstitutionCapabilityId())); } substitutionCapabilities.put(operation.getSubstitutionCapabilityId(), new SubstitutionTarget(operation.getNodeTemplateName(), operation.getCapabilityId())); } }
@Override public void process(Csar csar, Topology topology, AddRequirementSubstitutionTypeOperation operation) { if (topology.getNodeTemplates() == null || !topology.getNodeTemplates().containsKey(operation.getNodeTemplateName())) { throw new NotFoundException("Node " + operation.getNodeTemplateName() + " do not exist"); } NodeTemplate nodeTemplate = topology.getNodeTemplates().get(operation.getNodeTemplateName()); if (nodeTemplate.getRequirements() == null || !nodeTemplate.getRequirements().containsKey(operation.getRequirementId())) { throw new NotFoundException("Requirement " + operation.getRequirementId() + " do not exist for node " + operation.getNodeTemplateName()); } if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) { throw new NotFoundException("No substitution type has been found"); } Map<String, SubstitutionTarget> substitutionRequirements = topology.getSubstitutionMapping().getRequirements(); if (substitutionRequirements == null) { substitutionRequirements = Maps.newHashMap(); topology.getSubstitutionMapping().setRequirements(substitutionRequirements); } else if (substitutionRequirements.containsKey(operation.getSubstitutionRequirementId())) { // ensure name unicity throw new AlreadyExistException(String.format("The substitution requirement <%s> already exists", operation.getSubstitutionRequirementId())); } substitutionRequirements.put(operation.getSubstitutionRequirementId(), new SubstitutionTarget(operation.getNodeTemplateName(), operation.getRequirementId())); } }