Search in sources :

Example 11 with Interface

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

the class InterfaceParser method parseInterfaceDefinition.

private Interface parseInterfaceDefinition(MappingNode node, ParsingContextExecution context) {
    Interface interfaz = new Interface();
    Map<String, Operation> operations = Maps.newHashMap();
    interfaz.setOperations(operations);
    Map<String, IValue> interfaceInputs = null;
    for (NodeTuple entry : node.getValue()) {
        String key = scalarParser.parse(entry.getKeyNode(), context);
        if (INPUTS_KEY.equals(key)) {
            interfaceInputs = inputsParser.parse(entry.getValueNode(), context);
        } else if (DESCRIPTION_KEY.equals(key)) {
            interfaz.setDescription(scalarParser.parse(entry.getValueNode(), context));
        } else if (TYPE_KEY.equals(key)) {
            interfaz.setType(getInterfaceType(scalarParser.parse(entry.getValueNode(), context)));
        } else {
            if (entry.getValueNode() instanceof ScalarNode) {
                Operation operation = new Operation();
                // implementation artifact parsing should be done using a deferred parser as we need to look for artifact types.
                operation.setImplementationArtifact(implementationArtifactParser.parse(entry.getValueNode(), context));
                operations.put(key, operation);
            } else {
                operations.put(key, operationParser.parse(entry.getValueNode(), context));
            }
        }
    }
    if (interfaceInputs != null) {
        for (Operation operation : operations.values()) {
            if (operation.getInputParameters() == null) {
                operation.setInputParameters(Maps.newHashMap());
            }
            for (Entry<String, IValue> inputEntry : interfaceInputs.entrySet()) {
                if (!operation.getInputParameters().containsKey(inputEntry.getKey())) {
                    operation.getInputParameters().put(inputEntry.getKey(), inputEntry.getValue());
                }
            }
        }
    }
    return interfaz;
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) Operation(org.alien4cloud.tosca.model.definitions.Operation) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 12 with Interface

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

the class InterfacesParser method parse.

@Override
public Map<String, Interface> parse(Node node, ParsingContextExecution context) {
    if (node instanceof MappingNode) {
        Map<String, Interface> interfaces = super.parse(node, context);
        Map<String, Interface> cleanedInterfaces = Maps.newHashMap();
        for (Map.Entry<String, Interface> entry : interfaces.entrySet()) {
            String interfaceType = InterfaceParser.getInterfaceType(entry.getKey());
            if (entry.getValue().getType() == null) {
                entry.getValue().setType(interfaceType);
            }
            cleanedInterfaces.put(interfaceType, entry.getValue());
        }
        return cleanedInterfaces;
    }
    // In a node type interfaces definition allow to reference an interface type or multiple ones using array, in that case the keyname of the interface is
    // the actual value type.
    Map<String, Interface> interfaces = Maps.newHashMap();
    if (node instanceof SequenceNode) {
        for (Node interfaceTypeNode : ((SequenceNode) node).getValue()) {
            if (interfaceTypeNode instanceof ScalarNode) {
                addInterfaceFromType((ScalarNode) interfaceTypeNode, interfaces, context);
            } else {
                ParserUtils.addTypeError(interfaceTypeNode, context.getParsingErrors(), "interface");
            }
        }
    } else if (node instanceof ScalarNode) {
        addInterfaceFromType((ScalarNode) node, interfaces, context);
    } else {
        ParserUtils.addTypeError(node, context.getParsingErrors(), "interfaces");
    }
    return interfaces;
}
Also used : MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) Map(java.util.Map) Interface(org.alien4cloud.tosca.model.definitions.Interface) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode)

Example 13 with Interface

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

the class ServiceResourceRelationshipService method processTargetOperations.

private void processTargetOperations(PaaSRelationshipTemplate paaSRelationshipTemplate, ServiceResource serviceResource, Interface templateInterface) {
    // Drop default target operations as the service is the target of a relationship
    dropOperations(templateInterface, PRE_CONFIGURE_TARGET, POST_CONFIGURE_TARGET, ADD_SOURCE, REMOVE_SOURCE);
    // for services that are target of a relationship, all operations related to target (the service) are not run.
    if (paaSRelationshipTemplate.getTemplate().getTargetedCapabilityName() != null && serviceResource.getCapabilitiesRelationshipTypes() != null) {
        String relationshipTypeId = serviceResource.getCapabilitiesRelationshipTypes().get(paaSRelationshipTemplate.getTemplate().getTargetedCapabilityName());
        if (relationshipTypeId != null) {
            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_TARGET, POST_CONFIGURE_TARGET, ADD_SOURCE, REMOVE_SOURCE);
            }
        }
    }
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 14 with Interface

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

the class ServiceResourceRelationshipService method processService.

private void processService(PaaSNodeTemplate paaSNodeTemplate) {
    ServiceNodeTemplate serviceNodeTemplate = (ServiceNodeTemplate) paaSNodeTemplate.getTemplate();
    ServiceResource serviceResource = serviceResourceService.getOrFail(serviceNodeTemplate.getServiceResourceId());
    for (PaaSRelationshipTemplate paaSRelationshipTemplate : paaSNodeTemplate.getRelationshipTemplates()) {
        Interface templateInterface = safe(paaSRelationshipTemplate.getInterfaces()).get(ToscaRelationshipLifecycleConstants.CONFIGURE);
        if (templateInterface != null) {
            if (paaSRelationshipTemplate.getSource().equals(paaSNodeTemplate.getId())) {
                processSourceOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
            } else {
                processTargetOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
            }
        }
    }
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) ServiceResource(alien4cloud.model.service.ServiceResource) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 15 with Interface

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

the class LocationMatchNodesArtifactsElector method isEligible.

private boolean isEligible(AbstractInstantiableTemplate template, LocationMatchNodeFilter.NodeMatchContext matchContext) {
    if (template == null) {
        return true;
    }
    ArtifactSupport artifactSupport = matchContext.getArtifactSupport();
    // if no supported artifact defined, then return true
    if (artifactSupport == null || ArrayUtils.isEmpty(artifactSupport.getTypes())) {
        return true;
    }
    String[] supportedArtifacts = artifactSupport.getTypes();
    AbstractInstantiableToscaType indexedArtifactToscaElement = matchContext.getElement(AbstractInstantiableToscaType.class, template.getType());
    if (MapUtils.isNotEmpty(indexedArtifactToscaElement.getInterfaces())) {
        for (Interface interfaz : indexedArtifactToscaElement.getInterfaces().values()) {
            for (Operation operation : interfaz.getOperations().values()) {
                if (operation.getImplementationArtifact() != null) {
                    String artifactTypeString = operation.getImplementationArtifact().getArtifactType();
                    ArtifactType artifactType = matchContext.getElement(ArtifactType.class, artifactTypeString);
                    // stop the checking once one artifactType is not supported
                    if (!isFromOneOfTypes(supportedArtifacts, artifactType)) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : ArtifactType(org.alien4cloud.tosca.model.types.ArtifactType) AbstractInstantiableToscaType(org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType) Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface) ArtifactSupport(alien4cloud.model.orchestrators.ArtifactSupport)

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