Added getSupportedProviders()

This commit is contained in:
Ivan Meredith 2010-04-26 22:55:07 +12:00
parent 950776c0e9
commit 47ed07d0d7
2 changed files with 60 additions and 0 deletions

View File

@ -23,12 +23,16 @@ import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.concurrent.ConcurrentUtils.awaitCompletion; import static org.jclouds.concurrent.ConcurrentUtils.awaitCompletion;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -61,9 +65,11 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.io.Resources;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -392,4 +398,32 @@ public class ComputeUtils {
.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), .getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(),
newCredentials); newCredentials);
} }
/**
* Gets a set of supported providers. Idea stolen from pallets (supported-clouds).
* Uses compute.properties to populate the set.
*
* XXX: Pass in extra properties to support ones that aren't in compute.properties
*/
public static Set<String> getSupportedProviders() {
Properties properties = new Properties();
try {
properties.load(Resources.newInputStreamSupplier(
Resources.getResource("compute.properties")).getInput());
} catch (IOException e) {
throw new RuntimeException(e);
}
Set<Object> keys = properties.keySet();
Set<String> providers = new HashSet<String>();
for (Object key : keys) {
String keyString = key.toString();
if (keyString.endsWith(".contextbuilder")) {
providers.add(keyString.substring(0, keyString.length()
- ".contextbuilder".length()));
}
}
return providers;
}
} }

View File

@ -0,0 +1,26 @@
package org.jclouds.compute.internal;
import java.util.Set;
import org.jclouds.compute.util.ComputeUtils;
import org.testng.annotations.Test;
/**
* Test the compute utils.
*
* @author Ivan Meredith
*
*/
@Test(groups = "unit")
public class ComputeUtilsTest {
/**
* Test some of the currently supported clouds against compute.properties.
*/
@Test
public void testSupportedProviders(){
Set<String> providers = ComputeUtils.getSupportedProviders();
assert providers.contains("rimuhosting");
assert providers.contains("cloudservers");
assert providers.contains("gogrid");
}
}