* 'master' of https://github.com/jcscoobyrs/jclouds:
  Added a note to the org.jclouds.providers.BaseProviderMetadata class in core
  Implemented the provider metadata for the aws-ec2 cloud provider.
  Updated the core project POM to exclude ProviderMetadata plugins from the
  Added an abstract ProviderMetadata object to allow for overriding the equals and
This commit is contained in:
Adrian Cole 2011-05-12 15:31:18 -07:00
commit 6e483c7f7c
9 changed files with 313 additions and 53 deletions

View File

@ -119,6 +119,32 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<!--
These files are excluded to avoid corrupting the classpath with ProviderMetadata implementation
classes that should only be availble when running the core tests.
-->
<excludes>
<exclude>META-INF/services/</exclude>
<exclude>org/jclouds/providers/*Test*.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles> <profiles>
<profile> <profile>
<id>distribution</id> <id>distribution</id>

View File

@ -0,0 +1,109 @@
/**
*
* 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.providers;
import java.net.URI;
/**
* The BaseProviderMetadata class is an abstraction of {@link ProviderMetadata} to be extended
* by those implementing ProviderMetadata.
*
* (Note: This class must be abstract to allow {@link java.util.ServiceLoader} to work properly.
*
* @author Jeremy Whitlock <jwhitlock@apache.org>
*/
public abstract class BaseProviderMetadata implements ProviderMetadata {
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
URI console = getConsole();
URI homepage = getHomepage();
String id = getId();
String name = getName();
String type = getType();
result = prime * result + ((console == null) ? 0 : console.hashCode());
result = prime * result + ((homepage == null) ? 0 : homepage.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
URI tConsole = getConsole();
URI tHomepage = getHomepage();
String tId = getId();
String tName = getName();
String tType = getType();
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProviderMetadata other = (ProviderMetadata) obj;
URI oConsole = other.getConsole();
URI oHomepage = other.getHomepage();
String oId = other.getId();
String oName = other.getName();
String oType = other.getType();
if (tConsole == null) {
if (oConsole != null)
return false;
} else if (!tConsole.equals(oConsole))
return false;
if (tHomepage == null) {
if (oHomepage != null)
return false;
} else if (!tHomepage.equals(oHomepage))
return false;
if (tId == null) {
if (oId != null)
return false;
} else if (!tId.equals(oId))
return false;
if (tName == null) {
if (oName != null)
return false;
} else if (!tName.equals(oName))
return false;
if (tType == null) {
if (oType != null)
return false;
} else if (!tType.equals(oType))
return false;
return true;
}
}

View File

@ -31,39 +31,39 @@ public interface ProviderMetadata {
public static final String BLOBSTORE_TYPE = "blobstore"; public static final String BLOBSTORE_TYPE = "blobstore";
public static final String COMPUTE_TYPE = "compute"; public static final String COMPUTE_TYPE = "compute";
/** /**
* Returns an identifier unique to the provider. * Returns an identifier unique to the provider.
* *
* @return the provider's unique identifier * @return the provider's unique identifier
*/ */
public String getId(); public String getId();
/** /**
* Returns the provider type. * Returns the provider type.
* *
* @return the provider's type * @return the provider's type
*/ */
public String getType(); public String getType();
/** /**
* Returns the name of the provider. * Returns the name of the provider.
* *
* @return the name (display name) of the provider * @return the name (display name) of the provider
*/ */
public String getName(); public String getName();
/** /**
* Returns the URI to the provider's homepage. * Returns the URI to the provider's homepage.
* *
* @return the url for the provider's homepage * @return the url for the provider's homepage
*/ */
public URI getHomepage(); public URI getHomepage();
/** /**
* Returns the URI to the provider's console. * Returns the URI to the provider's console.
* *
* @return the url for the provider's console * @return the url for the provider's console
*/ */
public URI getConsole(); public URI getConsole();
} }

View File

