use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class AddRequirementSubstitutionTypeProcessor method process.
@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()));
}
use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class SetSubstitutionCapabilityServiceRelationshipProcessor method process.
@Override
public void process(Csar csar, Topology topology, SetSubstitutionCapabilityServiceRelationshipOperation operation) {
if (topology.getSubstitutionMapping() == null) {
throw new NotFoundException("The substitution capability with id <" + operation.getSubstitutionCapabilityId() + "> cannot be found.");
}
SubstitutionTarget substitutionTarget = safe(topology.getSubstitutionMapping().getCapabilities()).get(operation.getSubstitutionCapabilityId());
if (substitutionTarget == null) {
throw new NotFoundException("The substitution capability with id <" + operation.getSubstitutionCapabilityId() + "> cannot be found.");
}
super.process(csar, topology, substitutionTarget, operation.getRelationshipType(), operation.getRelationshipVersion());
}
use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class SetSubstitutionRequirementServiceRelationshipProcessor method process.
@Override
public void process(Csar csar, Topology topology, SetSubstitutionRequirementServiceRelationshipOperation operation) {
if (topology.getSubstitutionMapping() == null) {
throw new NotFoundException("The substitution requirement with id <" + operation.getSubstitutionRequirementId() + "> cannot be found.");
}
SubstitutionTarget substitutionTarget = safe(topology.getSubstitutionMapping().getRequirements()).get(operation.getSubstitutionRequirementId());
if (substitutionTarget == null) {
throw new NotFoundException("The substitution requirement with id <" + operation.getSubstitutionRequirementId() + "> cannot be found.");
}
super.process(csar, topology, substitutionTarget, operation.getRelationshipType(), operation.getRelationshipVersion());
}
use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class UpdateRequirementSubstitutionTypeProcessor method process.
@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);
}
use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class TopologyUtils method updateOnNodeTemplateNameChange.
/**
* Update properties in a topology
*/
private static void updateOnNodeTemplateNameChange(String oldNodeTemplateName, String newNodeTemplateName, Topology topology) {
// Output properties
updateKey(topology.getOutputProperties(), oldNodeTemplateName, newNodeTemplateName);
// output capabilities properties
updateKey(topology.getOutputCapabilityProperties(), oldNodeTemplateName, newNodeTemplateName);
// output attributes
updateKey(topology.getOutputAttributes(), oldNodeTemplateName, newNodeTemplateName);
// substitution mapping
if (topology.getSubstitutionMapping() != null) {
if (topology.getSubstitutionMapping().getCapabilities() != null) {
for (SubstitutionTarget st : topology.getSubstitutionMapping().getCapabilities().values()) {
if (st.getNodeTemplateName().equals(oldNodeTemplateName)) {
st.setNodeTemplateName(newNodeTemplateName);
}
}
}
if (topology.getSubstitutionMapping().getRequirements() != null) {
for (SubstitutionTarget st : topology.getSubstitutionMapping().getRequirements().values()) {
if (st.getNodeTemplateName().equals(oldNodeTemplateName)) {
st.setNodeTemplateName(newNodeTemplateName);
}
}
}
}
}
Aggregations