Search in sources :

Example 6 with Interface

use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.

the class TopologyServiceInterfaceOverrideCheckerService method findWarnings.

public List<IllegalOperationWarning> findWarnings(Topology topology) {
    Set<IllegalOperationWarning> warnings = Sets.newHashSet();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    for (Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
        NodeTemplate nodeTemplate = nodeTempEntry.getValue();
        Map<String, RelationshipTemplate> relationships = nodeTemplate.getRelationships();
        if (relationships != null) {
            for (Entry<String, RelationshipTemplate> entry : relationships.entrySet()) {
                RelationshipTemplate relationshipTemplate = entry.getValue();
                String target = relationshipTemplate.getTarget();
                NodeTemplate targetNodeTemplate = nodeTemplates.get(target);
                boolean serviceIsSource = isService(nodeTemplate);
                boolean serviceIsTarget = isService(targetNodeTemplate);
                if (serviceIsSource || serviceIsTarget) {
                    RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
                    if (relationshipType != null) {
                        Map<String, Interface> interfaces = relationshipType.getInterfaces();
                        if (interfaces != null) {
                            interfaces.forEach((relationshipName, relationshipInterface) -> {
                                Map<String, Operation> operations = relationshipInterface.getOperations();
                                if (operations != null) {
                                    operations.forEach((operationName, operation) -> {
                                        String serviceName;
                                        if (serviceIsTarget) {
                                            serviceName = nodeTemplate.getName();
                                            switch(operationName.toLowerCase()) {
                                                case "add_source":
                                                case "remove_source":
                                                case "source_changed":
                                                case "post_configure_target":
                                                case "pre_configure_target":
                                                    ImplementationArtifact artifact = operation.getImplementationArtifact();
                                                    boolean stepDoSomething = artifact != null;
                                                    if (stepDoSomething) {
                                                        addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
                                                    }
                                                    break;
                                            }
                                        }
                                        if (serviceIsSource) {
                                            serviceName = targetNodeTemplate.getName();
                                            switch(operationName.toLowerCase()) {
                                                case "add_target":
                                                case "remove_target":
                                                case "target_changed":
                                                case "pre_configure_source":
                                                case "post_configure_source":
                                                    ImplementationArtifact artifact = operation.getImplementationArtifact();
                                                    boolean stepDoSomething = artifact != null;
                                                    if (stepDoSomething) {
                                                        addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
                                                    }
                                                    break;
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    }
                }
            }
        }
    }
    return warnings.isEmpty() ? null : new ArrayList<>(warnings);
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Operation(org.alien4cloud.tosca.model.definitions.Operation) IllegalOperationWarning(alien4cloud.topology.warning.IllegalOperationWarning) ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 7 with Interface

use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.

the class WorkflowUtils method getOperation.

/**
 * @return the operation browsing the type hierarchy
 *         FIXME: should we browse hierarchy ? what about order ?
 */
public static Operation getOperation(String nodeTypeName, String interfaceName, String operationName, TopologyContext topologyContext) {
    NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTypeName);
    if (nodeType == null) {
        return null;
    }
    if (nodeType.getInterfaces() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    Interface interfaceType = nodeType.getInterfaces().get(interfaceName);
    if (interfaceType == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    if (interfaceType.getOperations() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    Operation operation = interfaceType.getOperations().get(operationName);
    if (interfaceType.getOperations() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    return operation;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 8 with Interface

use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.

the class ServiceResourceRelationshipService method processSourceOperations.

private void processSourceOperations(PaaSRelationshipTemplate paaSRelationshipTemplate, ServiceResource serviceResource, Interface templateInterface) {
    // Drop default source operations as the service is the source of a relationship
    dropOperations(templateInterface, PRE_CONFIGURE_SOURCE, POST_CONFIGURE_SOURCE, ADD_TARGET, REMOVE_TARGET);
    // for services that are source of a relationship, all operations related to source (the service) are not run.
    String relationshipTypeId = serviceResource.getRequirementsRelationshipTypes().get(paaSRelationshipTemplate.getTemplate().getRequirementName());
    if (relationshipTypeId != null) {
        // The relationship may not exist in the topology archive so we don't use the TOSCA context but make a direct query
        RelationshipType relationshipType = toscaTypeSearchService.findByIdOrFail(RelationshipType.class, relationshipTypeId);
        Interface serviceInterface = safe(relationshipType.getInterfaces()).get(ToscaRelationshipLifecycleConstants.CONFIGURE);
        if (serviceInterface != null) {
            overrideOperations(paaSRelationshipTemplate.getTemplate(), templateInterface, relationshipType, serviceInterface, PRE_CONFIGURE_SOURCE, POST_CONFIGURE_SOURCE, ADD_TARGET, REMOVE_TARGET);
        }
    }
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 9 with Interface

use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.

the class RelationshipTemplateParser method parse.

@Override
public RelationshipTemplate parse(Node node, ParsingContextExecution context) {
    // To parse a relationship template we actually get the parent node to retrieve the requirement name;
    if (!(node instanceof MappingNode) || ((MappingNode) node).getValue().size() != 1) {
        ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
    }
    MappingNode assignmentNode = (MappingNode) node;
    RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
    String relationshipId = scalarParser.parse(assignmentNode.getValue().get(0).getKeyNode(), context);
    // The relationship's id which is used to identify the relationship within the source
    relationshipTemplate.setName(relationshipId);
    // By default the relationship id is the requirement name, it can be overridden with 'type_requirement'
    relationshipTemplate.setRequirementName(relationshipId);
    // Now parse the content of the relationship assignment.
    node = assignmentNode.getValue().get(0).getValueNode();
    if (node instanceof ScalarNode) {
        // Short notation (host: compute)
        relationshipTemplate.setTarget(scalarParser.parse(node, context));
    } else if (node instanceof MappingNode) {
        MappingNode mappingNode = (MappingNode) node;
        for (NodeTuple nodeTuple : mappingNode.getValue()) {
            String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
            switch(key) {
                case "node":
                    relationshipTemplate.setTarget(scalarParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "capability":
                    relationshipTemplate.setTargetedCapabilityName(scalarParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "type_requirement":
                    relationshipTemplate.setRequirementName(scalarParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "relationship":
                    relationshipTemplate.setType(scalarParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "properties":
                    INodeParser<AbstractPropertyValue> propertyValueParser = context.getRegistry().get("node_template_property");
                    MapParser<AbstractPropertyValue> mapParser = baseParserFactory.getMapParser(propertyValueParser, "node_template_property");
                    relationshipTemplate.setProperties(mapParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "interfaces":
                    INodeParser<Map<String, Interface>> interfacesParser = context.getRegistry().get("interfaces");
                    relationshipTemplate.setInterfaces(interfacesParser.parse(nodeTuple.getValueNode(), context));
                    break;
                default:
                    context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_ARTIFACT_KEY, null, node.getStartMark(), "Unrecognized key while parsing implementation artifact", node.getEndMark(), key));
            }
        }
    } else {
        ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
    }
    return relationshipTemplate;
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) INodeParser(alien4cloud.tosca.parser.INodeParser) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) MapParser(alien4cloud.tosca.parser.impl.base.MapParser) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 10 with Interface

use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.

the class RelationshipTemplateParser method parse.

@Override
public RelationshipTemplate parse(Node node, ParsingContextExecution context) {
    // To parse a relationship template we actually get the parent node to retrieve the requirement name;
    if (!(node instanceof MappingNode) || ((MappingNode) node).getValue().size() != 1) {
        ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
    }
    MappingNode assignmentNode = (MappingNode) node;
    RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
    relationshipTemplate.setRequirementName(scalarParser.parse(assignmentNode.getValue().get(0).getKeyNode(), context));
    // Now parse the content of the relationship assignment.
    node = assignmentNode.getValue().get(0).getValueNode();
    if (node instanceof ScalarNode) {
        // Short notation (host: compute)
        relationshipTemplate.setTarget(scalarParser.parse(node, context));
    } else if (node instanceof MappingNode) {
        MappingNode mappingNode = (MappingNode) node;
        for (NodeTuple nodeTuple : mappingNode.getValue()) {
            String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
            switch(key) {
                case "node":
                    relationshipTemplate.setTarget(scalarParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "capability":
                    relationshipTemplate.setTargetedCapabilityName(scalarParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "relationship":
                    relationshipTemplate.setType(scalarParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "properties":
                    INodeParser<AbstractPropertyValue> propertyValueParser = context.getRegistry().get("node_template_property");
                    MapParser<AbstractPropertyValue> mapParser = baseParserFactory.getMapParser(propertyValueParser, "node_template_property");
                    relationshipTemplate.setProperties(mapParser.parse(nodeTuple.getValueNode(), context));
                    break;
                case "interfaces":
                    INodeParser<Map<String, Interface>> interfacesParser = context.getRegistry().get("interfaces");
                    relationshipTemplate.setInterfaces(interfacesParser.parse(nodeTuple.getValueNode(), context));
                    break;
                default:
                    context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_ARTIFACT_KEY, null, node.getStartMark(), "Unrecognized key while parsing implementation artifact", node.getEndMark(), key));
            }
        }
    } else {
        ParserUtils.addTypeError(node, context.getParsingErrors(), "Requirement assignment");
    }
    return relationshipTemplate;
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) INodeParser(alien4cloud.tosca.parser.INodeParser) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) MapParser(alien4cloud.tosca.parser.impl.base.MapParser) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Aggregations

Interface (org.alien4cloud.tosca.model.definitions.Interface)28 Operation (org.alien4cloud.tosca.model.definitions.Operation)16 Test (org.junit.Test)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)4 Map (java.util.Map)3 IValue (org.alien4cloud.tosca.model.definitions.IValue)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)3 AbstractInstantiableToscaType (org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType)3 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)3 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)3 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)2 INodeParser (alien4cloud.tosca.parser.INodeParser)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 MapParser (alien4cloud.tosca.parser.impl.base.MapParser)2 Set (java.util.Set)2 ImplementationArtifact (org.alien4cloud.tosca.model.definitions.ImplementationArtifact)2