mirror of https://github.com/apache/jclouds.git
Issue 888, 895: temporary workaround to stop openstack-nova-ec2 from using # characters
This commit is contained in:
parent
f70ef81828
commit
6f6b958aad
|
@ -21,6 +21,7 @@ package org.jclouds.ec2;
|
||||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG;
|
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG;
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
|
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER;
|
||||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS;
|
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS;
|
||||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT;
|
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT;
|
||||||
|
@ -44,6 +45,7 @@ public class EC2PropertiesBuilder extends PropertiesBuilder {
|
||||||
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "*");
|
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "*");
|
||||||
properties.setProperty(PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT, "500");
|
properties.setProperty(PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT, "500");
|
||||||
properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "false");
|
properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "false");
|
||||||
|
properties.setProperty(RESOURCENAME_DELIMITER, "#");
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,16 @@ package org.jclouds.ec2.compute;
|
||||||
import static com.google.common.collect.Iterables.concat;
|
import static com.google.common.collect.Iterables.concat;
|
||||||
import static com.google.common.collect.Iterables.filter;
|
import static com.google.common.collect.Iterables.filter;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER;
|
||||||
import static org.jclouds.util.Preconditions2.checkNotEmpty;
|
import static org.jclouds.util.Preconditions2.checkNotEmpty;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -73,8 +73,9 @@ import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -111,6 +112,10 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
this.securityGroupMap = securityGroupMap;
|
this.securityGroupMap = securityGroupMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(optional = true)
|
||||||
|
@Named(RESOURCENAME_DELIMITER)
|
||||||
|
char delimiter = '#';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws IllegalStateException If the security group was in use
|
* @throws IllegalStateException If the security group was in use
|
||||||
*/
|
*/
|
||||||
|
@ -118,7 +123,7 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
void deleteSecurityGroup(String region, String group) {
|
void deleteSecurityGroup(String region, String group) {
|
||||||
checkNotEmpty(region, "region");
|
checkNotEmpty(region, "region");
|
||||||
checkNotEmpty(group, "group");
|
checkNotEmpty(group, "group");
|
||||||
String groupName = String.format("jclouds#%s#%s", group, region);
|
String groupName = String.format("jclouds#%s#%s", group, region).replace('#', delimiter);
|
||||||
if (ec2Client.getSecurityGroupServices().describeSecurityGroupsInRegion(region, groupName).size() > 0) {
|
if (ec2Client.getSecurityGroupServices().describeSecurityGroupsInRegion(region, groupName).size() > 0) {
|
||||||
logger.debug(">> deleting securityGroup(%s)", groupName);
|
logger.debug(">> deleting securityGroup(%s)", groupName);
|
||||||
ec2Client.getSecurityGroupServices().deleteSecurityGroupInRegion(region, groupName);
|
ec2Client.getSecurityGroupServices().deleteSecurityGroupInRegion(region, groupName);
|
||||||
|
@ -133,11 +138,11 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
for (KeyPair keyPair : ec2Client.getKeyPairServices().describeKeyPairsInRegion(region)) {
|
for (KeyPair keyPair : ec2Client.getKeyPairServices().describeKeyPairsInRegion(region)) {
|
||||||
if (
|
if (
|
||||||
// when the keypair is unique per group
|
// when the keypair is unique per group
|
||||||
keyPair.getKeyName().equals("jclouds#" + group)
|
keyPair.getKeyName().equals("jclouds"+ delimiter + group)
|
||||||
|| keyPair.getKeyName().matches(String.format("jclouds#%s#%s", group, "[0-9a-f]+"))
|
|| keyPair.getKeyName().matches(String.format("jclouds#%s#%s", group, "[0-9a-f]+").replace('#', delimiter))
|
||||||
// old keypair pattern too verbose as it has an unnecessary
|
// old keypair pattern too verbose as it has an unnecessary
|
||||||
// region qualifier
|
// region qualifier
|
||||||
|| keyPair.getKeyName().matches(String.format("jclouds#%s#%s#%s", group, region, "[0-9a-f]+"))) {
|
|| keyPair.getKeyName().matches(String.format("jclouds#%s#%s#%s", group, region, "[0-9a-f]+").replace('#', delimiter))) {
|
||||||
Set<String> instancesUsingKeyPair = extractIdsFromInstances(filter(concat(ec2Client.getInstanceServices()
|
Set<String> instancesUsingKeyPair = extractIdsFromInstances(filter(concat(ec2Client.getInstanceServices()
|
||||||
.describeInstancesInRegion(region)), usingKeyPairAndNotDead(keyPair)));
|
.describeInstancesInRegion(region)), usingKeyPairAndNotDead(keyPair)));
|
||||||
if (instancesUsingKeyPair.size() > 0) {
|
if (instancesUsingKeyPair.size() > 0) {
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
package org.jclouds.ec2.compute.functions;
|
package org.jclouds.ec2.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ import org.jclouds.logging.Logger;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -75,7 +76,11 @@ public class CreateUniqueKeyPair implements Function<RegionAndName, KeyPair> {
|
||||||
return keyPair;
|
return keyPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(optional=true)
|
||||||
|
@Named(RESOURCENAME_DELIMITER)
|
||||||
|
char delimiter = '#';
|
||||||
|
|
||||||
private String getNextName(String region, String group) {
|
private String getNextName(String region, String group) {
|
||||||
return String.format("jclouds#%s#%s#%s", group, region, randomSuffix.get());
|
return String.format("jclouds#%s#%s#%s", group, region, randomSuffix.get()).replace('#', delimiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,16 @@ package org.jclouds.ec2.compute.functions;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Predicates.not;
|
import static com.google.common.base.Predicates.not;
|
||||||
import static com.google.common.collect.Iterables.filter;
|
import static com.google.common.collect.Iterables.filter;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.collect.Memoized;
|
import org.jclouds.collect.Memoized;
|
||||||
|
@ -60,11 +61,12 @@ import com.google.common.base.Supplier;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSet.Builder;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -195,6 +197,10 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(optional = true)
|
||||||
|
@Named(RESOURCENAME_DELIMITER)
|
||||||
|
char delimiter = '#';
|
||||||
|
|
||||||
private String parseGroupFrom(final RunningInstance instance, final Set<String> data) {
|
private String parseGroupFrom(final RunningInstance instance, final Set<String> data) {
|
||||||
String group = null;
|
String group = null;
|
||||||
try {
|
try {
|
||||||
|
@ -202,13 +208,13 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(String input) {
|
public boolean apply(String input) {
|
||||||
return input.startsWith("jclouds#") && input.contains("#" + instance.getRegion());
|
return input.startsWith("jclouds" + delimiter) && input.contains(delimiter + instance.getRegion());
|
||||||
}
|
}
|
||||||
})).split("#")[1];
|
})).split(delimiter + "")[1];
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
logger.debug("no group parsed from %s's data: %s", instance.getId(), data);
|
logger.debug("no group parsed from %s's data: %s", instance.getId(), data);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
logger.debug("too many groups match %s; %s's data: %s", "jclouds#", instance.getId(), data);
|
logger.debug("too many groups match %s%s; %s's data: %s", "jclouds", delimiter, instance.getId(), data);
|
||||||
}
|
}
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,13 @@ package org.jclouds.ec2.compute.strategy;
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER;
|
||||||
import static org.jclouds.crypto.SshKeys.fingerprintPrivateKey;
|
import static org.jclouds.crypto.SshKeys.fingerprintPrivateKey;
|
||||||
import static org.jclouds.crypto.SshKeys.sha1PrivateKey;
|
import static org.jclouds.crypto.SshKeys.sha1PrivateKey;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -47,6 +47,7 @@ import com.google.common.base.Function;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSet.Builder;
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -159,12 +160,16 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions {
|
||||||
return keyPair.getKeyName();
|
return keyPair.getKeyName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(optional = true)
|
||||||
|
@Named(RESOURCENAME_DELIMITER)
|
||||||
|
char delimiter = '#';
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public Set<String> getSecurityGroupsForTagAndOptions(String region, @Nullable String group, TemplateOptions options) {
|
public Set<String> getSecurityGroupsForTagAndOptions(String region, @Nullable String group, TemplateOptions options) {
|
||||||
Builder<String> groups = ImmutableSet.<String> builder();
|
Builder<String> groups = ImmutableSet.<String> builder();
|
||||||
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
String markerGroup = String.format("jclouds#%s#%s", group, region);
|
String markerGroup = String.format("jclouds#%s#%s", group, region).replace('#', delimiter);
|
||||||
groups.add(markerGroup);
|
groups.add(markerGroup);
|
||||||
|
|
||||||
RegionNameAndIngressRules regionNameAndIngessRulesForMarkerGroup;
|
RegionNameAndIngressRules regionNameAndIngessRulesForMarkerGroup;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||||
import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME;
|
import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME;
|
||||||
import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS;
|
import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER;
|
||||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||||
|
|
||||||
|
@ -42,6 +43,8 @@ public class NovaEC2PropertiesBuilder extends EC2PropertiesBuilder {
|
||||||
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:8773/services/Cloud");
|
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:8773/services/Cloud");
|
||||||
properties.setProperty(PROPERTY_REGIONS, "nova");
|
properties.setProperty(PROPERTY_REGIONS, "nova");
|
||||||
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "admin");
|
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "admin");
|
||||||
|
// hash characters are banned
|
||||||
|
properties.setProperty(RESOURCENAME_DELIMITER, "-");
|
||||||
// often, we are dealing with IP addresses, not hostnames
|
// often, we are dealing with IP addresses, not hostnames
|
||||||
properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true");
|
properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true");
|
||||||
properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true");
|
properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true");
|
||||||
|
|
Loading…
Reference in New Issue