@ -25,7 +25,7 @@ import java.net.URI;
* *
* @author Jeremy Whitlock <jwhitlock@apache.org> * @author Jeremy Whitlock <jwhitlock@apache.org>
*/ */
public class JcloudsTestBlobStoreProviderMetadata implements ProviderMetadata { public class JcloudsTestBlobStoreProviderMetadata extends BaseProviderMetadata {
/** /**
* {@ see org.jclouds.types.ProviderMetadata#getId()} * {@ see org.jclouds.types.ProviderMetadata#getId()}

View File

@ -25,7 +25,7 @@ import java.net.URI;
* *
* @author Jeremy Whitlock <jwhitlock@apache.org> * @author Jeremy Whitlock <jwhitlock@apache.org>
*/ */
public class JcloudsTestComputeProviderMetadata implements ProviderMetadata { public class JcloudsTestComputeProviderMetadata extends BaseProviderMetadata {
/** /**
* {@ see org.jclouds.types.ProviderMetadata#getId()} * {@ see org.jclouds.types.ProviderMetadata#getId()}

View File

@ -33,6 +33,9 @@ import org.testng.annotations.Test;
@Test( groups = "unit" ) @Test( groups = "unit" )
public class ProvidersTest { public class ProvidersTest {
private final ProviderMetadata testBlobstoreProvider = new JcloudsTestBlobStoreProviderMetadata();
private final ProviderMetadata testComputeProvider = new JcloudsTestComputeProviderMetadata();
@Test @Test
public void testWithId() { public void testWithId() {
ProviderMetadata providerMetadata; ProviderMetadata providerMetadata;
@ -45,9 +48,9 @@ public class ProvidersTest {
; // Expected ; // Expected
} }
providerMetadata = Providers.withId("test-blobstore-provider"); providerMetadata = Providers.withId(testBlobstoreProvider.getId());
assertEquals("Test Blobstore Provider", providerMetadata.getName()); assertEquals(testBlobstoreProvider, providerMetadata);
} }
@Test @Test
@ -55,21 +58,13 @@ public class ProvidersTest {
Iterable<ProviderMetadata> providersMetadata = Providers.ofType(ProviderMetadata.BLOBSTORE_TYPE); Iterable<ProviderMetadata> providersMetadata = Providers.ofType(ProviderMetadata.BLOBSTORE_TYPE);
for (ProviderMetadata providerMetadata : providersMetadata) { for (ProviderMetadata providerMetadata : providersMetadata) {
assertEquals("Test Blobstore Provider", providerMetadata.getName()); assertEquals(testBlobstoreProvider, providerMetadata);
assertEquals("test-blobstore-provider", providerMetadata.getId());
assertEquals(ProviderMetadata.BLOBSTORE_TYPE, providerMetadata.getType());
assertEquals("http://jclouds.org", providerMetadata.getHomepage().toString());
assertEquals("http://jclouds.org/console", providerMetadata.getConsole().toString());
} }
providersMetadata = Providers.ofType(ProviderMetadata.COMPUTE_TYPE); providersMetadata = Providers.ofType(ProviderMetadata.COMPUTE_TYPE);
for (ProviderMetadata providerMetadata : providersMetadata) { for (ProviderMetadata providerMetadata : providersMetadata) {
assertEquals("Test Compute Provider", providerMetadata.getName()); assertEquals(testComputeProvider, providerMetadata);
assertEquals("test-compute-provider", providerMetadata.getId());
assertEquals(ProviderMetadata.COMPUTE_TYPE, providerMetadata.getType());
assertEquals("http://jclouds.org", providerMetadata.getHomepage().toString());
assertEquals("http://jclouds.org/console", providerMetadata.getConsole().toString());
} }
providersMetadata = Providers.ofType("fake-type"); providersMetadata = Providers.ofType("fake-type");
@ -83,16 +78,9 @@ public class ProvidersTest {
for (ProviderMetadata providerMetadata : providersMetadata) { for (ProviderMetadata providerMetadata : providersMetadata) {
if (providerMetadata.getName().equals("Test Blobstore Provider")) { if (providerMetadata.getName().equals("Test Blobstore Provider")) {
assertEquals("test-blobstore-provider", providerMetadata.getId()); assertEquals(testBlobstoreProvider, providerMetadata);
assertEquals(ProviderMetadata.BLOBSTORE_TYPE, providerMetadata.getType());
assertEquals("http://jclouds.org", providerMetadata.getHomepage().toString());
assertEquals("http://jclouds.org/console", providerMetadata.getConsole().toString());
} else { } else {
assertEquals("Test Compute Provider", providerMetadata.getName()); assertEquals(testComputeProvider, providerMetadata);
assertEquals("test-compute-provider", providerMetadata.getId());
assertEquals(ProviderMetadata.COMPUTE_TYPE, providerMetadata.getType());
assertEquals("http://jclouds.org", providerMetadata.getHomepage().toString());
assertEquals("http://jclouds.org/console", providerMetadata.getConsole().toString());
} }
} }
} }

View File

@ -0,0 +1,71 @@
/**
*
* 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.providers;
import java.net.URI;
/**
* Implementation of {@ link org.jclouds.types.ProviderMetadata} for Amazon's
* Elastic Compute Cloud (EC2) provider.
*
* @author Jeremy Whitlock <jwhitlock@apache.org>
*/
public class AWSEC2ProviderMetadata extends BaseProviderMetadata {
/**
* {@ see org.jclouds.types.ProviderMetadata#getId()}
*/
@Override
public String getId() {
return "aws-ec2";
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getType()}
*/
@Override
public String getType() {
return ProviderMetadata.COMPUTE_TYPE;
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getName()}
*/
@Override
public String getName() {
return "Amazon Elastic Compute Cloud (EC2)";
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getHomepage()}
*/
@Override
public URI getHomepage() {
return URI.create("http://aws.amazon.com/");
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getConsole()}
*/
@Override
public URI getConsole() {
return URI.create("http://aws.amazon.com/console/");
}
}

View File

@ -0,0 +1 @@
org.jclouds.providers.AWSEC2ProviderMetadata

View File

@ -0,0 +1,65 @@
/**
*
* 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.providers;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import org.testng.annotations.Test;
/**
* The AWSEC2ProviderTest tests the org.jclouds.providers.AWSEC2Provider class.
*
* @author Jeremy Whitlock <jwhitlock@apache.org>
*/
@Test( groups = "unit" )
public class AWSEC2ProviderTest {
private final ProviderMetadata awsEc2ProviderMetadata = new AWSEC2ProviderMetadata();
@Test
public void testWithId() {
ProviderMetadata providerMetadata = Providers.withId(awsEc2ProviderMetadata.getId());
assertEquals(awsEc2ProviderMetadata, providerMetadata);
}
@Test
public void testOfType() {
Iterable<ProviderMetadata> providersMetadata = Providers.ofType(ProviderMetadata.COMPUTE_TYPE);
for (ProviderMetadata providerMetadata : providersMetadata) {
assertEquals(awsEc2ProviderMetadata, providerMetadata);
}
providersMetadata = Providers.ofType(ProviderMetadata.BLOBSTORE_TYPE);
assertFalse(providersMetadata.iterator().hasNext());
}
@Test
public void testAll() {
Iterable<ProviderMetadata> providersMetadata = Providers.all();
for (ProviderMetadata providerMetadata : providersMetadata) {
assertEquals(awsEc2ProviderMetadata, providerMetadata);
}
}
}