@Override public void process(SubstitutionMapping instance) { if (instance == null) { // no substitution mapping. return; } NodeType substitutionDerivedFrom = ToscaContext.get(NodeType.class, instance.getSubstitutionType()); Node node = ParsingContextExecution.getObjectToNodeMap().get(instance.getSubstitutionType()); if (substitutionDerivedFrom == null) { addError(ErrorCode.TYPE_NOT_FOUND, "Type not found", "The type from the element is not found neither in the archive or it's dependencies or is not defined while required.", instance.getSubstitutionType(), node); } else if (!substitutionDerivedFrom.isAbstract()) { addError(ErrorCode.DERIVED_FROM_CONCRETE_TYPE_SUBSTITUTION, "Substitution cannot derive from concrete type", "The substitution derives from " + instance.getSubstitutionType() + " which is not abstract.", instance.getSubstitutionType(), node); } } }
/** * Get the indexed node types used in a topology. * * @param topology The topology for which to get indexed node types. * @param abstractOnly If true, only abstract types will be retrieved. * @param useTemplateNameAsKey If true the name of the node template will be used as key for the type in the returned map, if not the type will be used as * key. * @param failOnTypeNotFound * @return A map of indexed node types. */ public Map<String, NodeType> getIndexedNodeTypesFromTopology(Topology topology, boolean abstractOnly, boolean useTemplateNameAsKey, boolean failOnTypeNotFound) { Map<String, NodeType> nodeTypeMap = getIndexedNodeTypesFromDependencies(topology.getNodeTemplates(), topology.getDependencies(), abstractOnly, useTemplateNameAsKey, failOnTypeNotFound); if (!useTemplateNameAsKey && topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) { NodeType nodeType = getFromContextIfDefined(NodeType.class, topology.getSubstitutionMapping().getSubstitutionType(), topology.getDependencies(), failOnTypeNotFound); nodeTypeMap.put(topology.getSubstitutionMapping().getSubstitutionType(), nodeType); } return nodeTypeMap; }
@Override public void process(Csar csar, Topology topology, RemoveSubstitutionTypeOperation operation) { if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) { throw new NotFoundException("No substitution type has been found"); } // FIXME check also on live edited topologies. // the substitute type os within the topology's archive if (hasArchiveUsing(csar.getName(), csar.getVersion())) { throw new DeleteReferencedObjectException("The substitution can not be removed since it's type is already used in at least another topology"); } topologyService.unloadType(topology, topology.getSubstitutionMapping().getSubstitutionType()); topology.setSubstitutionMapping(null); }
if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) { for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) { addRelationshipTypeFromSubstitutionTarget(topology, relationshipTypes, substitutionTarget, failOnTypeNotFound);
@Override public void process(Csar csar, Topology topology, RemoveCapabilitySubstitutionTypeOperation operation) { 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) { throw new NotFoundException("No substitution capabilities has been found"); } SubstitutionTarget target = substitutionCapabilities.remove(operation.getSubstitutionCapabilityId()); if (target == null) { throw new NotFoundException("No substitution capability has been found for key " + operation.getSubstitutionCapabilityId()); } } }
@Override public void process(Csar csar, Topology topology, RemoveRequirementSubstitutionTypeOperation operation) { 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) { throw new NotFoundException("No requirements has been found"); } SubstitutionTarget target = substitutionRequirements.remove(operation.getSubstitutionRequirementId()); if (target == null) { throw new NotFoundException("No substitution requirement has been found for key " + operation.getSubstitutionRequirementId()); } } }
@Override public void process(Csar csar, Topology topology, UpdateCapabilitySubstitutionTypeOperation operation) { 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) { throw new NotFoundException("No substitution capabilities has been found"); } SubstitutionTarget target = substitutionCapabilities.remove(operation.getSubstitutionCapabilityId()); if (target == null) { throw new NotFoundException("No substitution capability has been found for key " + operation.getSubstitutionCapabilityId()); } if (substitutionCapabilities.containsKey(operation.getNewCapabilityId())) { throw new AlreadyExistException( String.format("Can not rename from <%s> to <%s> since capability <%s> already exists", operation.getSubstitutionCapabilityId(), operation.getNewCapabilityId(), operation.getNewCapabilityId())); } substitutionCapabilities.put(operation.getNewCapabilityId(), target); } }
@Override public void process(Csar csar, Topology topology, UpdateRequirementSubstitutionTypeOperation operation) { 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) { throw new NotFoundException("No substitution requirement has been found"); } SubstitutionTarget target = substitutionRequirements.remove(operation.getSubstitutionRequirementId()); if (target == null) { throw new NotFoundException("No substitution requirement has been found for key " + operation.getSubstitutionRequirementId()); } if (substitutionRequirements.containsKey(operation.getNewRequirementId())) { throw new AlreadyExistException( String.format("Can not rename from <%s> to <%s> since requirement <%s> already exists", operation.getSubstitutionRequirementId(), operation.getNewRequirementId(), operation.getNewRequirementId())); } substitutionRequirements.put(operation.getNewRequirementId(), target); } }
@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())); } }
if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) { NodeType substitutionType = nodeTypes.get(topology.getSubstitutionMapping().getSubstitutionType()); loader.loadType(substitutionType.getElementId(), csarDependencyLoader.buildDependencyBean(substitutionType.getArchiveName(), substitutionType.getArchiveVersion()));
@ToscaContextual public void updateSubstitutionType(final Topology topology, Csar csar) { if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) { return; NodeType nodeType = ToscaContext.getOrFail(NodeType.class, topology.getSubstitutionMapping().getSubstitutionType()); if (csar.getDependencies() == null) { csar.setDependencies(Sets.newHashSet());