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");
}
Aggregations