normalized tag parsing code

This commit is contained in:
Adrian Cole 2010-08-16 12:25:22 -07:00
parent 5b215533f1
commit 6e09985659
8 changed files with 109 additions and 131 deletions

View File

@ -24,6 +24,8 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jclouds.compute.ComputeServiceContextBuilder;
import org.jclouds.compute.domain.Architecture;
@ -45,22 +47,24 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole
*/
public class ComputeServiceUtils {
public static final Pattern DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
public static String parseTagFromName(String from) {
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from);
return matcher.find() ? matcher.group(1) : "NOTAG-" + from;
}
public static final Map<org.jclouds.compute.domain.OsFamily, Map<String, String>> NAME_VERSION_MAP = ImmutableMap
.<org.jclouds.compute.domain.OsFamily, Map<String, String>> of(
org.jclouds.compute.domain.OsFamily.CENTOS, ImmutableMap
.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put(
"5.5", "5.5").build(),
org.jclouds.compute.domain.OsFamily.RHEL, ImmutableMap
.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put(
"5.5", "5.5").build(),
org.jclouds.compute.domain.OsFamily.UBUNTU, ImmutableMap
.<String, String> builder().put("hardy", "8.04").put("intrepid",
"8.10").put("jaunty", "9.04").put("karmic", "9.10").put(
"lucid", "10.04").put("maverick", "10.10").build());
.<org.jclouds.compute.domain.OsFamily, Map<String, String>> of(org.jclouds.compute.domain.OsFamily.CENTOS,
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5")
.build(), org.jclouds.compute.domain.OsFamily.RHEL,
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5")
.build(), org.jclouds.compute.domain.OsFamily.UBUNTU, ImmutableMap
.<String, String> builder().put("hardy", "8.04").put("intrepid", "8.10").put("jaunty",
"9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10")
.build());
public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family,
final String in) {
public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in) {
if (NAME_VERSION_MAP.containsKey(family)) {
CONTAINS_SUBSTRING contains = new CONTAINS_SUBSTRING(in.replace('-', '.'));
try {
@ -94,27 +98,24 @@ public class ComputeServiceUtils {
Formatter fmt = new Formatter().format("Execution failures:%n%n");
int index = 1;
for (Entry<?, Exception> errorMessage : executionExceptions.entrySet()) {
fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass()
.getSimpleName(), errorMessage.getKey(), Throwables
.getStackTraceAsString(errorMessage.getValue()));
fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), errorMessage
.getKey(), Throwables.getStackTraceAsString(errorMessage.getValue()));
}
return fmt.format("%s error[s]", executionExceptions.size()).toString();
}
public static String createNodeErrorMessage(
Map<? extends NodeMetadata, ? extends Throwable> failedNodes) {
public static String createNodeErrorMessage(Map<? extends NodeMetadata, ? extends Throwable> failedNodes) {
Formatter fmt = new Formatter().format("Node failures:%n%n");
int index = 1;
for (Entry<? extends NodeMetadata, ? extends Throwable> errorMessage : failedNodes.entrySet()) {
fmt.format("%s) %s on node %s:%n%s%n%n", index++, errorMessage.getValue().getClass()
.getSimpleName(), errorMessage.getKey().getId(), Throwables
.getStackTraceAsString(errorMessage.getValue()));
fmt.format("%s) %s on node %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(),
errorMessage.getKey().getId(), Throwables.getStackTraceAsString(errorMessage.getValue()));
}
return fmt.format("%s error[s]", failedNodes.size()).toString();
}
public static Iterable<? extends ComputeMetadata> filterByName(
Iterable<? extends ComputeMetadata> nodes, final String name) {
public static Iterable<? extends ComputeMetadata> filterByName(Iterable<? extends ComputeMetadata> nodes,
final String name) {
return Iterables.filter(nodes, new Predicate<ComputeMetadata>() {
@Override
public boolean apply(ComputeMetadata input) {
@ -144,8 +145,7 @@ public class ComputeServiceUtils {
public static boolean isKeyAuth(NodeMetadata createdNode) {
return createdNode.getCredentials().credential != null
&& createdNode.getCredentials().credential
.startsWith("-----BEGIN RSA PRIVATE KEY-----");
&& createdNode.getCredentials().credential.startsWith("-----BEGIN RSA PRIVATE KEY-----");
}
/**
@ -153,10 +153,9 @@ public class ComputeServiceUtils {
* returns a new instance of {@link NodeMetadata} that has new credentials
*/
public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) {
return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node
.getLocation(), node.getUri(), node.getUserMetadata(), node.getTag(), node
.getImage(), node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(),
node.getExtra(), newCredentials);
return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node.getLocation(),
node.getUri(), node.getUserMetadata(), node.getTag(), node.getImage(), node.getState(), node
.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), newCredentials);
}
public static Iterable<String> getSupportedProviders() {

View File

@ -195,8 +195,8 @@ public class ComputeUtils {
@Nullable SshCallable<?> last) {
checkState(this.sshFactory != null, "runScript requested, but no SshModule configured");
checkNodeHasPublicIps(node);
checkNotNull(node.getCredentials(), "credentials for node " + node.getId());
checkNotNull(node.getCredentials().credential, "credentials.credential for node " + node.getId());
checkNotNull(node.getCredentials(), "credentials for node " + node.getName());
checkNotNull(node.getCredentials().credential, "credentials.credential for node " + node.getName());
SshClient ssh = createSshClientOncePortIsListeningOnNode(node);
try {
ssh.connect();

View File

@ -20,12 +20,11 @@
package org.jclouds.gogrid.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -54,7 +53,6 @@ import com.google.common.collect.Iterables;
*/
@Singleton
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
public static final Pattern ALL_BEFORE_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
@Resource
protected Logger logger = Logger.NULL;
@ -74,14 +72,14 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
@Override
public boolean apply(Image input) {
return input.getProviderId().equals(instance.getImage().getId() + "")
&& (input.getLocation() == null || input.getLocation().getId().equals(
instance.getDatacenter().getId() + ""));
&& (input.getLocation() == null || input.getLocation().getId().equals(
instance.getDatacenter().getId() + ""));
}
}
@Inject
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client,
Set<? extends Image> images, Map<String, ? extends Location> locations) {
Set<? extends Image> images, Map<String, ? extends Location> locations) {
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images");
@ -90,8 +88,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
@Override
public NodeMetadata apply(Server from) {
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
final String tag = matcher.find() ? matcher.group(1) : null;
String tag = parseTagFromName(from.getName());
Set<String> ipSet = ImmutableSet.of(from.getIp().getIp());
NodeState state = serverStateToNodeState.get(from.getState());
Credentials creds = client.getServerServices().getServerCredentialsList().get(from.getName());
@ -102,8 +99,8 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
logger.warn("could not find a matching image for server %s", from);
}
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get(from
.getDatacenter().getId()
+ ""), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList.<String> of(),
ImmutableMap.<String, String> of(), creds);
.getDatacenter().getId()
+ ""), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList.<String> of(),
ImmutableMap.<String, String> of(), creds);
}
}

