JCLOUDS-692 Remove the CloudSigma v1 provider.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/f7aea987 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/f7aea987 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/f7aea987 Branch: refs/heads/master Commit: f7aea98742c2885eb85f07754b47abf7e71ec851 Parents: 5bac61d Author: Adrian Cole <[email protected]> Authored: Tue Sep 30 16:04:20 2014 -0700 Committer: Jeremy Daggett <[email protected]> Committed: Thu Oct 2 09:28:53 2014 -0700 ---------------------------------------------------------------------- allcompute/pom.xml | 15 - apis/cloudsigma/README.txt | 6 - apis/cloudsigma/pom.xml | 116 ---- .../org/jclouds/cloudsigma/CloudSigmaApi.java | 447 ------------- .../cloudsigma/CloudSigmaApiMetadata.java | 88 --- .../BindCloneDriveOptionsToPlainTextString.java | 87 --- .../binders/BindDriveDataToPlainTextString.java | 55 -- .../binders/BindDriveToPlainTextString.java | 55 -- .../binders/BindServerToPlainTextString.java | 55 -- .../CloudSigmaComputeServiceAdapter.java | 251 -------- .../compute/CloudSigmaTemplateBuilderImpl.java | 44 -- .../CloudSigmaComputeServiceContextModule.java | 120 ---- .../ParseOsFamilyVersion64BitFromImageName.java | 82 --- .../functions/PreinstalledDiskToImage.java | 62 -- .../functions/ServerInfoToNodeMetadata.java | 174 ----- .../options/CloudSigmaTemplateOptions.java | 323 ---------- .../config/CloudSigmaRestClientModule.java | 88 --- .../jclouds/cloudsigma/domain/AffinityType.java | 47 -- .../jclouds/cloudsigma/domain/BlockDevice.java | 79 --- .../jclouds/cloudsigma/domain/ClaimType.java | 52 -- .../cloudsigma/domain/CreateDriveRequest.java | 164 ----- .../org/jclouds/cloudsigma/domain/Device.java | 101 --- .../org/jclouds/cloudsigma/domain/Drive.java | 209 ------ .../jclouds/cloudsigma/domain/DriveData.java | 81 --- .../jclouds/cloudsigma/domain/DriveInfo.java | 466 -------------- .../jclouds/cloudsigma/domain/DriveMetrics.java | 132 ---- .../jclouds/cloudsigma/domain/DriveStatus.java | 41 -- .../jclouds/cloudsigma/domain/DriveType.java | 41 -- .../jclouds/cloudsigma/domain/IDEDevice.java | 91 --- .../org/jclouds/cloudsigma/domain/Item.java | 163 ----- .../jclouds/cloudsigma/domain/MediaType.java | 45 -- .../org/jclouds/cloudsigma/domain/Model.java | 40 -- .../java/org/jclouds/cloudsigma/domain/NIC.java | 170 ----- .../jclouds/cloudsigma/domain/ProfileInfo.java | 191 ------ .../jclouds/cloudsigma/domain/ProfileType.java | 40 -- .../jclouds/cloudsigma/domain/SCSIDevice.java | 85 --- .../org/jclouds/cloudsigma/domain/Server.java | 286 -------- .../jclouds/cloudsigma/domain/ServerInfo.java | 251 -------- .../cloudsigma/domain/ServerMetrics.java | 149 ----- .../jclouds/cloudsigma/domain/ServerStatus.java | 40 -- .../jclouds/cloudsigma/domain/StaticIPInfo.java | 224 ------- .../org/jclouds/cloudsigma/domain/VLANInfo.java | 159 ----- .../java/org/jclouds/cloudsigma/domain/VNC.java | 98 --- .../cloudsigma/functions/BaseDriveToMap.java | 50 -- .../cloudsigma/functions/DriveDataToMap.java | 77 --- ...yValuesDelimitedByBlankLinesToDriveInfo.java | 46 -- ...aluesDelimitedByBlankLinesToProfileInfo.java | 46 -- ...ValuesDelimitedByBlankLinesToServerInfo.java | 46 -- ...luesDelimitedByBlankLinesToStaticIPInfo.java | 46 -- ...eyValuesDelimitedByBlankLinesToVLANInfo.java | 46 -- ...luesDelimitedByBlankLinesToDriveInfoSet.java | 53 -- ...ValuesDelimitedByBlankLinesToListOfMaps.java | 54 -- ...esDelimitedByBlankLinesToProfileInfoSet.java | 53 -- ...uesDelimitedByBlankLinesToServerInfoSet.java | 54 -- ...sDelimitedByBlankLinesToStaticIPInfoSet.java | 53 -- ...aluesDelimitedByBlankLinesToVLANInfoSet.java | 53 -- ...sToListOfKeyValuesDelimitedByBlankLines.java | 51 -- .../cloudsigma/functions/MapToDevices.java | 95 --- .../cloudsigma/functions/MapToDriveInfo.java | 110 ---- .../cloudsigma/functions/MapToDriveMetrics.java | 80 --- .../jclouds/cloudsigma/functions/MapToNICs.java | 52 -- .../cloudsigma/functions/MapToProfileInfo.java | 54 -- .../cloudsigma/functions/MapToServerInfo.java | 87 --- .../functions/MapToServerMetrics.java | 53 -- .../cloudsigma/functions/MapToStaticIPInfo.java | 54 -- .../cloudsigma/functions/MapToVLANInfo.java | 50 -- .../cloudsigma/functions/ReturnPayload.java | 32 - .../cloudsigma/functions/ServerToMap.java | 74 --- .../cloudsigma/functions/SplitNewlines.java | 45 -- .../SplitNewlinesAndReturnSecondField.java | 60 -- .../handlers/CloudSigmaErrorHandler.java | 102 --- .../cloudsigma/options/CloneDriveOptions.java | 136 ---- .../cloudsigma/predicates/DriveClaimed.java | 56 -- .../reference/CloudSigmaConstants.java | 29 - .../org/jclouds/cloudsigma/util/Servers.java | 79 --- .../services/org.jclouds.apis.ApiMetadata | 1 - .../cloudsigma/CloudSigmaApiMetadataTest.java | 28 - .../jclouds/cloudsigma/CloudSigmaApiTest.java | 644 ------------------- .../cloudsigma/CloudSigmaClientLiveTest.java | 441 ------------- ...dCloneDriveOptionsToPlainTextStringTest.java | 67 -- .../BindDriveDataToPlainTextStringTest.java | 80 --- .../binders/BindDriveToPlainTextStringTest.java | 83 --- .../BindServerToPlainTextStringTest.java | 85 --- .../CloudSigmaComputeServiceLiveTest.java | 64 -- .../functions/BaseDriveToMapTest.java | 60 -- .../functions/DriveDataToMapTest.java | 74 --- ...uesDelimitedByBlankLinesToDriveInfoTest.java | 42 -- ...sDelimitedByBlankLinesToProfileInfoTest.java | 42 -- ...esDelimitedByBlankLinesToServerInfoTest.java | 73 --- ...luesDelimitedByBlankLinesToVLANInfoTest.java | 42 -- ...DelimitedByBlankLinesToDriveInfoSetTest.java | 44 -- ...esDelimitedByBlankLinesToListOfMapsTest.java | 59 -- ...elimitedByBlankLinesToServerInfoSetTest.java | 73 --- ...sDelimitedByBlankLinesToVLANInfoSetTest.java | 44 -- ...istOfKeyValuesDelimitedByBlankLinesTest.java | 53 -- .../functions/MapToDriveInfoTest.java | 90 --- .../functions/MapToProfileInfoTest.java | 51 -- .../functions/MapToServerInfoTest.java | 155 ----- .../cloudsigma/functions/MapToVLANInfoTest.java | 49 -- ...seOsFamilyVersion64BitFromImageNameTest.java | 74 --- .../cloudsigma/functions/ServerToMapTest.java | 59 -- .../cloudsigma/functions/SplitNewlinesTest.java | 48 -- .../handlers/CloudSigmaErrorHandlerTest.java | 131 ---- .../options/CloneDriveOptionsTest.java | 127 ---- .../src/test/resources/create_drive.txt | 5 - .../src/test/resources/create_server.txt | 11 - apis/cloudsigma/src/test/resources/drive.txt | 27 - .../src/test/resources/drive_data.txt | 6 - apis/cloudsigma/src/test/resources/log4j.xml | 151 ----- .../src/test/resources/new_server.txt | 24 - .../src/test/resources/osmatches.json | 174 ----- apis/cloudsigma/src/test/resources/profile.txt | 28 - apis/cloudsigma/src/test/resources/servers.txt | 40 -- apis/cloudsigma/src/test/resources/uuids.txt | 3 - apis/cloudsigma/src/test/resources/vlan.txt | 4 - apis/pom.xml | 1 - providers/cloudsigma-lvs/pom.xml | 125 ---- .../CloudSigmaLasVegasProviderMetadata.java | 81 --- .../org.jclouds.providers.ProviderMetadata | 1 - .../CloudSigmaLasVegasLondonClientLiveTest.java | 26 - .../CloudSigmaLasVegasProviderTest.java | 28 - ...loudSigmaLasVegasComputeServiceLiveTest.java | 28 - ...oudSigmaLasVegasTemplateBuilderLiveTest.java | 85 --- providers/cloudsigma-zrh/pom.xml | 126 ---- .../CloudSigmaZurichProviderMetadata.java | 81 --- .../org.jclouds.providers.ProviderMetadata | 1 - .../CloudSigmaZurichClientLiveTest.java | 26 - .../CloudSigmaZurichProviderTest.java | 28 - .../CloudSigmaZurichComputeServiceLiveTest.java | 75 --- ...CloudSigmaZurichTemplateBuilderLiveTest.java | 82 --- providers/pom.xml | 2 - 131 files changed, 11641 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/allcompute/pom.xml ---------------------------------------------------------------------- diff --git a/allcompute/pom.xml b/allcompute/pom.xml index c29e553..488a108 100644 --- a/allcompute/pom.xml +++ b/allcompute/pom.xml @@ -79,11 +79,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.jclouds.api</groupId> - <artifactId>cloudsigma</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> <groupId>org.apache.jclouds.provider</groupId> <artifactId>bluelock-vcloud-zone01</artifactId> <version>${project.version}</version> @@ -130,16 +125,6 @@ </dependency> <dependency> <groupId>org.apache.jclouds.provider</groupId> - <artifactId>cloudsigma-zrh</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds.provider</groupId> - <artifactId>cloudsigma-lvs</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds.provider</groupId> <artifactId>go2cloud-jhb1</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/README.txt ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/README.txt b/apis/cloudsigma/README.txt deleted file mode 100644 index bddfd04..0000000 --- a/apis/cloudsigma/README.txt +++ /dev/null @@ -1,6 +0,0 @@ -# -# The jclouds provider for CloudSigma (http://www.cloudsigma.com/). -# -# TODO: Implementation status. -# TODO: Supported features. -# TODO: Usage example. http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/pom.xml ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/pom.xml b/apis/cloudsigma/pom.xml deleted file mode 100644 index 859f62d..0000000 --- a/apis/cloudsigma/pom.xml +++ /dev/null @@ -1,116 +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>2.0.0-SNAPSHOT</version> - <relativePath>../../project/pom.xml</relativePath> - </parent> - <groupId>org.apache.jclouds.api</groupId> - <artifactId>cloudsigma</artifactId> - <name>jclouds CloudSigma API</name> - <description>ComputeService binding to the CloudSigma API</description> - <packaging>bundle</packaging> - - <properties> - <test.cloudsigma.endpoint>https://api.cloudsigma.com</test.cloudsigma.endpoint> - <test.cloudsigma.api-version>1.0</test.cloudsigma.api-version> - <test.cloudsigma.build-version /> - <test.cloudsigma.identity>FIXME_IDENTITY</test.cloudsigma.identity> - <test.cloudsigma.credential>FIXME_CREDENTIAL</test.cloudsigma.credential> - <test.cloudsigma.template>imageId=f3c7c665-cd54-4a78-8fd2-7ec2f028cf29</test.cloudsigma.template> - <jclouds.osgi.export>org.jclouds.cloudsigma*;version="${project.version}"</jclouds.osgi.export> - <jclouds.osgi.import> - org.jclouds.compute.internal;version="${project.version}", - org.jclouds.rest.internal;version="${project.version}", - org.jclouds*;version="${project.version}", - * - </jclouds.osgi.import> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-sshj</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-core</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-log4j</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - </dependencies> - <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.cloudsigma.endpoint>${test.cloudsigma.endpoint}</test.cloudsigma.endpoint> - <test.cloudsigma.api-version>${test.cloudsigma.api-version}</test.cloudsigma.api-version> - <test.cloudsigma.build-version>${test.cloudsigma.build-version}</test.cloudsigma.build-version> - <test.cloudsigma.identity>${test.cloudsigma.identity}</test.cloudsigma.identity> - <test.cloudsigma.credential>${test.cloudsigma.credential}</test.cloudsigma.credential> - <test.cloudsigma.template>${test.cloudsigma.template}</test.cloudsigma.template> - </systemPropertyVariables> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApi.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApi.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApi.java deleted file mode 100644 index da0156d..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApi.java +++ /dev/null @@ -1,447 +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.cloudsigma; - -import java.io.Closeable; -import java.util.Set; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.Fallbacks.VoidOnNotFoundOr404; -import org.jclouds.cloudsigma.binders.BindCloneDriveOptionsToPlainTextString; -import org.jclouds.cloudsigma.binders.BindDriveDataToPlainTextString; -import org.jclouds.cloudsigma.binders.BindDriveToPlainTextString; -import org.jclouds.cloudsigma.binders.BindServerToPlainTextString; -import org.jclouds.cloudsigma.domain.Drive; -import org.jclouds.cloudsigma.domain.DriveData; -import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.cloudsigma.domain.ProfileInfo; -import org.jclouds.cloudsigma.domain.Server; -import org.jclouds.cloudsigma.domain.ServerInfo; -import org.jclouds.cloudsigma.domain.StaticIPInfo; -import org.jclouds.cloudsigma.domain.VLANInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToProfileInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToStaticIPInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToVLANInfo; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet; -import org.jclouds.cloudsigma.functions.SplitNewlines; -import org.jclouds.cloudsigma.functions.SplitNewlinesAndReturnSecondField; -import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.Payload; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; - -/** - * Provides synchronous access to CloudSigma via their REST API. - * <p/> - * - * @see <a href="http://cloudsigma.com/en/platform-details/the-api" /> - */ -@RequestFilters(BasicAuthentication.class) -@Consumes(MediaType.TEXT_PLAIN) -public interface CloudSigmaApi extends Closeable { - - /** - * list of drive uuids that are in the library - * - * @return or empty set if no drives are found - */ - @GET - @Path("/drives/standard/list") - @ResponseParser(SplitNewlines.class) - Set<String> listStandardDrives(); - - /** - * list of cd uuids that are in the library - * - * @return or empty set if no cds are found - */ - @GET - @Path("/drives/standard/cd/list") - @ResponseParser(SplitNewlines.class) - Set<String> listStandardCds(); - - /** - * list of image uuids that are in the library - * - * @return or empty set if no images are found - */ - @GET - @Path("/drives/standard/img/list") - @ResponseParser(SplitNewlines.class) - Set<String> listStandardImages(); - - /** - * Clone an existing drive. By default, the size is the same as the source - * - * @param sourceUuid - * source to clone - * @param newName - * name of the resulting drive - * @param options - * options to control size - * @return new drive - */ - @POST - @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) - @Path("/drives/{uuid}/clone") - @MapBinder(BindCloneDriveOptionsToPlainTextString.class) - DriveInfo cloneDrive(@PathParam("uuid") String sourceUuid, @PayloadParam("name") String newName, - CloneDriveOptions... options); - - /** - * Get profile info - * - * @return info or null, if not found - */ - @GET - @Path("/profile/info") - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToProfileInfo.class) - ProfileInfo getProfileInfo(); - - /** - * Get all drives info - * - * @return or empty set if no drives are found - */ - @GET - @Path("/drives/info") - @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class) - Set<DriveInfo> listDriveInfo(); - - /** - * @param uuid - * what to get - * @return null, if not found - */ - @GET - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) - @Path("/drives/{uuid}/info") - DriveInfo getDriveInfo(@PathParam("uuid") String uuid); - - /** - * create a new drive - * - * @param createDrive - * required parameters: name, size - * @return newly created drive - */ - @POST - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) - @Path("/drives/create") - DriveInfo createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); - - /** - * set extra drive data - * - * @param uuid - * what drive to change - * @param createDrive - * what values to change - * @return new data - */ - @POST - @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) - @Path("/drives/{uuid}/set") - DriveInfo setDriveData(@PathParam("uuid") String uuid, - @BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive); - - /** - * create a new server - * - * @param createServer - * @return newly created server - */ - @POST - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) - @Path("/servers/create") - ServerInfo createServer(@BinderParam(BindServerToPlainTextString.class) Server createServer); - - /** - * Get all servers info - * - * @return or empty set if no servers are found - */ - @GET - @Path("/servers/info") - @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class) - Set<ServerInfo> listServerInfo(); - - /** - * @param uuid - * what to get - * @return null, if not found - */ - @GET - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) - @Path("/servers/{uuid}/info") - ServerInfo getServerInfo(@PathParam("uuid") String uuid); - - /** - * set server configuration - * - * @param uuid - * what server to change - * @param setServer - * what values to change - * @return new data - */ - @POST - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) - @Path("/servers/{uuid}/set") - ServerInfo setServerConfiguration(@PathParam("uuid") String uuid, - @BinderParam(BindServerToPlainTextString.class) Server setServer); - - /** - * list of server uuids in your account - * - * @return or empty set if no servers are found - */ - @GET - @Path("/servers/list") - @ResponseParser(SplitNewlines.class) - Set<String> listServers(); - - /** - * Destroy a server - * - * @param uuid - * what to destroy - */ - @GET - @Path("/servers/{uuid}/destroy") - @Fallback(VoidOnNotFoundOr404.class) - void destroyServer(@PathParam("uuid") String uuid); - - /** - * Start a server - * - * @param uuid - * what to start - */ - @POST - @Path("/servers/{uuid}/start") - void startServer(@PathParam("uuid") String uuid); - - /** - * Stop a server - * <p/> - * Kills the server immediately, equivalent to a power failure. Server reverts to a stopped - * status if it is persistent and is automatically destroyed otherwise. - * - * @param uuid - * what to stop - */ - @POST - @Path("/servers/{uuid}/stop") - void stopServer(@PathParam("uuid") String uuid); - - /** - * Shutdown a server - * <p/> - * Sends the server an ACPI power-down event. Server reverts to a stopped status if it is - * persistent and is automatically destroyed otherwise. - * <h4>note</h4> behaviour on shutdown depends on how your server OS is set up to respond to an - * ACPI power button signal. - * - * @param uuid - * what to shutdown - */ - @POST - @Path("/servers/{uuid}/shutdown") - void shutdownServer(@PathParam("uuid") String uuid); - - /** - * Reset a server - * - * @param uuid - * what to reset - */ - @POST - @Path("/servers/{uuid}/reset") - void resetServer(@PathParam("uuid") String uuid); - - /** - * list of drive uuids in your account - * - * @return or empty set if no drives are found - */ - @GET - @Path("/drives/list") - @ResponseParser(SplitNewlines.class) - Set<String> listDrives(); - - /** - * Destroy a drive - * - * @param uuid - * what to delete - */ - @GET - @Path("/drives/{uuid}/destroy") - @Fallback(VoidOnNotFoundOr404.class) - void destroyDrive(@PathParam("uuid") String uuid); - - /** - * create a new vlan - * - * @param name - * @return newly created vlan - */ - @POST - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToVLANInfo.class) - @Path("/resources/vlan/create") - @Payload("name {name}\n") - @Produces(MediaType.TEXT_PLAIN) - VLANInfo createVLAN(@PayloadParam("name") String name); - - /** - * Get all vlans info - * - * @return or empty set if no vlans are found - */ - @GET - @Path("/resources/vlan/info") - @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet.class) - Set<VLANInfo> listVLANInfo(); - - /** - * @param uuid - * what to get - * @return null, if not found - */ - @GET - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToVLANInfo.class) - @Path("/resources/vlan/{uuid}/info") - VLANInfo getVLANInfo(@PathParam("uuid") String uuid); - - /** - * set vlan configuration - * - * @param uuid - * what vlan to change - * @param name - * what the new name is - * @return new data - */ - @POST - @ResponseParser(KeyValuesDelimitedByBlankLinesToVLANInfo.class) - @Path("/resources/vlan/{uuid}/set") - @Payload("name {name}\n") - @Produces(MediaType.TEXT_PLAIN) - VLANInfo renameVLAN(@PathParam("uuid") String uuid, @PayloadParam("name") String name); - - /** - * list of vlan uuids in your account - * - * @return or empty set if no vlans are found - */ - @GET - @Path("/resources/vlan/list") - @ResponseParser(SplitNewlinesAndReturnSecondField.class) - Set<String> listVLANs(); - - /** - * Destroy a vlan - * - * @param uuid - * what to destroy - */ - @GET - @Path("/resources/vlan/{uuid}/destroy") - @Fallback(VoidOnNotFoundOr404.class) - void destroyVLAN(@PathParam("uuid") String uuid); - - /** - * create a new ip - * - * @return newly created ip - */ - @POST - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToStaticIPInfo.class) - @Path("/resources/ip/create") - StaticIPInfo createStaticIP(); - - /** - * Get all ips info - * - * @return or empty set if no ips are found - */ - @GET - @Path("/resources/ip/info") - @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet.class) - Set<StaticIPInfo> listStaticIPInfo(); - - /** - * @param uuid - * what to get - * @return null, if not found - */ - @GET - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToStaticIPInfo.class) - @Path("/resources/ip/{uuid}/info") - StaticIPInfo getStaticIPInfo(@PathParam("uuid") String uuid); - - /** - * list of ip uuids in your account - * - * @return or empty set if no ips are found - */ - @GET - @Path("/resources/ip/list") - @ResponseParser(SplitNewlinesAndReturnSecondField.class) - Set<String> listStaticIPs(); - - /** - * Destroy a ip - * - * @param uuid - * what to destroy - */ - @GET - @Path("/resources/ip/{uuid}/destroy") - @Fallback(VoidOnNotFoundOr404.class) - void destroyStaticIP(@PathParam("uuid") String uuid); - -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApiMetadata.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApiMetadata.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApiMetadata.java deleted file mode 100644 index 6a0192e..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApiMetadata.java +++ /dev/null @@ -1,88 +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.cloudsigma; -import static org.jclouds.cloudsigma.reference.CloudSigmaConstants.PROPERTY_VNC_PASSWORD; -import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE; -import static org.jclouds.reflect.Reflection2.typeToken; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.cloudsigma.compute.config.CloudSigmaComputeServiceContextModule; -import org.jclouds.cloudsigma.config.CloudSigmaRestClientModule; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Implementation of {@link ApiMetadata} for the Cloud Sigma API - */ -public class CloudSigmaApiMetadata extends BaseHttpApiMetadata<CloudSigmaApi> { - - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public CloudSigmaApiMetadata() { - this(new Builder()); - } - - protected CloudSigmaApiMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - Properties properties = BaseHttpApiMetadata.defaultProperties(); - properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d"); - // passwords are set post-boot, so auth failures are possible - // from a race condition applying the password set script - properties.setProperty("jclouds.ssh.max-retries", "7"); - properties.setProperty("jclouds.ssh.retry-auth", "true"); - properties.setProperty(TEMPLATE, "osFamily=UBUNTU,imageNameMatches=.*[Aa]utomated SSH Access.*,os64Bit=true"); - return properties; - } - - public static class Builder extends BaseHttpApiMetadata.Builder<CloudSigmaApi, Builder> { - - protected Builder() { - id("cloudsigma") - .name("CloudSigma API") - .identityName("Email") - .credentialName("Password") - .documentation(URI.create("http://cloudsigma.com/en/platform-details/the-api")) - .version("1.0") - .defaultEndpoint("https://api.cloudsigma.com") - .defaultProperties(CloudSigmaApiMetadata.defaultProperties()) - .view(typeToken(ComputeServiceContext.class)) - .defaultModules(ImmutableSet.<Class<? extends Module>>of(CloudSigmaRestClientModule.class, CloudSigmaComputeServiceContextModule.class)); - } - - @Override - public CloudSigmaApiMetadata build() { - return new CloudSigmaApiMetadata(this); - } - - @Override - protected Builder self() { - return this; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java deleted file mode 100644 index 9736efa..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java +++ /dev/null @@ -1,87 +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.cloudsigma.binders; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; -import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.MapBinder; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; - -@Singleton -public class BindCloneDriveOptionsToPlainTextString implements MapBinder { - private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; - - @Inject - public BindCloneDriveOptionsToPlainTextString( - ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { - this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; - } - - @Override - public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { - checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - GeneratedHttpRequest gRequest = GeneratedHttpRequest.class.cast(request); - - CloneDriveOptions options = findOptionsInArgsOrNull(gRequest); - if (options != null) { - postParams = ImmutableMap.<String, Object> builder().putAll(postParams).putAll(options.getOptions()).build(); - } - - request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(Maps.transformValues(postParams, new Function<Object, String>() { - @Override - public String apply(Object input) { - return input == null ? null : input.toString(); - } - })))); - request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - return request; - } - - static CloneDriveOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) { - for (Object arg : gRequest.getInvocation().getArgs()) { - if (arg instanceof CloneDriveOptions) { - return (CloneDriveOptions) arg; - } else if (arg instanceof CloneDriveOptions[]) { - CloneDriveOptions[] options = (CloneDriveOptions[]) arg; - return (options.length > 0) ? options[0] : null; - } - } - return null; - } - - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object input) { - throw new UnsupportedOperationException(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java deleted file mode 100644 index a3c8922..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java +++ /dev/null @@ -1,55 +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.cloudsigma.binders; - -import static com.google.common.base.Preconditions.checkArgument; - -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.cloudsigma.domain.DriveData; -import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.Binder; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; - -@Singleton -public class BindDriveDataToPlainTextString implements Binder { - private final Function<DriveData, Map<String, String>> createDriveRequestToMap; - private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; - - @Inject - public BindDriveDataToPlainTextString(Function<DriveData, Map<String, String>> createDriveRequestToMap, - ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { - this.createDriveRequestToMap = createDriveRequestToMap; - this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; - } - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object payload) { - checkArgument(payload instanceof DriveData, "this binder is only valid for DriveData!"); - DriveData create = DriveData.class.cast(payload); - Map<String, String> map = createDriveRequestToMap.apply(create); - request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); - request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - return request; - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java deleted file mode 100644 index 21b203f..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java +++ /dev/null @@ -1,55 +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.cloudsigma.binders; - -import static com.google.common.base.Preconditions.checkArgument; - -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.cloudsigma.domain.Drive; -import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.Binder; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; - -@Singleton -public class BindDriveToPlainTextString implements Binder { - private final Function<Drive, Map<String, String>> createDriveRequestToMap; - private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; - - @Inject - public BindDriveToPlainTextString(Function<Drive, Map<String, String>> createDriveRequestToMap, - ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { - this.createDriveRequestToMap = createDriveRequestToMap; - this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; - } - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object payload) { - checkArgument(payload instanceof Drive, "this binder is only valid for Drive!"); - Drive create = Drive.class.cast(payload); - Map<String, String> map = createDriveRequestToMap.apply(create); - request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); - request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - return request; - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java deleted file mode 100644 index 351de4e..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java +++ /dev/null @@ -1,55 +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.cloudsigma.binders; - -import static com.google.common.base.Preconditions.checkArgument; - -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.cloudsigma.domain.Server; -import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.Binder; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; - -@Singleton -public class BindServerToPlainTextString implements Binder { - private final Function<Server, Map<String, String>> createServerRequestToMap; - private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; - - @Inject - public BindServerToPlainTextString(Function<Server, Map<String, String>> createServerRequestToMap, - ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { - this.createServerRequestToMap = createServerRequestToMap; - this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; - } - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object payload) { - checkArgument(payload instanceof Server, "this binder is only valid for Server!"); - Server create = Server.class.cast(payload); - Map<String, String> map = createServerRequestToMap.apply(create); - request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); - request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - return request; - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java deleted file mode 100644 index c3159da..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java +++ /dev/null @@ -1,251 +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.cloudsigma.compute; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.contains; -import static com.google.common.collect.Iterables.filter; -import static org.jclouds.concurrent.FutureIterables.transformParallel; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.cloudsigma.CloudSigmaApi; -import org.jclouds.cloudsigma.compute.options.CloudSigmaTemplateOptions; -import org.jclouds.cloudsigma.domain.AffinityType; -import org.jclouds.cloudsigma.domain.Device; -import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.cloudsigma.domain.DriveType; -import org.jclouds.cloudsigma.domain.Server; -import org.jclouds.cloudsigma.domain.ServerInfo; -import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.cloudsigma.reference.CloudSigmaConstants; -import org.jclouds.cloudsigma.util.Servers; -import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.internal.VolumeImpl; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.domain.Location; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.UncheckedExecutionException; - -/** - * defines the connection between the {@link org.jclouds.cloudsigma.CloudSigmaApi} implementation - * and the jclouds {@link ComputeService} - */ -@Singleton -public class CloudSigmaComputeServiceAdapter implements - ComputeServiceAdapter<ServerInfo, Hardware, DriveInfo, Location> { - private static final Predicate<DriveInfo> PREINSTALLED_DISK = Predicates.and(Predicates.notNull(), - new Predicate<DriveInfo>() { - - @Override - public boolean apply(DriveInfo drive) { - return drive.getType().equals(DriveType.DISK) && drive.getDriveType().contains("preinstalled"); - } - - }); - private final CloudSigmaApi client; - private final Predicate<DriveInfo> driveNotClaimed; - private final String defaultVncPassword; - private final LoadingCache<String, DriveInfo> cache; - private final ListeningExecutorService userExecutor; - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - public CloudSigmaComputeServiceAdapter(CloudSigmaApi client, Predicate<DriveInfo> driveNotClaimed, - @Named(CloudSigmaConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword, - LoadingCache<String, DriveInfo> cache, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) { - this.client = checkNotNull(client, "client"); - this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed"); - this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword"); - checkArgument(defaultVncPassword.length() <= 8, "vnc passwords should be less that 8 characters!"); - this.cache = checkNotNull(cache, "cache"); - this.userExecutor = checkNotNull(userExecutor, "userExecutor"); - } - - @Override - public NodeAndInitialCredentials<ServerInfo> createNodeWithGroupEncodedIntoName(String tag, String name, Template template) { - long bootSize = (long) (template.getHardware().getVolumes().get(0).getSize() * 1024 * 1024 * 1024l); - AffinityType affinityType = AffinityType.HDD; - if (template.getOptions() instanceof CloudSigmaTemplateOptions) { - CloudSigmaTemplateOptions options = CloudSigmaTemplateOptions.class.cast(template.getOptions()); - affinityType = options.getDiskDriveAffinity(); - } - logger.debug(">> imaging boot drive source(%s) bytes(%d) affinityType(%s)", - template.getImage().getId(), bootSize, affinityType); - DriveInfo drive = client.cloneDrive(template.getImage().getId(), template.getImage().getId(), - new CloneDriveOptions().size(bootSize).affinity(affinityType)); - boolean success = driveNotClaimed.apply(drive); - logger.debug("<< image(%s) complete(%s)", drive.getUuid(), success); - if (!success) { - client.destroyDrive(drive.getUuid()); - throw new IllegalStateException("could not image drive in time!"); - } - - Server toCreate = Servers.small(name, drive.getUuid(), defaultVncPassword).mem(template.getHardware().getRam()) - .cpu((int) (template.getHardware().getProcessors().get(0).getSpeed())).build(); - - logger.debug(">> creating server"); - ServerInfo from = client.createServer(toCreate); - logger.debug("<< created server(%s)", from.getUuid()); - logger.debug(">> starting server(%s)", from.getUuid()); - client.startServer(from.getUuid()); - return new NodeAndInitialCredentials<ServerInfo>(from, from.getUuid(), LoginCredentials.builder() - .password(defaultVncPassword).authenticateSudo(true).build()); - } - - @Override - public Iterable<Hardware> listHardwareProfiles() { - Builder<Hardware> hardware = ImmutableSet.builder(); - for (double cpu : new double[] { 1000, 5000, 10000, 20000 }) - for (int ram : new int[] { 512, 1024, 4 * 1024, 16 * 1024, 32 * 1024 }) { - final float size = (float) cpu / 100; - String id = String.format("cpu=%f,ram=%s,disk=%f", cpu, ram, size); - hardware.add(new HardwareBuilder().supportsImage(new Predicate<Image>() { - - @Override - public boolean apply(Image input) { - String toParse = input.getUserMetadata().get("size"); - return toParse != null && new Float(toParse) <= size; - } - - @Override - public String toString() { - return "sizeLessThanOrEqual(" + size + ")"; - } - - }).ids(id).ram(ram).processors(ImmutableList.of(new Processor(1, cpu))).hypervisor("kvm") - .volumes(ImmutableList.<Volume>of(new VolumeImpl(size, true, true))).build()); - } - return hardware.build(); - } - - /** - * look up the current standard images and do not error out, if they are not - * found. - */ - @Override - public Iterable<DriveInfo> listImages() { - return FluentIterable.from(transformParallel(client.listStandardDrives(), - new Function<String, ListenableFuture<? extends DriveInfo>>() { - - @Override - public ListenableFuture<DriveInfo> apply(String input) { - try { - return Futures.immediateFuture(cache.getUnchecked(input)); - } catch (CacheLoader.InvalidCacheLoadException e) { - logger.debug("drive %s not found", input); - } catch (UncheckedExecutionException e) { - logger.warn(e, "error finding drive %s: %s", input, e.getMessage()); - } - return Futures.immediateFuture(null); - } - - @Override - public String toString() { - return "seedDriveCache()"; - } - }, userExecutor, null, logger, "drives")).filter(PREINSTALLED_DISK); - } - - @SuppressWarnings("unchecked") - @Override - public Iterable<ServerInfo> listNodes() { - return (Iterable<ServerInfo>) client.listServerInfo(); - } - - @Override - public Iterable<ServerInfo> listNodesByIds(final Iterable<String> ids) { - return filter(listNodes(), new Predicate<ServerInfo>() { - - @Override - public boolean apply(ServerInfo server) { - return contains(ids, server.getUuid()); - } - }); - } - - @Override - public Iterable<Location> listLocations() { - // Not using the adapter to determine locations - return ImmutableSet.<Location>of(); - } - - @Override - public ServerInfo getNode(String id) { - return client.getServerInfo(id); - } - - @Override - public DriveInfo getImage(String id) { - return client.getDriveInfo(id); - } - - @Override - public void destroyNode(String id) { - ServerInfo server = getNode(id); - if (server != null) { - client.stopServer(id); - client.destroyServer(id); - for (Device dev : server.getDevices().values()) - client.destroyDrive(dev.getDriveUuid()); - } - } - - @Override - public void rebootNode(String id) { - client.resetServer(id); - } - - @Override - public void resumeNode(String id) { - client.startServer(id); - - } - - @Override - public void suspendNode(String id) { - client.stopServer(id); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderImpl.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderImpl.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderImpl.java deleted file mode 100644 index c609806..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderImpl.java +++ /dev/null @@ -1,44 +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.cloudsigma.compute; - -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; - -import org.jclouds.collect.Memoized; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.domain.internal.TemplateBuilderImpl; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.compute.strategy.GetImageStrategy; -import org.jclouds.compute.suppliers.ImageCacheSupplier; -import org.jclouds.domain.Location; - -import com.google.common.base.Supplier; - -public class CloudSigmaTemplateBuilderImpl extends TemplateBuilderImpl { - @Inject - public CloudSigmaTemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations, - ImageCacheSupplier images, @Memoized Supplier<Set<? extends Hardware>> hardwares, - Supplier<Location> defaultLocation2, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider, - @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, GetImageStrategy getImageStrategy) { - super(locations, images, hardwares, defaultLocation2, optionsProvider, defaultTemplateProvider, getImageStrategy); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java deleted file mode 100644 index 9daff85..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java +++ /dev/null @@ -1,120 +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.cloudsigma.compute.config; - -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.jclouds.util.Predicates2.retry; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.cloudsigma.CloudSigmaApi; -import org.jclouds.cloudsigma.compute.CloudSigmaComputeServiceAdapter; -import org.jclouds.cloudsigma.compute.CloudSigmaTemplateBuilderImpl; -import org.jclouds.cloudsigma.compute.functions.ParseOsFamilyVersion64BitFromImageName; -import org.jclouds.cloudsigma.compute.functions.PreinstalledDiskToImage; -import org.jclouds.cloudsigma.compute.functions.ServerInfoToNodeMetadata; -import org.jclouds.cloudsigma.compute.functions.ServerInfoToNodeMetadata.DeviceToVolume; -import org.jclouds.cloudsigma.compute.functions.ServerInfoToNodeMetadata.GetImageIdFromServer; -import org.jclouds.cloudsigma.compute.options.CloudSigmaTemplateOptions; -import org.jclouds.cloudsigma.domain.Device; -import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.cloudsigma.domain.Server; -import org.jclouds.cloudsigma.domain.ServerInfo; -import org.jclouds.cloudsigma.predicates.DriveClaimed; -import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.ComputeServiceAdapterContextModule; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.OsFamilyVersion64Bit; -import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; -import org.jclouds.domain.Location; -import org.jclouds.functions.IdentityFunction; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; - -public class CloudSigmaComputeServiceContextModule extends - ComputeServiceAdapterContextModule<ServerInfo, Hardware, DriveInfo, Location> { - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - protected void configure() { - super.configure(); - bind(new TypeLiteral<ComputeServiceAdapter<ServerInfo, Hardware, DriveInfo, Location>>() { - }).to(CloudSigmaComputeServiceAdapter.class); - bind(new TypeLiteral<Function<ServerInfo, NodeMetadata>>() { - }).to(ServerInfoToNodeMetadata.class); - bind(new TypeLiteral<Function<Hardware, Hardware>>() { - }).to(Class.class.cast(IdentityFunction.class)); - bind(new TypeLiteral<Function<DriveInfo, Image>>() { - }).to(PreinstalledDiskToImage.class); - bind(new TypeLiteral<Function<Location, Location>>() { - }).to(Class.class.cast(IdentityFunction.class)); - bind(new TypeLiteral<Function<Device, Volume>>() { - }).to(DeviceToVolume.class); - bind(new TypeLiteral<Function<Server, String>>() { - }).to(GetImageIdFromServer.class); - bind(new TypeLiteral<Function<String, OsFamilyVersion64Bit>>() { - }).to(ParseOsFamilyVersion64BitFromImageName.class); - bind(TemplateBuilder.class) - .to(CloudSigmaTemplateBuilderImpl.class); - } - - @Provides - @Singleton - protected LoadingCache<String, DriveInfo> cache(GetDrive getDrive) { - return CacheBuilder.newBuilder().build(getDrive); - } - - @Singleton - public static class GetDrive extends CacheLoader<String, DriveInfo> { - private final CloudSigmaApi client; - - @Inject - public GetDrive(CloudSigmaApi client) { - this.client = client; - } - - @Override - public DriveInfo load(String input) { - return client.getDriveInfo(input); - } - } - - @Provides - @Singleton - protected Predicate<DriveInfo> supplyDriveUnclaimed(DriveClaimed driveClaimed, Timeouts timeouts) { - return retry(Predicates.not(driveClaimed), timeouts.nodeRunning, 1000, MILLISECONDS); - } - - @Provides - @Singleton - protected TemplateOptions templateOptions() { - return new CloudSigmaTemplateOptions(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java deleted file mode 100644 index bbea27d..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java +++ /dev/null @@ -1,82 +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.cloudsigma.compute.functions; - -import static com.google.common.base.Predicates.and; -import static com.google.common.base.Predicates.containsPattern; -import static com.google.common.base.Predicates.not; -import static com.google.common.base.Predicates.or; - -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.OsFamilyVersion64Bit; -import org.jclouds.compute.util.ComputeServiceUtils; - -import com.google.common.base.Function; - -/** - * Defaults to version null and 64bit, if the operating system is unrecognized and the pattern - * "32bit" isn't in the string. - */ -@Singleton -public class ParseOsFamilyVersion64BitFromImageName implements Function<String, OsFamilyVersion64Bit> { - private final Map<OsFamily, Map<String, String>> osVersionMap; - - @Inject - public ParseOsFamilyVersion64BitFromImageName(Map<OsFamily, Map<String, String>> osVersionMap) { - this.osVersionMap = osVersionMap; - } - - // ex CentOS 5.5 Linux 64bit Preinstalled System with AppFirst Monitoring - // ex. Centos-5.6-20110917 pub - public static final Pattern PATTERN = Pattern.compile("([^ -]+)[^0-9]([0-9.]+)[ -].*"); - - @Override - public OsFamilyVersion64Bit apply(String input) { - boolean is64Bit = and(not(containsPattern("32bit")), - or(containsPattern("64bit"), not(containsPattern("Windows")))).apply(input); - if (input.contains("Windows")) { - String version = null; - Matcher matcher = Pattern.compile(".*(20[01][0-9] R[1-9]).*").matcher(input); - if (matcher.find()) { - version = matcher.group(1); - } else { - matcher = Pattern.compile(".*(20[01][0-9]).*").matcher(input); - if (matcher.find()) - version = matcher.group(1); - } - return new OsFamilyVersion64Bit(OsFamily.WINDOWS, osVersionMap.get(OsFamily.WINDOWS).get(version), is64Bit); - } else { - Matcher matcher = PATTERN.matcher(input); - if (matcher.find()) { - OsFamily fam = OsFamily.fromValue(matcher.group(1).toLowerCase()); - if (fam == OsFamily.UNRECOGNIZED) - return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, null, is64Bit); - return new OsFamilyVersion64Bit(fam, ComputeServiceUtils.parseVersionOrReturnEmptyString(fam, matcher - .group(2), osVersionMap), is64Bit); - } else { - return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, null, is64Bit); - } - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java deleted file mode 100644 index c415556..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java +++ /dev/null @@ -1,62 +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.cloudsigma.compute.functions; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Image.Status; -import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OperatingSystem.Builder; -import org.jclouds.compute.domain.OsFamilyVersion64Bit; -import org.jclouds.domain.Location; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; - -@Singleton -public class PreinstalledDiskToImage implements Function<DriveInfo, Image> { - private final Supplier<Location> locationSupplier; - private final Function<String, OsFamilyVersion64Bit> imageParser; - - @Inject - public PreinstalledDiskToImage(Supplier<Location> locationSupplier, - Function<String, OsFamilyVersion64Bit> imageParser) { - this.locationSupplier = locationSupplier; - this.imageParser = imageParser; - } - - @Override - public Image apply(DriveInfo drive) { - if (drive.getName() == null) - return null; - String description = drive.getDescription() != null ? drive.getDescription() : drive.getName(); - Builder builder = OperatingSystem.builder(); - OsFamilyVersion64Bit parsed = imageParser.apply(drive.getName()); - builder.name(drive.getName()).description(description) - .is64Bit(drive.getBits() != null ? drive.getBits() == 64 : parsed.is64Bit).version(parsed.version) - .family(parsed.family); - return new ImageBuilder().ids(drive.getUuid()) - .userMetadata(ImmutableMap.<String, String> of("size", drive.getSize() / 1024 / 1024 / 1024 + "")) - .location(locationSupplier.get()).name(drive.getName()).description(description) - .operatingSystem(builder.build()).status(Status.AVAILABLE).version("").build(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java deleted file mode 100644 index 38ef7f4..0000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java +++ /dev/null @@ -1,174 +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.cloudsigma.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.compute.predicates.ImagePredicates.idEquals; - -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.cloudsigma.domain.Device; -import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.cloudsigma.domain.Server; -import org.jclouds.cloudsigma.domain.ServerInfo; -import org.jclouds.cloudsigma.domain.ServerStatus; -import org.jclouds.collect.Memoized; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadata.Status; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.VolumeBuilder; -import org.jclouds.compute.functions.GroupNamingConvention; -import org.jclouds.domain.Location; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.base.Supplier; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.util.concurrent.UncheckedExecutionException; - -@Singleton -public class ServerInfoToNodeMetadata implements Function<ServerInfo, NodeMetadata> { - public static final Map<ServerStatus, Status> serverStatusToNodeStatus = ImmutableMap - .<ServerStatus, Status> builder().put(ServerStatus.ACTIVE, Status.RUNNING)// - .put(ServerStatus.STOPPED, Status.SUSPENDED)// - .put(ServerStatus.PAUSED, Status.SUSPENDED)// - .put(ServerStatus.DUMPED, Status.PENDING)// - .put(ServerStatus.DEAD, Status.TERMINATED)// - .put(ServerStatus.UNRECOGNIZED, Status.UNRECOGNIZED)// - .build(); - - private final Function<Server, String> getImageIdFromServer; - private final Supplier<Set<? extends Image>> images; - private final Supplier<Location> locationSupplier; - private final Function<Device, Volume> deviceToVolume; - private final GroupNamingConvention nodeNamingConvention; - - @Inject - ServerInfoToNodeMetadata(Function<Server, String> getImageIdFromServer, @Memoized Supplier<Set<? extends Image>> images, - Function<Device, Volume> deviceToVolume, Supplier<Location> locationSupplier, - GroupNamingConvention.Factory namingConvention) { - this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix(); - this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier"); - this.deviceToVolume = checkNotNull(deviceToVolume, "deviceToVolume"); - this.images = checkNotNull(images, "images"); - this.getImageIdFromServer = checkNotNull(getImageIdFromServer, "getImageIdFromServer"); - } - - @Override - public NodeMetadata apply(ServerInfo from) { - NodeMetadataBuilder builder = new NodeMetadataBuilder(); - builder.ids(from.getUuid()); - builder.name(from.getName()); - builder.location(locationSupplier.get()); - builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); - - String imageId = getImageIdFromServer.apply(from); - if (imageId != null) { - Optional<? extends Image> image = FluentIterable.from(images.get()).firstMatch(idEquals(imageId)); - if (image.isPresent()) { - builder.operatingSystem(image.get().getOperatingSystem()); - } - } - builder.hardware(new HardwareBuilder().ids(from.getUuid()).hypervisor("kvm") - .processors(ImmutableList.of(new Processor(1, from.getCpu()))).ram(from.getMem()) - .volumes(Iterables.transform(from.getDevices().values(), deviceToVolume)).build()); - builder.status(serverStatusToNodeStatus.get(from.getStatus())); - builder.publicAddresses(ImmutableSet.<String> of(from.getVnc().getIp())); - builder.privateAddresses(ImmutableSet.<String> of()); - return builder.build(); - } - - @Singleton - public static final class DeviceToVolume implements Function<Device, Volume> { - @Resource - protected Logger logger = Logger.NULL; - - private final LoadingCache<String, DriveInfo> cache; - - @Inject - public DeviceToVolume(LoadingCache<String, DriveInfo> cache) { - this.cache = checkNotNull(cache, "cache"); - } - - @Override - public Volume apply(Device input) { - VolumeBuilder builder = new VolumeBuilder(); - builder.id(input.getId()); - try { - DriveInfo drive = cache.getUnchecked(input.getDriveUuid()); - builder.size((float) drive.getSize()); - } catch (NullPointerException e) { - logger.debug("drive %s not found", input.getDriveUuid()); - } catch (UncheckedExecutionException e) { - logger.warn(e, "error finding drive %s: %s", input.getDriveUuid(), e.getMessage()); - } - return builder.durable(true).type(Volume.Type.NAS).build(); - } - } - - /** - * When we create the boot drive of the server, by convention we set the name - * to the image it came from. - * - * - */ - @Singleton - public static class GetImageIdFromServer implements Function<Server, String> { - @Resource - protected Logger logger = Logger.NULL; - - private final LoadingCache<String, DriveInfo> cache; - - @Inject - public GetImageIdFromServer(LoadingCache<String, DriveInfo> cache) { - this.cache = cache; - } - - @Override - public String apply(Server from) { - String imageId = null; - String bootDeviceId = Iterables.get(from.getBootDeviceIds(), 0); - Device bootDevice = from.getDevices().get(bootDeviceId); - if (bootDevice != null) { - try { - DriveInfo drive = cache.getUnchecked(bootDevice.getDriveUuid()); - imageId = drive.getName(); - } catch (NullPointerException e) { - logger.debug("drive %s not found", bootDevice.getDriveUuid()); - } catch (UncheckedExecutionException e) { - logger.warn(e, "error finding drive %s: %s", bootDevice.getDriveUuid(), e.getMessage()); - } - } - return imageId; - } - } -}
