Search in sources :

Example 1 with DockerImageTag

use of org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag in project TOSCAna by StuPro-TOSCAna.

the class BaseImageMapper method addImagesForType.

/**
 *     Internal method used for converting the Data received from docker to the data model described
 *     in the <code>model</code> package
 */
private void addImagesForType(DockerBaseImages baseImage, List<ImageTags> pages) {
    List<DockerImageTag> tagList = new ArrayList<>();
    for (ImageTags page : pages) {
        for (ImageTag imageTag : page.getImageTags()) {
            Set<String> architectures = new HashSet<>();
            for (Image image : imageTag.getImages()) {
                // is amd64 in that case.
                if (image.getArchitecture() == null) {
                    architectures.add("amd64");
                } else {
                    architectures.add(image.getArchitecture());
                }
            }
            DockerImageTag tag = new DockerImageTag(imageTag.getName(), architectures);
            tagList.add(tag);
        }
    }
    tagStorage.put(baseImage.name().toLowerCase(), new DockerImage(baseImage, tagList));
}
Also used : ImageTag(org.opentosca.toscana.plugins.kubernetes.docker.mapper.api.model.ImageTag) DockerImageTag(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag) ArrayList(java.util.ArrayList) DockerImage(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImage) DockerImageTag(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag) DockerImage(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImage) Image(org.opentosca.toscana.plugins.kubernetes.docker.mapper.api.model.Image) ImageTags(org.opentosca.toscana.plugins.kubernetes.docker.mapper.api.model.ImageTags) HashSet(java.util.HashSet)

Example 2 with DockerImageTag

use of org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag in project TOSCAna by StuPro-TOSCAna.

the class MapperEngine method determineTagFromMinorVersion.

/**
 *     Tries to determine the tag from the list of possible minor versions
 */
private String determineTagFromMinorVersion(List<DockerImageTag> possibleTags, Semver version) {
    DockerImageTag resultTag = null;
    int i = 0;
    DockerImageTag tag;
    Semver tagVersion;
    do {
        tag = possibleTags.get(i);
        tagVersion = tag.toVersion();
        if (tagVersion.getMinor() == version.getMinor()) {
            int j = i;
            DockerImageTag prev = null;
            DockerImageTag t = null;
            Semver tv;
            do {
                prev = t;
                t = possibleTags.get(j);
                tv = t.toVersion();
                j++;
            } while (tv.getMinor().equals(version.getMinor()) && j < possibleTags.size());
            resultTag = prev;
        }
        i++;
    } while (i < possibleTags.size());
    if (resultTag == null) {
        throw new UnsupportedOperationException("Mapping failed");
    }
    return resultTag.getName();
}
Also used : DockerImageTag(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag) Semver(com.vdurmont.semver4j.Semver)

Example 3 with DockerImageTag

use of org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag in project TOSCAna by StuPro-TOSCAna.

the class MapperEngine method performMapping.

/**
 *     Perfoms the mapping to the base image
 */
private String performMapping(OsCapability capability, String tag, String distro) {
    DockerImage img = tagStorage.get(distro);
    String architecture = getCapabilityArchitecture(capability).orElseThrow(() -> new UnsupportedOperationException("Architecture not supported!"));
    DockerImageTag imgTag = img.findTagByName(tag).get();
    if (imgTag.isSupported(architecture)) {
        return img.getUsername() + "/" + img.getRepository() + ":" + imgTag.getName();
    } else {
        throw new UnsupportedOperationException("Could not map to base image. " + "The image '" + img.getUsername() + "/" + img.getRepository() + ":" + tag + "' " + "does not support the architecture " + architecture);
    }
}
Also used : DockerImage(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImage) DockerImageTag(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag)

Example 4 with DockerImageTag

use of org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag in project TOSCAna by StuPro-TOSCAna.

the class MapperEngine method lookForPossibleTag.

/**
 *     This method looks for a possible tag for the given version and Docker Image, Throws a unsupported operation
 *     exception if it fails
 */
private String lookForPossibleTag(String version, DockerImage img) {
    // Check if the Version definition is too specific e.g. ubuntu 16.04.3 that is non existant on dockerhub
    String tag;
    Semver semVer = new Semver(version, Semver.SemverType.LOOSE);
    List<DockerImageTag> eqMayorVersionTags = getTagsWithEqualMayorVersion(img, semVer.getMajor());
    List<DockerImageTag> possibleMinorImageTags = getPossibleMinorImageTags(semVer, eqMayorVersionTags);
    // If there is only one possibility return it.
    if (possibleMinorImageTags.size() == 1) {
        tag = possibleMinorImageTags.get(0).getName();
    } else {
        tag = determineTagFromMinorVersion(possibleMinorImageTags, semVer);
    }
    return tag;
}
Also used : Semver(com.vdurmont.semver4j.Semver) DockerImageTag(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag)

Aggregations

DockerImageTag (org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag)4 Semver (com.vdurmont.semver4j.Semver)2 DockerImage (org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImage)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Image (org.opentosca.toscana.plugins.kubernetes.docker.mapper.api.model.Image)1 ImageTag (org.opentosca.toscana.plugins.kubernetes.docker.mapper.api.model.ImageTag)1 ImageTags (org.opentosca.toscana.plugins.kubernetes.docker.mapper.api.model.ImageTags)1