View File

@ -20,11 +20,10 @@
package org.jclouds.ibmdev.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -50,7 +49,6 @@ import com.google.common.collect.ImmutableSet;
*/
@Singleton
public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata> {
public static final Pattern ALL_BEFORE_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
@Resource
protected Logger logger = Logger.NULL;
@ -61,11 +59,9 @@ public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata>
@Inject
InstanceToNodeMetadata(Map<Instance.Status, NodeState> instanceStateToNodeState,
Map<String, ? extends Image> images,
@Named("CREDENTIALS") Map<String, String> credentialsMap,
Map<String, ? extends Image> images, @Named("CREDENTIALS") Map<String, String> credentialsMap,
Map<String, ? extends Location> locations) {
this.instanceStateToNodeState = checkNotNull(instanceStateToNodeState,
"instanceStateToNodeState");
this.instanceStateToNodeState = checkNotNull(instanceStateToNodeState, "instanceStateToNodeState");
this.images = checkNotNull(images, "images");
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
this.locations = checkNotNull(locations, "locations");
@ -73,16 +69,14 @@ public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata>
@Override
public NodeMetadata apply(Instance from) {
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
final String tag = matcher.find() ? matcher.group(1) : null;
Set<String> ipSet = from.getIp() != null ? ImmutableSet.of(from.getIp()) : ImmutableSet
.<String> of();
String tag = parseTagFromName(from.getName());
Set<String> ipSet = from.getIp() != null ? ImmutableSet.of(from.getIp()) : ImmutableSet.<String> of();
NodeState state = instanceStateToNodeState.get(from.getStatus());
Image image = images.get(from.getImageId());
String key = tag != null ? credentialsMap.get(tag) : null;
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations
.get(image.getLocation()), null, ImmutableMap.<String, String> of(), tag, image,
state, ipSet, ImmutableList.<String> of(), ImmutableMap.<String, String> of(),
new Credentials(image.getDefaultCredentials().identity, key));
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get(image
.getLocation()), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList
.<String> of(), ImmutableMap.<String, String> of(), new Credentials(
image.getDefaultCredentials().identity, key));
}
}

