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;
|
||||||
|
@ -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());
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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 {
|
||||||
|
@ -97,4 +94,5 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
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;
|
||||||
|
@ -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;
|
||||||
|
@ -307,7 +309,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,8 +383,9 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@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()) {
|
||||||
|
@ -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;
|
||||||
|
@ -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));
|
||||||
|
|
|
@ -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,8 +66,6 @@ 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,
|
||||||
|
@ -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());
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue