mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of https://github.com/jcscoobyrs/jclouds
* '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:
commit
6e483c7f7c
26
core/pom.xml
26
core/pom.xml
|
@ -119,6 +119,32 @@
|
|||
</dependency>
|
||||
</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>
|
||||
<profile>
|
||||
<id>distribution</id>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -31,39 +31,39 @@ public interface ProviderMetadata {
|
|||
public static final String BLOBSTORE_TYPE = "blobstore";
|
||||
public static final String COMPUTE_TYPE = "compute";
|
||||
|
||||
/**
|
||||
* Returns an identifier unique to the provider.
|
||||
*
|
||||
* @return the provider's unique identifier
|
||||
*/
|
||||
public String getId();
|
||||
/**
|
||||
* Returns an identifier unique to the provider.
|
||||
*
|
||||
* @return the provider's unique identifier
|
||||
*/
|
||||
public String getId();
|
||||
|
||||
/**
|
||||
* Returns the provider type.
|
||||
*
|
||||
* @return the provider's type
|
||||
*/
|
||||
public String getType();
|
||||
/**
|
||||
* Returns the provider type.
|
||||
*
|
||||
* @return the provider's type
|
||||
*/
|
||||
public String getType();
|
||||
|
||||
/**
|
||||
* Returns the name of the provider.
|
||||
*
|
||||
* @return the name (display name) of the provider
|
||||
*/
|
||||
public String getName();
|
||||
/**
|
||||
* Returns the name of the provider.
|
||||
*
|
||||
* @return the name (display name) of the provider
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Returns the URI to the provider's homepage.
|
||||
*
|
||||
* @return the url for the provider's homepage
|
||||
*/
|
||||
public URI getHomepage();
|
||||
/**
|
||||
* Returns the URI to the provider's homepage.
|
||||
*
|
||||
* @return the url for the provider's homepage
|
||||
*/
|
||||
public URI getHomepage();
|
||||
|
||||
/**
|
||||
* Returns the URI to the provider's console.
|
||||
*
|
||||
* @return the url for the provider's console
|
||||
*/
|
||||
public URI getConsole();
|
||||
/**
|
||||
* Returns the URI to the provider's console.
|
||||
*
|
||||
* @return the url for the provider's console
|
||||
*/
|
||||
public URI getConsole();
|
||||
|
||||
}
|
|
@ -25,7 +25,7 @@ import java.net.URI;
|
|||
*
|
||||
* @author Jeremy Whitlock <jwhitlock@apache.org>
|
||||
*/
|
||||
public class JcloudsTestBlobStoreProviderMetadata implements ProviderMetadata {
|
||||
public class JcloudsTestBlobStoreProviderMetadata extends BaseProviderMetadata {
|
||||
|
||||
/**
|
||||
* {@ see org.jclouds.types.ProviderMetadata#getId()}
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.net.URI;
|
|||
*
|
||||
* @author Jeremy Whitlock <jwhitlock@apache.org>
|
||||
*/
|
||||
public class JcloudsTestComputeProviderMetadata implements ProviderMetadata {
|
||||
public class JcloudsTestComputeProviderMetadata extends BaseProviderMetadata {
|
||||
|
||||
/**
|
||||
* {@ see org.jclouds.types.ProviderMetadata#getId()}
|
||||
|
|
|
@ -33,6 +33,9 @@ import org.testng.annotations.Test;
|
|||
@Test( groups = "unit" )
|
||||
public class ProvidersTest {
|
||||
|
||||
private final ProviderMetadata testBlobstoreProvider = new JcloudsTestBlobStoreProviderMetadata();
|
||||
private final ProviderMetadata testComputeProvider = new JcloudsTestComputeProviderMetadata();
|
||||
|
||||
@Test
|
||||
public void testWithId() {
|
||||
ProviderMetadata providerMetadata;
|
||||
|
@ -45,9 +48,9 @@ public class ProvidersTest {
|
|||
; // Expected
|
||||
}
|
||||
|
||||
providerMetadata = Providers.withId("test-blobstore-provider");
|
||||
providerMetadata = Providers.withId(testBlobstoreProvider.getId());
|
||||
|
||||
assertEquals("Test Blobstore Provider", providerMetadata.getName());
|
||||
assertEquals(testBlobstoreProvider, providerMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -55,21 +58,13 @@ public class ProvidersTest {
|
|||
Iterable<ProviderMetadata> providersMetadata = Providers.ofType(ProviderMetadata.BLOBSTORE_TYPE);
|
||||
|
||||
for (ProviderMetadata providerMetadata : providersMetadata) {
|
||||
assertEquals("Test Blobstore Provider", providerMetadata.getName());
|
||||
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());
|
||||
assertEquals(testBlobstoreProvider, providerMetadata);
|
||||
}
|
||||
|
||||
providersMetadata = Providers.ofType(ProviderMetadata.COMPUTE_TYPE);
|
||||
|
||||
for (ProviderMetadata providerMetadata : providersMetadata) {
|
||||
assertEquals("Test Compute Provider", providerMetadata.getName());
|
||||
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());
|
||||
assertEquals(testComputeProvider, providerMetadata);
|
||||
}
|
||||
|
||||
providersMetadata = Providers.ofType("fake-type");
|
||||
|
@ -83,16 +78,9 @@ public class ProvidersTest {
|
|||
|
||||
for (ProviderMetadata providerMetadata : providersMetadata) {
|
||||
if (providerMetadata.getName().equals("Test Blobstore Provider")) {
|
||||
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());
|
||||
assertEquals(testBlobstoreProvider, providerMetadata);
|
||||
} else {
|
||||
assertEquals("Test Compute Provider", providerMetadata.getName());
|
||||
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());
|
||||
assertEquals(testComputeProvider, providerMetadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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/");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
org.jclouds.providers.AWSEC2ProviderMetadata
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue