mirror of https://github.com/apache/jclouds.git
normalized tag parsing code
This commit is contained in:
parent
5b215533f1
commit
6e09985659
|
@ -24,6 +24,8 @@ import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContextBuilder;
|
import org.jclouds.compute.ComputeServiceContextBuilder;
|
||||||
import org.jclouds.compute.domain.Architecture;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
|
@ -45,22 +47,24 @@ import com.google.common.collect.Iterables;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ComputeServiceUtils {
|
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
|
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, Map<String, String>> of(org.jclouds.compute.domain.OsFamily.CENTOS,
|
||||||
org.jclouds.compute.domain.OsFamily.CENTOS, ImmutableMap
|
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5")
|
||||||
.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put(
|
.build(), org.jclouds.compute.domain.OsFamily.RHEL,
|
||||||
"5.5", "5.5").build(),
|
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5")
|
||||||
org.jclouds.compute.domain.OsFamily.RHEL, ImmutableMap
|
.build(), org.jclouds.compute.domain.OsFamily.UBUNTU, ImmutableMap
|
||||||
.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put(
|
.<String, String> builder().put("hardy", "8.04").put("intrepid", "8.10").put("jaunty",
|
||||||
"5.5", "5.5").build(),
|
"9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10")
|
||||||
org.jclouds.compute.domain.OsFamily.UBUNTU, ImmutableMap
|
.build());
|
||||||
.<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,
|
public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in) {
|
||||||
final String in) {
|
|
||||||
if (NAME_VERSION_MAP.containsKey(family)) {
|
if (NAME_VERSION_MAP.containsKey(family)) {
|
||||||
CONTAINS_SUBSTRING contains = new CONTAINS_SUBSTRING(in.replace('-', '.'));
|
CONTAINS_SUBSTRING contains = new CONTAINS_SUBSTRING(in.replace('-', '.'));
|
||||||
try {
|
try {
|
||||||
|
@ -94,27 +98,24 @@ public class ComputeServiceUtils {
|
||||||
Formatter fmt = new Formatter().format("Execution failures:%n%n");
|
Formatter fmt = new Formatter().format("Execution failures:%n%n");
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (Entry<?, Exception> errorMessage : executionExceptions.entrySet()) {
|
for (Entry<?, Exception> errorMessage : executionExceptions.entrySet()) {
|
||||||
fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass()
|
fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), errorMessage
|
||||||
.getSimpleName(), errorMessage.getKey(), Throwables
|
.getKey(), Throwables.getStackTraceAsString(errorMessage.getValue()));
|
||||||
.getStackTraceAsString(errorMessage.getValue()));
|
|
||||||
}
|
}
|
||||||
return fmt.format("%s error[s]", executionExceptions.size()).toString();
|
return fmt.format("%s error[s]", executionExceptions.size()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createNodeErrorMessage(
|
public static String createNodeErrorMessage(Map<? extends NodeMetadata, ? extends Throwable> failedNodes) {
|
||||||
Map<? extends NodeMetadata, ? extends Throwable> failedNodes) {
|
|
||||||
Formatter fmt = new Formatter().format("Node failures:%n%n");
|
Formatter fmt = new Formatter().format("Node failures:%n%n");
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (Entry<? extends NodeMetadata, ? extends Throwable> errorMessage : failedNodes.entrySet()) {
|
for (Entry<? extends NodeMetadata, ? extends Throwable> errorMessage : failedNodes.entrySet()) {
|
||||||
fmt.format("%s) %s on node %s:%n%s%n%n", index++, errorMessage.getValue().getClass()
|
fmt.format("%s) %s on node %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(),
|
||||||
.getSimpleName(), errorMessage.getKey().getId(), Throwables
|
errorMessage.getKey().getId(), Throwables.getStackTraceAsString(errorMessage.getValue()));
|
||||||
.getStackTraceAsString(errorMessage.getValue()));
|
|
||||||
}
|
}
|
||||||
return fmt.format("%s error[s]", failedNodes.size()).toString();
|
return fmt.format("%s error[s]", failedNodes.size()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Iterable<? extends ComputeMetadata> filterByName(
|
public static Iterable<? extends ComputeMetadata> filterByName(Iterable<? extends ComputeMetadata> nodes,
|
||||||
Iterable<? extends ComputeMetadata> nodes, final String name) {
|
final String name) {
|
||||||
return Iterables.filter(nodes, new Predicate<ComputeMetadata>() {
|
return Iterables.filter(nodes, new Predicate<ComputeMetadata>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(ComputeMetadata input) {
|
public boolean apply(ComputeMetadata input) {
|
||||||
|
@ -144,8 +145,7 @@ public class ComputeServiceUtils {
|
||||||
|
|
||||||
public static boolean isKeyAuth(NodeMetadata createdNode) {
|
public static boolean isKeyAuth(NodeMetadata createdNode) {
|
||||||
return createdNode.getCredentials().credential != null
|
return createdNode.getCredentials().credential != null
|
||||||
&& createdNode.getCredentials().credential
|
&& createdNode.getCredentials().credential.startsWith("-----BEGIN RSA PRIVATE KEY-----");
|
||||||
.startsWith("-----BEGIN RSA PRIVATE KEY-----");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,10 +153,9 @@ public class ComputeServiceUtils {
|
||||||
* returns a new instance of {@link NodeMetadata} that has new credentials
|
* returns a new instance of {@link NodeMetadata} that has new credentials
|
||||||
*/
|
*/
|
||||||
public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) {
|
public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) {
|
||||||
return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node
|
return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node.getLocation(),
|
||||||
.getLocation(), node.getUri(), node.getUserMetadata(), node.getTag(), node
|
node.getUri(), node.getUserMetadata(), node.getTag(), node.getImage(), node.getState(), node
|
||||||
.getImage(), node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(),
|
.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), newCredentials);
|
||||||
node.getExtra(), newCredentials);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Iterable<String> getSupportedProviders() {
|
public static Iterable<String> getSupportedProviders() {
|
||||||
|
|
|
@ -195,8 +195,8 @@ public class ComputeUtils {
|
||||||
@Nullable SshCallable<?> last) {
|
@Nullable SshCallable<?> last) {
|
||||||
checkState(this.sshFactory != null, "runScript requested, but no SshModule configured");
|
checkState(this.sshFactory != null, "runScript requested, but no SshModule configured");
|
||||||
checkNodeHasPublicIps(node);
|
checkNodeHasPublicIps(node);
|
||||||
checkNotNull(node.getCredentials(), "credentials for node " + node.getId());
|
checkNotNull(node.getCredentials(), "credentials for node " + node.getName());
|
||||||
checkNotNull(node.getCredentials().credential, "credentials.credential for node " + node.getId());
|
checkNotNull(node.getCredentials().credential, "credentials.credential for node " + node.getName());
|
||||||
SshClient ssh = createSshClientOncePortIsListeningOnNode(node);
|
SshClient ssh = createSshClientOncePortIsListeningOnNode(node);
|
||||||
try {
|
try {
|
||||||
ssh.connect();
|
ssh.connect();
|
||||||
|
|
|
@ -20,12 +20,11 @@
|
||||||
package org.jclouds.gogrid.compute.functions;
|
package org.jclouds.gogrid.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -54,7 +53,6 @@ import com.google.common.collect.Iterables;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
public static final Pattern ALL_BEFORE_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
@ -74,14 +72,14 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImage().getId() + "")
|
return input.getProviderId().equals(instance.getImage().getId() + "")
|
||||||
&& (input.getLocation() == null || input.getLocation().getId().equals(
|
&& (input.getLocation() == null || input.getLocation().getId().equals(
|
||||||
instance.getDatacenter().getId() + ""));
|
instance.getDatacenter().getId() + ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client,
|
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.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
||||||
this.client = checkNotNull(client, "client");
|
this.client = checkNotNull(client, "client");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
|
@ -90,8 +88,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata apply(Server from) {
|
public NodeMetadata apply(Server from) {
|
||||||
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
|
String tag = parseTagFromName(from.getName());
|
||||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
|
||||||
Set<String> ipSet = ImmutableSet.of(from.getIp().getIp());
|
Set<String> ipSet = ImmutableSet.of(from.getIp().getIp());
|
||||||
NodeState state = serverStateToNodeState.get(from.getState());
|
NodeState state = serverStateToNodeState.get(from.getState());
|
||||||
Credentials creds = client.getServerServices().getServerCredentialsList().get(from.getName());
|
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);
|
logger.warn("could not find a matching image for server %s", from);
|
||||||
}
|
}
|
||||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get(from
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get(from
|
||||||
.getDatacenter().getId()
|
.getDatacenter().getId()
|
||||||
+ ""), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList.<String> of(),
|
+ ""), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList.<String> of(),
|
||||||
ImmutableMap.<String, String> of(), creds);
|
ImmutableMap.<String, String> of(), creds);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,11 +20,10 @@
|
||||||
package org.jclouds.ibmdev.compute.functions;
|
package org.jclouds.ibmdev.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -50,7 +49,6 @@ import com.google.common.collect.ImmutableSet;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata> {
|
public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata> {
|
||||||
public static final Pattern ALL_BEFORE_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
@ -61,11 +59,9 @@ public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata>
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
InstanceToNodeMetadata(Map<Instance.Status, NodeState> instanceStateToNodeState,
|
InstanceToNodeMetadata(Map<Instance.Status, NodeState> instanceStateToNodeState,
|
||||||
Map<String, ? extends Image> images,
|
Map<String, ? extends Image> images, @Named("CREDENTIALS") Map<String, String> credentialsMap,
|
||||||
@Named("CREDENTIALS") Map<String, String> credentialsMap,
|
|
||||||
Map<String, ? extends Location> locations) {
|
Map<String, ? extends Location> locations) {
|
||||||
this.instanceStateToNodeState = checkNotNull(instanceStateToNodeState,
|
this.instanceStateToNodeState = checkNotNull(instanceStateToNodeState, "instanceStateToNodeState");
|
||||||
"instanceStateToNodeState");
|
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
|
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
|
||||||
this.locations = checkNotNull(locations, "locations");
|
this.locations = checkNotNull(locations, "locations");
|
||||||
|
@ -73,16 +69,14 @@ public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata apply(Instance from) {
|
public NodeMetadata apply(Instance from) {
|
||||||
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
|
String tag = parseTagFromName(from.getName());
|
||||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
Set<String> ipSet = from.getIp() != null ? ImmutableSet.of(from.getIp()) : ImmutableSet.<String> of();
|
||||||
Set<String> ipSet = from.getIp() != null ? ImmutableSet.of(from.getIp()) : ImmutableSet
|
|
||||||
.<String> of();
|
|
||||||
NodeState state = instanceStateToNodeState.get(from.getStatus());
|
NodeState state = instanceStateToNodeState.get(from.getStatus());
|
||||||
Image image = images.get(from.getImageId());
|
Image image = images.get(from.getImageId());
|
||||||
String key = tag != null ? credentialsMap.get(tag) : null;
|
String key = tag != null ? credentialsMap.get(tag) : null;
|
||||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get(image
|
||||||
.get(image.getLocation()), null, ImmutableMap.<String, String> of(), tag, image,
|
.getLocation()), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList
|
||||||
state, ipSet, ImmutableList.<String> of(), ImmutableMap.<String, String> of(),
|
.<String> of(), ImmutableMap.<String, String> of(), new Credentials(
|
||||||
new Credentials(image.getDefaultCredentials().identity, key));
|
image.getDefaultCredentials().identity, key));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,12 +20,11 @@
|
||||||
package org.jclouds.rackspace.cloudservers.compute.functions;
|
package org.jclouds.rackspace.cloudservers.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -50,7 +49,6 @@ import com.google.common.collect.Iterables;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
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 Location location;
|
||||||
private final Map<ServerStatus, NodeState> serverToNodeState;
|
private final Map<ServerStatus, NodeState> serverToNodeState;
|
||||||
private final Set<? extends Image> images;
|
private final Set<? extends Image> images;
|
||||||
|
@ -70,13 +68,13 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImageId() + "")
|
return input.getProviderId().equals(instance.getImageId() + "")
|
||||||
&& (input.getLocation() == null || input.getLocation().equals(location.getParent()));
|
&& (input.getLocation() == null || input.getLocation().equals(location.getParent()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState, Set<? extends Image> images,
|
ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState, Set<? extends Image> images,
|
||||||
Location location) {
|
Location location) {
|
||||||
this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
this.location = checkNotNull(location, "location");
|
this.location = checkNotNull(location, "location");
|
||||||
|
@ -84,8 +82,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata apply(Server from) {
|
public NodeMetadata apply(Server from) {
|
||||||
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from.getName());
|
String tag = parseTagFromName(from.getName());
|
||||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
|
||||||
Location host = new LocationImpl(LocationScope.HOST, from.getHostId(), from.getHostId(), location);
|
Location host = new LocationImpl(LocationScope.HOST, from.getHostId(), from.getHostId(), location);
|
||||||
Image image = null;
|
Image image = null;
|
||||||
try {
|
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);
|
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(),
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", host, null, from.getMetadata(),
|
||||||
tag, image, serverToNodeState.get(from.getStatus()), from.getAddresses().getPublicAddresses(), from
|
tag, image, serverToNodeState.get(from.getStatus()), from.getAddresses().getPublicAddresses(), from
|
||||||
.getAddresses().getPrivateAddresses(), ImmutableMap.<String, String> of(), null);
|
.getAddresses().getPrivateAddresses(), ImmutableMap.<String, String> of(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@ package org.jclouds.rimuhosting.miro.compute.config;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
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 static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.PROPERTY_RIMUHOSTING_DEFAULT_DC;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -124,7 +125,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Named("DEFAULT")
|
@Named("DEFAULT")
|
||||||
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.sizeId("MIRO1B").osFamily(UBUNTU).architecture(Architecture.X86_32).imageNameMatches(
|
return template.sizeId("MIRO1B").osFamily(UBUNTU).architecture(Architecture.X86_32).imageNameMatches(
|
||||||
".*10\\.?04.*");
|
".*10\\.?04.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -183,7 +184,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client,
|
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.client = client;
|
||||||
this.getPublicAddresses = getPublicAddresses;
|
this.getPublicAddresses = getPublicAddresses;
|
||||||
this.runningStateToNodeState = runningStateToNodeState;
|
this.runningStateToNodeState = runningStateToNodeState;
|
||||||
|
@ -192,13 +194,13 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(String tag, String name, Template template) {
|
public NodeMetadata execute(String tag, String name, Template template) {
|
||||||
NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(),
|
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());
|
Server server = client.getServer(serverResponse.getServer().getId());
|
||||||
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template
|
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template
|
||||||
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage(),
|
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage(),
|
||||||
runningStateToNodeState.get(server.getState()), getPublicAddresses.apply(server), ImmutableList
|
runningStateToNodeState.get(server.getState()), getPublicAddresses.apply(server), ImmutableList
|
||||||
.<String> of(), ImmutableMap.<String, String> of(), new Credentials("root", serverResponse
|
.<String> of(), ImmutableMap.<String, String> of(), new Credentials("root", serverResponse
|
||||||
.getNewInstanceRequest().getCreateOptions().getPassword()));
|
.getNewInstanceRequest().getCreateOptions().getPassword()));
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +213,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected RimuHostingListNodesStrategy(RimuHostingClient client,
|
protected RimuHostingListNodesStrategy(RimuHostingClient client,
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||||
}
|
}
|
||||||
|
@ -236,7 +238,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected RimuHostingGetNodeMetadataStrategy(RimuHostingClient client,
|
protected RimuHostingGetNodeMetadataStrategy(RimuHostingClient client,
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||||
}
|
}
|
||||||
|
@ -251,11 +253,11 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final Map<RunningState, NodeState> runningStateToNodeState = ImmutableMap.<RunningState, NodeState> builder()
|
static final Map<RunningState, NodeState> runningStateToNodeState = ImmutableMap.<RunningState, NodeState> builder()
|
||||||
.put(RunningState.RUNNING, NodeState.RUNNING)//
|
.put(RunningState.RUNNING, NodeState.RUNNING)//
|
||||||
.put(RunningState.NOTRUNNING, NodeState.SUSPENDED)//
|
.put(RunningState.NOTRUNNING, NodeState.SUSPENDED)//
|
||||||
.put(RunningState.POWERCYCLING, NodeState.PENDING)//
|
.put(RunningState.POWERCYCLING, NodeState.PENDING)//
|
||||||
.put(RunningState.RESTARTING, NodeState.PENDING)//
|
.put(RunningState.RESTARTING, NodeState.PENDING)//
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -286,16 +288,16 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImageId())
|
return input.getProviderId().equals(instance.getImageId())
|
||||||
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation()
|
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation()
|
||||||
.equals(location.getParent()));
|
.equals(location.getParent()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Inject
|
@Inject
|
||||||
ServerToNodeMetadata(Function<Server, Iterable<String>> getPublicAddresses,
|
ServerToNodeMetadata(Function<Server, Iterable<String>> getPublicAddresses,
|
||||||
Map<RunningState, NodeState> runningStateToNodeState, Set<? extends Image> images,
|
Map<RunningState, NodeState> runningStateToNodeState, Set<? extends Image> images,
|
||||||
Set<? extends Location> locations) {
|
Set<? extends Location> locations) {
|
||||||
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
|
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
|
||||||
this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState");
|
this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
|
@ -306,8 +308,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
public NodeMetadata apply(Server from) {
|
public NodeMetadata apply(Server from) {
|
||||||
|
|
||||||
Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from.getLocation()
|
Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from.getLocation()
|
||||||
.getName(), null);
|
.getName(), null);
|
||||||
String tag = from.getName().replaceAll("-[0-9]+", "");
|
String tag = parseTagFromName(from.getName());
|
||||||
Credentials creds = null;
|
Credentials creds = null;
|
||||||
|
|
||||||
Image image = null;
|
Image image = null;
|
||||||
|
@ -318,8 +320,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
NodeState state = runningStateToNodeState.get(from.getState());
|
NodeState state = runningStateToNodeState.get(from.getState());
|
||||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
|
||||||
.<String, String> of(), tag, image, state, getPublicAddresses.apply(from), ImmutableList.<String> of(),
|
.<String, String> of(), tag, image, state, getPublicAddresses.apply(from), ImmutableList
|
||||||
ImmutableMap.<String, String> of(), creds);
|
.<String> of(), ImmutableMap.<String, String> of(), creds);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,14 +331,14 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
public Iterable<String> apply(Server server) {
|
public Iterable<String> apply(Server server) {
|
||||||
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(ImmutableList.of(server
|
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(ImmutableList.of(server
|
||||||
.getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps());
|
.getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Location getDefaultLocation(@Named(PROPERTY_RIMUHOSTING_DEFAULT_DC) final String defaultDC,
|
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>() {
|
return Iterables.find(locations, new Predicate<Location>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -350,14 +352,14 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Set<? extends Location> getDefaultLocations(RimuHostingClient sync, LogHolder holder,
|
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();
|
final Set<Location> locations = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing locations");
|
holder.logger.debug(">> providing locations");
|
||||||
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
||||||
for (final PricingPlan from : sync.getPricingPlanList()) {
|
for (final PricingPlan from : sync.getPricingPlanList()) {
|
||||||
try {
|
try {
|
||||||
locations.add(new LocationImpl(LocationScope.ZONE, from.getDataCenter().getId(), from.getDataCenter()
|
locations.add(new LocationImpl(LocationScope.ZONE, from.getDataCenter().getId(), from.getDataCenter()
|
||||||
.getName(), provider));
|
.getName(), provider));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
holder.logger.warn("datacenter not present in " + from.getId());
|
holder.logger.warn("datacenter not present in " + from.getId());
|
||||||
}
|
}
|
||||||
|
@ -380,9 +382,10 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Set<? extends Size> provideSizes(RimuHostingClient sync, Set<? extends Image> images,
|
protected Set<? extends Size> provideSizes(RimuHostingClient sync, Set<? extends Image> images,
|
||||||
Set<? extends Location> locations, LogHolder holder,
|
Set<? extends Location> locations, LogHolder holder,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, Function<ComputeMetadata, String> indexer)
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor,
|
||||||
throws InterruptedException, TimeoutException, ExecutionException {
|
Function<ComputeMetadata, String> indexer) throws InterruptedException, TimeoutException,
|
||||||
|
ExecutionException {
|
||||||
final Set<Size> sizes = Sets.newHashSet();
|
final Set<Size> sizes = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing sizes");
|
holder.logger.debug(">> providing sizes");
|
||||||
for (final PricingPlan from : sync.getPricingPlanList()) {
|
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
|
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) {
|
} catch (NullPointerException e) {
|
||||||
holder.logger.warn("datacenter not present in " + from.getId());
|
holder.logger.warn("datacenter not present in " + from.getId());
|
||||||
}
|
}
|
||||||
|
@ -417,7 +420,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Set<? extends Image> provideImages(final RimuHostingClient sync, LogHolder holder,
|
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();
|
final Set<Image> images = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing images");
|
holder.logger.debug(">> providing images");
|
||||||
for (final org.jclouds.rimuhosting.miro.domain.Image from : sync.getImageList()) {
|
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
|
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",
|
.<String, String> of(), from.getDescription(), version, os, osDescription, arch, new Credentials(
|
||||||
null)));
|
"root", null)));
|
||||||
}
|
}
|
||||||
holder.logger.debug("<< images(%d)", images.size());
|
holder.logger.debug("<< images(%d)", images.size());
|
||||||
return images;
|
return images;
|
||||||
|
|
|
@ -20,12 +20,11 @@
|
||||||
package org.jclouds.slicehost.compute.functions;
|
package org.jclouds.slicehost.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -47,7 +46,6 @@ import com.google.common.collect.Iterables;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
|
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 Location location;
|
||||||
private final Map<Slice.Status, NodeState> sliceToNodeState;
|
private final Map<Slice.Status, NodeState> sliceToNodeState;
|
||||||
private final Set<? extends Image> images;
|
private final Set<? extends Image> images;
|
||||||
|
@ -70,7 +68,7 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SliceToNodeMetadata(Map<Slice.Status, NodeState> sliceStateToNodeState, Set<? extends Image> images,
|
SliceToNodeMetadata(Map<Slice.Status, NodeState> sliceStateToNodeState, Set<? extends Image> images,
|
||||||
Location location) {
|
Location location) {
|
||||||
this.sliceToNodeState = checkNotNull(sliceStateToNodeState, "sliceStateToNodeState");
|
this.sliceToNodeState = checkNotNull(sliceStateToNodeState, "sliceStateToNodeState");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
this.location = checkNotNull(location, "location");
|
this.location = checkNotNull(location, "location");
|
||||||
|
@ -78,8 +76,7 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata apply(Slice from) {
|
public NodeMetadata apply(Slice from) {
|
||||||
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from.getName());
|
String tag = parseTagFromName(from.getName());
|
||||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
|
||||||
Image image = null;
|
Image image = null;
|
||||||
try {
|
try {
|
||||||
image = Iterables.find(images, new FindImageForSlice(from));
|
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
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
|
||||||
.<String, String> of(), tag, image, sliceToNodeState.get(from.getStatus()), Iterables.filter(from
|
.<String, String> of(), tag, image, sliceToNodeState.get(from.getStatus()), Iterables.filter(from
|
||||||
.getAddresses(), new Predicate<String>() {
|
.getAddresses(), new Predicate<String>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(String input) {
|
public boolean apply(String input) {
|
||||||
|
|
|
@ -20,12 +20,11 @@
|
||||||
package org.jclouds.vcloud.compute.functions;
|
package org.jclouds.vcloud.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -49,8 +48,8 @@ import org.jclouds.vcloud.domain.VAppStatus;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link VCloudComputeServiceContext}; requires
|
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
|
||||||
* {@link BaseVCloudComputeClient} bound.
|
* bound.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -67,12 +66,10 @@ public class VCloudGetNodeMetadata {
|
||||||
protected final GetExtra getExtra;
|
protected final GetExtra getExtra;
|
||||||
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
|
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
|
||||||
|
|
||||||
public static final Pattern TAG_PATTERN_WITHOUT_TEMPLATE = Pattern.compile("([^-]+)-[0-9a-f]+");
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient,
|
VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient,
|
||||||
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
|
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
|
||||||
FindLocationForResource findLocationForResourceInVDC, Provider<Set<? extends Image>> images) {
|
FindLocationForResource findLocationForResourceInVDC, Provider<Set<? extends Image>> images) {
|
||||||
this.client = checkNotNull(client, "client");
|
this.client = checkNotNull(client, "client");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
this.getExtra = checkNotNull(getExtra, "getExtra");
|
this.getExtra = checkNotNull(getExtra, "getExtra");
|
||||||
|
@ -83,22 +80,14 @@ public class VCloudGetNodeMetadata {
|
||||||
|
|
||||||
public NodeMetadata execute(String in) {
|
public NodeMetadata execute(String in) {
|
||||||
URI id = URI.create(in);
|
URI id = URI.create(in);
|
||||||
VApp vApp = client.getVApp(id);
|
VApp from = client.getVApp(id);
|
||||||
if (vApp == null)
|
if (from == null)
|
||||||
return null;
|
return null;
|
||||||
|
String tag = parseTagFromName(from.getName());
|
||||||
String tag = null;
|
Location location = findLocationForResourceInVDC.apply(from.getVDC());
|
||||||
Image image = null;
|
return new NodeMetadataImpl(in, from.getName(), in, location, from.getId(), ImmutableMap.<String, String> of(),
|
||||||
Matcher matcher = TAG_PATTERN_WITHOUT_TEMPLATE.matcher(vApp.getName());
|
tag, null, vAppStatusToNodeState.get(from.getStatus()), computeClient.getPublicAddresses(id),
|
||||||
if (matcher.find()) {
|
computeClient.getPrivateAddresses(id), getExtra.apply(from), null);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue