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