Search in sources :

Example 1 with UpdateDockerImageOperation

use of org.alien4cloud.tosca.editor.operations.nodetemplate.UpdateDockerImageOperation 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)

Aggregations

UpdateDockerImageOperation (org.alien4cloud.tosca.editor.operations.nodetemplate.UpdateDockerImageOperation)1 ImplementationArtifact (org.alien4cloud.tosca.model.definitions.ImplementationArtifact)1 Interface (org.alien4cloud.tosca.model.definitions.Interface)1 Operation (org.alien4cloud.tosca.model.definitions.Operation)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1