Search in sources :

Example 16 with Interface

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

the class TopologyTreeBuilderService method mergeInterfaces.

@SneakyThrows
private void mergeInterfaces(AbstractPaaSTemplate pasSTemplate, AbstractInstantiableTemplate abstractTemplate) {
    AbstractToscaType type = pasSTemplate.getIndexedToscaElement();
    Map<String, Interface> typeInterfaces = null;
    if (type instanceof AbstractInstantiableToscaType) {
        typeInterfaces = ((AbstractInstantiableToscaType) type).getInterfaces();
    }
    Map<String, Interface> templateInterfaces = abstractTemplate.getInterfaces();
    // Here merge interfaces: the interface defined in the template should override those from type.
    pasSTemplate.setInterfaces(IndexedModelUtils.mergeInterfaces(JsonUtil.toMap(JsonUtil.toString(typeInterfaces), String.class, Interface.class), templateInterfaces));
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) AbstractInstantiableToscaType(org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType) Interface(org.alien4cloud.tosca.model.definitions.Interface) SneakyThrows(lombok.SneakyThrows)

Example 17 with Interface

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

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

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

Example 20 with Interface

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

the class IndexedModelTest method testMergeInterfaceOperationsKeepTo.

@Test
public void testMergeInterfaceOperationsKeepTo() {
    // TO keeps it's own operation
    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("o1", o2);
    i2.setOperations(ios2);
    to.put("i1", i2);
    Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
    assertEquals(1, merged.size());
    assertSame(merged.get("i1").getOperations().get("o1"), o2);
}
Also used : Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface) Test(org.junit.Test)

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