Issue 550: added api docs, identity and credential names

This commit is contained in:
Adrian Cole 2011-05-16 21:37:25 -07:00
parent 4d81a5aa28
commit 36e6ca787d
15 changed files with 471 additions and 56 deletions

View File

@ -19,10 +19,13 @@
package org.jclouds.providers;
import java.net.URI;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
/**
* The BaseProviderMetadata class is an abstraction of {@link ProviderMetadata} to be extended
* by those implementing ProviderMetadata.
* 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.
*
@ -39,18 +42,26 @@ public abstract class BaseProviderMetadata implements ProviderMetadata {
int result = 1;
URI console = getConsole();
URI homepage = getHomepage();
URI docs = getApiDocumentation();
String id = getId();
String name = getName();
String identityName = getIdentityName();
String credentialName = getCredentialName();
String type = getType();
Set<String> linkedServices = getLinkedServices();
result = prime * result + ((console == null) ? 0 : console.hashCode());
result = prime * result + ((homepage == null) ? 0 : homepage.hashCode());
result = prime * result + ((docs == null) ? 0 : docs.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((identityName == null) ? 0 : identityName.hashCode());
result = prime * result + ((credentialName == null) ? 0 : credentialName.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((linkedServices == null) ? 0 : linkedServices.hashCode());
return result;
}
}
/**
* @see java.lang.Object#equals(java.lang.Object)
@ -59,9 +70,13 @@ public abstract class BaseProviderMetadata implements ProviderMetadata {
public boolean equals(Object obj) {
URI tConsole = getConsole();
URI tHomepage = getHomepage();
URI tDocs = getApiDocumentation();
String tId = getId();
String tName = getName();
String tIdentityName = getIdentityName();
String tCredentialName = getCredentialName();
String tType = getType();
Set<String> tLinkedServices = getLinkedServices();
if (this == obj)
return true;
@ -73,15 +88,24 @@ public abstract class BaseProviderMetadata implements ProviderMetadata {
ProviderMetadata other = (ProviderMetadata) obj;
URI oConsole = other.getConsole();
URI oHomepage = other.getHomepage();
URI oDocs = other.getApiDocumentation();
String oId = other.getId();
String oName = other.getName();
String oIdentityName = other.getIdentityName();
String oCredentialName = other.getCredentialName();
String oType = other.getType();
Set<String> oLinkedServices = other.getLinkedServices();
if (tConsole == null) {
if (oConsole != null)
return false;
} else if (!tConsole.equals(oConsole))
return false;
if (tDocs == null) {
if (oDocs != null)
return false;
} else if (!tDocs.equals(oDocs))
return false;
if (tHomepage == null) {
if (oHomepage != null)
return false;
@ -97,13 +121,38 @@ public abstract class BaseProviderMetadata implements ProviderMetadata {
return false;
} else if (!tName.equals(oName))
return false;
if (tIdentityName == null) {
if (oIdentityName != null)
return false;
} else if (!tIdentityName.equals(oIdentityName))
return false;
if (tCredentialName == null) {
if (oCredentialName != null)
return false;
} else if (!tCredentialName.equals(oCredentialName))
return false;
if (tType == null) {
if (oType != null)
return false;
} else if (!tType.equals(oType))
return false;
if (tLinkedServices == null) {
if (oLinkedServices != null)
return false;
} else if (!tLinkedServices.equals(oLinkedServices))
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getId() + ", type=" + getType() + ", name=" + getName() + ", identityName=" + getIdentityName()
+ ", credentialName=" + getCredentialName() + ", homePage=" + getHomepage() + ", console="
+ getConsole() + ", apiDocs=" + getApiDocumentation() + ", linkedServices=" + getLinkedServices() + "]";
}
@Override
public Set<String> getLinkedServices() {
return ImmutableSet.of(getId());
}
}

View File

@ -19,10 +19,13 @@
package org.jclouds.providers;
import java.net.URI;
import java.util.Set;
import javax.annotation.Nullable;
/**
* The ProviderMetadata interface allows jclouds to provide a plugin framework
* for gathering cloud provider metadata.
* The ProviderMetadata interface allows jclouds to provide a plugin framework for gathering cloud
* provider metadata.
*
* @author Jeremy Whitlock <jwhitlock@apache.org>
*/
@ -32,38 +35,59 @@ public interface ProviderMetadata {
public static final String COMPUTE_TYPE = "compute";
/**
* 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 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 name (display name) of an identity on this provider (ex. user, email, account,
* apikey)
*/
public String getIdentityName();
/**
*
* @return the name (display name) of a credential on this provider, or null if there is none
* (ex. password, secret, rsaKey)
*/
@Nullable
public String getCredentialName();
/**
*
* @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();
/**
*
* @return the url for the API documentation related to this service
*/
public URI getApiDocumentation();
/**
*
* @return all known services linked to the same account on this provider
*/
public Set<String> getLinkedServices();
}

