http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/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/89fab312/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/89fab312/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/89fab312/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/89fab312/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/89fab312/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/89fab312/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/89fab312/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/89fab312/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/89fab312/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/89fab312/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)]))))) - http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/ebs2.clj ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/ebs2.clj b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/ebs2.clj deleted file mode 100644 index 2bde9a5..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/ebs2.clj +++ /dev/null @@ -1,286 +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 "Chas Emerick, [email protected]" - :doc "A clojure binding to the jclouds EBS service interface."} - org.jclouds.ec2.ebs2 - (:use org.jclouds.compute2 [clojure.core.incubator :only (-?>)]) - (:import org.jclouds.aws.domain.Region - org.jclouds.compute.domain.NodeMetadata - (org.jclouds.ec2.domain Volume Volume$Status Snapshot Snapshot$Status AvailabilityZoneInfo) - (org.jclouds.ec2.options DescribeSnapshotsOptions DetachVolumeOptions CreateSnapshotOptions))) -(defn snapshot? - "Returns true iff the argument is a org.jclouds.ec2.domain.Snapshot." - [s] - (instance? Snapshot s)) - -(defn volume? - "Returns true iff the argument is a org.jclouds.ec2.domain.Volume." - [v] - (instance? Volume v)) - -(defn ^org.jclouds.ec2.services.ElasticBlockStoreClient - ebs-service - "" - [compute] - (-> compute - .getContext - .getProviderSpecificContext - .getApi - .getElasticBlockStoreServices)) - -(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 get-volume-id - "Returns a string volume ID taken from the given string, keyword, or Volume argument." - [v] - (cond - (instance? Volume v) (.getId ^Volume v) - (keyword? v) (name v) - (string? v) v - :else (throw (IllegalArgumentException. - (str "Can't obtain volume id from argument of type " (class v)))))) - -(defn volumes - "Returns a set of org.jclouds.ec2.domain.Volume instances corresponding to the - volumes in the specified region (defaulting to your account's default region)." - [compute & [region & volume-ids]] - (set - (.describeVolumesInRegion (ebs-service compute) - (get-region region) - (into-array String (map get-volume-id - (if (get-region region) - volume-ids - (when region (cons region volume-ids)))))))) - -(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- snapshot-options - [optmap] - (let [string-array #(let [v (% optmap)] - (into-array String (cond - (keyword? v) [(name v)] - (string? v) [v] - :else (map as-string v))))] - (-> (DescribeSnapshotsOptions.) - (.ownedBy (string-array :owner)) - (.snapshotIds (string-array :ids)) - (.restorableBy (string-array :restorable-by))))) - -(defn snapshots - "Returns a set of org.jclouds.aws.ec2.domain.Snapshot instances that match - the criteria provided. Options include: - - :region - region string, keyword, or NodeMetadata - :owner - AWS account id (or \"amazon\" or \"self\") - :restorable-by - AWS account id - - Multiple values for each type of criteria can be provided by passing a seq - of the appropriate types as values." - [compute & options] - (let [options (apply hash-map options) - region (:region options) - options (snapshot-options (dissoc options :region))] - (set - (.describeSnapshotsInRegion (ebs-service compute) - (get-region region) - (into-array DescribeSnapshotsOptions [options]))))) - -(defn create-snapshot - "Creates a snapshot of a volume in the specified region with an optional description. - If provided, the description must be < 255 characters in length. Returns the - org.jclouds.aws.ec2.domain.Snapshot object representing the created snapshot." - ([compute ^Volume volume] (create-snapshot compute volume nil)) - ([compute ^Volume volume description] (create-snapshot compute (.getRegion volume) (.getId volume) description)) - ([compute region volume-id description] - (.createSnapshotInRegion (ebs-service compute) - (get-region region) - (as-string volume-id) - (into-array CreateSnapshotOptions (when description - [(.withDescription (CreateSnapshotOptions.) description)]))))) - -(defn delete-snapshot - "Deletes a snapshot in the specified region." - ([compute ^Snapshot snapshot] (delete-snapshot compute (.getRegion snapshot) (.getId snapshot))) - ([compute region snapshot-id] - (.deleteSnapshotInRegion (ebs-service compute) - (get-region region) - (as-string snapshot-id)))) - -(defn get-zone - [v] - (cond - (instance? AvailabilityZoneInfo v) (.getZone v) - (instance? NodeMetadata v) (location ^NodeMetadata v) - (string? v) v - (keyword? v) (name v) - :else (throw (IllegalArgumentException. - (str "Can't obtain zone from argument of type " (class v)))))) - -(defn attach-volume - "Attaches a volume to an instance, returning the resulting org.jclouds.aws.ec2.domain.Attachment." - ([compute ^NodeMetadata node volume device] - (attach-volume compute node (.getProviderId node) (get-volume-id volume) device)) - ([compute region instance-id volume-id device] - (apply #(.attachVolumeInRegion (ebs-service compute) - (get-region region) % %2 %3) - (map as-string [volume-id instance-id device])))) - -(defn detach-volume - "Detaches a volume from the instance to which it is currently attached. - The volume may be specified with a Volume instance, a string, or a keyword. - Providing a logical true value for the :force option will cause the volume - to be forcibly detached, regardless of whether it is in-use (mounted) or not. - - If the volume is specified as a string or keyword, one of the following options - is additionally required: - - :region - the region where the volume is allocated - :node - a node in the region where the volume is allocated - - FYI: It appears that issuing a detatch-volume command while the volume in question is mounted - will cause the volume to be detatched immediately upon the volume beign unmounted." - [compute volume & options] - (let [options (apply hash-map options) - volume-id (get-volume-id volume) - region (get-region (if (instance? Volume volume) - (.getRegion volume) - (or (:region options) (:node options))))] - (when (not region) - (throw (IllegalArgumentException. - "Must specify volume's region via :region or :node options, or by providing a Volume instance."))) - (.detachVolumeInRegion (ebs-service compute) - region - volume-id - (boolean (:force options)) - (into-array DetachVolumeOptions [])))) - -(defn create-volume - "Creates a new volume given a set of options: - - - one of :zone (keyword, string, or AvailabilityZoneInfo) or :node (NodeMetadata) - - one or both of :snapshot (keyword, string, or Snapshot instance) or :size - (string, keyword, or number) - - :device (string or keyword) provided *only* when you want to attach the new volume to - the :node you specified! - - Returns a vector of [created org.jclouds.ec2.domain.Volume, - optional org.jclouds.ec2.domain.Attachment] - - Note that specifying :node instead of :zone will only attach the created volume - :device is also provided. Otherwise, the node is only used to obtain the desired - availability zone. - - Note also that if :device and :node are specified, and the attach operation fails, - you will have \"leaked\" the newly-created volume - (volume creation and attachment cannot be done atomically)." - [compute & options] - (when (-> options count odd?) - (throw (IllegalArgumentException. "Must provide key-value pairs, e.g. :zone :us-east-1d :size 200"))) - (let [options (apply hash-map options) - snapshot (get-string options :snapshot) - snapshot (if (snapshot? snapshot) (.getId snapshot) snapshot) - size (-?> (get-string options :size) as-int) - ^NodeMetadata node (:node options) - zone (or node (get-string options :zone)) - zone (if zone - (get-zone zone) - (throw (IllegalArgumentException. "Must supply a :zone or :node option."))) - ebs (ebs-service compute)] - (when (and (:device options) (not node)) - (throw (IllegalArgumentException. "Cannot create and attach new volume; no :node specified"))) - (let [new-volume (cond - (and snapshot size) (.createVolumeFromSnapshotInAvailabilityZone ebs zone size snapshot) - snapshot (.createVolumeFromSnapshotInAvailabilityZone ebs zone snapshot) - size (.createVolumeInAvailabilityZone ebs zone size) - :else (throw (IllegalArgumentException. "Must supply :size and/or :snapshot options.")))] - [new-volume (when (:device options) - (attach-volume compute node new-volume (as-string (:device options))))]))) - -(defn delete-volume - "Deletes a volume in the specified region." - ([compute ^Volume volume] - (delete-volume (.getRegion volume) (.getId volume))) - ([compute region volume-id] - (.deleteVolumeInRegion (ebs-service compute) - (get-region region) - (as-string volume-id)))) - -(defn status - "Returns the status of the given entity; works for Volumes and Snapshots." - [k] - (.getStatus k)) - -(defn status-available? - [^Volume v] - (= Volume$Status/AVAILABLE (status v))) - -(defn status-creating? - [^Volume v] - (= Volume$Status/CREATING (status v))) - -(defn status-deleting? - [^Volume v] - (= Volume$Status/DELETING (status v))) - -(defn status-in-use? - [^Volume v] - (= Volume$Status/IN_USE (status v))) - -(defn status-completed? - [^Snapshot s] - (= Snapshot$Status/COMPLETED (status s))) - -(defn status-error? - [^Snapshot s] - (= Snapshot$Status/ERROR (status s))) - -(defn status-pending? - [^Snapshot s] - (= Snapshot$Status/PENDING (status s))) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/elastic_ip2.clj ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/elastic_ip2.clj b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/elastic_ip2.clj deleted file mode 100644 index 68c372f..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/elastic_ip2.clj +++ /dev/null @@ -1,80 +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 "Chas Emerick, [email protected]" - :doc "A clojure binding for the jclouds AWS elastic IP address interface."} - org.jclouds.ec2.elastic-ip2 - (:require (org.jclouds [compute2 :as compute]) - [org.jclouds.ec2.ebs2 :as ebs]) - (:import org.jclouds.compute.domain.NodeMetadata - (org.jclouds.ec2.domain PublicIpInstanceIdPair))) - -(defn ^org.jclouds.ec2.features.ElasticIPAddressApi - eip-service - "Returns an ElasticIPAddressApi for the given ComputeService" - [compute] - (-> compute - .getContext .getProviderSpecificContext .getApi .getElasticIPAddressApi().get)) - -(defn allocate - "Claims a new elastic IP address within the (optionally) specified region for your account. - Region may be a string, keyword, or a node from which the region - is inferred. Returns the IP address as a string." - ([compute] (allocate compute nil)) - ([compute region] - (.allocateAddressInRegion (eip-service compute) (ebs/get-region region)))) - -(defn associate - "Associates an elastic IP address with a node." - ([compute ^NodeMetadata node public-ip] - (associate node public-ip (.getProviderId node))) - ([compute region public-ip instance-id] - (.associateAddressInRegion (eip-service compute) - (ebs/get-region region) - public-ip - instance-id))) - -(defn addresses - "Returns a map of elastic IP addresses to maps with slots: - - :region - the region (string/keyword/NodeMetadata) the IP address is allocated within - :node-id - the ID of the instance with which the IP address is associated (optional) - - You may optionally specify which IP addresses you would like to query." - ([compute] (addresses compute nil)) - ([compute region & public-ips] - (into {} (for [^PublicIpInstanceIdPair pair (.describeAddressesInRegion (eip-service compute) - (ebs/get-region region) - (into-array String public-ips))] - [(.getPublicIp pair) (merge {:region (.getRegion pair)} - (when (.getInstanceId pair) {:node-id (.getInstanceId pair)}))])))) - -(defn dissociate - "Dissociates an elastic IP address from the node with which it is currently associated." - [compute region public-ip] - (.disassociateAddressInRegion (eip-service compute) - (ebs/get-region region) - public-ip)) - -(defn release - "Disclaims an elastic IP address from your account." - ([compute public-ip] (release compute public-ip nil)) - ([compute public-ip region] - (.releaseAddressInRegion (eip-service compute) - (ebs/get-region region) - public-ip))) http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/security_group2.clj ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/security_group2.clj b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/security_group2.clj deleted file mode 100644 index a4f33cf..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/clojure/org/jclouds/ec2/security_group2.clj +++ /dev/null @@ -1,99 +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 "Juegen Hoetzel, [email protected]" - :doc "A clojure binding for the jclouds AWS security group interface."} - org.jclouds.ec2.security-group2 - (:require (org.jclouds [compute2 :as compute]) - [org.jclouds.ec2.ebs2 :as ebs]) - (:import org.jclouds.ec2.domain.SecurityGroup - org.jclouds.ec2.features.SecurityGroupApi - org.jclouds.net.domain.IpProtocol)) - -(defn #^SecurityGroupApi - sg-service - "Returns the SecurityGroup Api associated with the specified compute service." - [compute] - (-> compute .getContext .getProviderSpecificContext .getApi .getSecurityGroupApi().get)) - -(defn create-group - "Creates a new security group. - - e.g. (create-group compute \"Database Server\" \"Description for group\" :region :us-west-1)" - [compute name & {:keys [description region]}] - (.createSecurityGroupInRegion (sg-service compute) (ebs/get-region region) name (or description name))) - -(defn delete-group - "Deletes a security group. - - e.g. (delete-group compute \"Database Server\" :region :us-west-1)" - [compute name & {:keys [region]}] - (.deleteSecurityGroupInRegion (sg-service compute) (ebs/get-region region) name)) - -(defn groups - "Returns a map of GroupName -> org.jclouds.ec2.domain.SecurityGroup instances. - - e.g. (groups compute :region :us-east-1)" - [compute & {:keys [region]}] - (into {} (for [#^SecurityGroup group (.describeSecurityGroupsInRegion (sg-service compute) - (ebs/get-region region) - (into-array String '()))] - [(.getName group) group]))) - -(defn get-protocol [v] - "Coerce argument to a IP Protocol." - (cond - (instance? IpProtocol v) v - (keyword? v) (if-let [p (get {:tcp IpProtocol/TCP - :udp IpProtocol/UDP - :icmp IpProtocol/ICMP} - v)] - p - (throw (IllegalArgumentException. - (str "Can't obtain IP protocol from " v " (valid :tcp, :udp and :icmp)")))) - (nil? v) IpProtocol/TCP - :else (throw (IllegalArgumentException. - (str "Can't obtain IP protocol from argument of type " (type v)))))) - -(defn authorize - "Adds permissions to a security group. - - e.g. (authorize compute \"jclouds#webserver#us-east-1\" 80 :ip-range \"0.0.0.0/0\") - (authorize compute \"jclouds#webserver#us-east-1\" [1000,2000] :protocol :udp)" - - [compute group-name port & {:keys [protocol ip-range region]}] - (let [group ((groups compute :region region) group-name) - [from-port to-port] (if (number? port) [port port] port)] - (if group - (.authorizeSecurityGroupIngressInRegion - (sg-service compute) (ebs/get-region region) (.getName group) (get-protocol protocol) from-port to-port (or ip-range "0.0.0.0/0")) - (throw (IllegalArgumentException. - (str "Can't find security group for name " group-name)))))) - -(defn revoke - "Revokes permissions from a security group. - - e.g. (revoke compute 80 \"jclouds#webserver#us-east-1\" :protocol :tcp 80 80 :ip-range \"0.0.0.0/0\")" - [compute group-name port & {:keys [protocol ip-range region]}] - (let [group ((groups compute :region region) group-name) - [from-port to-port] (if (number? port) [port port] port)] - (if group - (.revokeSecurityGroupIngressInRegion - (sg-service compute) (ebs/get-region region) (.getName group) (get-protocol protocol) from-port to-port (or ip-range "0.0.0.0/0")) - (throw (IllegalArgumentException. - (str "Can't find security group for name " group-name)))))) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2Api.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2Api.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2Api.java deleted file mode 100644 index d8637e8..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2Api.java +++ /dev/null @@ -1,167 +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. - */ -package org.jclouds.ec2; - -import java.io.Closeable; -import java.util.Set; -import org.jclouds.ec2.features.SubnetApi; -import org.jclouds.ec2.features.TagApi; -import org.jclouds.ec2.features.WindowsApi; -import org.jclouds.ec2.features.AMIApi; -import org.jclouds.ec2.features.AvailabilityZoneAndRegionApi; -import org.jclouds.ec2.features.ElasticBlockStoreApi; -import org.jclouds.ec2.features.ElasticIPAddressApi; -import org.jclouds.ec2.features.InstanceApi; -import org.jclouds.ec2.features.KeyPairApi; -import org.jclouds.ec2.features.SecurityGroupApi; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.Region; -import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; -import org.jclouds.rest.annotations.Delegate; -import org.jclouds.rest.annotations.EndpointParam; - -import com.google.common.base.Optional; -import com.google.inject.Provides; - -/** - * Provides access to EC2 features, broken up by feature group. Use of the - * {@link Optional} type allows you to check to see if the underlying - * implementation supports a particular feature before attempting to use it. - * This is useful in clones like OpenStack, CloudStack, or Eucalyptus, which - * track the api, but are always behind Amazon's service. In the case of Amazon - * ({@code aws-ec2}), you can expect all features to be present. - * - * - * Example - * - * <pre> - * Optional<? extends WindowsApi> windowsOption = ec2Api.getWindowsApi(); - * checkState(windowsOption.isPresent(), "windows feature required, but not present"); - * </pre> - * - * @author Adrian Cole - */ -public interface EC2Api extends Closeable { - /** - * - * @return the Region codes configured - */ - @Provides - @Region - Set<String> getConfiguredRegions(); - - /** - * Provides synchronous access to Windows features. - */ - @Delegate - Optional<? extends WindowsApi> getWindowsApi(); - - @Delegate - Optional<? extends WindowsApi> getWindowsApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - /** - * Provides synchronous access to Tag features. - */ - @Delegate - Optional<? extends TagApi> getTagApi(); - - @Delegate - Optional<? extends TagApi> getTagApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - /** - * Provides synchronous access to Subnet features. - */ - @Delegate - Optional<? extends SubnetApi> getSubnetApi(); - - @Delegate - Optional<? extends SubnetApi> getSubnetApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - /** - * Provides synchronous access to AMI services. - */ - @Delegate - Optional<? extends AMIApi> getAMIApi(); - - @Delegate - Optional<? extends AMIApi> getAMIApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - - /** - * Provides synchronous access to Elastic IP Address services. - */ - @Delegate - Optional<? extends ElasticIPAddressApi> getElasticIPAddressApi(); - - @Delegate - Optional<? extends ElasticIPAddressApi> getElasticIPAddressApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - /** - * Provides synchronous access to Instance services. - */ - @Delegate - Optional<? extends InstanceApi> getInstanceApi(); - - @Delegate - Optional<? extends InstanceApi> getInstanceApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - /** - * Provides synchronous access to KeyPair services. - */ - @Delegate - Optional<? extends KeyPairApi> getKeyPairApi(); - - @Delegate - Optional<? extends KeyPairApi> getKeyPairApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - /** - * Provides synchronous access to SecurityGroup services. - */ - @Delegate - Optional<? extends SecurityGroupApi> getSecurityGroupApi(); - - @Delegate - Optional<? extends SecurityGroupApi> getSecurityGroupApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - /** - * Provides synchronous access to Availability Zones and Regions services. - */ - @Delegate - Optional<? extends AvailabilityZoneAndRegionApi> getAvailabilityZoneAndRegionApi(); - - @Delegate - Optional<? extends AvailabilityZoneAndRegionApi> getAvailabilityZoneAndRegionApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - - /** - * Provides synchronous access to Elastic Block Store services. - */ - @Delegate - Optional<? extends ElasticBlockStoreApi> getElasticBlockStoreApi(); - - @Delegate - Optional<? extends ElasticBlockStoreApi> getElasticBlockStoreApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); -} http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java deleted file mode 100644 index 2b081c5..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java +++ /dev/null @@ -1,91 +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. - */ -package org.jclouds.ec2; - -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; -import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.apis.ApiMetadata; -import org.jclouds.ec2.compute.EC2ComputeServiceContext; -import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule; -import org.jclouds.ec2.compute.config.EC2ResolveImagesModule; -import org.jclouds.ec2.config.EC2HttpApiModule; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -public final class EC2ApiMetadata extends BaseHttpApiMetadata<EC2Api> { - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public EC2ApiMetadata() { - super(new Builder()); - } - - protected EC2ApiMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - Properties properties = BaseHttpApiMetadata.defaultProperties(); - properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.setProperty(PROPERTY_HEADER_TAG, "amz"); - properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "*"); - properties.setProperty(PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT, "500"); - properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "false"); - properties.setProperty(RESOURCENAME_DELIMITER, "#"); - properties.setProperty(PROPERTY_EC2_GENERATE_INSTANCE_NAMES, "true"); - return properties; - } - - public static final class Builder extends BaseHttpApiMetadata.Builder<EC2Api, Builder> { - public Builder() { - id("ec2") - .name("Amazon Elastic Compute Cloud (EC2) API") - .identityName("Access Key ID") - .credentialName("Secret Access Key") - .defaultEndpoint("https://ec2.us-east-1.amazonaws.com") - .documentation(URI.create("http://docs.amazonwebservices.com/AWSEC2/latest/APIReference")) - .version("2010-08-31") - .defaultProperties(EC2ApiMetadata.defaultProperties()) - .view(EC2ComputeServiceContext.class) - .defaultModules(ImmutableSet.<Class<? extends Module>>of(EC2HttpApiModule.class, EC2ResolveImagesModule.class, EC2ComputeServiceContextModule.class)); - } - - @Override - public ApiMetadata build() { - return new EC2ApiMetadata(this); - } - - @Override - protected Builder self() { - return this; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2Fallbacks.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2Fallbacks.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2Fallbacks.java deleted file mode 100644 index 7cb4675..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/EC2Fallbacks.java +++ /dev/null @@ -1,50 +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. - */ -package org.jclouds.ec2; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Throwables.propagate; -import static com.google.common.util.concurrent.Futures.immediateFuture; - -import org.jclouds.Fallback; -import org.jclouds.aws.AWSResponseException; - -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.ListenableFuture; - -public final class EC2Fallbacks { - private EC2Fallbacks() { - } - - public static final class VoidOnVolumeAvailable implements Fallback<Void> { - @Override - public ListenableFuture<Void> create(Throwable t) throws Exception { - return immediateFuture(createOrPropagate(t)); - } - - @Override - public Void createOrPropagate(Throwable t) throws Exception { - if (checkNotNull(t, "throwable") instanceof AWSResponseException) { - AWSResponseException e = AWSResponseException.class.cast(t); - if (Predicates.in(ImmutableSet.of("IncorrectState", "available")).apply(e.getError().getCode())) - return null; - } - throw propagate(t); - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java deleted file mode 100644 index 2286d56..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java +++ /dev/null @@ -1,67 +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. - */ -package org.jclouds.ec2.binders; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; -import static org.jclouds.http.utils.Queries.queryParser; -import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; - -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.ec2.domain.BlockDevice; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.Binder; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -/** - * @author Oleksiy Yarmula - * @author Adrian Cole - */ -public class BindBlockDeviceMappingToIndexedFormParams implements Binder { - - private static final String deviceNamePattern = "BlockDeviceMapping.%d.DeviceName"; - private static final String deleteOnTerminationPattern = "BlockDeviceMapping.%d.Ebs.DeleteOnTermination"; - private static final String volumeIdPattern = "BlockDeviceMapping.%d.Ebs.VolumeId"; - - @SuppressWarnings("unchecked") - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object input) { - checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Map"); - Map<String, BlockDevice> blockDeviceMapping = (Map<String, BlockDevice>) input; - Multimap<String, String> original = queryParser().apply(request.getPayload().getRawContent().toString()); - ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder(); - builder.putAll("Action", "ModifyInstanceAttribute"); - int amazonOneBasedIndex = 1; // according to docs, counters must start with 1 - for (Entry<String, BlockDevice> ebsBlockDeviceName : blockDeviceMapping.entrySet()) { - // not null by contract - builder.put(format(deviceNamePattern, amazonOneBasedIndex), ebsBlockDeviceName.getKey()); - builder.put(format(deleteOnTerminationPattern, amazonOneBasedIndex), - String.valueOf(ebsBlockDeviceName.getValue().isDeleteOnTermination())); - builder.put(format(volumeIdPattern, amazonOneBasedIndex), ebsBlockDeviceName.getValue().getVolumeId()); - amazonOneBasedIndex++; - } - builder.putAll("InstanceId", original.get("InstanceId")); - request.setPayload(newUrlEncodedFormPayload(builder.build())); - return request; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindBundleIdsToIndexedFormParams.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindBundleIdsToIndexedFormParams.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindBundleIdsToIndexedFormParams.java deleted file mode 100644 index c37d3e1..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindBundleIdsToIndexedFormParams.java +++ /dev/null @@ -1,37 +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. - */ -package org.jclouds.ec2.binders; - -import javax.inject.Singleton; - -import org.jclouds.aws.util.AWSUtils; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.Binder; - -/** - * Binds the String [] to form parameters named with BundleId.index - * - * @author Adrian Cole - */ -@Singleton -public class BindBundleIdsToIndexedFormParams implements Binder { - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object input) { - return AWSUtils.indexStringArrayToFormValuesWithPrefix(request, "BundleId", input); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/89fab312/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindFiltersToIndexedFormParams.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindFiltersToIndexedFormParams.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindFiltersToIndexedFormParams.java deleted file mode 100644 index db22895..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/binders/BindFiltersToIndexedFormParams.java +++ /dev/null @@ -1,57 +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. - */ -package org.jclouds.ec2.binders; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.inject.Singleton; - -import org.jclouds.aws.util.AWSUtils; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.Binder; - -import com.google.common.collect.Multimap; - -/** - * Binds the Multimap to form parameters for filtering. - * - * <pre> - * https://ec2.amazonaws.com/?Action=DescribeTags - * &Filter.1.Name=resource-type - * &Filter.1.Value.1=instance - * &Filter.2.Name=key - * &Filter.2.Value.1=stack - * &Filter.3.Name=value - * &Filter.3.Value.1=Test - * &Filter.3.Value.2=Production - * &AUTHPARAMS - * </pre> - * - * @author Adrian Cole - */ -@Singleton -public class BindFiltersToIndexedFormParams implements Binder { - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object input) { - checkArgument(checkNotNull(input, "input") instanceof Multimap, "this binder is only valid for Multimap"); - @SuppressWarnings("unchecked") - Multimap<String, String> filters = (Multimap<String, String>) input; - return AWSUtils.indexMultimapToFormValuesWithPrefix(request, "Filter", "Name", "Value", filters); - } - -}
