diff --git a/apis/docker/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java b/apis/docker/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java index 7e9de039b0..f030d9ac1b 100644 --- a/apis/docker/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java +++ b/apis/docker/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java @@ -16,9 +16,10 @@ */ package org.jclouds.docker.compute.functions; -import com.google.common.base.Function; -import com.google.common.base.Splitter; -import com.google.common.collect.Iterables; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Named; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; @@ -27,11 +28,8 @@ import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; -import javax.annotation.Resource; -import javax.inject.Named; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.get; +import com.google.common.base.Function; +import com.google.common.collect.Iterables; public class ImageToImage implements Function { @@ -46,13 +44,24 @@ public class ImageToImage implements Function"); + final int versionSeparatorPos = firstRepoTag.lastIndexOf(':'); - OsFamily osFamily = osFamily().apply(description); - String osVersion = parseVersion(description); + final String name; + final String osVersion; + if (versionSeparatorPos > -1) { + name = firstRepoTag.substring(0, versionSeparatorPos); + osVersion = firstRepoTag.substring(versionSeparatorPos + 1); + } else { + name = firstRepoTag; + osVersion = firstRepoTag; + } + logger.debug("os version for item: %s is %s", firstRepoTag, osVersion); + + OsFamily osFamily = osFamily().apply(firstRepoTag); OperatingSystem os = OperatingSystem.builder() - .description(description) + .description(firstRepoTag) .family(osFamily) .version(osVersion) .is64Bit(is64bit(from)) @@ -60,8 +69,8 @@ public class ImageToImage implements Function of() // repoTags + ); + + private static final org.jclouds.docker.domain.Image IMAGE_REPOTAG_WITH_PORT = org.jclouds.docker.domain.Image.create( + "id", // id + "author", + "comment", + Config.builder() + .image("imageId") + .build(), + Config.builder() + .image("imageId") + .build(), + "parent", // parent + new Date(), // created + "containerId", // container + "1.3.1", // dockerVersion + "x86_64", // architecture + "os", // os + 0l, // size + 0l, // virtualSize + ImmutableList.of("registry.company.example:8888/a/b/c/d:latest") // repoTags + ); + private ImageToImage function; private org.jclouds.docker.domain.Image image; @@ -76,6 +118,23 @@ public class ImageToImageTest { assertEquals(mockImage.id(), image.getId().toString()); } + public void testEmptyRepoTags() { + Image image = function.apply(IMAGE_EMPTY_REPOTAGS); + + assertEquals(image.getId(), "id"); + assertEquals(image.getDescription(), ""); + assertEquals(image.getOperatingSystem().getVersion(), ""); + assertEquals(image.getName(), ""); + } + + public void testRepoTagWithHostPort() { + Image image = function.apply(IMAGE_REPOTAG_WITH_PORT); + + assertEquals(image.getDescription(), "registry.company.example:8888/a/b/c/d:latest"); + assertEquals(image.getOperatingSystem().getVersion(), "latest"); + assertEquals(image.getName(), "registry.company.example:8888/a/b/c/d"); + } + private org.jclouds.docker.domain.Image mockImage() { org.jclouds.docker.domain.Image mockImage = EasyMock.createMock(org.jclouds.docker.domain.Image.class);