Issue 550: updated aws provider metadata

This commit is contained in:
Adrian Cole 2011-05-17 00:01:52 -07:00
parent c880c057b1
commit f70b793533
10 changed files with 318 additions and 46 deletions

View File

@ -26,15 +26,14 @@ import java.util.ServiceLoader;
/** /**
* The Providers class provides static methods for accessing providers. * The Providers class provides static methods for accessing providers.
* *
* @author Jeremy Whitlock <jwhitlock@apache.org> * @author Jeremy Whitlock <jwhitlock@apache.org>
*/ */
public class Providers { public class Providers {
/** /**
* Returns the providers located on the classpath via * Returns the providers located on the classpath via {@link java.util.ServiceLoader}.
* {@link java.util.ServiceLoader}. *
*
* @return all available providers loaded from classpath via ServiceLoader * @return all available providers loaded from classpath via ServiceLoader
*/ */
private static Iterable<ProviderMetadata> fromServiceLoader() { private static Iterable<ProviderMetadata> fromServiceLoader() {
@ -43,7 +42,7 @@ public class Providers {
/** /**
* Returns all available providers. * Returns all available providers.
* *
* @return all available providers * @return all available providers
*/ */
public static Iterable<ProviderMetadata> all() { public static Iterable<ProviderMetadata> all() {
@ -52,24 +51,23 @@ public class Providers {
/** /**
* Returns the first provider with the provided id * Returns the first provider with the provided id
* *
* @param id * @param id
* the id of the provider to return * the id of the provider to return
* *
* @return the provider with the given id * @return the provider with the given id
* *
* @throws NoSuchElementException * @throws NoSuchElementException
* whenever there are no providers with the provided id * whenever there are no providers with the provided id
*/ */
public static ProviderMetadata withId(String id) public static ProviderMetadata withId(String id) throws NoSuchElementException {
throws NoSuchElementException {
return find(all(), ProviderPredicates.id(id)); return find(all(), ProviderPredicates.id(id));
} }
/** /**
* Returns the providers that are of type * Returns the providers that are of type
* {@link org.jclouds.providers.ProviderMetadata#BLOBSTORE_TYPE}. * {@link org.jclouds.providers.ProviderMetadata#BLOBSTORE_TYPE}.
* *
* @return the blobstore providers * @return the blobstore providers
*/ */
public static Iterable<ProviderMetadata> allBlobStore() { public static Iterable<ProviderMetadata> allBlobStore() {
@ -79,19 +77,49 @@ public class Providers {
/** /**
* Returns the providers that are of type * Returns the providers that are of type
* {@link org.jclouds.providers.ProviderMetadata#COMPUTE_TYPE}. * {@link org.jclouds.providers.ProviderMetadata#COMPUTE_TYPE}.
* *
* @return the compute service providers * @return the compute service providers
*/ */
public static Iterable<ProviderMetadata> allCompute() { public static Iterable<ProviderMetadata> allCompute() {
return filter(all(), ProviderPredicates.type(ProviderMetadata.COMPUTE_TYPE)); return filter(all(), ProviderPredicates.type(ProviderMetadata.COMPUTE_TYPE));
} }
/**
* Returns the providers that are of type
* {@link org.jclouds.providers.ProviderMetadata#QUEUE_TYPE}.
*
* @return the queue service providers
*/
public static Iterable<ProviderMetadata> allQueue() {
return filter(all(), ProviderPredicates.type(ProviderMetadata.QUEUE_TYPE));
}
/**
* Returns the providers that are of type
* {@link org.jclouds.providers.ProviderMetadata#TABLE_TYPE}.
*
* @return the table service providers
*/
public static Iterable<ProviderMetadata> allTable() {
return filter(all(), ProviderPredicates.type(ProviderMetadata.TABLE_TYPE));
}
/**
* Returns the providers that are of type
* {@link org.jclouds.providers.ProviderMetadata#LOADBALANCER_TYPE}.
*
* @return the load balancer service providers
*/
public static Iterable<ProviderMetadata> allLoadBalancer() {
return filter(all(), ProviderPredicates.type(ProviderMetadata.LOADBALANCER_TYPE));
}
/** /**
* Returns the providers that are of the provided type. * Returns the providers that are of the provided type.
* *
* @param type * @param type
* the type to providers to return * the type to providers to return
* *
* @return the providers of the provided type * @return the providers of the provided type
*/ */
public static Iterable<ProviderMetadata> ofType(String type) { public static Iterable<ProviderMetadata> ofType(String type) {

View File

@ -26,7 +26,6 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/** /**
* *
@ -36,6 +35,7 @@ import com.google.common.collect.Sets;
public abstract class BaseProviderMetadataTest { public abstract class BaseProviderMetadataTest {
protected Set<String> allTypes = ImmutableSet.of(ProviderMetadata.BLOBSTORE_TYPE, ProviderMetadata.COMPUTE_TYPE, protected Set<String> allTypes = ImmutableSet.of(ProviderMetadata.BLOBSTORE_TYPE, ProviderMetadata.COMPUTE_TYPE,
ProviderMetadata.LOADBALANCER_TYPE, ProviderMetadata.QUEUE_TYPE, ProviderMetadata.TABLE_TYPE); ProviderMetadata.LOADBALANCER_TYPE, ProviderMetadata.QUEUE_TYPE, ProviderMetadata.TABLE_TYPE);
private final ProviderMetadata toTest; private final ProviderMetadata toTest;
private final String expectedType; private final String expectedType;
@ -52,21 +52,15 @@ public abstract class BaseProviderMetadataTest {
assert providerMetadata.getLinkedServices().contains(toTest.getId()); assert providerMetadata.getLinkedServices().contains(toTest.getId());
} }
// it is ok to have multiple services in the same classpath (ex. ec2 vs elb)
@Test @Test
public void testOfType() { public void testOfTypeContains() {
assertEquals(Iterables.getOnlyElement(Providers.ofType(expectedType)), toTest); assert ImmutableSet.of(Providers.ofType(expectedType)).contains(toTest);
for (String type : Sets.difference(allTypes, ImmutableSet.of(expectedType)))
assertEquals(Iterables.size(Providers.ofType(type)), 0);
} }
@Test @Test
public void testAll() { public void testAllContains() {
Iterable<ProviderMetadata> providersMetadata = Providers.all(); assert ImmutableSet.of(Providers.all()).contains(toTest);
for (ProviderMetadata providerMetadata : providersMetadata) {
assertEquals(toTest, providerMetadata);
}
} }
@Test @Test

View File

@ -63,7 +63,7 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata {
*/ */
@Override @Override
public String getIdentityName() { public String getIdentityName() {
return "accessKeyID"; return "Access Key ID";
} }
/** /**
@ -71,7 +71,7 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata {
*/ */
@Override @Override
public String getCredentialName() { public String getCredentialName() {
return "secretAccessKey"; return "Secret Access Key";
} }
/** /**
@ -102,7 +102,7 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata {
*/ */
@Override @Override
public Set<String> getLinkedServices() { public Set<String> getLinkedServices() {
return ImmutableSet.of(getId(), "aws-s3"); return ImmutableSet.of("aws-s3", "aws-ec2", "aws-elb", "aws-simpledb");
} }
} }

View File

@ -55,7 +55,7 @@ public class AWSS3ProviderMetadata extends BaseProviderMetadata {
*/ */
@Override @Override
public String getName() { public String getName() {
return "Amazon Elastic Compute Cloud (S3)"; return "Amazon Simple Storage Service (S3)";
} }
/** /**
@ -63,7 +63,7 @@ public class AWSS3ProviderMetadata extends BaseProviderMetadata {
*/ */
@Override @Override
public String getIdentityName() { public String getIdentityName() {
return "accessKeyID"; return "Access Key ID";
} }
/** /**
@ -71,7 +71,7 @@ public class AWSS3ProviderMetadata extends BaseProviderMetadata {
*/ */
@Override @Override
public String getCredentialName() { public String getCredentialName() {
return "secretAccessKey"; return "Secret Access Key";
} }
/** /**

View File

@ -0,0 +1,108 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.elb;
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 Elastic Load Balancing
* provider.
*
* @author Adrian Cole
*/
public class AWSELBProviderMetadata extends BaseProviderMetadata {
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return "aws-elb";
}
/**
* {@inheritDoc}
*/
@Override
public String getType() {
return ProviderMetadata.LOADBALANCER_TYPE;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return "Amazon Elastic Load Balancing";
}
/**
* {@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/elasticloadbalancing");
}
/**
* {@inheritDoc}
*/
@Override
public URI getConsole() {
return URI.create("https://console.aws.amazon.com/ec2/home");
}
/**
* {@inheritDoc}
*/
@Override
public URI getApiDocumentation() {
return URI.create("http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference");
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getLinkedServices() {
return ImmutableSet.of("aws-s3", "aws-ec2", "aws-elb", "aws-simpledb");
}
}

View File

@ -0,0 +1 @@
org.jclouds.aws.elb.AWSELBProviderMetadata

View File

@ -18,23 +18,19 @@
*/ */
package org.jclouds.aws.elb; package org.jclouds.aws.elb;
import org.jclouds.rest.Providers; import org.jclouds.providers.BaseProviderMetadataTest;
import org.jclouds.providers.ProviderMetadata;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/** /**
* The AWSELBProviderTest tests the org.jclouds.providers.AWSELBProvider class.
* *
* @author Adrian Cole * @author Adrian Cole
*
*/ */
@Test(groups = "unit") @Test(groups = "unit", testName = "AWSELBProviderTest")
public class ProvidersInPropertiesTest { public class AWSELBProviderTest extends BaseProviderMetadataTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Providers.getSupportedProviders();
assert Iterables.contains(providers, "aws-elb") : providers;
}
} public AWSELBProviderTest() {
super(new AWSELBProviderMetadata(), ProviderMetadata.LOADBALANCER_TYPE);
}
}

View File

@ -0,0 +1,108 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.simpledb;
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 SimpleDB provider.
*
* @author Adrian Cole
*/
public class AWSSimpleDBProviderMetadata extends BaseProviderMetadata {
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return "aws-simpledb";
}
/**
* {@inheritDoc}
*/
@Override
public String getType() {
return ProviderMetadata.TABLE_TYPE;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return "Amazon SimpleDB";
}
/**
* {@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/simpledb");
}
/**
* {@inheritDoc}
*/
@Override
public URI getConsole() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public URI getApiDocumentation() {
return URI.create("http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide");
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getLinkedServices() {
return ImmutableSet.of("aws-s3", "aws-ec2", "aws-elb", "aws-simpledb");
}
}

View File

@ -0,0 +1 @@
org.jclouds.aws.simpledb.AWSSimpleDBProviderMetadata

View File

@ -0,0 +1,36 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.simpledb;
import org.jclouds.providers.BaseProviderMetadataTest;
import org.jclouds.providers.ProviderMetadata;
import org.testng.annotations.Test;
/**
* The AWSSimpleDBProviderTest tests the org.jclouds.providers.AWSSimpleDBProvider class.
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "AWSSimpleDBProviderTest")
public class AWSSimpleDBProviderTest extends BaseProviderMetadataTest {
public AWSSimpleDBProviderTest() {
super(new AWSSimpleDBProviderMetadata(), ProviderMetadata.TABLE_TYPE);
}
}