Search in sources :

Example 6 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation 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 7 with Operation

use of org.alien4cloud.tosca.model.definitions.Operation 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)

Example 8 with Operation

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

the class UpdateDockerImageProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UpdateDockerImageOperation operation, NodeTemplate nodeTemplate) {
    NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
    if (!ToscaTypeUtils.isOfType(nodeType, NormativeNodeTypesConstants.DOCKER_TYPE)) {
        throw new IllegalArgumentException("Updating docker image can only be done on docker nodes. [" + nodeTemplate.getName() + "] does not inherit from [" + NormativeNodeTypesConstants.DOCKER_TYPE + "].");
    }
    Interface standard = safe(nodeTemplate.getInterfaces()).get(ToscaNodeLifecycleConstants.STANDARD);
    if (standard == null) {
        standard = new Interface(ToscaNodeLifecycleConstants.STANDARD);
        if (nodeTemplate.getInterfaces() == null) {
            nodeTemplate.setInterfaces(Maps.newHashMap());
        }
        nodeTemplate.getInterfaces().put(ToscaNodeLifecycleConstants.STANDARD, standard);
    }
    Operation create = safe(standard.getOperations()).get(ToscaNodeLifecycleConstants.CREATE);
    if (create == null) {
        create = getCreateOperation(nodeType.getInterfaces());
        if (create == null) {
            create = new Operation();
        } else {
            create = CloneUtil.clone(create);
        }
        if (standard.getOperations() == null) {
            standard.setOperations(Maps.newHashMap());
        }
        standard.getOperations().put(ToscaNodeLifecycleConstants.CREATE, create);
        if (create.getImplementationArtifact() == null) {
            ImplementationArtifact createIA = new ImplementationArtifact();
            createIA.setArtifactType(NormativeArtifactTypes.DOCKER);
            createIA.setRepositoryName("docker");
            create.setImplementationArtifact(createIA);
        }
    }
    create.getImplementationArtifact().setArchiveName(csar.getName());
    create.getImplementationArtifact().setArchiveVersion(csar.getVersion());
    create.getImplementationArtifact().setArtifactRef(operation.getDockerImage());
    create.getImplementationArtifact().setArtifactRepository("a4c_ignore");
}
Also used : ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) NodeType(org.alien4cloud.tosca.model.types.NodeType) Operation(org.alien4cloud.tosca.model.definitions.Operation) UpdateDockerImageOperation(org.alien4cloud.tosca.editor.operations.nodetemplate.UpdateDockerImageOperation) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 9 with Operation

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

the class IndexedModelTest method testMergeInterfaceOperationsMerge.

@Test
public void testMergeInterfaceOperationsMerge() {
    // both are merged
    Map<String, Interface> from = Maps.newHashMap();
    Interface i1 = new Interface();
    Map<String, Operation> ios1 = Maps.newHashMap();
    Operation o1 = new Operation();
    ios1.put("o1", o1);
    i1.setOperations(ios1);
    from.put("i1", i1);
    Map<String, Interface> to = Maps.newHashMap();
    Interface i2 = new Interface();
    Map<String, Operation> ios2 = Maps.newHashMap();
    Operation o2 = new Operation();
    ios2.put("o2", o2);
    i2.setOperations(ios2);
    to.put("i1", i2);
    Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
    assertEquals(1, merged.size());
    assertEquals(2, merged.get("i1").getOperations().size());
    assertSame(merged.get("i1").getOperations().get("o1"), o1);
    assertSame(merged.get("i1").getOperations().get("o2"), o2);
}
Also used : Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface) Test(org.junit.Test)

Example 10 with Operation

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

the class IndexedModelTest method testMergeInterfaceOperationsToNull.

@Test
public void testMergeInterfaceOperationsToNull() {
    // TO's operation is null
    Map<String, Interface> from = Maps.newHashMap();
    Interface i1 = new Interface();
    Map<String, Operation> ios1 = Maps.newHashMap();
    Operation o1 = new Operation();
    ios1.put("o1", o1);
    i1.setOperations(ios1);
    from.put("i1", i1);
    Map<String, Interface> to = Maps.newHashMap();
    Interface i2 = new Interface();
    to.put("i1", i2);
    Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
    assertEquals(1, merged.size());
    assertSame(merged.get("i1").getOperations().get("o1"), o1);
}
Also used : Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface) Test(org.junit.Test)

Aggregations

Operation (org.alien4cloud.tosca.model.definitions.Operation)19 Interface (org.alien4cloud.tosca.model.definitions.Interface)16 Test (org.junit.Test)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)4 Map (java.util.Map)3 IValue (org.alien4cloud.tosca.model.definitions.IValue)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ImplementationArtifact (org.alien4cloud.tosca.model.definitions.ImplementationArtifact)2 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)2 AbstractInstantiableToscaType (org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType)2 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)2 NotFoundException (alien4cloud.exception.NotFoundException)1 ArtifactSupport (alien4cloud.model.orchestrators.ArtifactSupport)1 IllegalOperationWarning (alien4cloud.topology.warning.IllegalOperationWarning)1 ToscaContext (alien4cloud.tosca.context.ToscaContext)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ParsingContextExecution (alien4cloud.tosca.parser.ParsingContextExecution)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1 ParsingErrorLevel (alien4cloud.tosca.parser.ParsingErrorLevel)1