View File

@ -20,12 +20,11 @@
package org.jclouds.rackspace.cloudservers.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -50,7 +49,6 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole
*/
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
public static final Pattern DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
private final Location location;
private final Map<ServerStatus, NodeState> serverToNodeState;
private final Set<? extends Image> images;
@ -70,13 +68,13 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
@Override
public boolean apply(Image input) {
return input.getProviderId().equals(instance.getImageId() + "")
&& (input.getLocation() == null || input.getLocation().equals(location.getParent()));
&& (input.getLocation() == null || input.getLocation().equals(location.getParent()));
}
}
@Inject
ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState, Set<? extends Image> images,
Location location) {
Location location) {
this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
this.images = checkNotNull(images, "images");
this.location = checkNotNull(location, "location");
@ -84,8 +82,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
@Override
public NodeMetadata apply(Server from) {
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from.getName());
final String tag = matcher.find() ? matcher.group(1) : null;
String tag = parseTagFromName(from.getName());
Location host = new LocationImpl(LocationScope.HOST, from.getHostId(), from.getHostId(), location);
Image image = null;
try {
@ -94,7 +91,8 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
logger.warn("could not find a matching image for server %s in location %s", from, location);
}
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", host, null, from.getMetadata(),
tag, image, serverToNodeState.get(from.getStatus()), from.getAddresses().getPublicAddresses(), from
.getAddresses().getPrivateAddresses(), ImmutableMap.<String, String> of(), null);
tag, image, serverToNodeState.get(from.getStatus()), from.getAddresses().getPublicAddresses(), from
.getAddresses().getPrivateAddresses(), ImmutableMap.<String, String> of(), null);
}
}

View File

