use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillRequirements.
private void fillRequirements(Topology topology, NodeType substituteNodeType) {
if (topology.getSubstitutionMapping().getRequirements() != null) {
for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getRequirements().entrySet()) {
String key = e.getKey();
String nodeName = e.getValue().getNodeTemplateName();
String requirementName = e.getValue().getTargetId();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
RequirementDefinition requirementDefinition = IndexedModelUtils.getRequirementDefinitionById(nodeTemplateType.getRequirements(), requirementName);
// We cannot change the capability definition here or we will change the original one so we need a clone
requirementDefinition = CloneUtil.clone(requirementDefinition);
requirementDefinition.setId(key);
substituteNodeType.getRequirements().add(requirementDefinition);
}
}
}
use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillCapabilities.
private void fillCapabilities(Topology topology, NodeType substituteNodeType) {
if (topology.getSubstitutionMapping().getCapabilities() != null) {
for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getCapabilities().entrySet()) {
String key = e.getKey();
String nodeName = e.getValue().getNodeTemplateName();
String capabilityName = e.getValue().getTargetId();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
CapabilityDefinition capabilityDefinition = IndexedModelUtils.getCapabilityDefinitionById(nodeTemplateType.getCapabilities(), capabilityName);
// We cannot change the capability definition here or we will change the original one so we need a clone
capabilityDefinition = CloneUtil.clone(capabilityDefinition);
capabilityDefinition.setId(key);
substituteNodeType.getCapabilities().add(capabilityDefinition);
}
}
}
use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class AddCapabilitySubstitutionTypeProcessor method process.
@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()));
}
use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class RemoveCapabilitySubstitutionTypeProcessor method process.
@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());
}
}
use of org.alien4cloud.tosca.model.templates.SubstitutionTarget in project alien4cloud by alien4cloud.
the class RemoveRequirementSubstitutionTypeProcessor method process.
@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());
}
}
Aggregations