http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceAdapterLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceAdapterLiveTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceAdapterLiveTest.java new file mode 100644 index 0000000..faee982 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceAdapterLiveTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.compute; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import java.util.Properties; +import java.util.Random; + +import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.docker.DockerApi; +import org.jclouds.docker.compute.strategy.DockerComputeServiceAdapter; +import org.jclouds.docker.domain.Container; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.inject.Injector; +import com.google.inject.Module; + +@Test(groups = "live", singleThreaded = true, testName = "DockerComputeServiceAdapterLiveTest") +public class DockerComputeServiceAdapterLiveTest extends BaseDockerApiLiveTest { + + private DockerComputeServiceAdapter adapter; + private TemplateBuilder templateBuilder; + private NodeAndInitialCredentials<Container> guest; + + @Override + protected DockerApi create(Properties props, Iterable<Module> modules) { + Injector injector = newBuilder().modules(modules).overrides(props).buildInjector(); + adapter = injector.getInstance(DockerComputeServiceAdapter.class); + templateBuilder = injector.getInstance(TemplateBuilder.class); + return injector.getInstance(DockerApi.class); + } + + public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { + String group = "foo"; + String name = "container-" + new Random().nextInt(); + + Template template = templateBuilder.smallest() + .osDescriptionMatches("jclouds/default:latest").build(); + + guest = adapter.createNodeWithGroupEncodedIntoName(group, name, template); + assertEquals(guest.getNodeId(), guest.getNode().getId() + ""); + } + + public void testListHardwareProfiles() { + Iterable<Hardware> profiles = adapter.listHardwareProfiles(); + assertFalse(Iterables.isEmpty(profiles)); + + for (Hardware profile : profiles) { + assertNotNull(profile); + } + } + + @AfterGroups(groups = "live") + protected void tearDown() { + if (guest != null) { + adapter.destroyNode(guest.getNode().getId() + ""); + } + super.tearDown(); + } + + @Override + protected Iterable<Module> setupModules() { + return ImmutableSet.<Module>of(getLoggingModule(), new SshjSshClientModule()); + } + + @Override + protected Properties setupProperties() { + Properties properties = super.setupProperties(); + properties.setProperty("jclouds.ssh.max-retries", "10"); + return properties; + } +}
http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceLiveTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceLiveTest.java new file mode 100644 index 0000000..cc460c3 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceLiveTest.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.compute; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.inject.Module; + +/** + * Live tests for the {@link org.jclouds.compute.ComputeService} integration. + */ +@Test(groups = "live", singleThreaded = true, testName = "DockerComputeServiceLiveTest") +public class DockerComputeServiceLiveTest extends BaseComputeServiceLiveTest { + + private static final String DEFAULT_JCLOUDS_IMAGE = "jclouds/default"; + private Image defaultImage; + + public DockerComputeServiceLiveTest() { + provider = "docker"; + } + + @Override + protected Module getSshModule() { + return new SshjSshClientModule(); + } + + @Override + protected void initializeContext() { + super.initializeContext(); + Optional<? extends Image> optionalImage = Iterables.tryFind(client.listImages(), new Predicate<Image>() { + @Override + public boolean apply(Image image) { + return image.getName().equals(DEFAULT_JCLOUDS_IMAGE); + } + }); + if (optionalImage.isPresent()) { + defaultImage = optionalImage.get(); + } else { + Assert.fail("Please create an ssh-able image called " + DEFAULT_JCLOUDS_IMAGE); + } + } + + @Override + protected Template buildTemplate(TemplateBuilder templateBuilder) { + return templateBuilder.imageId(defaultImage.getId()).build(); + } + + @Override + public void testOptionToNotBlock() throws Exception { + // Docker ComputeService implementation has to block until the node + // is provisioned, to be able to return it. + } + + @Override + protected void checkTagsInNodeEquals(NodeMetadata node, ImmutableSet<String> tags) { + // Docker does not support tags + } + + @Override + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap<String, String> userMetadata) { + // Docker does not support user metadata + } + + @Override + public void testCreateAndRunAService() throws Exception { + // Docker does not support blockOnPort + } + + @Override + @Test(enabled = true, dependsOnMethods = { "testCompareSizes" }) + public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception { + super.testAScriptExecutionAfterBootWithBasicTemplate(); + } + + @Override + @Test(enabled = true, dependsOnMethods = "testReboot", expectedExceptions = UnsupportedOperationException.class) + public void testSuspendResume() throws Exception { + super.testSuspendResume(); + } + + @Override + @Test(enabled = true, dependsOnMethods = "testSuspendResume") + public void testGetNodesWithDetails() throws Exception { + super.testGetNodesWithDetails(); + } + + @Override + @Test(enabled = true, dependsOnMethods = "testSuspendResume") + public void testListNodes() throws Exception { + super.testListNodes(); + } + + @Override + @Test(enabled = true, dependsOnMethods = "testSuspendResume") + public void testListNodesByIds() throws Exception { + super.testListNodesByIds(); + } + + @Override + @Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails", "testListNodesByIds" }) + public void testDestroyNodes() { + super.testDestroyNodes(); + } + + @Test(enabled = true, expectedExceptions = NullPointerException.class) + public void testCorrectExceptionRunningNodesNotFound() throws Exception { + super.testCorrectExceptionRunningNodesNotFound(); + } + + @Test(enabled = true, expectedExceptions = NullPointerException.class) + public void testCorrectAuthException() throws Exception { + // Docker does not support authentication yet + super.testCorrectAuthException(); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java new file mode 100644 index 0000000..f7a3b57 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * work for additional information regarding copyright ownership. + * The ASF licenses file to You under the Apache License, Version 2.0 + * (the "License"); you may not use file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.compute.functions; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.easymock.EasyMock; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.functions.GroupNamingConvention; +import org.jclouds.docker.domain.Config; +import org.jclouds.docker.domain.Container; +import org.jclouds.docker.domain.HostConfig; +import org.jclouds.docker.domain.NetworkSettings; +import org.jclouds.docker.domain.Port; +import org.jclouds.docker.domain.State; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.providers.ProviderMetadata; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; + +/** + * Unit tests for the {@link org.jclouds.docker.compute.functions.ContainerToNodeMetadata} class. + */ +@Test(groups = "unit", testName = "ContainerToNodeMetadataTest") +public class ContainerToNodeMetadataTest { + private ContainerToNodeMetadata function; + + private Container container; + + @BeforeMethod + public void setup() { + Config containerConfig = Config.builder() + .hostname("6d35806c1bd2") + .domainName("") + .user("") + .memory(0) + .memorySwap(0) + .cpuShares(0) + .attachStdin(false) + .attachStdout(false) + .attachStderr(false) + .exposedPorts(ImmutableMap.of("22/tcp", ImmutableMap.of())) + .tty(false) + .openStdin(false) + .stdinOnce(false) + .env(null) + .cmd(ImmutableList.of("/usr/sbin/sshd", "-D")) + .imageId("jclouds/ubuntu") + .volumesFrom("") + .workingDir("") + .entrypoint(null) + .networkDisabled(false) + .build(); + State state = State.builder() + .pid(3626) + .running(true) + .exitCode(0) + .startedAt("2014-03-24T20:28:37.537659054Z") + .finishedAt("0001-01-01T00:00:00Z") + .ghost(false) + .build(); + container = Container.builder() + .id("6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9") + .name("/hopeful_mclean") + .created("2014-03-22T07:16:45.784120972Z") + .path("/usr/sbin/sshd") + .args(new String[] {"-D"}) + .containerConfig(containerConfig) + .state(state) + .image("af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6") + .networkSettings(NetworkSettings.builder() + .ipAddress("172.17.0.2") + .ipPrefixLen(16) + .gateway("172.17.42.1") + .bridge("docker0") + .ports(ImmutableMap.<String, List<Map<String, String>>>of("22/tcp", + ImmutableList.<Map<String, String>>of(ImmutableMap.of("HostIp", "0.0.0.0", "HostPort", + "49199")))) + .build()) + .resolvConfPath("/etc/resolv.conf") + .driver("aufs") + .execDriver("native-0.1") + .volumes(ImmutableMap.<String, String>of()) + .volumesRW(ImmutableMap.<String, Boolean>of()) + .command("") + .status("") + .hostConfig(HostConfig.builder().publishAllPorts(true).build()) + .ports(ImmutableList.<Port>of()) + .build(); + ProviderMetadata providerMetadata = EasyMock.createMock(ProviderMetadata.class); + expect(providerMetadata.getEndpoint()).andReturn("http://127.0.0.1:4243"); + replay(providerMetadata); + + GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class); + + Supplier<Map<String, ? extends Image>> images = new Supplier<Map<String, ? extends Image>>() { + @Override + public Map<String, ? extends Image> get() { + OperatingSystem os = OperatingSystem.builder() + .description("Ubuntu 12.04 64bit") + .family(OsFamily.UBUNTU) + .version("12.04") + .is64Bit(true) + .build(); + + return ImmutableMap.of("af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6", + new ImageBuilder() + .ids("af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6") + .name("ubuntu") + .description("Ubuntu 12.04 64bit") + .operatingSystem(os) + .status(Image.Status.AVAILABLE) + .build()); + } + }; + + Supplier<Set<? extends Location>> locations = new Supplier<Set< ? extends Location>>() { + @Override + public Set<? extends Location> get() { + + return ImmutableSet.of( + new LocationBuilder() + .id("docker") + .description("http://localhost:2375") + .scope(LocationScope.PROVIDER) + .build() + ); + } + }; + + function = new ContainerToNodeMetadata(providerMetadata, toPortableStatus(), namingConvention, images, locations); + } + + private Function<State, NodeMetadata.Status> toPortableStatus() { + StateToStatus function = EasyMock.createMock(StateToStatus.class); + expect(function.apply(anyObject(State.class))).andReturn(NodeMetadata.Status.RUNNING); + replay(function); + return function; + } + + public void testVirtualMachineToNodeMetadata() { + Container mockContainer = mockContainer(); + + NodeMetadata node = function.apply(mockContainer); + + verify(mockContainer); + + assertEquals(node.getId(), "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9"); + assertEquals(node.getGroup(), "hopeful_mclean"); + assertEquals(node.getImageId(), "af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6"); + assertEquals(node.getLoginPort(), 49199); + assertEquals(node.getPrivateAddresses().size(), 1); + assertEquals(node.getPublicAddresses().size(), 1); + } + + private Container mockContainer() { + Container mockContainer = EasyMock.createMock(Container.class); + + expect(mockContainer.getId()).andReturn(container.getId()); + expect(mockContainer.getName()).andReturn(container.getName()); + expect(mockContainer.getContainerConfig()).andReturn(container.getContainerConfig()).anyTimes(); + expect(mockContainer.getNetworkSettings()).andReturn(container.getNetworkSettings()).anyTimes(); + expect(mockContainer.getState()).andReturn(container.getState()); + expect(mockContainer.getImage()).andReturn(container.getImage()).anyTimes(); + replay(mockContainer); + + return mockContainer; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/ImageToImageTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/ImageToImageTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/ImageToImageTest.java new file mode 100644 index 0000000..e9754d0 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/ImageToImageTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * work for additional information regarding copyright ownership. + * The ASF licenses file to You under the Apache License, Version 2.0 + * (the "License"); you may not use file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.compute.functions; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.compute.domain.Image; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Unit tests for the {@link org.jclouds.docker.compute.functions.ImageToImage} class. + */ +@Test(groups = "unit", testName = "ImageToImageTest") +public class ImageToImageTest { + private ImageToImage function; + + private org.jclouds.docker.domain.Image image; + + @BeforeMethod + public void setup() { + image = org.jclouds.docker.domain.Image.builder() + .id("id") + .parent("parent") + .created("created") + .architecture("x86_64") + .repoTags(ImmutableList.of("repoTag1:version")) + .size(0l) + .build(); + function = new ImageToImage(); + } + + public void testImageToImage() { + org.jclouds.docker.domain.Image mockImage = mockImage(); + + Image image = function.apply(mockImage); + + verify(mockImage); + + assertEquals(mockImage.getId(), image.getId().toString()); + } + + private org.jclouds.docker.domain.Image mockImage() { + org.jclouds.docker.domain.Image mockImage = EasyMock.createMock(org.jclouds.docker.domain.Image.class); + + expect(mockImage.getId()).andReturn(image.getId()).anyTimes(); + expect(mockImage.getRepoTags()).andReturn(image.getRepoTags()).anyTimes(); + expect(mockImage.getArchitecture()).andReturn(image.getArchitecture()).anyTimes(); + replay(mockImage); + + return mockImage; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/StateToStatusTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/StateToStatusTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/StateToStatusTest.java new file mode 100644 index 0000000..899a66c --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/functions/StateToStatusTest.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * work for additional information regarding copyright ownership. + * The ASF licenses file to You under the Apache License, Version 2.0 + * (the "License"); you may not use file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.compute.functions; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.docker.domain.State; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link StateToStatus} class. + */ +@Test(groups = "unit", testName = "StateToStatusTest") +public class StateToStatusTest { + private StateToStatus function; + + @BeforeMethod + public void setup() { + function = new StateToStatus(); + } + + public void testStateRunningToStatusRunning() { + State mockState = mockStateRunning(); + + NodeMetadata.Status status = function.apply(mockState); + + verify(mockState); + + assertEquals(mockState.isRunning(), true); + assertEquals(status, NodeMetadata.Status.RUNNING); + } + + public void testStateNotRunningToStatusTerminated() { + State mockState = mockStateNotRunning(); + + NodeMetadata.Status status = function.apply(mockState); + + verify(mockState); + + assertEquals(mockState.isRunning(), false); + assertEquals(status, NodeMetadata.Status.TERMINATED); + } + + private State mockStateRunning() { + State mockState = EasyMock.createMock(State.class); + + expect(mockState.isRunning()).andReturn(true).anyTimes(); + replay(mockState); + + return mockState; + } + + private State mockStateNotRunning() { + State mockState = EasyMock.createMock(State.class); + + expect(mockState.isRunning()).andReturn(false).anyTimes(); + replay(mockState); + + return mockState; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/options/DockerTemplateOptionsTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/options/DockerTemplateOptionsTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/options/DockerTemplateOptionsTest.java new file mode 100644 index 0000000..3a98228 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/compute/options/DockerTemplateOptionsTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.compute.options; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.options.TemplateOptions; +import org.testng.annotations.Test; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; + +/** + * Unit tests for the {@link DockerTemplateOptions} class. + */ +@Test(groups = "unit", testName = "DockerTemplateOptionsTest") +public class DockerTemplateOptionsTest { + + @Test + public void testHostname() { + TemplateOptions options = new DockerTemplateOptions().hostname("hostname"); + assertEquals(options.as(DockerTemplateOptions.class).getHostname(), Optional.of("hostname")); + } + + @Test + public void testMemory() { + TemplateOptions options = new DockerTemplateOptions().memory(1024); + assertEquals(options.as(DockerTemplateOptions.class).getMemory(), Optional.of(1024)); + } + + @Test + public void testCpuShares() { + TemplateOptions options = new DockerTemplateOptions().cpuShares(2); + assertEquals(options.as(DockerTemplateOptions.class).getCpuShares(), Optional.of(2)); + } + + @Test + public void testVolumes() { + TemplateOptions options = new DockerTemplateOptions().volumes(ImmutableMap.of("/tmp", "/tmp")); + assertEquals(options.as(DockerTemplateOptions.class).getVolumes(), Optional.of(ImmutableMap.of("/tmp", "/tmp"))); + } + + @Test + public void testDns() { + TemplateOptions options = new DockerTemplateOptions().dns("8.8.8.8"); + assertEquals(options.as(DockerTemplateOptions.class).getDns(), Optional.of("8.8.8.8")); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/config/DockerParserModuleTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/config/DockerParserModuleTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/config/DockerParserModuleTest.java new file mode 100644 index 0000000..4f5ba75 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/config/DockerParserModuleTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.config; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.jclouds.docker.domain.Container; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.jclouds.docker.config.DockerParserModule.ContainerTypeAdapter; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +/** + * Unit tests for the {@link org.jclouds.docker.config.DockerParserModule} class. + */ +@Test(groups = "unit", testName = "DockerParserModuleTest") +public class DockerParserModuleTest { + + private Gson gson; + + @BeforeMethod + public void setup() { + gson = new GsonBuilder() + .registerTypeAdapter(Container.class, new ContainerTypeAdapter()) + .create(); + } + + @Test + public void testContainerWithVolumesNull() { + Container container = gson.fromJson( + "{ \"Volumes\": null }", Container.class); + assertNotNull(container); + assertEquals(container.getVolumes(), null); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java new file mode 100644 index 0000000..34feddd --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.features; + +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import com.google.common.io.Resources; +import org.jclouds.docker.compute.BaseDockerApiLiveTest; +import org.jclouds.docker.domain.Config; +import org.jclouds.docker.domain.Container; +import org.jclouds.docker.domain.Image; +import org.jclouds.docker.options.BuildOptions; +import org.jclouds.docker.options.CreateImageOptions; +import org.jclouds.docker.options.DeleteImageOptions; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +@Test(groups = "live", testName = "RemoteApiLiveTest", singleThreaded = true) +public class RemoteApiLiveTest extends BaseDockerApiLiveTest { + + private static final String BUSYBOX_IMAGE = "busybox"; + private Container container = null; + private Image image = null; + + @Test + public void testVersion() { + assertEquals(api().getVersion().getVersion(), "1.0.0"); + } + + @Test(dependsOnMethods = "testVersion") + public void testCreateImage() throws IOException, InterruptedException { + CreateImageOptions options = CreateImageOptions.Builder.fromImage(BUSYBOX_IMAGE); + InputStream createImageStream = api().createImage(options); + consumeStream(createImageStream, false); + image = api().inspectImage(BUSYBOX_IMAGE); + assertNotNull(image); + } + + @Test(dependsOnMethods = "testCreateImage") + public void testListImages() { + assertNotNull(api().listImages()); + } + + @Test(dependsOnMethods = "testListImages") + public void testCreateContainer() throws IOException, InterruptedException { + Config containerConfig = Config.builder().imageId(image.getId()) + .cmd(ImmutableList.of("/bin/sh", "-c", "while true; do echo hello world; sleep 1; done")) + .build(); + container = api().createContainer("testCreateContainer", containerConfig); + assertNotNull(container); + assertNotNull(container.getId()); + } + + @Test(dependsOnMethods = "testCreateContainer") + public void testStartContainer() throws IOException, InterruptedException { + api().startContainer(container.getId()); + assertTrue(api().inspectContainer(container.getId()).getState().isRunning()); + } + + @Test(dependsOnMethods = "testStartContainer") + public void testStopContainer() { + api().stopContainer(container.getId()); + assertFalse(api().inspectContainer(container.getId()).getState().isRunning()); + } + + @Test(dependsOnMethods = "testStopContainer", expectedExceptions = NullPointerException.class) + public void testRemoveContainer() { + api().removeContainer(container.getId()); + assertFalse(api().inspectContainer(container.getId()).getState().isRunning()); + } + + @Test(dependsOnMethods = "testRemoveContainer", expectedExceptions = ResourceNotFoundException.class) + public void testDeleteImage() { + InputStream deleteImageStream = api().deleteImage(image.getId()); + consumeStream(deleteImageStream, false); + assertNull(api().inspectImage(image.getId())); + } + + public void testBuildImage() throws IOException, InterruptedException, URISyntaxException { + BuildOptions options = BuildOptions.Builder.tag("testBuildImage").verbose(false).nocache(false); + InputStream buildImageStream = api().build(new File(Resources.getResource("Dockerfile").toURI()), options); + String buildStream = consumeStream(buildImageStream, false); + Iterable<String> splitted = Splitter.on("\n").split(buildStream.replace("\r", "").trim()); + String lastStreamedLine = Iterables.getLast(splitted).trim(); + String rawImageId = Iterables.getLast(Splitter.on("Successfully built ").split(lastStreamedLine)); + String imageId = rawImageId.substring(0, 11); + Image image = api().inspectImage(imageId); + api().deleteImage(image.getId(), DeleteImageOptions.Builder.force(true)); + } + + private RemoteApi api() { + return api.getRemoteApi(); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java new file mode 100644 index 0000000..760f723 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java @@ -0,0 +1,376 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.features; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMultimap; +import com.squareup.okhttp.mockwebserver.MockResponse; +import com.squareup.okhttp.mockwebserver.MockWebServer; +import org.jclouds.docker.DockerApi; +import org.jclouds.docker.domain.Config; +import org.jclouds.docker.domain.Container; +import org.jclouds.docker.internal.BaseDockerMockTest; +import org.jclouds.docker.options.BuildOptions; +import org.jclouds.docker.options.CreateImageOptions; +import org.jclouds.docker.options.ListContainerOptions; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.util.Set; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +/** + * Mock tests for the {@link org.jclouds.docker.DockerApi} class. + */ +@Test(groups = "unit", testName = "RemoteApiMockTest") +public class RemoteApiMockTest extends BaseDockerMockTest { + + public void testListContainers() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/containers.json"))); + + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + + try { + Set<Container> containers = remoteApi.listContainers(); + assertRequestHasCommonFields(server.takeRequest(), "/containers/json"); + assertEquals(containers.size(), 1); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testListNonexistentContainers() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + + try { + Set<Container> containers = remoteApi.listContainers(); + assertRequestHasCommonFields(server.takeRequest(), "/containers/json"); + assertTrue(containers.isEmpty()); + } finally { + api.close(); + server.shutdown(); + } + } + + + @Test(timeOut = 10000l) + public void testListAllContainers() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/containers.json"))); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + Set<Container> containers = remoteApi.listContainers(ListContainerOptions.Builder.all(true)); + assertRequestHasParameters(server.takeRequest(), "/containers/json", ImmutableMultimap.of("all", "true")); + assertEquals(containers.size(), 1); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testGetContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/container.json"))); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + String containerId = "b03d4cd15b76f8876110615cdeed15eadf77c9beb408d62f1687dcc69192cd6d"; + try { + Container container = remoteApi.inspectContainer(containerId); + assertRequestHasCommonFields(server.takeRequest(), "/containers/" + containerId + "/json"); + assertNotNull(container); + assertNotNull(container.getId(), containerId); + assertNotNull(container.getContainerConfig()); + assertNotNull(container.getHostConfig()); + assertEquals(container.getName(), "/tender_lumiere"); + assertEquals(container.getState().isRunning(), true); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testGetNonExistingContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + String containerId = "notExisting"; + try { + Container container = remoteApi.inspectContainer(containerId); + assertRequestHasCommonFields(server.takeRequest(), "/containers/" + containerId + "/json"); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testCreateContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/container-creation.json"))); + + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + Config containerConfig = Config.builder().cmd(ImmutableList.of("date")) + .attachStdin(false) + .attachStderr(true) + .attachStdout(true) + .tty(false) + .imageId("base") + .build(); + try { + Container container = remoteApi.createContainer("test", containerConfig); + assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/create?name=test"); + assertNotNull(container); + assertEquals(container.getId(), "c6c74153ae4b1d1633d68890a68d89c40aa5e284a1ea016cbc6ef0e634ee37b2"); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testRemoveContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(204)); + + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + String containerId = "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9"; + + try { + remoteApi.removeContainer(containerId); + assertRequestHasCommonFields(server.takeRequest(), "DELETE", "/containers/" + containerId); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testRemoveNonExistingContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + String containerId = "nonExisting"; + try { + remoteApi.removeContainer(containerId); + fail("Remove container must fail on 404"); + } catch (ResourceNotFoundException ex) { + // Expected exception + } finally { + api.close(); + server.shutdown(); + } + } + + public void testStartContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(200)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + remoteApi.startContainer("1"); + assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/1/start"); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testStartNonExistingContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + try { + remoteApi.startContainer("1"); + fail("Start container must fail on 404"); + } catch (ResourceNotFoundException ex) { + // Expected exception + } + } finally { + api.close(); + server.shutdown(); + } + } + + public void testStopContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(200)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + remoteApi.stopContainer("1"); + assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/1/stop"); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testStopNonExistingContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + remoteApi.stopContainer("1"); + fail("Stop container must fail on 404"); + } catch (ResourceNotFoundException ex) { + // Expected exception + } finally { + api.close(); + server.shutdown(); + } + } + + public void testCreateImage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(200)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + remoteApi.createImage(CreateImageOptions.Builder.fromImage("base")); + assertRequestHasParameters(server.takeRequest(), "POST", "/images/create", ImmutableMultimap.of("fromImage", + "base")); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testCreateImageFailure() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + remoteApi.createImage(CreateImageOptions.Builder.fromImage("base")); + fail("Create image must fail on 404"); + } catch (ResourceNotFoundException ex) { + // Expected exception + } finally { + api.close(); + server.shutdown(); + } + } + + public void testDeleteImage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(204)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + remoteApi.deleteImage("1"); + assertRequestHasCommonFields(server.takeRequest(), "DELETE", "/images/1"); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testDeleteNotExistingImage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + try { + remoteApi.deleteImage("1"); + fail("Delete image must fail on 404"); + } catch (ResourceNotFoundException ex) { + // Expected exception + } finally { + api.close(); + server.shutdown(); + } + } + + public void testBuildContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(200)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + File dockerFile = File.createTempFile("docker", "tmp"); + try { + remoteApi.build(dockerFile, BuildOptions.NONE); + assertRequestHasCommonFields(server.takeRequest(), "POST", "/build"); + } finally { + dockerFile.delete(); + api.close(); + server.shutdown(); + } + } + + public void testBuildContainerUsingPayload() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(200)); + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + + File file = File.createTempFile("docker", "tmp"); + FileInputStream data = new FileInputStream(file); + Payload payload = Payloads.newInputStreamPayload(data); + payload.getContentMetadata().setContentLength(file.length()); + + try { + remoteApi.build(payload, BuildOptions.NONE); + assertRequestHasCommonFields(server.takeRequest(), "POST", "/build"); + } finally { + api.close(); + server.shutdown(); + } + } + + public void testBuildNonexistentContainer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + DockerApi api = api(server.getUrl("/")); + RemoteApi remoteApi = api.getRemoteApi(); + + File dockerFile = File.createTempFile("docker", "tmp"); + try { + try { + remoteApi.build(dockerFile, BuildOptions.NONE); + fail("Build container must fail on 404"); + } catch (ResourceNotFoundException ex) { + // Expected exception + } + } finally { + dockerFile.delete(); + api.close(); + server.shutdown(); + } + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/internal/ArchivesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/internal/ArchivesTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/internal/ArchivesTest.java new file mode 100644 index 0000000..15eb3ff --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/features/internal/ArchivesTest.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.features.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.getOnlyElement; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; + +import javax.annotation.Resource; +import javax.inject.Named; + +import org.apache.commons.compress.archivers.ArchiveStreamFactory; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.archivers.tar.TarUtils; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.beust.jcommander.internal.Lists; +import com.google.common.io.ByteStreams; +import com.google.common.io.Files; + +@Test(groups = "unit", testName = "ArchivesTest") +public class ArchivesTest { + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private File tmpDir; + private File outputDir; + private long checkSum; + + @BeforeClass + private void init() throws IOException { + tmpDir = Files.createTempDir(); + outputDir = Files.createTempDir(); + File sampleFile = writeSampleFile("test", "this is a test to tar a hierarchy of folders and files\n"); + checkSum = TarUtils.computeCheckSum(Files.asByteSource(sampleFile).read()); + } + + public void testTarSingleFile() throws Exception { + File archive = Archives.tar(tmpDir, new File(outputDir + File.separator + "test.tar.gz")); + List<File> untarredFiles = unTar(archive, outputDir); + File untarredSampleFile = getOnlyElement(untarredFiles, null); + assertNotNull(untarredSampleFile); + assertTrue(checkSum == TarUtils.computeCheckSum(Files.asByteSource(untarredSampleFile).read())); + } + + private List<File> unTar(final File inputFile, final File outputDir) throws Exception { + final List<File> untarredFiles = Lists.newArrayList(); + final InputStream is = new FileInputStream(inputFile); + final TarArchiveInputStream tarArchiveInputStream = (TarArchiveInputStream) + new ArchiveStreamFactory().createArchiveInputStream("tar", is); + TarArchiveEntry entry; + while ((entry = (TarArchiveEntry) tarArchiveInputStream.getNextEntry()) != null) { + final File outputFile = new File(outputDir, entry.getName()); + if (entry.isDirectory()) { + if (!outputFile.exists()) { + if (!outputFile.mkdirs()) { + throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath())); + } + } + } else { + OutputStream outputFileStream = new FileOutputStream(outputFile); + ByteStreams.copy(tarArchiveInputStream, outputFileStream); + outputFileStream.close(); + } + untarredFiles.add(outputFile); + } + tarArchiveInputStream.close(); + return untarredFiles; + } + + private File writeSampleFile(String fileName, final String contents) { + checkNotNull(fileName, "Provided file name for writing must NOT be null."); + checkNotNull(contents, "Unable to write null contents."); + File sampleFile = new File(tmpDir + File.separator + fileName); + try { + Files.write(contents.getBytes(), sampleFile); + } catch (IOException e) { + logger.error("ERROR trying to write to file '" + fileName + "' - " + e.toString()); + Assert.fail(); + } + return sampleFile; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java new file mode 100644 index 0000000..146b2a0 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.docker.internal; + +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; +import static org.jclouds.http.utils.Queries.encodeQueryLine; +import static org.jclouds.util.Strings2.toStringAndClose; +import static org.testng.Assert.assertEquals; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; +import java.util.Set; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + +import org.jclouds.ContextBuilder; +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.docker.DockerApi; + +import com.google.common.base.Charsets; +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; +import com.google.inject.Module; +import com.squareup.okhttp.mockwebserver.MockWebServer; +import com.squareup.okhttp.mockwebserver.RecordedRequest; + +/** + * Base class for all Docker mock tests. + */ +public class BaseDockerMockTest { + private final Set<Module> modules = ImmutableSet.<Module> of(new ExecutorServiceModule(sameThreadExecutor(), + sameThreadExecutor())); + + protected String provider; + + public BaseDockerMockTest() { + provider = "docker"; + } + + public DockerApi api(URL url) { + return ContextBuilder.newBuilder(provider) + .credentials("clientid", "apikey") + .endpoint(url.toString()) + .modules(modules) + .overrides(setupProperties()) + .buildApi(DockerApi.class); + } + + protected Properties setupProperties() { + return new Properties(); + } + + public static MockWebServer mockWebServer() throws IOException { + MockWebServer server = new MockWebServer(); + server.play(); + return server; + } + + public byte[] payloadFromResource(String resource) { + try { + return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8); + } catch (IOException e) { + throw Throwables.propagate(e); + } + } + + protected static void assertRequestHasCommonFields(final RecordedRequest request, final String path) + throws InterruptedException { + assertRequestHasParameters(request, "GET", path, ImmutableMultimap.<String, String> of()); + } + + protected static void assertRequestHasCommonFields(final RecordedRequest request, + final String verb, final String path) + throws InterruptedException { + assertRequestHasParameters(request, verb, path, ImmutableMultimap.<String, String> of()); + } + + protected static void assertRequestHasParameters(final RecordedRequest request, final String path, + Multimap<String, String> parameters) throws InterruptedException { + assertRequestHasParameters(request, "GET", path, parameters); + } + + protected static void assertRequestHasParameters(final RecordedRequest request, String verb, final String path, + Multimap<String, String> parameters) throws InterruptedException { + String queryParameters = ""; + if (!parameters.isEmpty()) { + Multimap<String, String> allparams = ImmutableMultimap.<String, String>builder() + .putAll(parameters) + .build(); + + assertRequestHasAcceptHeader(request); + queryParameters = "?" + encodeQueryLine(allparams); + } + assertEquals(request.getRequestLine(), verb + " " + path + queryParameters + " HTTP/1.1"); + } + + protected static void assertRequestHasAcceptHeader(final RecordedRequest request) throws InterruptedException { + assertEquals(request.getHeader(HttpHeaders.ACCEPT), MediaType.APPLICATION_JSON); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/Dockerfile ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/Dockerfile b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/Dockerfile new file mode 100644 index 0000000..1318715 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/Dockerfile @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +FROM centos:6.4 +MAINTAINER Andrea Turli <[email protected]> + +# RUN yum -y groupinstall 'Development Tools' +RUN yum -y install openssh-server openssh-clients + +RUN chkconfig sshd on +RUN service sshd start +RUN echo 'root:password' | chpasswd + +EXPOSE 22 +CMD ["/usr/sbin/sshd", "-D"] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/container-creation.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/container-creation.json b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/container-creation.json new file mode 100644 index 0000000..3e34e0b --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/container-creation.json @@ -0,0 +1 @@ +{"Id":"c6c74153ae4b1d1633d68890a68d89c40aa5e284a1ea016cbc6ef0e634ee37b2","Warnings":null} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/container.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/container.json b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/container.json new file mode 100644 index 0000000..b353012 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/container.json @@ -0,0 +1,81 @@ +{ + "Args": [ + "-c", + "yum -y install openssh-server openssh-clients" + ], + "Config": { + "AttachStderr": false, + "AttachStdin": false, + "AttachStdout": false, + "Cmd": [ + "/bin/sh", + "-c", + "yum -y install openssh-server openssh-clients" + ], + "CpuShares": 0, + "Cpuset": "", + "Domainname": "", + "Entrypoint": null, + "Env": [ + "HOME=/", + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + ], + "ExposedPorts": null, + "Hostname": "9088c45a9592", + "Image": "1e2d12a45cd57ae3fe3c31ede149d800aaf6a711c61646fad340080f531775c8", + "Memory": 0, + "MemorySwap": 0, + "NetworkDisabled": false, + "OnBuild": [], + "OpenStdin": false, + "PortSpecs": null, + "StdinOnce": false, + "Tty": false, + "User": "", + "Volumes": null, + "WorkingDir": "" + }, + "Created": "2014-06-18T08:49:25.36448943Z", + "Driver": "aufs", + "ExecDriver": "native-0.2", + "HostConfig": { + "Binds": null, + "ContainerIDFile": "", + "Dns": null, + "DnsSearch": null, + "Links": null, + "LxcConf": null, + "NetworkMode": "", + "PortBindings": null, + "Privileged": false, + "PublishAllPorts": false, + "VolumesFrom": null + }, + "HostnamePath": "/mnt/sda1/var/lib/docker/containers/be1d295c091720abc9a3105219ab75a0a7367d74156cc6048aa599fcc7d650e2/hostname", + "HostsPath": "/mnt/sda1/var/lib/docker/containers/be1d295c091720abc9a3105219ab75a0a7367d74156cc6048aa599fcc7d650e2/hosts", + "Id": "be1d295c091720abc9a3105219ab75a0a7367d74156cc6048aa599fcc7d650e2", + "Image": "1e2d12a45cd57ae3fe3c31ede149d800aaf6a711c61646fad340080f531775c8", + "MountLabel": "", + "Name": "/tender_lumiere", + "NetworkSettings": { + "Bridge": "docker0", + "Gateway": "172.17.42.1", + "IPAddress": "172.17.0.100", + "IPPrefixLen": 16, + "PortMapping": null, + "Ports": {} + }, + "Path": "/bin/sh", + "ProcessLabel": "", + "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/be1d295c091720abc9a3105219ab75a0a7367d74156cc6048aa599fcc7d650e2/resolv.conf", + "State": { + "ExitCode": 0, + "FinishedAt": "0001-01-01T00:00:00Z", + "Paused": false, + "Pid": 16422, + "Running": true, + "StartedAt": "2014-06-18T08:49:25.63685385Z" + }, + "Volumes": {}, + "VolumesRW": {} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/containers.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/containers.json b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/containers.json new file mode 100644 index 0000000..8f789b7 --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/containers.json @@ -0,0 +1,20 @@ +[ + { + "Command": "/usr/sbin/sshd -D", + "Created": 1395472605, + "Id": "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9", + "Image": "jclouds/ubuntu:latest", + "Names": [ + "/hopeful_mclean" + ], + "Ports": [ + { + "IP": "0.0.0.0", + "PrivatePort": 22, + "PublicPort": 49231, + "Type": "tcp" + } + ], + "Status": "Up 55 seconds" + } +] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/logback.xml ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/logback.xml b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/logback.xml new file mode 100644 index 0000000..bbb5d7f --- /dev/null +++ b/dependencies/jclouds/apis/docker/1.8.0-stratos/src/test/resources/logback.xml @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<configuration> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>- %msg%n</pattern> + </encoder> + </appender> + <root level="info"> + <appender-ref ref="STDOUT"/> + </root> + <logger name="jclouds.compute" level="debug"/> + <logger name="net.schmizz" level="warn"/> + <logger name="jclouds.wire" level="debug"/> + <logger name="jclouds.headers" level="debug"/> + <logger name="jclouds.ssh" level="debug"/> +</configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/README.txt ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/README.txt b/dependencies/jclouds/apis/ec2/1.7.1-stratos/README.txt deleted file mode 100644 index 11db7a2..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/README.txt +++ /dev/null @@ -1,15 +0,0 @@ -# -# The jclouds API for Amazon's EC2 service (http://aws.amazon.com/ec2/). -# -# TODO: Implementation status. -# TODO: Supported features. -# TODO: Usage example. - -NOTE: The live tests in apis/ec2 will *not* work against AWS EC2 with AWS accounts created -from December 04, 2013 and onward, due to those accounts only supporting VPC, and VPC requiring -different parameters (ID rather than name) for referring to and acting on security groups. - -To run the EC2 live tests against AWS, go to providers/aws-ec2. - -apis/ec2 will retain the older security group name usage to support EC2 API shims, -such as OpenStack, CloudStack, etc. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/pom.xml ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/pom.xml b/dependencies/jclouds/apis/ec2/1.7.1-stratos/pom.xml deleted file mode 100644 index c4de90c..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/pom.xml +++ /dev/null @@ -1,144 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-project</artifactId> - <version>1.7.1</version> - </parent> - <groupId>org.apache.stratos</groupId> - <artifactId>ec2</artifactId> - <version>1.7.1-stratos</version> - <name>jclouds ec2 api</name> - <description>jclouds components to access an implementation of EC2</description> - <packaging>bundle</packaging> - - <properties> - <jclouds.version>1.7.1</jclouds.version> - <test.ec2.endpoint>https://ec2.us-east-1.amazonaws.com</test.ec2.endpoint> - <test.ec2.api-version>2010-08-31</test.ec2.api-version> - <test.ec2.build-version /> - <test.ec2.identity>${test.aws.identity}</test.ec2.identity> - <test.ec2.credential>${test.aws.credential}</test.ec2.credential> - <!-- default template pattern gets a problematic Ubuntu 10.04 AMI --> - <test.ec2.template>hardwareId=m1.small,imageId=us-east-1/ami-1ab3ce73</test.ec2.template> - <!-- Active EBS template as of 9/25/2013 --> - <test.ec2.ebs-template>hardwareId=m1.small,imageId=us-east-1/ami-53b1ff3a</test.ec2.ebs-template> - <!-- Windows_Server-2008-R2 with WinRM enabled (setup instructions at http://www.frontiertown.co.uk/2011/12/overthere-control-windows-from-java/) --> - <test.ec2.windows-template>hardwareId=m1.small,imageId=us-east-1/ami-0cb76d65</test.ec2.windows-template> - <jclouds.osgi.export>org.jclouds.ec2*;version="${project.version}"</jclouds.osgi.export> - <jclouds.osgi.import> - org.jclouds.compute.internal;version="${jclouds.version}", - org.jclouds.rest.internal;version="${jclouds.version}", - org.jclouds*;version="${jclouds.version}", - * - </jclouds.osgi.import> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.jclouds.api</groupId> - <artifactId>sts</artifactId> - <version>${jclouds.version}</version> - <type>jar</type> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>${jclouds.version}</version> - <type>jar</type> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-core</artifactId> - <version>${jclouds.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>${jclouds.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-log4j</artifactId> - <version>${jclouds.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-sshj</artifactId> - <version>${jclouds.version}</version> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>com.theoryinpractise</groupId> - <artifactId>clojure-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>live</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <executions> - <execution> - <id>integration</id> - <phase>integration-test</phase> - <goals> - <goal>test</goal> - </goals> - <configuration> - <systemPropertyVariables> - <test.ec2.endpoint>${test.ec2.endpoint}</test.ec2.endpoint> - <test.ec2.api-version>${test.ec2.api-version}</test.ec2.api-version> - <test.ec2.build-version>${test.ec2.build-version}</test.ec2.build-version> - <test.ec2.identity>${test.ec2.identity}</test.ec2.identity> - <test.ec2.credential>${test.ec2.credential}</test.ec2.credential> - <test.ec2.template>${test.ec2.template}</test.ec2.template> - <test.ec2.ebs-template>${test.ec2.ebs-template}</test.ec2.ebs-template> - <test.ec2.windows-template>${test.ec2.windows-template}</test.ec2.windows-template> - <test.ec2.windows-owner>${test.ec2.windows-owner}</test.ec2.windows-owner> - </systemPropertyVariables> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - - <scm> - <tag>4.0.0-rc4</tag> - </scm> -</project> - http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/ami2.clj ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/ami2.clj b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/ami2.clj deleted file mode 100644 index d58eb6b..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/ami2.clj +++ /dev/null @@ -1,84 +0,0 @@ -; -; Licensed to the Apache Software Foundation (ASF) under one or more -; contributor license agreements. See the NOTICE file distributed with -; this work for additional information regarding copyright ownership. -; The ASF licenses this file to You under the Apache License, Version 2.0 -; (the "License"); you may not use this file except in compliance with -; the License. You may obtain a copy of the License at -; -; http://www.apache.org/licenses/LICENSE-2.0 -; -; Unless required by applicable law or agreed to in writing, software -; distributed under the License is distributed on an "AS IS" BASIS, -; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; See the License for the specific language governing permissions and -; limitations under the License. -; - -(ns - #^{:author "Hunter Hutchinson, [email protected]" - :doc "A clojure binding to the jclouds AMI service interface."} - org.jclouds.ec2.ami2 - (:use org.jclouds.compute2) - (:import org.jclouds.aws.domain.Region - org.jclouds.ec2.features.AMIApi - org.jclouds.ec2.options.CreateImageOptions - org.jclouds.compute.domain.NodeMetadata - (org.jclouds.ec2.domain Volume Volume$Status Snapshot Snapshot$Status AvailabilityZoneInfo))) - -(defn ^org.jclouds.ec2.features.AMIApi - ami-service - "" - [compute] - (-> compute - .getContext - .getProviderSpecificContext - .getApi - .getAMIApi().get)) - -(defn get-region - "Coerces the first parameter into a Region string; strings, keywords, and - NodeMetadata instances are acceptable arguments. An optional second argument - is returned if the first cannot be coerced into a region string. - Returns nil otherwise." - ([v] (get-region v nil)) - ([v default-region] - (cond - (string? v) v - (keyword? v) (name v) - (instance? NodeMetadata v) (let [zone (location v)] - ; no easier way to go from zone -> region? - (if (> (.indexOf zone "-") -1) - (subs zone 0 (-> zone count dec)) - zone)) - :else default-region))) - -(defn- as-string - [v] - (cond - (string? v) v - (keyword? v) (name v) - :else v)) - -(defn- get-string - [map key] - (as-string (get map key))) - -(defn- as-int - [v] - (cond - (number? v) (int v) - (string? v) (Integer/parseInt v) - :else (throw (IllegalArgumentException. - (str "Don't know how to convert object of type " (class v) " to a string"))))) - -(defn create-image-in-region - ([compute region name node-id description] - (.createImageInRegion (ami-service compute) - (get-region region) - (as-string name) - (as-string node-id) - (into-array CreateImageOptions - (when description - [(.withDescription (CreateImageOptions.) description)]))))) -