@ -21,6 +21,7 @@ package org.jclouds.rimuhosting.miro.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.PROPERTY_RIMUHOSTING_DEFAULT_DC;
import java.util.Map;
@ -124,7 +125,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Named("DEFAULT")
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
return template.sizeId("MIRO1B").osFamily(UBUNTU).architecture(Architecture.X86_32).imageNameMatches(
".*10\\.?04.*");
".*10\\.?04.*");
}
@Provides
@ -183,7 +184,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Inject
protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client,
Function<Server, Iterable<String>> getPublicAddresses, Map<RunningState, NodeState> runningStateToNodeState) {
Function<Server, Iterable<String>> getPublicAddresses,
Map<RunningState, NodeState> runningStateToNodeState) {
this.client = client;
this.getPublicAddresses = getPublicAddresses;
this.runningStateToNodeState = runningStateToNodeState;
@ -192,13 +194,13 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Override
public NodeMetadata execute(String tag, String name, Template template) {
NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(),
"imageId"), checkNotNull(template.getSize().getProviderId(), "sizeId"));
"imageId"), checkNotNull(template.getSize().getProviderId(), "sizeId"));
Server server = client.getServer(serverResponse.getServer().getId());
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage(),
runningStateToNodeState.get(server.getState()), getPublicAddresses.apply(server), ImmutableList
.<String> of(), ImmutableMap.<String, String> of(), new Credentials("root", serverResponse
.getNewInstanceRequest().getCreateOptions().getPassword()));
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage(),
runningStateToNodeState.get(server.getState()), getPublicAddresses.apply(server), ImmutableList
.<String> of(), ImmutableMap.<String, String> of(), new Credentials("root", serverResponse
.getNewInstanceRequest().getCreateOptions().getPassword()));
return node;
}
@ -211,7 +213,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Inject
protected RimuHostingListNodesStrategy(RimuHostingClient client,
Function<Server, NodeMetadata> serverToNodeMetadata) {
Function<Server, NodeMetadata> serverToNodeMetadata) {
this.client = client;
this.serverToNodeMetadata = serverToNodeMetadata;
}
@ -236,7 +238,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Inject
protected RimuHostingGetNodeMetadataStrategy(RimuHostingClient client,
Function<Server, NodeMetadata> serverToNodeMetadata) {
Function<Server, NodeMetadata> serverToNodeMetadata) {
this.client = client;
this.serverToNodeMetadata = serverToNodeMetadata;
}
@ -251,11 +253,11 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@VisibleForTesting
static final Map<RunningState, NodeState> runningStateToNodeState = ImmutableMap.<RunningState, NodeState> builder()
.put(RunningState.RUNNING, NodeState.RUNNING)//
.put(RunningState.NOTRUNNING, NodeState.SUSPENDED)//
.put(RunningState.POWERCYCLING, NodeState.PENDING)//
.put(RunningState.RESTARTING, NodeState.PENDING)//
.build();
.put(RunningState.RUNNING, NodeState.RUNNING)//
.put(RunningState.NOTRUNNING, NodeState.SUSPENDED)//
.put(RunningState.POWERCYCLING, NodeState.PENDING)//
.put(RunningState.RESTARTING, NodeState.PENDING)//
.build();
@Singleton
@Provides
@ -286,16 +288,16 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Override
public boolean apply(Image input) {
return input.getProviderId().equals(instance.getImageId())
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation()
.equals(location.getParent()));
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation()
.equals(location.getParent()));
}
}
@SuppressWarnings("unused")
@Inject
ServerToNodeMetadata(Function<Server, Iterable<String>> getPublicAddresses,
Map<RunningState, NodeState> runningStateToNodeState, Set<? extends Image> images,
Set<? extends Location> locations) {
Map<RunningState, NodeState> runningStateToNodeState, Set<? extends Image> images,
Set<? extends Location> locations) {
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState");
this.images = checkNotNull(images, "images");
@ -306,8 +308,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
public NodeMetadata apply(Server from) {
Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from.getLocation()
.getName(), null);
String tag = from.getName().replaceAll("-[0-9]+", "");
.getName(), null);
String tag = parseTagFromName(from.getName());
Credentials creds = null;
Image image = null;
@ -318,8 +320,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
}
NodeState state = runningStateToNodeState.get(from.getState());
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
.<String, String> of(), tag, image, state, getPublicAddresses.apply(from), ImmutableList.<String> of(),
ImmutableMap.<String, String> of(), creds);
.<String, String> of(), tag, image, state, getPublicAddresses.apply(from), ImmutableList
.<String> of(), ImmutableMap.<String, String> of(), creds);
}
}
@ -329,14 +331,14 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Override
public Iterable<String> apply(Server server) {
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(ImmutableList.of(server
.getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps());
.getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps());
}
}
@Provides
@Singleton
Location getDefaultLocation(@Named(PROPERTY_RIMUHOSTING_DEFAULT_DC) final String defaultDC,
Set<? extends Location> locations) {
Set<? extends Location> locations) {
return Iterables.find(locations, new Predicate<Location>() {
@Override
@ -350,14 +352,14 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Provides
@Singleton
Set<? extends Location> getDefaultLocations(RimuHostingClient sync, LogHolder holder,
Function<ComputeMetadata, String> indexer, @Provider String providerName) {
Function<ComputeMetadata, String> indexer, @Provider String providerName) {
final Set<Location> locations = Sets.newHashSet();
holder.logger.debug(">> providing locations");
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
for (final PricingPlan from : sync.getPricingPlanList()) {
try {
locations.add(new LocationImpl(LocationScope.ZONE, from.getDataCenter().getId(), from.getDataCenter()
.getName(), provider));
.getName(), provider));
} catch (NullPointerException e) {
holder.logger.warn("datacenter not present in " + from.getId());
}
@ -380,9 +382,10 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Provides
@Singleton
protected Set<? extends Size> provideSizes(RimuHostingClient sync, Set<? extends Image> images,
Set<? extends Location> locations, LogHolder holder,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, Function<ComputeMetadata, String> indexer)
throws InterruptedException, TimeoutException, ExecutionException {
Set<? extends Location> locations, LogHolder holder,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor,
Function<ComputeMetadata, String> indexer) throws InterruptedException, TimeoutException,
ExecutionException {
final Set<Size> sizes = Sets.newHashSet();
holder.logger.debug(">> providing sizes");
for (final PricingPlan from : sync.getPricingPlanList()) {
@ -397,7 +400,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
});
sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap
.<String, String> of(), 1, from.getRam(), from.getDiskSize(), ImagePredicates.any()));
.<String, String> of(), 1, from.getRam(), from.getDiskSize(), ImagePredicates.any()));
} catch (NullPointerException e) {
holder.logger.warn("datacenter not present in " + from.getId());
}
@ -417,7 +420,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
@Provides
@Singleton
protected Set<? extends Image> provideImages(final RimuHostingClient sync, LogHolder holder,
Function<ComputeMetadata, String> indexer) throws InterruptedException, ExecutionException, TimeoutException {
Function<ComputeMetadata, String> indexer) throws InterruptedException, ExecutionException,
TimeoutException {
final Set<Image> images = Sets.newHashSet();
holder.logger.debug(">> providing images");
for (final org.jclouds.rimuhosting.miro.domain.Image from : sync.getImageList()) {
@ -438,8 +442,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
}
images.add(new ImageImpl(from.getId(), from.getDescription(), from.getId(), null, null, ImmutableMap
.<String, String> of(), from.getDescription(), version, os, osDescription, arch, new Credentials("root",
null)));
.<String, String> of(), from.getDescription(), version, os, osDescription, arch, new Credentials(
"root", null)));
}
holder.logger.debug("<< images(%d)", images.size());
return images;

