Search in sources :

Example 36 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate 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);
            }
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) LinkedHashMap(java.util.LinkedHashMap) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 37 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class UpdateRelationshipPropertyValueProcessor method process.

@Override
public void process(Csar csar, Topology topology, UpdateRelationshipPropertyValueOperation operation) {
    NodeTemplate nodeTemplate = AlienUtils.getOrFail(topology.getNodeTemplates(), operation.getNodeName(), "The node with name [ {} ] cannot be found in the topology.", operation.getNodeName());
    RelationshipTemplate relationshipTemplate = AlienUtils.getOrFail(nodeTemplate.getRelationships(), operation.getRelationshipName(), "The relationship with name [ {} ] cannot be found in the node [ {} ].", operation.getRelationshipName(), operation.getNodeName());
    RelationshipType relationshipType = ToscaContext.getOrFail(RelationshipType.class, relationshipTemplate.getType());
    PropertyDefinition propertyDefinition = AlienUtils.getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property [ {} ] doesn't exists in type [ {} ] for relationship [ {} ] of node [ {} ].", operation.getPropertyName(), relationshipTemplate.getType(), operation.getRelationshipName(), operation.getNodeName());
    log.debug("Updating property [ {} ] of the relationship [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", operation.getPropertyName(), relationshipType, operation.getNodeName(), topology.getId(), relationshipType.getProperties().get(operation.getPropertyName()), operation.getPropertyValue());
    try {
        propertyService.setPropertyValue(relationshipTemplate, propertyDefinition, operation.getPropertyName(), operation.getPropertyValue());
    } catch (ConstraintFunctionalException e) {
        throw new PropertyValueException("Error when setting relationship " + operation.getNodeName() + "." + operation.getRelationshipName() + " property.", e, operation.getPropertyName(), operation.getPropertyValue());
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 38 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class AbstractRelationshipProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, T operation, NodeTemplate nodeTemplate) {
    RelationshipTemplate relationshipTemplate = safe(nodeTemplate.getRelationships()).get(operation.getRelationshipName());
    if (relationshipTemplate == null) {
        throw new NotFoundException("The relationship with name [" + operation.getRelationshipName() + "] do not exist for the node [" + operation.getNodeName() + "] of the topology [" + topology.getId() + "]");
    }
    processRelationshipOperation(csar, topology, operation, nodeTemplate, relationshipTemplate);
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NotFoundException(alien4cloud.exception.NotFoundException)

Example 39 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class PaaSUtilsTest method buildFakeRelationShip.

private RelationshipTemplate buildFakeRelationShip(String target, String targetedCapability) {
    Map<String, AbstractPropertyValue> props = Maps.newHashMap();
    props.put(fake1, new ScalarPropertyValue("1_rel"));
    props.put(fake2, null);
    props.put(fake3, new ComplexPropertyValue(MapUtil.newHashMap(new String[] { "toto" }, new String[] { "tata" })));
    props.put(fake5, new ScalarPropertyValue("5_rel"));
    RelationshipTemplate fakeRel = Mockito.mock(RelationshipTemplate.class);
    Mockito.when(fakeRel.getTarget()).thenReturn(target);
    Mockito.when(fakeRel.getTargetedCapabilityName()).thenReturn(targetedCapability);
    Mockito.when(fakeRel.getProperties()).thenReturn(props);
    return fakeRel;
}
Also used : PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate)

Example 40 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class WorkflowGraphUtils method isStepEmpty.

public static boolean isStepEmpty(WorkflowStep step, TopologyContext topologyContext) {
    // No activity
    if (step.getActivity() == null) {
        return true;
    }
    // Inline activity is never empty
    if (step.getActivity() instanceof DelegateWorkflowActivity || step.getActivity() instanceof SetStateWorkflowActivity || step.getActivity() instanceof InlineWorkflowActivity) {
        return false;
    }
    CallOperationWorkflowActivity callOperationWorkflowActivity = (CallOperationWorkflowActivity) step.getActivity();
    NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(step.getTarget());
    String stepInterfaceName = ToscaNormativeUtil.getLongInterfaceName(callOperationWorkflowActivity.getInterfaceName());
    String stepOperationName = callOperationWorkflowActivity.getOperationName();
    if (step instanceof NodeWorkflowStep) {
        return !hasImplementation(nodeTemplate, NodeType.class, topologyContext, stepInterfaceName, stepOperationName);
    } else if (step instanceof RelationshipWorkflowStep) {
        RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) step;
        RelationshipTemplate relationshipTemplate = nodeTemplate.getRelationships().get(relationshipWorkflowStep.getTargetRelationship());
        return !hasImplementation(relationshipTemplate, RelationshipType.class, topologyContext, stepInterfaceName, stepOperationName);
    } else {
        return false;
    }
}
Also used : InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SetStateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.SetStateWorkflowActivity) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) DelegateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity) CallOperationWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.CallOperationWorkflowActivity)

Aggregations

RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)47 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)37 Map (java.util.Map)12 Capability (org.alien4cloud.tosca.model.templates.Capability)12 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)11 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7 NotFoundException (alien4cloud.exception.NotFoundException)6 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)4 LinkedHashMap (java.util.LinkedHashMap)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 AlreadyExistException (alien4cloud.exception.AlreadyExistException)3 ParsingError (alien4cloud.tosca.parser.ParsingError)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Interface (org.alien4cloud.tosca.model.definitions.Interface)3 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)3 Requirement (org.alien4cloud.tosca.model.templates.Requirement)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)3