use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class NodeMatchingReplaceModifier method processSpecificReplacement.
@Override
protected void processSpecificReplacement(NodeTemplate replacingNode, NodeTemplate replacedTopologyNode, Set<String> topologyNotMergedProps) {
// Also merge relationships
replacingNode.setRelationships(replacedTopologyNode.getRelationships());
// not miss any capability
for (Map.Entry<String, Capability> locationCapabilityEntry : safe(replacingNode.getCapabilities()).entrySet()) {
// Merge capabilities properties from the topology into the substituted node un-set properties
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, locationCapabilityEntry.getValue().getType());
Capability locationCapability = locationCapabilityEntry.getValue();
Capability abstractCapability = safe(replacedTopologyNode.getCapabilities()).get(locationCapabilityEntry.getKey());
// Ignore injection of location values for scalable capability
if (abstractCapability != null && MapUtils.isNotEmpty(abstractCapability.getProperties())) {
if (capabilityType != null && !ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) {
locationCapability.setProperties(CollectionUtils.merge(abstractCapability.getProperties(), locationCapability.getProperties(), true, topologyNotMergedProps));
} else {
locationCapability.setProperties(abstractCapability.getProperties());
}
}
}
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class UnSetNodeCapabilityPropertyAsOutputProcessor method check.
@SuppressWarnings("unchecked")
private void check(UnSetNodeCapabilityPropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) {
if (nodeTemplate.getCapabilities() == null || nodeTemplate.getCapabilities().get(operation.getCapabilityName()) == null) {
throw new NotFoundException("Capability " + operation.getCapabilityName() + " not found in node template " + operation.getNodeName());
}
Capability capabilityTemplate = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
CapabilityType indexedCapabilityType = EditionContextManager.get().getToscaContext().getElement(CapabilityType.class, capabilityTemplate.getType(), true);
if (indexedCapabilityType.getProperties() == null || !indexedCapabilityType.getProperties().containsKey(operation.getPropertyName())) {
throw new NotFoundException("Property " + operation.getPropertyName() + " not found in capability " + operation.getCapabilityName() + " of node " + operation.getNodeName());
}
Set<String> values = (Set<String>) MapUtil.get(topology.getOutputCapabilityProperties(), operation.getNodeName().concat(".").concat(operation.getCapabilityName()));
if (!AlienUtils.safe(values).contains(operation.getPropertyName())) {
throw new NotFoundException("Node " + operation.getNodeName() + " capability " + operation.getCapabilityName() + " 's property " + operation.getPropertyName() + " not found in outputs");
}
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class RenameInputProcessor method processInputOperation.
@Override
protected void processInputOperation(Csar csar, Topology topology, RenameInputOperation operation, Map<String, PropertyDefinition> inputs) {
if (!inputs.containsKey(operation.getInputName())) {
throw new NotFoundException("Input " + operation.getInputName() + " not found");
}
if (operation.getInputName().equals(operation.getNewInputName())) {
// nothing has changed.
return;
}
if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
}
if (inputs.containsKey(operation.getNewInputName())) {
throw new AlreadyExistException("Input " + operation.getNewInputName() + " already existed");
}
PropertyDefinition propertyDefinition = inputs.remove(operation.getInputName());
inputs.put(operation.getNewInputName(), propertyDefinition);
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
for (NodeTemplate nodeTemp : safe(nodeTemplates).values()) {
renameInputInProperties(nodeTemp.getProperties(), operation.getInputName(), operation.getNewInputName());
if (nodeTemp.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemp.getRelationships().values()) {
renameInputInProperties(relationshipTemplate.getProperties(), operation.getInputName(), operation.getNewInputName());
}
}
if (nodeTemp.getCapabilities() != null) {
for (Capability capability : nodeTemp.getCapabilities().values()) {
renameInputInProperties(capability.getProperties(), operation.getInputName(), operation.getNewInputName());
}
}
}
// rename preconfigured input
renamePreconfiguredInput(csar, topology, operation);
log.debug("Change the name of an input parameter [ {} ] to [ {} ] for the topology ", operation.getInputName(), operation.getNewInputName(), topology.getId());
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class ReplaceNodeProcessor method updateRelationshipsCapabilitiesRelationships.
private void updateRelationshipsCapabilitiesRelationships(Topology topology, NodeTemplate nodeTemplate) {
List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTemplate.getName(), topology.getNodeTemplates());
for (RelationshipEntry targetRelationshipEntry : targetRelationships) {
RelationshipTemplate targetRelationship = targetRelationshipEntry.getRelationship();
Capability capability = safe(nodeTemplate.getCapabilities()).get(targetRelationship.getTargetedCapabilityName());
if (capability == null || isCapabilityNotOfType(capability, targetRelationship.getRequirementType())) {
Entry<String, Capability> capabilityEntry = NodeTemplateUtils.getCapabilitEntryyByType(nodeTemplate, targetRelationship.getRequirementType());
targetRelationship.setTargetedCapabilityName(capabilityEntry.getKey());
// check that the relationship type is still valid with the new capability
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, targetRelationship.getType());
if (!isValidRelationship(relationshipType, capabilityEntry.getValue())) {
NodeType sourceNodeType = ToscaContext.get(NodeType.class, targetRelationshipEntry.getSource().getType());
RequirementDefinition requirementDefinition = NodeTypeUtils.getRequirementById(sourceNodeType, targetRelationshipEntry.getRelationship().getRequirementName());
NodeType targetNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
CapabilityDefinition capabilityDefinition = NodeTypeUtils.getCapabilityById(targetNodeType, capabilityEntry.getKey());
RelationshipType validRelationshipType = danglingRequirementService.fetchValidRelationshipType(requirementDefinition, capabilityDefinition);
targetRelationship.setType(validRelationshipType.getElementId());
targetRelationship.setType(validRelationshipType.getElementId());
targetRelationship.setArtifacts(newLinkedHashMap(safe(validRelationshipType.getArtifacts())));
targetRelationship.setAttributes(newLinkedHashMap(safe(validRelationshipType.getAttributes())));
Map<String, AbstractPropertyValue> properties = new LinkedHashMap();
TemplateBuilder.fillProperties(properties, validRelationshipType.getProperties(), null);
targetRelationship.setProperties(properties);
}
}
}
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class FunctionEvaluatorTest method getEvaluationContext.
/**
* Generate the topology below (no need type validations) and inputs to be used for next tests.
*
* @return A function evaluator context for the test topology.
*/
private FunctionEvaluatorContext getEvaluationContext() {
NodeTemplate myNode = new NodeTemplate();
myNode.setProperties(Maps.newHashMap());
setPropertiesValues(myNode.getProperties(), "");
Capability capability = new Capability();
myNode.setCapabilities(Maps.newHashMap());
myNode.getCapabilities().put("my_capability", capability);
capability.setProperties(Maps.newHashMap());
setPropertiesValues(capability.getProperties(), "capa ");
Topology topology = new Topology();
topology.setNodeTemplates(Maps.newHashMap());
topology.getNodeTemplates().put("my_node", myNode);
Map<String, AbstractPropertyValue> inputs = Maps.newHashMap();
inputs.put("scalar_input", new ScalarPropertyValue("scalar input value"));
return new FunctionEvaluatorContext(topology, inputs);
}
Aggregations