View File

@ -20,12 +20,11 @@
package org.jclouds.slicehost.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -47,7 +46,6 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole
*/
public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
public static final Pattern DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
private final Location location;
private final Map<Slice.Status, NodeState> sliceToNodeState;
private final Set<? extends Image> images;
@ -70,7 +68,7 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
@Inject
SliceToNodeMetadata(Map<Slice.Status, NodeState> sliceStateToNodeState, Set<? extends Image> images,
Location location) {
Location location) {
this.sliceToNodeState = checkNotNull(sliceStateToNodeState, "sliceStateToNodeState");
this.images = checkNotNull(images, "images");
this.location = checkNotNull(location, "location");
@ -78,8 +76,7 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
@Override
public NodeMetadata apply(Slice from) {
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from.getName());
final String tag = matcher.find() ? matcher.group(1) : null;
String tag = parseTagFromName(from.getName());
Image image = null;
try {
image = Iterables.find(images, new FindImageForSlice(from));
@ -88,8 +85,8 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
}
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
.<String, String> of(), tag, image, sliceToNodeState.get(from.getStatus()), Iterables.filter(from
.getAddresses(), new Predicate<String>() {
.<String, String> of(), tag, image, sliceToNodeState.get(from.getStatus()), Iterables.filter(from
.getAddresses(), new Predicate<String>() {
@Override
public boolean apply(String input) {

View File

@ -20,12 +20,11 @@
package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -49,8 +48,8 @@ import org.jclouds.vcloud.domain.VAppStatus;
import com.google.common.collect.ImmutableMap;
/**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link BaseVCloudComputeClient} bound.
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
* bound.
*
* @author Adrian Cole
*/
@ -67,12 +66,10 @@ public class VCloudGetNodeMetadata {
protected final GetExtra getExtra;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
public static final Pattern TAG_PATTERN_WITHOUT_TEMPLATE = Pattern.compile("([^-]+)-[0-9a-f]+");
@Inject
VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Provider<Set<? extends Image>> images) {
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Provider<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images");
this.getExtra = checkNotNull(getExtra, "getExtra");
@ -83,22 +80,14 @@ public class VCloudGetNodeMetadata {
public NodeMetadata execute(String in) {
URI id = URI.create(in);
VApp vApp = client.getVApp(id);
if (vApp == null)
VApp from = client.getVApp(id);
if (from == null)
return null;
String tag = null;
Image image = null;
Matcher matcher = TAG_PATTERN_WITHOUT_TEMPLATE.matcher(vApp.getName());
if (matcher.find()) {
tag = matcher.group(1);
} else {
tag = "NOTAG-" + vApp.getName();
}
Location location = findLocationForResourceInVDC.apply(vApp.getVDC());
return new NodeMetadataImpl(vApp.getId().toASCIIString(), vApp.getName(), vApp.getId()
.toASCIIString(), location, vApp.getId(), ImmutableMap.<String, String> of(), tag, image,
vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(id), computeClient
.getPrivateAddresses(id), getExtra.apply(vApp), null);
String tag = parseTagFromName(from.getName());
Location location = findLocationForResourceInVDC.apply(from.getVDC());
return new NodeMetadataImpl(in, from.getName(), in, location, from.getId(), ImmutableMap.<String, String> of(),
tag, null, vAppStatusToNodeState.get(from.getStatus()), computeClient.getPublicAddresses(id),
computeClient.getPrivateAddresses(id), getExtra.apply(from), null);
}
}