View File

@ -33,12 +33,12 @@ import com.google.common.collect.Sets;
* @author Jeremy Whitlock <jwhitlock@apache.org>
*/
@Test(groups = "unit")
public abstract class BaseProviderTest {
public abstract class BaseProviderMetadataTest {
protected Set<String> allTypes = ImmutableSet.of(ProviderMetadata.BLOBSTORE_TYPE, ProviderMetadata.COMPUTE_TYPE);
private final ProviderMetadata toTest;
private final String expectedType;
public BaseProviderTest(ProviderMetadata toTest, String expectedType) {
public BaseProviderMetadataTest(ProviderMetadata toTest, String expectedType) {
this.toTest = toTest;
this.expectedType = expectedType;
}
@ -48,6 +48,7 @@ public abstract class BaseProviderTest {
ProviderMetadata providerMetadata = Providers.withId(toTest.getId());
assertEquals(toTest, providerMetadata);
assert providerMetadata.getLinkedServices().contains(toTest.getId());
}
@Test

View File

@ -21,14 +21,14 @@ package org.jclouds.providers;
import java.net.URI;
/**
* Implementation of {@ link org.jclouds.types.ProviderMetadata} for testing.
* Implementation of @ link org.jclouds.types.ProviderMetadata} for testing.
*
* @author Jeremy Whitlock <jwhitlock@apache.org>
*/
public class JcloudsTestBlobStoreProviderMetadata extends BaseProviderMetadata {
/**
* {@ see org.jclouds.types.ProviderMetadata#getId()}
* {@inheritDoc}
*/
@Override
public String getId() {
@ -36,7 +36,7 @@ public class JcloudsTestBlobStoreProviderMetadata extends BaseProviderMetadata {
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getType()}
* {@inheritDoc}
*/
@Override
public String getType() {
@ -44,7 +44,7 @@ public class JcloudsTestBlobStoreProviderMetadata extends BaseProviderMetadata {
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getName()}
* {@inheritDoc}
*/
@Override
public String getName() {
@ -52,7 +52,23 @@ public class JcloudsTestBlobStoreProviderMetadata extends BaseProviderMetadata {
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getHomepage()}
* {@inheritDoc}
*/
@Override
public String getCredentialName() {
return "user";
}
/**
* {@inheritDoc}
*/
@Override
public String getIdentityName() {
return "password";
}
/**
* {@inheritDoc}
*/
@Override
public URI getHomepage() {
@ -60,11 +76,19 @@ public class JcloudsTestBlobStoreProviderMetadata extends BaseProviderMetadata {
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getConsole()}
* {@inheritDoc}
*/
@Override
public URI getConsole() {
return URI.create("http://jclouds.org/console");
}
/**
* {@inheritDoc}
*/
@Override
public URI getApiDocumentation() {
return URI.create("http://jclouds.org/documentation");
}
}

View File

@ -21,7 +21,7 @@ package org.jclouds.providers;
import java.net.URI;
/**
* Implementation of {@ link org.jclouds.types.ProviderMetadata} for testing.
* Implementation of @ link org.jclouds.types.ProviderMetadata} for testing.
*
* @author Jeremy Whitlock <jwhitlock@apache.org>
*/
@ -51,6 +51,22 @@ public class JcloudsTestComputeProviderMetadata extends BaseProviderMetadata {
return "Test Compute Provider";
}
/**
* {@inheritDoc}
*/
@Override
public String getCredentialName() {
return "user";
}
/**
* {@inheritDoc}
*/
@Override
public String getIdentityName() {
return "password";
}
/**
* {@ see org.jclouds.types.ProviderMetadata#getHomepage()}
*/
@ -67,4 +83,12 @@ public class JcloudsTestComputeProviderMetadata extends BaseProviderMetadata {
return URI.create("http://jclouds.org/console");
}
/**
* {@inheritDoc}
*/
@Override
public URI getApiDocumentation() {
return URI.create("http://jclouds.org/documentation");
}
}

View File

@ -19,10 +19,13 @@
package org.jclouds.aws.ec2;
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 Compute Cloud (EC2) provider.
@ -55,6 +58,22 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata {
return "Amazon Elastic Compute Cloud (EC2)";
}
/**
* {@inheritDoc}
*/
@Override
public String getIdentityName() {
return "accessKeyID";
}
/**
* {@inheritDoc}
*/
@Override
public String getCredentialName() {
return "secretAccessKey";
}
/**
* {@inheritDoc}
*/
@ -70,5 +89,20 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata {
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/AWSEC2/latest/APIReference");
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getLinkedServices() {
return ImmutableSet.of(getId(), "aws-s3");
}
}

View File

@ -16,9 +16,11 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.providers;
package org.jclouds.aws.ec2;
import org.jclouds.aws.ec2.AWSEC2ProviderMetadata;
import org.jclouds.providers.BaseProviderMetadataTest;
import org.jclouds.providers.ProviderMetadata;
import org.testng.annotations.Test;
/**
@ -27,7 +29,7 @@ import org.testng.annotations.Test;
* @author Jeremy Whitlock <jwhitlock@apache.org>
*/
@Test(groups = "unit", testName = "AWSEC2ProviderTest")
public class AWSEC2ProviderTest extends BaseProviderTest {
public class AWSEC2ProviderTest extends BaseProviderMetadataTest {
public AWSEC2ProviderTest() {
super(new AWSEC2ProviderMetadata(), ProviderMetadata.COMPUTE_TYPE);

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.aws.s3;
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 Simple Storage Service
* (S3) provider.
*
* @author Adrian Cole
*/
public class AWSS3ProviderMetadata extends BaseProviderMetadata {
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return "aws-s3";
}
/**
* {@inheritDoc}
*/
@Override
public String getType() {
return ProviderMetadata.BLOBSTORE_TYPE;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return "Amazon Elastic Compute Cloud (S3)";
}
/**
* {@inheritDoc}
*/
@Override
public String getIdentityName() {
return "accessKeyID";
}
/**
* {@inheritDoc}
*/
@Override
public String getCredentialName() {
return "secretAccessKey";
}
/**
* {@inheritDoc}
*/
@Override
public URI getHomepage() {
return URI.create("http://aws.amazon.com/s3/");
}
/**
* {@inheritDoc}
*/
@Override
public URI getConsole() {
return URI.create("https://console.aws.amazon.com/s3/home");
}
/**
* {@inheritDoc}
*/
@Override
public URI getApiDocumentation() {
return URI.create("http://docs.amazonwebservices.com/AmazonS3/latest/API");
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getLinkedServices() {
return ImmutableSet.of(getId(), "aws-ec2");
}
}

View File

@ -0,0 +1 @@
org.jclouds.aws.s3.AWSS3ProviderMetadata

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.s3;
import org.jclouds.providers.BaseProviderMetadataTest;
import org.jclouds.providers.ProviderMetadata;
import org.testng.annotations.Test;
/**
* The AWSS3ProviderTest tests the org.jclouds.providers.AWSS3Provider class.
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "AWSS3ProviderTest")
public class AWSS3ProviderTest extends BaseProviderMetadataTest {
public AWSS3ProviderTest() {
super(new AWSS3ProviderMetadata(), ProviderMetadata.BLOBSTORE_TYPE);
}
}

View File

@ -0,0 +1,97 @@
/**
*
* 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.vcloud.terremark;
import java.net.URI;
import org.jclouds.providers.BaseProviderMetadata;
import org.jclouds.providers.ProviderMetadata;
/**
* Implementation of {@link org.jclouds.types.ProviderMetadata} for Terremark's Enterprise Cloud.
*
* @author Adrian Cole
*/
public class TerremarkECloudProviderMetadata extends BaseProviderMetadata {
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return "trmk-ecloud";
}
/**
* {@inheritDoc}
*/
@Override
public String getType() {
return ProviderMetadata.COMPUTE_TYPE;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return "Terremark Enterprise Cloud";
}
/**
* {@inheritDoc}
*/
@Override
public String getIdentityName() {
return "email";
}
/**
* {@inheritDoc}
*/
@Override
public String getCredentialName() {
return "password";
}
/**
* {@inheritDoc}
*/
@Override
public URI getHomepage() {
return URI.create("http://www.terremark.com/services/cloudcomputing/theenterprisecloud.aspx");
}
/**
* {@inheritDoc}
*/
@Override
public URI getConsole() {
return URI.create("https://icenter.digitalops.net");
}
/**
* {@inheritDoc}
*/
@Override
public URI getApiDocumentation() {
return URI.create("http://support.theenterprisecloud.com/kb/default.asp?id=533&Lang=1&SID=");
}
}

View File

@ -0,0 +1 @@
org.jclouds.vcloud.terremark.TerremarkECloudProviderMetadata

View File

@ -18,32 +18,19 @@
*/
package org.jclouds.vcloud.terremark;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.rest.Providers;
import org.jclouds.providers.BaseProviderMetadataTest;
import org.jclouds.providers.ProviderMetadata;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* The TerremarkECloudProviderTest tests the org.jclouds.providers.TerremarkECloudProvider class.
*
* @author Adrian Cole
*
*/
@Test(groups = "unit")
public class ProvidersInPropertiesTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Providers.getSupportedProviders();
assert Iterables.contains(providers, "trmk-ecloud") : providers;
@Test(groups = "unit", testName = "TerremarkECloudProviderTest")
public class TerremarkECloudProviderTest extends BaseProviderMetadataTest {
public TerremarkECloudProviderTest() {
super(new TerremarkECloudProviderMetadata(), ProviderMetadata.COMPUTE_TYPE);
}
@Test
public void testSupportedComputeServiceProviders() {
Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
assert Iterables.contains(providers, "trmk-ecloud") : providers;
}
}

View File

@ -46,6 +46,22 @@ public class TerremarkVCloudExpressProviderMetadata extends BaseProviderMetadata
return ProviderMetadata.COMPUTE_TYPE;
}
/**
* {@inheritDoc}
*/
@Override
public String getIdentityName() {
return "email";
}
/**
* {@inheritDoc}
*/
@Override
public String getCredentialName() {
return "password";
}
/**
* {@inheritDoc}
*/
@ -70,4 +86,12 @@ public class TerremarkVCloudExpressProviderMetadata extends BaseProviderMetadata
return URI.create("https://my.vcloudexpress.terremark.com");
}
/**
* {@inheritDoc}
*/
@Override
public URI getApiDocumentation() {
return URI.create("https://community.vcloudexpress.terremark.com/en-us/product_docs/m/vcefiles/2342.aspx");
}
}

View File

@ -16,8 +16,10 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.providers;
package org.jclouds.vcloud.terremark;
import org.jclouds.providers.BaseProviderMetadataTest;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressProviderMetadata;
import org.testng.annotations.Test;
@ -27,7 +29,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "TerremarkVCloudExpressProviderTest")
public class TerremarkVCloudExpressProviderTest extends BaseProviderTest {
public class TerremarkVCloudExpressProviderTest extends BaseProviderMetadataTest {
public TerremarkVCloudExpressProviderTest() {
super(new TerremarkVCloudExpressProviderMetadata(), ProviderMetadata.COMPUTE_TYPE);