diff --git a/README.txt b/README.txt index 2dda1e16fe..292ddfb81a 100644 --- a/README.txt +++ b/README.txt @@ -39,6 +39,8 @@ our loadbalancer api supports: cloudloadbalancers-us * note * the pom dependency org.jclouds/jclouds-allloadbalancer gives you access to to all of these providers +we also have aws-cloudwatch support. + we also have support for: ibmdev, mezeo, nirvanix, boxdotnet, openstack nova, scality ring, hosteurope-storage, tiscali-storage, scaleup-storage, googlestorage, azurequeue, simpledb, cloudstack as well as a async-http-client diff --git a/all/pom.xml b/all/pom.xml index ff9372db45..e9d9983726 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -30,6 +30,11 @@ jclouds-all all + + org.jclouds.provider + aws-cloudwatch + ${project.version} + ${project.groupId} jclouds-allloadbalancer diff --git a/sandbox-apis/cloudwatch/pom.xml b/apis/cloudwatch/pom.xml similarity index 100% rename from sandbox-apis/cloudwatch/pom.xml rename to apis/cloudwatch/pom.xml diff --git a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java similarity index 98% rename from sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java rename to apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java index 9c05d5b1b4..7d9e54c01c 100644 --- a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java @@ -21,7 +21,6 @@ package org.jclouds.cloudwatch; import java.util.Date; import java.util.Set; -import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -30,6 +29,7 @@ import org.jclouds.aws.filters.FormSigner; import org.jclouds.cloudwatch.domain.Datapoint; import org.jclouds.cloudwatch.functions.ISO8601Format; import org.jclouds.cloudwatch.xml.GetMetricStatisticsResponseHandler; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.FormParams; diff --git a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java similarity index 98% rename from sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java rename to apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java index 9507968217..276bcef2d7 100644 --- a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java @@ -22,10 +22,9 @@ import java.util.Date; import java.util.Set; import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; - import org.jclouds.cloudwatch.domain.Datapoint; import org.jclouds.concurrent.Timeout; +import org.jclouds.javax.annotation.Nullable; /** * Provides access to Amazon CloudWatch via the Query API diff --git a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchContextBuilder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchContextBuilder.java similarity index 100% rename from sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchContextBuilder.java rename to apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchContextBuilder.java diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java new file mode 100644 index 0000000000..b641d2c2e5 --- /dev/null +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.cloudwatch; + +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; + +import java.util.Properties; + +import org.jclouds.PropertiesBuilder; + +/** + * Builds properties used in Cloud Watch Clients + * + * @author Adrian Cole + */ +public class CloudWatchPropertiesBuilder extends PropertiesBuilder { + + @Override + protected Properties defaultProperties() { + Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); + properties.setProperty(PROPERTY_HEADER_TAG, "amz"); + properties.setProperty(PROPERTY_API_VERSION, CloudWatchAsyncClient.VERSION); + return properties; + } + + public CloudWatchPropertiesBuilder() { + super(); + } + + public CloudWatchPropertiesBuilder(Properties properties) { + super(properties); + } + +} diff --git a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java similarity index 100% rename from sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java rename to apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java diff --git a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Datapoint.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Datapoint.java similarity index 99% rename from sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Datapoint.java rename to apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Datapoint.java index eb6461bb90..77a7aecf4a 100644 --- a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Datapoint.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Datapoint.java @@ -20,7 +20,7 @@ package org.jclouds.cloudwatch.domain; import java.util.Date; -import javax.annotation.Nullable; +import org.jclouds.javax.annotation.Nullable; /** * @see createContextSpec() { - return new RestContextFactory().createContextSpec("cloudwatch", "identity", "credential", new Properties()); + Properties props = new Properties(); + props.setProperty("cloudwatch.endpoint", "https://monitoring.us-east-1.amazonaws.com"); + return new RestContextFactory().createContextSpec("cloudwatch", "identity", "credential", props); } @Override diff --git a/sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java similarity index 90% rename from sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java rename to apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java index 87278c20f2..f7755ae9c4 100644 --- a/sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java @@ -25,7 +25,6 @@ import java.util.Date; import java.util.Properties; import org.jclouds.Constants; -import org.jclouds.aws.domain.Region; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; @@ -55,7 +54,7 @@ public class CloudWatchClientLiveTest { protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); + + ".credential"); endpoint = System.getProperty("test." + provider + ".endpoint", null); apiversion = System.getProperty("test." + provider + ".apiversion", null); } @@ -78,17 +77,19 @@ public class CloudWatchClientLiveTest { setupCredentials(); Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides); + overrides); client = context.getApi(); } @Test - void testGetMetricStatisticsInRegion() { + protected void testGetMetricStatisticsInRegion() { + getMetricStatisticsInRegion(null); + } + + protected void getMetricStatisticsInRegion(String region) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, -1); - for (String region : Region.DEFAULT_REGIONS) { - assert client.getMetricStatisticsInRegion(region, "CPUUtilization", cal.getTime(), new Date(), 60, "Average") != null; - } + assert client.getMetricStatisticsInRegion(region, "CPUUtilization", cal.getTime(), new Date(), 60, "Average") != null; } @AfterTest diff --git a/sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/xml/GetMetricStatisticsResponseHandlerTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/xml/GetMetricStatisticsResponseHandlerTest.java similarity index 100% rename from sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/xml/GetMetricStatisticsResponseHandlerTest.java rename to apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/xml/GetMetricStatisticsResponseHandlerTest.java diff --git a/sandbox-apis/cloudwatch/src/test/resources/get_metric_statistics.xml b/apis/cloudwatch/src/test/resources/get_metric_statistics.xml similarity index 100% rename from sandbox-apis/cloudwatch/src/test/resources/get_metric_statistics.xml rename to apis/cloudwatch/src/test/resources/get_metric_statistics.xml diff --git a/sandbox-apis/cloudwatch/src/test/resources/log4j.xml b/apis/cloudwatch/src/test/resources/log4j.xml similarity index 100% rename from sandbox-apis/cloudwatch/src/test/resources/log4j.xml rename to apis/cloudwatch/src/test/resources/log4j.xml diff --git a/apis/pom.xml b/apis/pom.xml index ab9e16a797..8fbb299ae3 100644 --- a/apis/pom.xml +++ b/apis/pom.xml @@ -46,5 +46,6 @@ elasticstack atmos nova + cloudwatch diff --git a/core/src/main/java/org/jclouds/providers/ProviderMetadata.java b/core/src/main/java/org/jclouds/providers/ProviderMetadata.java index 98fde7499f..3fec3088bc 100644 --- a/core/src/main/java/org/jclouds/providers/ProviderMetadata.java +++ b/core/src/main/java/org/jclouds/providers/ProviderMetadata.java @@ -36,6 +36,7 @@ public interface ProviderMetadata { public static final String LOADBALANCER_TYPE = "loadbalancer"; public static final String TABLE_TYPE = "table"; public static final String QUEUE_TYPE = "queue"; + public static final String MONITOR_TYPE = "monitor"; /** * diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index bd4e1ab76a..23c8facee5 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -29,6 +29,9 @@ aws-elb.propertiesbuilder=org.jclouds.aws.elb.AWSELBPropertiesBuilder cloudwatch.contextbuilder=org.jclouds.cloudwatch.CloudWatchContextBuilder cloudwatch.propertiesbuilder=org.jclouds.cloudwatch.CloudWatchPropertiesBuilder +aws-cloudwatch.contextbuilder=org.jclouds.cloudwatch.CloudWatchContextBuilder +aws-cloudwatch.propertiesbuilder=org.jclouds.aws.cloudwatch.AWSCloudWatchPropertiesBuilder + aws-s3.contextbuilder=org.jclouds.aws.s3.AWSS3ContextBuilder aws-s3.propertiesbuilder=org.jclouds.aws.s3.AWSS3PropertiesBuilder diff --git a/providers/aws-cloudwatch/pom.xml b/providers/aws-cloudwatch/pom.xml new file mode 100644 index 0000000000..474d1c49ef --- /dev/null +++ b/providers/aws-cloudwatch/pom.xml @@ -0,0 +1,151 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.2.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.provider + aws-cloudwatch + jclouds Amazon Elastic Load Balancer provider + Elastic Load Balancer implementation targeted to Amazon Web Services + bundle + + + https://monitoring.us-east-1.amazonaws.com + 2009-05-15 + ${test.aws.identity} + ${test.aws.credential} + + + + + org.jclouds.api + cloudwatch + ${project.version} + jar + + + org.jclouds.api + cloudwatch + ${project.version} + test-jar + test + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-log4j + ${project.version} + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + + test.aws-cloudwatch.endpoint + ${test.aws-cloudwatch.endpoint} + + + test.aws-cloudwatch.apiversion + ${test.aws-cloudwatch.apiversion} + + + test.aws-cloudwatch.identity + ${test.aws-cloudwatch.identity} + + + test.aws-cloudwatch.credential + ${test.aws-cloudwatch.credential} + + + test.aws-cloudwatch.compute.provider + ${test.aws-cloudwatch.compute.provider} + + + test.aws-cloudwatch.compute.endpoint + ${test.aws-cloudwatch.compute.endpoint} + + + test.aws-cloudwatch.compute.apiversion + ${test.aws-cloudwatch.compute.apiversion} + + + test.aws-cloudwatch.compute.identity + ${test.aws-cloudwatch.compute.identity} + + + test.aws-cloudwatch.compute.credential + ${test.aws-cloudwatch.compute.credential} + + + + + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + org.jclouds.aws.cloudwatch.*;version="${project.version}" + org.jclouds.*;version="${project.version}",* + + + + + + + diff --git a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java b/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchPropertiesBuilder.java similarity index 86% rename from sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java rename to providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchPropertiesBuilder.java index 179f089668..ee801adf12 100644 --- a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java +++ b/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchPropertiesBuilder.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.cloudwatch; +package org.jclouds.aws.cloudwatch; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; @@ -26,15 +26,16 @@ import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; import java.util.Properties; -import org.jclouds.PropertiesBuilder; import org.jclouds.aws.domain.Region; +import org.jclouds.cloudwatch.CloudWatchAsyncClient; +import org.jclouds.cloudwatch.CloudWatchPropertiesBuilder; /** - * Builds properties used in Cloud Watch Clients + * Builds properties used in CloudWatch Clients * * @author Adrian Cole */ -public class CloudWatchPropertiesBuilder extends PropertiesBuilder { +public class AWSCloudWatchPropertiesBuilder extends CloudWatchPropertiesBuilder { @Override protected Properties defaultProperties() { @@ -57,11 +58,11 @@ public class CloudWatchPropertiesBuilder extends PropertiesBuilder { return properties; } - public CloudWatchPropertiesBuilder() { + public AWSCloudWatchPropertiesBuilder() { super(); } - public CloudWatchPropertiesBuilder(Properties properties) { + public AWSCloudWatchPropertiesBuilder(Properties properties) { super(properties); } diff --git a/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderMetadata.java b/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderMetadata.java new file mode 100644 index 0000000000..dac2845e30 --- /dev/null +++ b/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderMetadata.java @@ -0,0 +1,115 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.aws.cloudwatch; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.providers.ProviderMetadata; + +import com.google.common.collect.ImmutableSet; + +/** + * Implementation of @ link org.jclouds.types.ProviderMetadata} for Amazon's CloudWatch + * provider. + * + * @author Adrian Cole + */ +public class AWSCloudWatchProviderMetadata extends BaseProviderMetadata { + + /** + * {@inheritDoc} + */ + @Override + public String getId() { + return "aws-cloudwatch"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getType() { + return ProviderMetadata.MONITOR_TYPE; + } + + /** + * {@inheritDoc} + */ + @Override + public String getName() { + return "Amazon CloudWatch"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getIdentityName() { + return "Access Key ID"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getCredentialName() { + return "Secret Access Key"; + } + + /** + * {@inheritDoc} + */ + @Override + public URI getHomepage() { + return URI.create("http://aws.amazon.com/cloudwatch"); + } + + /** + * {@inheritDoc} + */ + @Override + public URI getConsole() { + return URI.create("https://console.aws.amazon.com/cloudwatch/home"); + } + /** + * {@inheritDoc} + */ + @Override + public URI getApiDocumentation() { + return URI.create("http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/"); + } + + /** + * {@inheritDoc} + */ + @Override + public Set getLinkedServices() { + return ImmutableSet.of("aws-s3", "aws-ec2", "aws-cloudwatch", "aws-simpledb"); + } + + /** + * {@inheritDoc} + */ + @Override + public Set getIso3166Codes() { + return ImmutableSet.of("US-VA", "US-CA", "IE", "SG", "JP-13"); + } +} diff --git a/providers/aws-cloudwatch/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/providers/aws-cloudwatch/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..553504a806 --- /dev/null +++ b/providers/aws-cloudwatch/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.aws.cloudwatch.AWSCloudWatchProviderMetadata diff --git a/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchClientLiveTest.java b/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchClientLiveTest.java new file mode 100644 index 0000000000..e494ad5403 --- /dev/null +++ b/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchClientLiveTest.java @@ -0,0 +1,42 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.aws.cloudwatch; + +import org.jclouds.aws.domain.Region; +import org.jclouds.cloudwatch.CloudWatchClientLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code CloudWatchClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "AWSCloudWatchClientLiveTest") +public class AWSCloudWatchClientLiveTest extends CloudWatchClientLiveTest { + public AWSCloudWatchClientLiveTest() { + provider = "aws-cloudwatch"; + } + + @Test + public void testGetMetricStatisticsInRegion() { + for (String region : Region.DEFAULT_REGIONS) { + getMetricStatisticsInRegion(region); + } + } +} diff --git a/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderTest.java b/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderTest.java new file mode 100644 index 0000000000..83fb1f3883 --- /dev/null +++ b/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderTest.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.aws.cloudwatch; + +import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.ProviderMetadata; +import org.testng.annotations.Test; + +/** + * The AWSCloudWatchProviderTest tests the org.jclouds.providers.AWSCloudWatchProvider class. + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "AWSCloudWatchProviderTest") +public class AWSCloudWatchProviderTest extends BaseProviderMetadataTest { + + public AWSCloudWatchProviderTest() { + super(new AWSCloudWatchProviderMetadata(), ProviderMetadata.MONITOR_TYPE); + } +} diff --git a/providers/aws-ec2/pom.xml b/providers/aws-ec2/pom.xml index 635f3d82f9..f3cf5d6165 100644 --- a/providers/aws-ec2/pom.xml +++ b/providers/aws-ec2/pom.xml @@ -58,6 +58,12 @@ test-jar test + + org.jclouds.provider + aws-cloudwatch + ${project.version} + test + org.jclouds jclouds-core diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java index c716920316..b1867a2ae2 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java @@ -20,12 +20,16 @@ package org.jclouds.aws.ec2.compute; import static org.testng.Assert.assertEquals; +import java.util.Date; import java.util.Set; import org.jclouds.aws.ec2.AWSEC2Client; import org.jclouds.aws.ec2.domain.AWSRunningInstance; import org.jclouds.aws.ec2.domain.MonitoringState; import org.jclouds.aws.ec2.services.AWSSecurityGroupClient; +import org.jclouds.cloudwatch.CloudWatchAsyncClient; +import org.jclouds.cloudwatch.CloudWatchClient; +import org.jclouds.cloudwatch.domain.Datapoint; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.predicates.NodePredicates; @@ -38,12 +42,17 @@ import org.jclouds.ec2.domain.SecurityGroup; import org.jclouds.ec2.services.InstanceClient; import org.jclouds.ec2.services.KeyPairClient; import org.jclouds.ec2.util.IpPermissions; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextFactory; import org.jclouds.scriptbuilder.domain.Statements; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; +import com.google.inject.Module; /** * @@ -73,7 +82,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { TemplateOptions options = client.templateOptions(); - // Date before = new Date(); + Date before = new Date(); options.as(AWSEC2TemplateOptions.class).enableMonitoring(); options.as(AWSEC2TemplateOptions.class).spotPrice(0.3f); @@ -114,20 +123,17 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { assertEquals(instance.getKeyName(), group); assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED); - // TODO when the cloudwatchclient is finished - // RestContext monitoringContext = new - // RestContextFactory().createContext( - // "cloudwatch", identity, credential, ImmutableSet. of(new Log4JLoggingModule())); - // - // try { - // Set datapoints = - // monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(), - // "CPUUtilization", before, new Date(), 60, "Average"); - // assert datapoints != null; - // } finally { - // monitoringContext.close(); - // } + RestContext monitoringContext = new RestContextFactory() + .createContext("aws-cloudwatch", identity, credential, ImmutableSet. of(new Log4JLoggingModule())); + + try { + Set datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(), + "CPUUtilization", before, new Date(), 60, "Average"); + assert datapoints != null; + } finally { + monitoringContext.close(); + } // make sure we made our dummy group and also let in the user's group assertEquals(Sets.newTreeSet(instance.getGroupIds()), ImmutableSortedSet. of("jclouds#" + group + "#" diff --git a/providers/pom.xml b/providers/pom.xml index 782fefd730..6515b61fd2 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -62,5 +62,6 @@ skalicloud-sdg-my savvis-symphonyvpdc greenhousedata-element-vcloud + aws-cloudwatch diff --git a/sandbox-providers/softlayer/pom.xml b/sandbox-providers/softlayer/pom.xml index c204951150..5327ed1298 100644 --- a/sandbox-providers/softlayer/pom.xml +++ b/sandbox-providers/softlayer/pom.xml @@ -56,7 +56,7 @@ org.jclouds - jclouds-core + jclouds-compute ${project.version} @@ -67,9 +67,10 @@ test - log4j - log4j - 1.2.16 + org.jclouds + jclouds-compute + ${project.version} + test-jar test @@ -78,6 +79,12 @@ ${project.version} test + + org.jclouds.driver + jclouds-sshj + ${project.version} + test + diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java index 23f8777f4f..f2b2aaa19f 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java @@ -21,7 +21,8 @@ package org.jclouds.softlayer; import java.util.List; import java.util.Properties; -import org.jclouds.rest.RestContextBuilder; +import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.softlayer.compute.config.SoftLayerComputeServiceContextModule; import org.jclouds.softlayer.config.SoftLayerRestClientModule; import com.google.inject.Module; @@ -30,13 +31,18 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class SoftLayerContextBuilder extends - RestContextBuilder { +public class SoftLayerContextBuilder extends ComputeServiceContextBuilder { public SoftLayerContextBuilder(Properties props) { super(SoftLayerClient.class, SoftLayerAsyncClient.class, props); } + @Override + protected void addContextModule(List modules) { + modules.add(new SoftLayerComputeServiceContextModule()); + } + + @Override protected void addClientModule(List modules) { modules.add(new SoftLayerRestClientModule()); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java index a7c43c428d..b0fd78214b 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java @@ -24,6 +24,7 @@ import static org.jclouds.Constants.PROPERTY_ENDPOINT; import java.util.Properties; import org.jclouds.PropertiesBuilder; +import org.jclouds.softlayer.reference.SoftLayerConstants; /** * Builds properties used in SoftLayer Clients @@ -36,6 +37,7 @@ public class SoftLayerPropertiesBuilder extends PropertiesBuilder { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_ENDPOINT, "https://api.softlayer.com/rest"); properties.setProperty(PROPERTY_API_VERSION, "3"); + properties.setProperty(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME, "Cloud Server"); return properties; } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java new file mode 100644 index 0000000000..575f21a67d --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.softlayer.compute.config; + +import java.util.Set; + +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.domain.Location; +import org.jclouds.location.suppliers.OnlyLocationOrFirstZone; +import org.jclouds.softlayer.SoftLayerAsyncClient; +import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.compute.functions.DatacenterToLocation; +import org.jclouds.softlayer.compute.functions.ProductItemPriceToImage; +import org.jclouds.softlayer.compute.functions.ProductItemPricesToHardware; +import org.jclouds.softlayer.compute.functions.VirtualGuestToNodeMetadata; +import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.ProductItemPrice; +import org.jclouds.softlayer.domain.VirtualGuest; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +public class SoftLayerComputeServiceContextModule extends + ComputeServiceAdapterContextModule, ProductItemPrice, Datacenter> { + + public SoftLayerComputeServiceContextModule() { + super(SoftLayerClient.class, SoftLayerAsyncClient.class); + } + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral, ProductItemPrice, Datacenter>>() { + }).to(SoftLayerComputeServiceAdapter.class); + bind(new TypeLiteral>() { + }).to(VirtualGuestToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to(ProductItemPriceToImage.class); + bind(new TypeLiteral, org.jclouds.compute.domain.Hardware>>() { + }).to(ProductItemPricesToHardware.class); + bind(new TypeLiteral>() { + }).to(DatacenterToLocation.class); + bind(new TypeLiteral>() { + }).to(OnlyLocationOrFirstZone.class); + } +} \ No newline at end of file diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/functions/AccountToLocation.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/DatacenterToLocation.java similarity index 55% rename from sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/functions/AccountToLocation.java rename to sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/DatacenterToLocation.java index a900da9250..f36d1ba039 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/functions/AccountToLocation.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/DatacenterToLocation.java @@ -16,35 +16,49 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.softlayer.functions; +package org.jclouds.softlayer.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.location.suppliers.JustProvider; +import org.jclouds.softlayer.domain.Address; +import org.jclouds.softlayer.domain.Datacenter; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationBuilder; -import org.jclouds.domain.LocationScope; -import org.jclouds.softlayer.domain.Address; - -import javax.annotation.Nullable; /** - * Converts an Address into a Location. + * Converts an Datacenter into a Location. */ -public class AccountToLocation implements Function { +public class DatacenterToLocation implements Function { + private final JustProvider provider; + // allow us to lazy discover the provider of a resource + @Inject + public DatacenterToLocation(JustProvider provider) { + this.provider = checkNotNull(provider, "provider"); + } + @Override - public Location apply(Address address) { + public Location apply(Datacenter datacenter) { return new LocationBuilder().scope(LocationScope.ZONE) .metadata(ImmutableMap.of()) - .description(address.getDescription()) - .id(Long.toString(address.getId())) - .iso3166Codes(createIso3166Codes(address)) + .description(datacenter.getLongName()) + .id(Long.toString(datacenter.getId())) + .iso3166Codes(createIso3166Codes(datacenter.getLocationAddress())) + .parent(Iterables.getOnlyElement(provider.get())) .build(); - } + } - private Iterable createIso3166Codes(Address address) { - return ImmutableSet.of(""+address.getCountry()+"-"+address.getState()); - } + private Iterable createIso3166Codes(Address address) { + return address != null ? ImmutableSet. of("" + address.getCountry() + "-" + address.getState()) + : ImmutableSet. of(); + } } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPriceToImage.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPriceToImage.java new file mode 100644 index 0000000000..7bf56a6bae --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPriceToImage.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.softlayer.compute.functions; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.softlayer.domain.ProductItemPrice; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class ProductItemPriceToImage implements Function { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + @Override + public Image apply(ProductItemPrice from) { + + ImageBuilder builder = new ImageBuilder(); + //TODO +// builder.ids(from.id + ""); +// builder.name(from.name); +// builder.description(from.name); +// +// OsFamily family = null; +// try { +// family = OsFamily.fromValue(from.name); +// builder.operatingSystem(new OperatingSystem.Builder().name(from.name).family(family).build()); +// } catch (IllegalArgumentException e) { +// logger.debug("<< didn't match os(%s)", from); +// } + return builder.build(); + } + +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPricesToHardware.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPricesToHardware.java new file mode 100644 index 0000000000..2b8ba0b0ed --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPricesToHardware.java @@ -0,0 +1,48 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.softlayer.compute.functions; + +import java.util.Set; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.softlayer.domain.ProductItemPrice; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class ProductItemPricesToHardware implements Function, Hardware> { + + @Override + public Hardware apply(Set from) { + HardwareBuilder builder = new HardwareBuilder(); +// builder.ids(from.id + ""); +// builder.name(from.name); +// builder.processors(ImmutableList.of(new Processor(from.cores, 1.0))); +// builder.ram(from.ram); +// builder.volumes(ImmutableList. of(new VolumeImpl(from.disk, true, false))); + return builder.build(); + } + +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java new file mode 100644 index 0000000000..95e4d8fa79 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java @@ -0,0 +1,139 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.softlayer.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.FindResourceInSet; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.softlayer.domain.VirtualGuest; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Singleton +public class VirtualGuestToNodeMetadata implements Function { + + public static final Map serverStateToNodeState = ImmutableMap + . builder().put(VirtualGuest.State.RUNNING, NodeState.RUNNING)// + .put(VirtualGuest.State.STARTING, NodeState.PENDING)// + .put(VirtualGuest.State.DESTROYED, NodeState.TERMINATED)// + // TODO other states + .put(VirtualGuest.State.UNRECOGNIZED, NodeState.UNRECOGNIZED)// + .build(); + + private final FindHardwareForVirtualGuest findHardwareForVirtualGuest; + private final FindLocationForVirtualGuest findLocationForVirtualGuest; + private final FindImageForVirtualGuest findImageForVirtualGuest; + private final Map credentialStore; + + @Inject + VirtualGuestToNodeMetadata(Map credentialStore, FindHardwareForVirtualGuest findHardwareForVirtualGuest, + FindLocationForVirtualGuest findLocationForVirtualGuest, FindImageForVirtualGuest findImageForVirtualGuest) { + this.credentialStore = checkNotNull(credentialStore, "credentialStore"); + this.findHardwareForVirtualGuest = checkNotNull(findHardwareForVirtualGuest, "findHardwareForVirtualGuest"); + this.findLocationForVirtualGuest = checkNotNull(findLocationForVirtualGuest, "findLocationForVirtualGuest"); + this.findImageForVirtualGuest = checkNotNull(findImageForVirtualGuest, "findImageForVirtualGuest"); + } + + @Override + public NodeMetadata apply(VirtualGuest from) { + // convert the result object to a jclouds NodeMetadata + NodeMetadataBuilder builder = new NodeMetadataBuilder(); + builder.ids(from.getId() + ""); + builder.name(from.getNotes()); + builder.location(findLocationForVirtualGuest.apply(from)); + builder.group(parseGroupFromName(from.getNotes())); + //TODO determine image id (product price)from virtual guest +// builder.imageId(from.imageId + ""); + Image image = findImageForVirtualGuest.apply(from); + if (image != null) + builder.operatingSystem(image.getOperatingSystem()); + builder.hardware(findHardwareForVirtualGuest.apply(from)); + // TODO get state +// builder.state(serverStateToNodeState.get(from.getState())); + builder.publicAddresses(ImmutableSet. of(from.getPrimaryIpAddress())); + builder.privateAddresses(ImmutableSet. of(from.getPrimaryBackendIpAddress())); + builder.credentials(credentialStore.get("node#"+ from.getId())); + return builder.build(); + } + + @Singleton + public static class FindHardwareForVirtualGuest extends FindResourceInSet { + + @Inject + public FindHardwareForVirtualGuest(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(VirtualGuest from, Hardware input) { + return input.getProviderId().equals(from.getId() + ""); + } + } + + @Singleton + public static class FindImageForVirtualGuest extends FindResourceInSet { + + @Inject + public FindImageForVirtualGuest(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(VirtualGuest from, Image input) { + // TODO determine the price list from the virtual guest which would have the image in it. + return false; + } + } + + @Singleton + public static class FindLocationForVirtualGuest extends FindResourceInSet { + + @Inject + public FindLocationForVirtualGuest(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(VirtualGuest from, Location input) { + // TODO determine the price list from the virtual guest which would have the image in it. + return false; + } + } +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java new file mode 100644 index 0000000000..db1bc6f349 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java @@ -0,0 +1,129 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.softlayer.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.Template; +import org.jclouds.domain.Credentials; +import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.ProductItemPrice; +import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.predicates.ProductPackagePredicates; +import org.jclouds.softlayer.reference.SoftLayerConstants; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +/** + * defines the connection between the {@link SoftLayerClient} implementation and the jclouds + * {@link ComputeService} + * + */ +@Singleton +public class SoftLayerComputeServiceAdapter implements + ComputeServiceAdapter, ProductItemPrice, Datacenter> { + private final SoftLayerClient client; + private final String virtualGuestPackageName; + + @Inject + public SoftLayerComputeServiceAdapter(SoftLayerClient client, + @Named(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) String virtualGuestPackageName) { + this.client = checkNotNull(client, "client"); + this.virtualGuestPackageName = checkNotNull(virtualGuestPackageName, "virtualGuestPackageName"); + } + + @Override + public VirtualGuest createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, + Template template, Map credentialStore) { + VirtualGuest from = null; // TODO create the backend object using parameters from the + // template. ex. + // VirtualGuest from = + // client.getVirtualGuestClient().createServerInDC(template.getLocation().getId(), name, + // Long.parseLong(template.getImage().getProviderId()), + // Long.parseLong(template.getHardware().getProviderId())); + // store the credentials so that later functions can use them + // credentialStore.put("node#"+ from.getId() + "", new Credentials(from.loginUser, + // from.password)); + return from; + } + + @Override + public Iterable> listHardwareProfiles() { + // TODO: get the set of product item prices corresponding to the hardware profiles + return ImmutableSet.of(); + } + + @Override + public Iterable listImages() { + // TODO: get the list of product item prices corresponding to images + return ImmutableSet.of(); + } + + @Override + public Iterable listNodes() { + return client.getVirtualGuestClient().listVirtualGuests(); + } + + @Override + public Iterable listLocations() { + // TODO we should be able to specify a filter that gets the datacenters here. + ProductPackage virtualGuestPackage = Iterables.find(client.getAccountClient().getActivePackages(), + ProductPackagePredicates.named(virtualGuestPackageName)); + return client.getProductPackageClient().getProductPackage(virtualGuestPackage.getId()).getDatacenters(); + } + + @Override + public VirtualGuest getNode(String id) { + long serverId = Long.parseLong(id); + return client.getVirtualGuestClient().getVirtualGuest(serverId); + } + + @Override + public void destroyNode(String id) { + // TODO + // client.getVirtualGuestClient().destroyVirtualGuest(Long.parseLong(id)); + } + + @Override + public void rebootNode(String id) { + client.getVirtualGuestClient().rebootHardVirtualGuest(Long.parseLong(id)); + } + + @Override + public void resumeNode(String id) { + client.getVirtualGuestClient().resumeVirtualGuest(Long.parseLong(id)); + } + + @Override + public void suspendNode(String id) { + client.getVirtualGuestClient().pauseVirtualGuest(Long.parseLong(id)); + } +} \ No newline at end of file diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItem.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItem.java index ea5e283571..ad1d3a6164 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItem.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItem.java @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Set; -import javax.annotation.Nullable; +import org.jclouds.javax.annotation.Nullable; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java index a3b88c8f6a..b23ea6c152 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java @@ -18,7 +18,7 @@ */ package org.jclouds.softlayer.domain; -import javax.annotation.Nullable; +import org.jclouds.javax.annotation.Nullable; /** * The SoftLayer_Product_Item_Price data type contains general information diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductPackagePredicates.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductPackagePredicates.java index 5f3447d462..67481f3154 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductPackagePredicates.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductPackagePredicates.java @@ -18,33 +18,18 @@ */ package org.jclouds.softlayer.predicates; -import com.google.common.base.Predicate; import org.jclouds.softlayer.domain.ProductPackage; -import org.jclouds.softlayer.features.AccountClient; -import java.util.NoSuchElementException; +import com.google.common.base.Predicate; public class ProductPackagePredicates { - /** - * Attempts to obtain the packageId for the supplied packageName. - * @param accountClient @see AccountClient - * @param packageName The name field of the @see ProductPackage to find - * @return The id of the package or null if no match found - */ - public static Long getProductPackageId(AccountClient accountClient,String packageName) { - for (ProductPackage productPackage : accountClient.getActivePackages()) { - if (named(packageName).apply(productPackage)) return productPackage.getId(); - } - throw new NoSuchElementException("ProductPackage:"+packageName+" not found"); - } - /** * Tests if the product package name equals the packageName * @param packageName * @return true if the name is equal, otherwise false. */ - public static Predicate named(final String packageName) { + public static Predicate named(final String packageName) { return new Predicate() { public boolean apply(ProductPackage productPackage) { return productPackage.getName().equals(packageName); diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java new file mode 100644 index 0000000000..8640e596a4 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java @@ -0,0 +1,32 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.softlayer.reference; + +/** + * Configuration properties and constants used in SoftLayer connections. + * + * @author Adrian Cole + */ +public interface SoftLayerConstants { + /** + * Name of the product package corresponding to cloud servers + */ + public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME = "jclouds.softlayer.virtualguest.package-name"; + +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java new file mode 100644 index 0000000000..6319a8a3d0 --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.softlayer.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "SoftLayerExperimentLiveTest") +public class SoftLayerExperimentLiveTest { + protected String provider = "softlayer"; + protected String identity; + protected String credential; + protected String endpoint; + protected String apiversion; + + @BeforeClass + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); + } + + @Test + public void testAndExperiment() { + ComputeServiceContext context = null; + try { + String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity"); + String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential"); + + context = new ComputeServiceContextFactory().createContext("softlayer", identity, credential, ImmutableSet + . of(new Log4JLoggingModule(), new SshjSshClientModule())); + + assertEquals(context.getComputeService().listAssignableLocations().size(), 5); + + } finally { + if (context != null) + context.close(); + } + } + +} \ No newline at end of file diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/functions/AddressToLocationTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java similarity index 64% rename from sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/functions/AddressToLocationTest.java rename to sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java index 93a48c8bc0..9de3ce59ec 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/functions/AddressToLocationTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java @@ -16,56 +16,58 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.softlayer.functions; - -import org.jclouds.domain.Location; -import org.jclouds.softlayer.domain.Address; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.Set; +package org.jclouds.softlayer.compute.functions; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; +import java.net.URI; +import java.util.Set; + +import org.jclouds.domain.Location; +import org.jclouds.location.suppliers.JustProvider; +import org.jclouds.softlayer.domain.Address; +import org.jclouds.softlayer.domain.Datacenter; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + /** - * Tests {@code AddressToLocation} - * + * Tests {@code DatacenterToLocation} + * * @author Jason King */ -@Test(sequential = true,groups = "unit") -public class AddressToLocationTest { +@Test(singleThreaded = true, groups = "unit") +public class DatacenterToLocationTest { - private AccountToLocation function; + private DatacenterToLocation function; @BeforeMethod public void setup() { - function = new AccountToLocation(); + function = new DatacenterToLocation(new JustProvider(ImmutableSet.of(), "softlayer", URI.create("foo"))); } @Test - public void testAddressToLocation() { - Address address = Address.builder().id(1) - .country("US") - .state("TX") - .description("This is Texas!").build(); + public void testDatacenterToLocation() { + Datacenter address = Datacenter.builder().id(1).longName("This is Texas!").locationAddress( + Address.builder().country("US").state("TX").description("This is Texas!").build()).build(); + Location location = function.apply(address); assertEquals(location.getId(), Long.toString(address.getId())); Set iso3166Codes = location.getIso3166Codes(); - assertEquals(iso3166Codes.size(),1); + assertEquals(iso3166Codes.size(), 1); assertTrue(iso3166Codes.contains("US-TX")); } @Test public void testGetIso3166CodeNoCountryAndState() { - Address address = Address.builder().id(1) - .description("Nowhere").build(); + Datacenter address = Datacenter.builder().id(1).longName("Nowhere").build(); Location location = function.apply(address); assertEquals(location.getId(), Long.toString(address.getId())); Set iso3166Codes = location.getIso3166Codes(); - assertEquals(iso3166Codes.size(),1); - assertTrue(iso3166Codes.contains("null-null")); + assertEquals(iso3166Codes.size(), 0); } } diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java index 898daf0551..b1705f53c0 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java @@ -20,15 +20,11 @@ package org.jclouds.softlayer.features; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Properties; - +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.softlayer.SoftLayerAsyncClient; import org.jclouds.softlayer.SoftLayerClient; -import org.jclouds.softlayer.SoftLayerContextBuilder; -import org.jclouds.softlayer.SoftLayerPropertiesBuilder; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -51,12 +47,9 @@ public class BaseSoftLayerClientLiveTest { String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity"); String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential"); - Properties restProperties = new Properties(); - restProperties.setProperty("softlayer.contextbuilder", SoftLayerContextBuilder.class.getName()); - restProperties.setProperty("softlayer.propertiesbuilder", SoftLayerPropertiesBuilder.class.getName()); - context = new RestContextFactory(restProperties).createContext("softlayer", identity, credential, - ImmutableSet. of(new Log4JLoggingModule())); + context = new ComputeServiceContextFactory().createContext("softlayer", identity, credential, + ImmutableSet. of(new Log4JLoggingModule())).getProviderSpecificContext(); } diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java index 671563add0..4833a1f5d8 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java @@ -19,6 +19,8 @@ package org.jclouds.softlayer.features; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + import org.jclouds.softlayer.domain.*; import org.jclouds.softlayer.predicates.ProductPackagePredicates; import org.testng.annotations.BeforeGroups; @@ -83,8 +85,10 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest { Set expected = builder.build(); - Long productPackageId = ProductPackagePredicates.getProductPackageId(accountClient, CLOUD_SERVER_PACKAGE_NAME); - assertNotNull(productPackageId); + // note we don't need to check null, as this will throw NoSuchElementException if + // a product package named as below isn't found. + long productPackageId = Iterables.find(accountClient.getActivePackages(), + ProductPackagePredicates.named(CLOUD_SERVER_PACKAGE_NAME)).getId(); ProductPackage productPackage = client.getProductPackage(productPackageId); Set datacenters = productPackage.getDatacenters();