mirror of https://github.com/apache/jclouds.git
Banned use of InetAddress and InetSocketAddress as these break google appengine. Introduced IPSocket class instead
This commit is contained in:
parent
6a7b9a0a86
commit
f297c9d7d5
|
@ -21,8 +21,6 @@ package org.jclouds.aws.ec2.binders;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.util.EC2Utils;
|
||||
|
@ -36,21 +34,17 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class BindInetAddressesToIndexedFormParams implements Binder {
|
||||
public class BindPublicIpsToIndexedFormParams implements Binder {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input") instanceof InetAddress[],
|
||||
"this binder is only valid for InetAddress[] : " + input.getClass());
|
||||
InetAddress[] addresses = (InetAddress[]) input;
|
||||
String[] addressStrings = new String[addresses.length];
|
||||
for (int i = 0; i < addresses.length; i++) {
|
||||
addressStrings[i] = addresses[i].getHostAddress();
|
||||
}
|
||||
EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest<?>) request, "PublicIp",
|
||||
addressStrings);
|
||||
checkArgument(checkNotNull(input, "input") instanceof String[],
|
||||
"this binder is only valid for String[] : " + input.getClass());
|
||||
String[] addressStrings = (String[]) input;
|
||||
EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest<?>) request,
|
||||
"PublicIp", addressStrings);
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.compute.functions;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.util.Utils.nullSafeSet;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
@ -161,8 +160,8 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
|
||||
NodeState state = instanceToNodeState.get(instance.getInstanceState());
|
||||
|
||||
Set<InetAddress> publicAddresses = nullSafeSet(instance.getIpAddress());
|
||||
Set<InetAddress> privateAddresses = nullSafeSet(instance.getPrivateIpAddress());
|
||||
Set<String> publicAddresses = nullSafeSet(instance.getIpAddress());
|
||||
Set<String> privateAddresses = nullSafeSet(instance.getPrivateIpAddress());
|
||||
|
||||
Map<String, String> extra = getExtra(instance);
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.compute.strategy;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -53,9 +52,8 @@ public class EC2DestroyLoadBalancerStrategy implements DestroyLoadBalancerStrate
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(InetAddress loadBalancer) {
|
||||
Map<String, String> tuple = EC2Utils.getLoadBalancerNameAndRegionFromDnsName(loadBalancer
|
||||
.getHostName());
|
||||
public boolean execute(String loadBalancer) {
|
||||
Map<String, String> tuple = EC2Utils.getLoadBalancerNameAndRegionFromDnsName(loadBalancer);
|
||||
// Only one load balancer per DNS name is expected
|
||||
for (String key : tuple.keySet()) {
|
||||
elbClient.deleteLoadBalancerInRegion(key, tuple.get(key));
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.config;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
@ -67,6 +66,7 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
@ -106,8 +106,8 @@ public class EC2RestClientModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 1, TimeUnit.SECONDS);
|
||||
protected Predicate<IPSocket> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<IPSocket>(open, 130, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.jclouds.aws.ec2.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import com.google.inject.internal.Nullable;
|
||||
|
||||
/**
|
||||
|
@ -35,9 +33,9 @@ public class PublicIpInstanceIdPair implements Comparable<PublicIpInstanceIdPair
|
|||
private final String region;
|
||||
@Nullable
|
||||
private final String instanceId;
|
||||
private final InetAddress publicIp;
|
||||
private final String publicIp;
|
||||
|
||||
public PublicIpInstanceIdPair(String region, InetAddress publicIp, @Nullable String instanceId) {
|
||||
public PublicIpInstanceIdPair(String region, String publicIp, @Nullable String instanceId) {
|
||||
this.region = checkNotNull(region, "region");
|
||||
this.instanceId = instanceId;
|
||||
this.publicIp = checkNotNull(publicIp, "publicIp");
|
||||
|
@ -54,8 +52,7 @@ public class PublicIpInstanceIdPair implements Comparable<PublicIpInstanceIdPair
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
public int compareTo(PublicIpInstanceIdPair o) {
|
||||
return (this == o) ? 0 : getPublicIp().getHostAddress().compareTo(
|
||||
o.getPublicIp().getHostAddress());
|
||||
return (this == o) ? 0 : getPublicIp().compareTo(o.getPublicIp());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +65,7 @@ public class PublicIpInstanceIdPair implements Comparable<PublicIpInstanceIdPair
|
|||
/**
|
||||
* The public IP address.
|
||||
*/
|
||||
public InetAddress getPublicIp() {
|
||||
public String getPublicIp() {
|
||||
return publicIp;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.aws.ec2.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -128,7 +127,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
private final InstanceState instanceState;
|
||||
private final String instanceType;
|
||||
@Nullable
|
||||
private final InetAddress ipAddress;
|
||||
private final String ipAddress;
|
||||
@Nullable
|
||||
private final String kernelId;
|
||||
@Nullable
|
||||
|
@ -141,7 +140,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
@Nullable
|
||||
private final String privateDnsName;
|
||||
@Nullable
|
||||
private final InetAddress privateIpAddress;
|
||||
private final String privateIpAddress;
|
||||
private final Set<String> productCodes;
|
||||
@Nullable
|
||||
private final String ramdiskId;
|
||||
|
@ -163,10 +162,10 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
public RunningInstance(String region, Iterable<String> groupIds,
|
||||
@Nullable String amiLaunchIndex, @Nullable String dnsName, String imageId,
|
||||
String instanceId, InstanceState instanceState, String instanceType,
|
||||
@Nullable InetAddress ipAddress, @Nullable String kernelId, @Nullable String keyName,
|
||||
@Nullable String ipAddress, @Nullable String kernelId, @Nullable String keyName,
|
||||
Date launchTime, boolean monitoring, String availabilityZone,
|
||||
@Nullable String platform, @Nullable String privateDnsName,
|
||||
@Nullable InetAddress privateIpAddress, Set<String> productCodes,
|
||||
@Nullable String privateIpAddress, Set<String> productCodes,
|
||||
@Nullable String ramdiskId, @Nullable String reason, @Nullable String subnetId,
|
||||
@Nullable String vpcId, RootDeviceType rootDeviceType, @Nullable String rootDeviceName,
|
||||
Map<String, EbsBlockDevice> ebsBlockDevices) {
|
||||
|
@ -254,7 +253,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
/**
|
||||
* Specifies the IP address of the instance.
|
||||
*/
|
||||
public InetAddress getIpAddress() {
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
|
@ -311,7 +310,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
/**
|
||||
* Specifies the private IP address that is assigned to the instance (Amazon VPC).
|
||||
*/
|
||||
public InetAddress getPrivateIpAddress() {
|
||||
public String getPrivateIpAddress() {
|
||||
return privateIpAddress;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.services;
|
|||
import static org.jclouds.aws.ec2.reference.EC2Parameters.ACTION;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -29,7 +28,7 @@ import javax.ws.rs.FormParam;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
import org.jclouds.aws.ec2.binders.BindInetAddressesToIndexedFormParams;
|
||||
import org.jclouds.aws.ec2.binders.BindPublicIpsToIndexedFormParams;
|
||||
import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair;
|
||||
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
|
||||
import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler;
|
||||
|
@ -38,11 +37,9 @@ import org.jclouds.aws.filters.FormSigner;
|
|||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.FormParams;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.VirtualHost;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.InetAddressToHostAddress;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
|
@ -64,7 +61,7 @@ public interface ElasticIPAddressAsyncClient {
|
|||
@Path("/")
|
||||
@XMLResponseParser(AllocateAddressResponseHandler.class)
|
||||
@FormParams(keys = ACTION, values = "AllocateAddress")
|
||||
ListenableFuture<InetAddress> allocateAddressInRegion(
|
||||
ListenableFuture<String> allocateAddressInRegion(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
|
@ -75,7 +72,7 @@ public interface ElasticIPAddressAsyncClient {
|
|||
@FormParams(keys = ACTION, values = "AssociateAddress")
|
||||
ListenableFuture<Void> associateAddressInRegion(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
|
||||
@FormParam("PublicIp") @ParamParser(InetAddressToHostAddress.class) InetAddress publicIp,
|
||||
@FormParam("PublicIp") String publicIp,
|
||||
@FormParam("InstanceId") String instanceId);
|
||||
|
||||
/**
|
||||
|
@ -86,7 +83,7 @@ public interface ElasticIPAddressAsyncClient {
|
|||
@FormParams(keys = ACTION, values = "DisassociateAddress")
|
||||
ListenableFuture<Void> disassociateAddressInRegion(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
|
||||
@FormParam("PublicIp") @ParamParser(InetAddressToHostAddress.class) InetAddress publicIp);
|
||||
@FormParam("PublicIp") String publicIp);
|
||||
|
||||
/**
|
||||
* @see BaseEC2Client#releaseAddressInRegion
|
||||
|
@ -96,7 +93,7 @@ public interface ElasticIPAddressAsyncClient {
|
|||
@FormParams(keys = ACTION, values = "ReleaseAddress")
|
||||
ListenableFuture<Void> releaseAddressInRegion(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
|
||||
@FormParam("PublicIp") @ParamParser(InetAddressToHostAddress.class) InetAddress publicIp);
|
||||
@FormParam("PublicIp") String publicIp);
|
||||
|
||||
/**
|
||||
* @see BaseEC2Client#describeAddressesInRegion
|
||||
|
@ -107,6 +104,6 @@ public interface ElasticIPAddressAsyncClient {
|
|||
@XMLResponseParser(DescribeAddressesResponseHandler.class)
|
||||
ListenableFuture<? extends Set<PublicIpInstanceIdPair>> describeAddressesInRegion(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
|
||||
@BinderParam(BindInetAddressesToIndexedFormParams.class) InetAddress... publicIps);
|
||||
@BinderParam(BindPublicIpsToIndexedFormParams.class) String... publicIps);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.services;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -48,7 +47,7 @@ public interface ElasticIPAddressClient {
|
|||
* @see #disassociateAddress
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-AllocateAddress.html"
|
||||
*/
|
||||
InetAddress allocateAddressInRegion(@Nullable String region);
|
||||
String allocateAddressInRegion(@Nullable String region);
|
||||
|
||||
/**
|
||||
* Associates an elastic IP address with an instance. If the IP address is currently assigned to
|
||||
|
@ -68,7 +67,7 @@ public interface ElasticIPAddressClient {
|
|||
* @see #disassociateAddress
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-AssociateAddress.html"
|
||||
*/
|
||||
void associateAddressInRegion(@Nullable String region, InetAddress publicIp, String instanceId);
|
||||
void associateAddressInRegion(@Nullable String region, String publicIp, String instanceId);
|
||||
|
||||
/**
|
||||
* Disassociates the specified elastic IP address from the instance to which it is assigned. This
|
||||
|
@ -86,7 +85,7 @@ public interface ElasticIPAddressClient {
|
|||
* @see #associateAddress
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DisdisassociateAddress.html"
|
||||
*/
|
||||
void disassociateAddressInRegion(@Nullable String region, InetAddress publicIp);
|
||||
void disassociateAddressInRegion(@Nullable String region, String publicIp);
|
||||
|
||||
/**
|
||||
* Releases an elastic IP address associated with your account.
|
||||
|
@ -102,7 +101,7 @@ public interface ElasticIPAddressClient {
|
|||
* @see #disassociateAddress
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-ReleaseAddress.html"
|
||||
*/
|
||||
void releaseAddressInRegion(@Nullable String region, InetAddress publicIp);
|
||||
void releaseAddressInRegion(@Nullable String region, String publicIp);
|
||||
|
||||
/**
|
||||
* Lists elastic IP addresses assigned to your account or provides information about a specific
|
||||
|
@ -121,6 +120,6 @@ public interface ElasticIPAddressClient {
|
|||
* />
|
||||
*/
|
||||
Set<PublicIpInstanceIdPair> describeAddressesInRegion(@Nullable String region,
|
||||
InetAddress... publicIps);
|
||||
String... publicIps);
|
||||
|
||||
}
|
|
@ -18,9 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
|
@ -29,12 +26,12 @@ import org.jclouds.logging.Logger;
|
|||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class AllocateAddressResponseHandler extends HandlerWithResult<InetAddress> {
|
||||
public class AllocateAddressResponseHandler extends HandlerWithResult<String> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private InetAddress ipAddress;
|
||||
private String ipAddress;
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
protected String currentOrNull() {
|
||||
|
@ -44,31 +41,17 @@ public class AllocateAddressResponseHandler extends HandlerWithResult<InetAddres
|
|||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (qName.equals("publicIp")) {
|
||||
ipAddress = parseInetAddress(currentOrNull());
|
||||
ipAddress = currentOrNull();
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
private InetAddress parseInetAddress(String string) {
|
||||
String[] byteStrings = string.split("\\.");
|
||||
byte[] bytes = new byte[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.warn(e, "error parsing ipAddress", currentText);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getResult() {
|
||||
public String getResult() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -73,7 +71,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
|
|||
private String instanceId;
|
||||
private InstanceState instanceState;
|
||||
private String instanceType;
|
||||
private InetAddress ipAddress;
|
||||
private String ipAddress;
|
||||
private String kernelId;
|
||||
private String keyName;
|
||||
private Date launchTime;
|
||||
|
@ -81,7 +79,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
|
|||
private String availabilityZone;
|
||||
private String platform;
|
||||
private String privateDnsName;
|
||||
private InetAddress privateIpAddress;
|
||||
private String privateIpAddress;
|
||||
private Set<String> productCodes = Sets.newHashSet();
|
||||
private String ramdiskId;
|
||||
private String reason;
|
||||
|
@ -140,7 +138,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
|
|||
} else if (qName.equals("instanceType")) {
|
||||
instanceType = currentOrNull();
|
||||
} else if (qName.equals("ipAddress")) {
|
||||
ipAddress = parseInetAddress(currentOrNull());
|
||||
ipAddress = currentOrNull();
|
||||
} else if (qName.equals("kernelId")) {
|
||||
kernelId = currentOrNull();
|
||||
} else if (qName.equals("keyName")) {
|
||||
|
@ -156,7 +154,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
|
|||
} else if (qName.equals("privateDnsName")) {
|
||||
privateDnsName = currentOrNull();
|
||||
} else if (qName.equals("privateIpAddress")) {
|
||||
privateIpAddress = parseInetAddress(currentOrNull());
|
||||
privateIpAddress = currentOrNull();
|
||||
} else if (qName.equals("ramdiskId")) {
|
||||
ramdiskId = currentOrNull();
|
||||
} else if (qName.equals("reason")) {
|
||||
|
@ -239,20 +237,6 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
|
|||
}
|
||||
}
|
||||
|
||||
private InetAddress parseInetAddress(String string) {
|
||||
String[] byteStrings = string.split("\\.");
|
||||
byte[] bytes = new byte[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.warn(e, "error parsing ipAddress", currentText);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -43,7 +41,7 @@ public class DescribeAddressesResponseHandler extends
|
|||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private Set<PublicIpInstanceIdPair> pairs = Sets.newLinkedHashSet();
|
||||
private InetAddress ipAddress;
|
||||
private String ipAddress;
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
@Inject
|
||||
@EC2
|
||||
|
@ -57,7 +55,7 @@ public class DescribeAddressesResponseHandler extends
|
|||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (qName.equals("publicIp")) {
|
||||
ipAddress = parseInetAddress(currentOrNull());
|
||||
ipAddress = currentOrNull();
|
||||
} else if (qName.equals("instanceId")) {
|
||||
instanceId = currentOrNull();
|
||||
} else if (qName.equals("item")) {
|
||||
|
@ -71,20 +69,6 @@ public class DescribeAddressesResponseHandler extends
|
|||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
private InetAddress parseInetAddress(String string) {
|
||||
String[] byteStrings = string.split("\\.");
|
||||
byte[] bytes = new byte[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.warn(e, "error parsing ipAddress", currentText);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@ import static org.testng.Assert.assertFalse;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -49,6 +47,7 @@ import org.jclouds.aws.ec2.predicates.InstanceHasIpAddress;
|
|||
import org.jclouds.aws.ec2.predicates.InstanceStateRunning;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.scriptbuilder.ScriptBuilder;
|
||||
|
@ -83,9 +82,9 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
|
|||
private KeyPair keyPair;
|
||||
private String securityGroupName;
|
||||
private String instanceId;
|
||||
private InetAddress address;
|
||||
private String address;
|
||||
|
||||
private RetryablePredicate<InetSocketAddress> socketTester;
|
||||
private RetryablePredicate<IPSocket> socketTester;
|
||||
private RetryablePredicate<RunningInstance> hasIpTester;
|
||||
private RetryablePredicate<RunningInstance> runningTester;
|
||||
|
||||
|
@ -102,8 +101,8 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
|
|||
.getInstanceServices()), 180, 5, TimeUnit.SECONDS);
|
||||
hasIpTester = new RetryablePredicate<RunningInstance>(new InstanceHasIpAddress(client
|
||||
.getInstanceServices()), 180, 5, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<InetSocketAddress>(new SocketOpen(), 180, 1,
|
||||
TimeUnit.SECONDS);
|
||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 180, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
|
@ -155,12 +154,12 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
|
|||
|
||||
System.out.printf("%d: running instance%n", System.currentTimeMillis());
|
||||
Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow
|
||||
// ec2
|
||||
// to
|
||||
// chose
|
||||
// an
|
||||
// availability
|
||||
// zone
|
||||
// ec2
|
||||
// to
|
||||
// chose
|
||||
// an
|
||||
// availability
|
||||
// zone
|
||||
"ami-ccf615a5", // alestic ami allows auto-invoke of user data scripts
|
||||
1, // minimum instances
|
||||
1, // maximum instances
|
||||
|
@ -307,8 +306,8 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
|
|||
Thread.sleep(1000);
|
||||
instance = getInstance(instanceId);
|
||||
blockUntilWeCanSshIntoInstance(instance);
|
||||
SshClient ssh = sshFactory.create(new InetSocketAddress(instance.getIpAddress(), 22), "root",
|
||||
keyPair.getKeyMaterial().getBytes());
|
||||
SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), "root", keyPair
|
||||
.getKeyMaterial().getBytes());
|
||||
try {
|
||||
ssh.connect();
|
||||
ExecResponse uptime = ssh.exec("uptime");
|
||||
|
@ -374,7 +373,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
|
|||
|
||||
System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(),
|
||||
instance.getIpAddress());
|
||||
assert socketTester.apply(new InetSocketAddress(instance.getIpAddress(), 22));
|
||||
assert socketTester.apply(new IPSocket(instance.getIpAddress(), 22));
|
||||
|
||||
System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance
|
||||
.getDnsName());
|
||||
|
@ -384,7 +383,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
|
|||
|
||||
System.out.printf("%d: %s awaiting http service to start%n", System.currentTimeMillis(),
|
||||
instance.getIpAddress());
|
||||
assert socketTester.apply(new InetSocketAddress(instance.getIpAddress(), 80));
|
||||
assert socketTester.apply(new IPSocket(instance.getIpAddress(), 80));
|
||||
System.out.printf("%d: %s http service started%n", System.currentTimeMillis(), instance
|
||||
.getDnsName());
|
||||
return instance;
|
||||
|
@ -419,9 +418,9 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
|
|||
doCheckKey(newDetails.getIpAddress());
|
||||
}
|
||||
|
||||
private void doCheckKey(InetAddress address) {
|
||||
SshClient ssh = sshFactory.create(new InetSocketAddress(address, 22), "root", keyPair
|
||||
.getKeyMaterial().getBytes());
|
||||
private void doCheckKey(String address) {
|
||||
SshClient ssh = sshFactory.create(new IPSocket(address, 22), "root", keyPair.getKeyMaterial()
|
||||
.getBytes());
|
||||
try {
|
||||
ssh.connect();
|
||||
ExecResponse hello = ssh.exec("echo hello");
|
||||
|
|
|
@ -27,8 +27,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -60,6 +58,7 @@ import org.jclouds.aws.ec2.predicates.VolumeAttached;
|
|||
import org.jclouds.aws.ec2.predicates.VolumeAvailable;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.scriptbuilder.InitBuilder;
|
||||
|
@ -101,7 +100,7 @@ public class EBSBootEC2ClientLiveTest {
|
|||
private KeyPair keyPair;
|
||||
private String securityGroupName;
|
||||
|
||||
private RetryablePredicate<InetSocketAddress> socketTester;
|
||||
private RetryablePredicate<IPSocket> socketTester;
|
||||
private RetryablePredicate<Attachment> attachTester;
|
||||
private RetryablePredicate<Volume> volumeTester;
|
||||
private RunningInstance instance;
|
||||
|
@ -126,7 +125,7 @@ public class EBSBootEC2ClientLiveTest {
|
|||
client = injector.getInstance(EC2Client.class);
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||
socketTester = new RetryablePredicate<InetSocketAddress>(socketOpen, 120, 1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS);
|
||||
|
||||
VolumeAvailable volumeAvailable = injector.getInstance(VolumeAvailable.class);
|
||||
volumeTester = new RetryablePredicate<Volume>(volumeAvailable, 60, 1, TimeUnit.SECONDS);
|
||||
|
@ -273,7 +272,7 @@ public class EBSBootEC2ClientLiveTest {
|
|||
|
||||
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume")
|
||||
void testBundleInstance() {
|
||||
SshClient ssh = sshFactory.create(new InetSocketAddress(instance.getIpAddress(), 22),
|
||||
SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22),
|
||||
"ubuntu", keyPair.getKeyMaterial().getBytes());
|
||||
try {
|
||||
ssh.connect();
|
||||
|
@ -533,8 +532,8 @@ public class EBSBootEC2ClientLiveTest {
|
|||
doCheckKey(newDetails.getIpAddress());
|
||||
}
|
||||
|
||||
private void doCheckKey(InetAddress address) {
|
||||
SshClient ssh = sshFactory.create(new InetSocketAddress(address, 22), "ubuntu", keyPair
|
||||
private void doCheckKey(String address) {
|
||||
SshClient ssh = sshFactory.create(new IPSocket(address, 22), "ubuntu", keyPair
|
||||
.getKeyMaterial().getBytes());
|
||||
try {
|
||||
ssh.connect();
|
||||
|
@ -560,7 +559,7 @@ public class EBSBootEC2ClientLiveTest {
|
|||
|
||||
System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(),
|
||||
instance.getIpAddress());
|
||||
assert socketTester.apply(new InetSocketAddress(instance.getIpAddress(), 22));
|
||||
assert socketTester.apply(new IPSocket(instance.getIpAddress(), 22));
|
||||
System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance
|
||||
.getDnsName());
|
||||
sshPing(instance);
|
||||
|
|
|
@ -25,7 +25,6 @@ import static org.easymock.classextension.EasyMock.verify;
|
|||
import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.imageIds;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -91,10 +90,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
|
||||
|
@ -150,10 +147,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
|
||||
|
@ -210,10 +205,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
|
||||
|
@ -276,10 +269,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
|
||||
|
@ -334,10 +325,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
|
||||
|
@ -393,10 +382,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
Set<Location> locations = ImmutableSet.<Location> of(location);
|
||||
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
|
||||
expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
|
||||
|
@ -464,10 +451,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
Set<Location> locations = ImmutableSet.<Location> of(location);
|
||||
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
|
||||
expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.services;
|
|||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler;
|
||||
import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler;
|
||||
|
@ -45,9 +44,9 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
public void testDisassociateAddress() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("disassociateAddressInRegion",
|
||||
String.class, InetAddress.class);
|
||||
String.class, String.class);
|
||||
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest(
|
||||
method, null, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||
method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
|
@ -64,9 +63,9 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
|
||||
public void testAssociateAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("associateAddressInRegion",
|
||||
String.class, InetAddress.class, String.class);
|
||||
String.class, String.class, String.class);
|
||||
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest(
|
||||
method, null, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), "me");
|
||||
method, null, "127.0.0.1", "me");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
|
@ -83,9 +82,9 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
|
||||
public void testReleaseAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("releaseAddressInRegion",
|
||||
String.class, InetAddress.class);
|
||||
String.class, String.class);
|
||||
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest(
|
||||
method, null, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||
method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
|
@ -101,9 +100,9 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
|
||||
public void testDescribeAddresses() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("describeAddressesInRegion",
|
||||
String.class, Array.newInstance(InetAddress.class, 0).getClass());
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest(
|
||||
method, null, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||
method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.xml;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
|
@ -38,9 +37,9 @@ public class AllocateAddressResponseHandlerTest extends BaseHandlerTest {
|
|||
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/allocate_address.xml");
|
||||
|
||||
InetAddress result = factory.create(
|
||||
injector.getInstance(AllocateAddressResponseHandler.class)).parse(is);
|
||||
String result = factory.create(injector.getInstance(AllocateAddressResponseHandler.class))
|
||||
.parse(is);
|
||||
|
||||
assertEquals(result, InetAddress.getByName("67.202.55.255"));
|
||||
assertEquals(result, "67.202.55.255");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.easymock.classextension.EasyMock.replay;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -52,9 +51,9 @@ public class DescribeAddressesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
|
||||
Set<PublicIpInstanceIdPair> result = factory.create(handler).parse(is);
|
||||
|
||||
assertEquals(result, ImmutableList.of(new PublicIpInstanceIdPair(defaultRegion, InetAddress
|
||||
.getByName("67.202.55.255"), "i-f15ebb98"), new PublicIpInstanceIdPair(
|
||||
defaultRegion, InetAddress.getByName("67.202.55.233"), null)));
|
||||
assertEquals(result, ImmutableList.of(new PublicIpInstanceIdPair(defaultRegion,
|
||||
"67.202.55.255", "i-f15ebb98"), new PublicIpInstanceIdPair(defaultRegion,
|
||||
"67.202.55.233", null)));
|
||||
}
|
||||
|
||||
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.easymock.classextension.EasyMock.replay;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -73,13 +72,13 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSet
|
||||
.of("adriancole.ec2ingress"), "0",
|
||||
"ec2-174-129-81-68.compute-1.amazonaws.com", "ami-1fd73376", "i-0799056f",
|
||||
InstanceState.RUNNING, InstanceType.M1_SMALL, InetAddress
|
||||
.getByName("174.129.81.68"), "aki-a71cf9ce", "adriancole.ec21",
|
||||
dateService.iso8601DateParse("2009-11-09T03:00:34.000Z"), false,
|
||||
InstanceState.RUNNING, InstanceType.M1_SMALL, "174.129.81.68",
|
||||
"aki-a71cf9ce", "adriancole.ec21", dateService
|
||||
.iso8601DateParse("2009-11-09T03:00:34.000Z"), false,
|
||||
AvailabilityZone.US_EAST_1C, null, "ip-10-243-42-70.ec2.internal",
|
||||
InetAddress.getByName("10.243.42.70"), ImmutableSet.<String> of(),
|
||||
"ari-a51cf9cc", null, null, null, RootDeviceType.INSTANCE_STORE, null,
|
||||
ImmutableMap.<String, EbsBlockDevice> of())), "993194456877", null,
|
||||
"10.243.42.70", ImmutableSet.<String> of(), "ari-a51cf9cc", null, null,
|
||||
null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of())), "993194456877", null,
|
||||
"r-a3c508cb"));
|
||||
|
||||
Set<Reservation> result = getReservations(is);
|
||||
|
@ -95,7 +94,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
contents.add(new Reservation(defaultRegion, ImmutableSet.of("default"), ImmutableSet.of(
|
||||
new RunningInstance(defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-4.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64341",
|
||||
InstanceState.RUNNING, InstanceType.M1_LARGE, (InetAddress) null,
|
||||
InstanceState.RUNNING, InstanceType.M1_LARGE, (String) null,
|
||||
"aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), false,
|
||||
AvailabilityZone.US_EAST_1B, null, "10-251-50-132.ec2.internal", null,
|
||||
|
@ -104,7 +103,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
.<String, EbsBlockDevice> of()), new RunningInstance(
|
||||
defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-6.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64435",
|
||||
InstanceState.RUNNING, InstanceType.M1_LARGE, (InetAddress) null,
|
||||
InstanceState.RUNNING, InstanceType.M1_LARGE, (String) null,
|
||||
"aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), false,
|
||||
AvailabilityZone.US_EAST_1B, null, "10-251-50-134.ec2.internal", null,
|
||||
|
@ -127,18 +126,17 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSet
|
||||
.of("adriancole.ec2ebsingress"), "0",
|
||||
"ec2-75-101-203-146.compute-1.amazonaws.com", "ami-849875ed", "i-e564438d",
|
||||
InstanceState.RUNNING, InstanceType.M1_SMALL, InetAddress
|
||||
.getByName("75.101.203.146"), "aki-a71cf9ce",
|
||||
"adriancole.ec2ebs1", dateService
|
||||
InstanceState.RUNNING, InstanceType.M1_SMALL, "75.101.203.146",
|
||||
"aki-a71cf9ce", "adriancole.ec2ebs1", dateService
|
||||
.iso8601DateParse("2009-12-30T04:06:23.000Z"), false,
|
||||
AvailabilityZone.US_EAST_1B, null,
|
||||
"domU-12-31-39-09-CE-53.compute-1.internal", InetAddress
|
||||
.getByName("10.210.209.157"), ImmutableSet.<String> of(),
|
||||
"ari-a51cf9cc", null, null, null, RootDeviceType.EBS, "/dev/sda1",
|
||||
ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1", new EbsBlockDevice(
|
||||
"vol-dc6ca8b5", Attachment.Status.ATTACHED, dateService
|
||||
.iso8601DateParse("2009-12-30T04:06:29.000Z"), true)))),
|
||||
"993194456877", null, "r-596dd731"));
|
||||
"domU-12-31-39-09-CE-53.compute-1.internal", "10.210.209.157", ImmutableSet
|
||||
.<String> of(), "ari-a51cf9cc", null, null, null,
|
||||
RootDeviceType.EBS, "/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of(
|
||||
"/dev/sda1", new EbsBlockDevice("vol-dc6ca8b5",
|
||||
Attachment.Status.ATTACHED, dateService
|
||||
.iso8601DateParse("2009-12-30T04:06:29.000Z"),
|
||||
true)))), "993194456877", null, "r-596dd731"));
|
||||
|
||||
Set<Reservation> result = getReservations(is);
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.easymock.classextension.EasyMock.replay;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.jclouds.aws.ec2.domain.AvailabilityZone;
|
||||
import org.jclouds.aws.ec2.domain.InstanceState;
|
||||
|
@ -69,25 +68,25 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
Reservation expected = new Reservation(defaultRegion, ImmutableSortedSet.of("default"),
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSortedSet.of("default"),
|
||||
"0", null, "ami-60a54009", "i-2ba64342", InstanceState.PENDING,
|
||||
InstanceType.M1_SMALL, (InetAddress) null, null, "example-key-name",
|
||||
InstanceType.M1_SMALL, (String) null, null, "example-key-name",
|
||||
dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"), true,
|
||||
AvailabilityZone.US_EAST_1B, null, null, (InetAddress) null, Sets
|
||||
AvailabilityZone.US_EAST_1B, null, null, (String) null, Sets
|
||||
.<String> newTreeSet(), null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of()), new RunningInstance(
|
||||
defaultRegion, ImmutableSortedSet.of("default"), "1", null, "ami-60a54009",
|
||||
"i-2bc64242", InstanceState.PENDING, InstanceType.M1_SMALL,
|
||||
(InetAddress) null, null, "example-key-name", dateService
|
||||
(String) null, null, "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:51:50.000Z"), true,
|
||||
AvailabilityZone.US_EAST_1B, null, null, (InetAddress) null, Sets
|
||||
AvailabilityZone.US_EAST_1B, null, null, (String) null, Sets
|
||||
.<String> newTreeSet(), null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of()), new RunningInstance(
|
||||
defaultRegion, ImmutableSortedSet.of("default"), "2", null, "ami-60a54009",
|
||||
"i-2be64332", InstanceState.PENDING, InstanceType.M1_SMALL,
|
||||
(InetAddress) null, null, "example-key-name", dateService
|
||||
(String) null, null, "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:51:50.000Z"), true,
|
||||
AvailabilityZone.US_EAST_1B, null, null, (InetAddress) null, Sets
|
||||
AvailabilityZone.US_EAST_1B, null, null, (String) null, Sets
|
||||
.<String> newTreeSet(), null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of())
|
||||
|
|
|
@ -21,4 +21,4 @@
|
|||
# 1. execute 'mvn install' to build the sample
|
||||
# 2. invoke the jar, passing your aws credentials and the bucket you wish to create
|
||||
# ex.
|
||||
# java -jar target/jclouds-aws-sample-createandlistbuckets-jar-with-dependencies.jar accesskey secretkey testbucketName
|
||||
# java -jar target/jclouds-aws-demo-createandlistbuckets-jar-with-dependencies.jar $AWS_USER $AWS_PWD testbucketmeo
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.compute;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
|
@ -59,13 +58,14 @@ public interface LoadBalancerService {
|
|||
* which the server on the instance is listening. Valid instance ports are one (1)
|
||||
* through 65535. This property cannot be modified for the life of the LoadBalancer.
|
||||
*
|
||||
* @return DNS Name of the load balancer
|
||||
* @return DNS Name of the load balancer; note we don't use String, as it is incompatible
|
||||
* with google appengine.
|
||||
*/
|
||||
@Beta
|
||||
Set<InetAddress> loadBalanceNodesMatching(Predicate<NodeMetadata> filter,
|
||||
String loadBalancerName, String protocol, int loadBalancerPort, int instancePort);
|
||||
Set<String> loadBalanceNodesMatching(Predicate<NodeMetadata> filter, String loadBalancerName,
|
||||
String protocol, int loadBalancerPort, int instancePort);
|
||||
|
||||
@Beta
|
||||
void destroyLoadBalancer(InetAddress handle);
|
||||
void destroyLoadBalancer(String handle);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.compute.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -55,12 +54,12 @@ public interface NodeMetadata extends ComputeMetadata {
|
|||
/**
|
||||
* All public IP addresses, potentially including shared ips.
|
||||
*/
|
||||
Set<InetAddress> getPublicAddresses();
|
||||
Set<String> getPublicAddresses();
|
||||
|
||||
/**
|
||||
* All private IP addresses.
|
||||
*/
|
||||
Set<InetAddress> getPrivateAddresses();
|
||||
Set<String> getPrivateAddresses();
|
||||
|
||||
/**
|
||||
* If possible, these are returned upon all detail requests. However, it is often the case that
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.compute.domain.internal;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -47,8 +46,8 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
private static final long serialVersionUID = 7924307572338157887L;
|
||||
|
||||
private final NodeState state;
|
||||
private final Set<InetAddress> publicAddresses = Sets.newLinkedHashSet();
|
||||
private final Set<InetAddress> privateAddresses = Sets.newLinkedHashSet();
|
||||
private final Set<String> publicAddresses = Sets.newLinkedHashSet();
|
||||
private final Set<String> privateAddresses = Sets.newLinkedHashSet();
|
||||
private final Map<String, String> extra = Maps.newLinkedHashMap();
|
||||
private final Credentials credentials;
|
||||
private final String tag;
|
||||
|
@ -56,8 +55,8 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
|
||||
public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri,
|
||||
Map<String, String> userMetadata, @Nullable String tag, @Nullable Image image,
|
||||
NodeState state, Iterable<InetAddress> publicAddresses,
|
||||
Iterable<InetAddress> privateAddresses, Map<String, String> extra,
|
||||
NodeState state, Iterable<String> publicAddresses,
|
||||
Iterable<String> privateAddresses, Map<String, String> extra,
|
||||
@Nullable Credentials credentials) {
|
||||
super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata);
|
||||
this.tag = tag;
|
||||
|
@ -98,7 +97,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<InetAddress> getPublicAddresses() {
|
||||
public Set<String> getPublicAddresses() {
|
||||
return publicAddresses;
|
||||
}
|
||||
|
||||
|
@ -106,7 +105,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<InetAddress> getPrivateAddresses() {
|
||||
public Set<String> getPrivateAddresses() {
|
||||
return privateAddresses;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,6 @@ package org.jclouds.compute.internal;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -98,7 +96,7 @@ public class BaseLoadBalancerService implements LoadBalancerService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<InetAddress> loadBalanceNodesMatching(Predicate<NodeMetadata> filter,
|
||||
public Set<String> loadBalanceNodesMatching(Predicate<NodeMetadata> filter,
|
||||
String loadBalancerName, String protocol, int loadBalancerPort, int instancePort) {
|
||||
checkNotNull(loadBalancerName, "loadBalancerName");
|
||||
checkNotNull(protocol, "protocol");
|
||||
|
@ -115,21 +113,12 @@ public class BaseLoadBalancerService implements LoadBalancerService {
|
|||
ids.add(node.getProviderId());
|
||||
locationMap.put(node.getLocation(), ids);
|
||||
}
|
||||
Set<InetAddress> dnsNames = Sets.newHashSet();
|
||||
Set<String> dnsNames = Sets.newHashSet();
|
||||
for (Location location : locationMap.keySet()) {
|
||||
logger.debug(">> creating load balancer (%s)", loadBalancerName);
|
||||
String dnsName = loadBalancerStrategy.execute(location, loadBalancerName, protocol,
|
||||
loadBalancerPort, instancePort, locationMap.get(location));
|
||||
for (int i = 0; i < dnsRetries; i++) {
|
||||
try {
|
||||
dnsNames.add(InetAddress.getByName(dnsName));
|
||||
} catch (UnknownHostException from) {
|
||||
backoffLimitedRetryHandler.imposeBackoffExponentialDelay(200L, 2, i + 1, dnsRetries,
|
||||
String.format("%s/%s@%s:%d:%d connection error: %s", location,
|
||||
loadBalancerName, dnsName, loadBalancerPort, instancePort));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
dnsNames.add(dnsName);
|
||||
logger.debug("<< created load balancer (%s) DNS (%s)", loadBalancerName, dnsName);
|
||||
}
|
||||
return dnsNames;
|
||||
|
@ -139,7 +128,7 @@ public class BaseLoadBalancerService implements LoadBalancerService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void destroyLoadBalancer(InetAddress loadBalancer) {
|
||||
public void destroyLoadBalancer(String loadBalancer) {
|
||||
checkNotNull(loadBalancer, "loadBalancer");
|
||||
logger.debug(">> destroying load balancer(%s)", loadBalancer);
|
||||
boolean successful = destroyLoadBalancerStrategy.execute(loadBalancer);
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.jclouds.compute.strategy;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
|
||||
/**
|
||||
|
@ -31,6 +29,6 @@ import com.google.common.annotations.Beta;
|
|||
@Beta
|
||||
public interface DestroyLoadBalancerStrategy {
|
||||
|
||||
boolean execute(InetAddress loadBalancer);
|
||||
boolean execute(String loadBalancer);
|
||||
|
||||
}
|
|
@ -25,9 +25,6 @@ import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Comparator;
|
||||
import java.util.Formatter;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -54,8 +51,8 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
|||
import org.jclouds.concurrent.ConcurrentUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.scriptbuilder.InitBuilder;
|
||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||
import org.jclouds.ssh.ExecResponse;
|
||||
|
@ -83,11 +80,11 @@ public class ComputeUtils {
|
|||
@Inject(optional = true)
|
||||
private SshClient.Factory sshFactory;
|
||||
protected final Predicate<CommandUsingClient> runScriptNotRunning;
|
||||
private final Predicate<InetSocketAddress> socketTester;
|
||||
private final Predicate<IPSocket> socketTester;
|
||||
private final ExecutorService executor;
|
||||
|
||||
@Inject
|
||||
public ComputeUtils(Predicate<InetSocketAddress> socketTester,
|
||||
public ComputeUtils(Predicate<IPSocket> socketTester,
|
||||
@Named("NOT_RUNNING") Predicate<CommandUsingClient> runScriptNotRunning,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
this.socketTester = socketTester;
|
||||
|
@ -160,15 +157,6 @@ public class ComputeUtils {
|
|||
});
|
||||
}
|
||||
|
||||
public static final Comparator<InetAddress> ADDRESS_COMPARATOR = new Comparator<InetAddress>() {
|
||||
|
||||
@Override
|
||||
public int compare(InetAddress o1, InetAddress o2) {
|
||||
return (o1 == o2) ? 0 : o1.getHostAddress().compareTo(o2.getHostAddress());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public void runOptionsOnNode(NodeMetadata node, TemplateOptions options) {
|
||||
List<SshCallable<?>> callables = Lists.newArrayList();
|
||||
if (options.getRunScript() != null) {
|
||||
|
@ -196,11 +184,11 @@ public class ComputeUtils {
|
|||
"node does not have IP addresses configured: " + node);
|
||||
}
|
||||
|
||||
private void blockUntilPortIsListeningOnPublicIp(int port, int seconds, InetAddress inetAddress) {
|
||||
private void blockUntilPortIsListeningOnPublicIp(int port, int seconds, String inetAddress) {
|
||||
logger.debug(">> blocking on port %s:%d for %d seconds", inetAddress, port, seconds);
|
||||
RetryablePredicate<InetSocketAddress> tester = new RetryablePredicate<InetSocketAddress>(
|
||||
new SocketOpen(), seconds, 1, TimeUnit.SECONDS);
|
||||
InetSocketAddress socket = new InetSocketAddress(inetAddress, port);
|
||||
RetryablePredicate<IPSocket> tester = new RetryablePredicate<IPSocket>(socketTester, seconds,
|
||||
1, TimeUnit.SECONDS);
|
||||
IPSocket socket = new IPSocket(inetAddress, port);
|
||||
boolean passed = tester.apply(socket);
|
||||
if (passed)
|
||||
logger.debug("<< port %s:%d opened", inetAddress, port);
|
||||
|
@ -258,8 +246,7 @@ public class ComputeUtils {
|
|||
}
|
||||
|
||||
public SshClient createSshClientOncePortIsListeningOnNode(NodeMetadata node) {
|
||||
InetSocketAddress socket = new InetSocketAddress(Iterables.get(node.getPublicAddresses(), 0),
|
||||
22);
|
||||
IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), 22);
|
||||
socketTester.apply(socket);
|
||||
SshClient ssh = isKeyAuth(node) ? sshFactory.create(socket, node.getCredentials().account,
|
||||
node.getCredentials().key.getBytes()) : sshFactory.create(socket, node
|
||||
|
@ -347,12 +334,11 @@ public class ComputeUtils {
|
|||
logger.debug("<< complete(%d)", returnVal.getExitCode());
|
||||
if (logger.isDebugEnabled() || returnVal.getExitCode() != 0) {
|
||||
logger.debug("<< stdout from %s as %s@%s\n%s", scriptName,
|
||||
node.getCredentials().account, Iterables.get(node.getPublicAddresses(), 0)
|
||||
.getHostAddress(), ssh.exec("./" + scriptName + " tail").getOutput());
|
||||
node.getCredentials().account, Iterables.get(node.getPublicAddresses(), 0),
|
||||
ssh.exec("./" + scriptName + " tail").getOutput());
|
||||
logger.debug("<< stderr from %s as %s@%s\n%s", scriptName,
|
||||
node.getCredentials().account, Iterables.get(node.getPublicAddresses(), 0)
|
||||
.getHostAddress(), ssh.exec("./" + scriptName + " tailerr")
|
||||
.getOutput());
|
||||
node.getCredentials().account, Iterables.get(node.getPublicAddresses(), 0),
|
||||
ssh.exec("./" + scriptName + " tailerr").getOutput());
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -366,16 +352,15 @@ public class ComputeUtils {
|
|||
private ExecResponse runScriptAsRoot() {
|
||||
if (node.getCredentials().account.equals("root")) {
|
||||
logger.debug(">> running %s as %s@%s", scriptName, node.getCredentials().account,
|
||||
Iterables.get(node.getPublicAddresses(), 0).getHostAddress());
|
||||
Iterables.get(node.getPublicAddresses(), 0));
|
||||
return ssh.exec("./" + scriptName + " start");
|
||||
} else if (isKeyAuth(node)) {
|
||||
logger.debug(">> running sudo %s as %s@%s", scriptName, node.getCredentials().account,
|
||||
Iterables.get(node.getPublicAddresses(), 0).getHostAddress());
|
||||
Iterables.get(node.getPublicAddresses(), 0));
|
||||
return ssh.exec("sudo ./" + scriptName + " start");
|
||||
} else {
|
||||
logger.debug(">> running sudo -S %s as %s@%s", scriptName,
|
||||
node.getCredentials().account, Iterables.get(node.getPublicAddresses(), 0)
|
||||
.getHostAddress());
|
||||
node.getCredentials().account, Iterables.get(node.getPublicAddresses(), 0));
|
||||
return ssh.exec(String.format("echo '%s'|sudo -S ./%s", node.getCredentials().key,
|
||||
scriptName + " start"));
|
||||
}
|
||||
|
@ -383,7 +368,7 @@ public class ComputeUtils {
|
|||
|
||||
private ExecResponse runScriptAsDefaultUser() {
|
||||
logger.debug(">> running script %s as %s@%s", scriptName, node.getCredentials().account,
|
||||
Iterables.get(node.getPublicAddresses(), 0).getHostAddress());
|
||||
Iterables.get(node.getPublicAddresses(), 0));
|
||||
return ssh.exec(String.format("./%s", scriptName + " start"));
|
||||
}
|
||||
|
||||
|
@ -410,7 +395,7 @@ public class ComputeUtils {
|
|||
ssh.exec("mkdir .ssh");
|
||||
ssh.put(".ssh/id_rsa", new ByteArrayInputStream(privateKey.getBytes()));
|
||||
logger.debug(">> installing rsa key for %s@%s", node.getCredentials().account, Iterables
|
||||
.get(node.getPublicAddresses(), 0).getHostAddress());
|
||||
.get(node.getPublicAddresses(), 0));
|
||||
return ssh.exec("chmod 600 .ssh/id_rsa");
|
||||
}
|
||||
|
||||
|
@ -443,7 +428,7 @@ public class ComputeUtils {
|
|||
ssh.exec("mkdir .ssh");
|
||||
ssh.put(".ssh/id_rsa.pub", new ByteArrayInputStream(publicKey.getBytes()));
|
||||
logger.debug(">> authorizing rsa public key for %s@%s", node.getCredentials().account,
|
||||
Iterables.get(node.getPublicAddresses(), 0).getHostAddress());
|
||||
Iterables.get(node.getPublicAddresses(), 0));
|
||||
ExecResponse returnVal = ssh.exec("cat .ssh/id_rsa.pub >> .ssh/authorized_keys");
|
||||
returnVal = ssh.exec("chmod 600 .ssh/authorized_keys");
|
||||
logger.debug("<< complete(%d)", returnVal.getExitCode());
|
||||
|
|
|
@ -19,21 +19,22 @@
|
|||
package org.jclouds.ssh;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.jclouds.net.IPSocket;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface SshClient {
|
||||
|
||||
interface Factory {
|
||||
SshClient create(InetSocketAddress socket, String username, String password);
|
||||
SshClient create(IPSocket socket, String username, String password);
|
||||
|
||||
SshClient create(InetSocketAddress socket, String username, byte[] privateKey);
|
||||
SshClient create(IPSocket socket, String username, byte[] privateKey);
|
||||
|
||||
Map<String, String> generateRSAKeyPair(String comment, String passphrase);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import static org.testng.Assert.assertNotNull;
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
@ -52,6 +51,7 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
|
@ -89,7 +89,7 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
protected SshClient.Factory sshFactory;
|
||||
protected String tag;
|
||||
|
||||
protected RetryablePredicate<InetSocketAddress> socketTester;
|
||||
protected RetryablePredicate<IPSocket> socketTester;
|
||||
protected SortedSet<NodeMetadata> nodes;
|
||||
protected ComputeServiceContext context;
|
||||
protected ComputeService client;
|
||||
|
@ -121,7 +121,7 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
Injector injector = Guice.createInjector(getSshModule());
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||
socketTester = new RetryablePredicate<InetSocketAddress>(socketOpen, 60, 1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS);
|
||||
injector.injectMembers(socketOpen); // add logger
|
||||
// keyPair = sshFactory.generateRSAKeyPair("", "");
|
||||
keyPair = ImmutableMap.<String, String> of("private", secret, "public", Files.toString(
|
||||
|
@ -165,8 +165,7 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
@Test(enabled = true, dependsOnMethods = "testImagesCache")
|
||||
public void testTemplateMatch() throws Exception {
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
Template toMatch = client.templateBuilder().imageId(template.getImage().getId())
|
||||
.build();
|
||||
Template toMatch = client.templateBuilder().imageId(template.getImage().getId()).build();
|
||||
assertEquals(toMatch.getImage(), template.getImage());
|
||||
}
|
||||
|
||||
|
@ -460,8 +459,7 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
}
|
||||
|
||||
protected void doCheckJavaIsInstalledViaSsh(NodeMetadata node) throws IOException {
|
||||
InetSocketAddress socket = new InetSocketAddress(Iterables.get(node.getPublicAddresses(), 0),
|
||||
22);
|
||||
IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), 22);
|
||||
socketTester.apply(socket); // TODO add transitionTo option that accepts a socket conection
|
||||
// state.
|
||||
SshClient ssh = sshFactory.create(socket, node.getCredentials().account, keyPair.get(
|
||||
|
|
|
@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
@ -37,6 +35,7 @@ import org.jclouds.compute.domain.Template;
|
|||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.predicates.NodePredicates;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
|
@ -65,7 +64,7 @@ public abstract class BaseLoadBalancerServiceLiveTest {
|
|||
protected SshClient.Factory sshFactory;
|
||||
protected String tag;
|
||||
|
||||
protected RetryablePredicate<InetSocketAddress> socketTester;
|
||||
protected RetryablePredicate<IPSocket> socketTester;
|
||||
protected SortedSet<NodeMetadata> nodes;
|
||||
protected ComputeServiceContext context;
|
||||
protected ComputeService client;
|
||||
|
@ -74,7 +73,7 @@ public abstract class BaseLoadBalancerServiceLiveTest {
|
|||
protected String password;
|
||||
protected Template template;
|
||||
protected Map<String, String> keyPair;
|
||||
protected Set<InetAddress> loadbalancers;
|
||||
protected Set<String> loadbalancers;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
|
@ -89,7 +88,7 @@ public abstract class BaseLoadBalancerServiceLiveTest {
|
|||
Injector injector = Guice.createInjector(getSshModule());
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||
socketTester = new RetryablePredicate<InetSocketAddress>(socketOpen, 60, 1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS);
|
||||
injector.injectMembers(socketOpen); // add logger
|
||||
|
||||
Template template = client.templateBuilder().build();
|
||||
|
@ -128,7 +127,7 @@ public abstract class BaseLoadBalancerServiceLiveTest {
|
|||
|
||||
@Test(enabled = true, dependsOnMethods = "testLoadBalanceNodesMatching")
|
||||
public void testDestroyLoadBalancers() throws Exception {
|
||||
for (InetAddress lb : loadbalancers) {
|
||||
for (String lb : loadbalancers) {
|
||||
lbClient.destroyLoadBalancer(lb);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,8 @@
|
|||
package org.jclouds.http.functions.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -38,10 +34,8 @@ import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
|||
import org.xml.sax.XMLReader;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.InstanceCreator;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
|
@ -49,7 +43,6 @@ import com.google.gson.JsonParseException;
|
|||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.ImplementedBy;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -84,41 +77,6 @@ public class ParserModule extends AbstractModule {
|
|||
}
|
||||
}
|
||||
|
||||
private static final Comparator<InetAddress> ADDRESS_COMPARATOR = new Comparator<InetAddress>() {
|
||||
|
||||
@Override
|
||||
public int compare(InetAddress o1, InetAddress o2) {
|
||||
return (o1 == o2) ? 0 : o1.getHostAddress().compareTo(o2.getHostAddress());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static class SortedSetOfInetAddressCreator implements InstanceCreator<SortedSet<InetAddress>> {
|
||||
|
||||
@Override
|
||||
public SortedSet<InetAddress> createInstance(Type arg0) {
|
||||
return Sets.newTreeSet(ADDRESS_COMPARATOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class InetAddressAdapter implements JsonSerializer<InetAddress>,
|
||||
JsonDeserializer<InetAddress> {
|
||||
public JsonElement serialize(InetAddress src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getHostAddress());
|
||||
}
|
||||
|
||||
public InetAddress deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
try {
|
||||
return InetAddress.getByName(json.getAsJsonPrimitive().getAsString());
|
||||
} catch (UnknownHostException e) {
|
||||
throw new JsonParseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
SAXParserFactory provideSAXParserFactory() {
|
||||
|
@ -131,13 +89,9 @@ public class ParserModule extends AbstractModule {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Provides
|
||||
@Singleton
|
||||
Gson provideGson(DateAdapter adapter, SortedSetOfInetAddressCreator addressSetCreator,
|
||||
GsonAdapterBindings bindings) {
|
||||
Gson provideGson(DateAdapter adapter, GsonAdapterBindings bindings) {
|
||||
GsonBuilder gson = new GsonBuilder();
|
||||
gson.registerTypeAdapter(InetAddress.class, new InetAddressAdapter());
|
||||
gson.registerTypeAdapter(Date.class, adapter);
|
||||
gson.registerTypeAdapter(new TypeToken<SortedSet<InetAddress>>() {
|
||||
}.getType(), addressSetCreator);
|
||||
for (Map.Entry<Class, Object> binding : bindings.getBindings().entrySet()) {
|
||||
gson.registerTypeAdapter(binding.getKey(), binding.getValue());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.net;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* As google appengine prohibits use of java.net classes, this will serve as a replacement.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class IPSocket implements Serializable {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 2978329372952402188L;
|
||||
|
||||
private final String address;
|
||||
private final int port;
|
||||
|
||||
public IPSocket(String address, int port) {
|
||||
this.address = address;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((address == null) ? 0 : address.hashCode());
|
||||
result = prime * result + port;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
IPSocket other = (IPSocket) obj;
|
||||
if (address == null) {
|
||||
if (other.address != null)
|
||||
return false;
|
||||
} else if (!address.equals(other.address))
|
||||
return false;
|
||||
if (port != other.port)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[address=" + address + ", port=" + port + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +1,9 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.predicates;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.net.IPSocket;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -37,38 +11,7 @@ import com.google.inject.Inject;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SocketOpen implements Predicate<InetSocketAddress> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject(optional = true)
|
||||
@Named("org.jclouds.socket_timeout")
|
||||
private int timeout = 2000;
|
||||
|
||||
@Override
|
||||
public boolean apply(InetSocketAddress socketAddress) {
|
||||
Socket socket = null;
|
||||
try {
|
||||
logger.trace("testing socket %s", socketAddress);
|
||||
socket = new Socket();
|
||||
socket.setReuseAddress(false);
|
||||
socket.setSoLinger(false, 1);
|
||||
socket.setSoTimeout(timeout);
|
||||
socket.connect(socketAddress, timeout);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException ioe) {
|
||||
// no work to do
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ImplementedBy(SocketOpenUnsupported.class)
|
||||
public interface SocketOpen extends Predicate<IPSocket> {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package org.jclouds.predicates;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.net.IPSocket;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SocketOpenUnsupported implements SocketOpen {
|
||||
|
||||
@Override
|
||||
public boolean apply(IPSocket socketA) {
|
||||
throw new UnsupportedOperationException("socket testing not configured");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.rest.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class InetAddressToHostAddress implements Function<Object, String> {
|
||||
|
||||
@Override
|
||||
public String apply(Object from) {
|
||||
checkArgument(checkNotNull(from, "from") instanceof InetAddress,
|
||||
"this binder is only valid for InetAddress!");
|
||||
return ((InetAddress) from).getHostAddress();
|
||||
}
|
||||
|
||||
}
|
|
@ -30,8 +30,6 @@ import static com.google.common.collect.Iterables.any;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
@ -43,6 +41,7 @@ import org.apache.commons.io.input.ProxyInputStream;
|
|||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
||||
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.ssh.ExecResponse;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.SshException;
|
||||
|
@ -85,7 +84,7 @@ public class JschSshClient implements SshClient {
|
|||
}
|
||||
}
|
||||
|
||||
private final InetAddress host;
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
@ -112,9 +111,8 @@ public class JschSshClient implements SshClient {
|
|||
private final int timeout;
|
||||
private final BackoffLimitedRetryHandler backoffLimitedRetryHandler;
|
||||
|
||||
public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler,
|
||||
InetSocketAddress socket, int timeout, String username, String password,
|
||||
byte[] privateKey) {
|
||||
public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket,
|
||||
int timeout, String username, String password, byte[] privateKey) {
|
||||
this.host = checkNotNull(socket, "socket").getAddress();
|
||||
checkArgument(socket.getPort() > 0, "ssh port must be greater then zero" + socket.getPort());
|
||||
checkArgument(password != null || privateKey != null, "you must specify a password or a key");
|
||||
|
@ -131,20 +129,20 @@ public class JschSshClient implements SshClient {
|
|||
checkNotNull(path, "path");
|
||||
|
||||
checkConnected();
|
||||
logger.debug("%s@%s:%d: Opening sftp Channel.", username, host.getHostAddress(), port);
|
||||
logger.debug("%s@%s:%d: Opening sftp Channel.", username, host, port);
|
||||
ChannelSftp sftp = null;
|
||||
try {
|
||||
sftp = (ChannelSftp) session.openChannel("sftp");
|
||||
sftp.connect();
|
||||
} catch (JSchException e) {
|
||||
throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, host
|
||||
.getHostAddress(), port), e);
|
||||
throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username,
|
||||
host, port), e);
|
||||
}
|
||||
try {
|
||||
return new CloseFtpChannelOnCloseInputStream(sftp.get(path), sftp);
|
||||
} catch (SftpException e) {
|
||||
throw new SshException(String.format("%s@%s:%d: Error getting path: %s", username, host
|
||||
.getHostAddress(), port, path), e);
|
||||
throw new SshException(String.format("%s@%s:%d: Error getting path: %s", username, host,
|
||||
port, path), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,20 +151,20 @@ public class JschSshClient implements SshClient {
|
|||
checkNotNull(contents, "contents");
|
||||
|
||||
checkConnected();
|
||||
logger.debug("%s@%s:%d: Opening sftp Channel.", username, host.getHostAddress(), port);
|
||||
logger.debug("%s@%s:%d: Opening sftp Channel.", username, host, port);
|
||||
ChannelSftp sftp = null;
|
||||
try {
|
||||
sftp = (ChannelSftp) session.openChannel("sftp");
|
||||
sftp.connect();
|
||||
} catch (JSchException e) {
|
||||
throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, host
|
||||
.getHostAddress(), port), e);
|
||||
throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username,
|
||||
host, port), e);
|
||||
}
|
||||
try {
|
||||
sftp.put(contents, path);
|
||||
} catch (SftpException e) {
|
||||
throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host
|
||||
.getHostAddress(), port, path), e);
|
||||
throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host,
|
||||
port, path), e);
|
||||
} finally {
|
||||
Closeables.closeQuietly(contents);
|
||||
}
|
||||
|
@ -174,7 +172,7 @@ public class JschSshClient implements SshClient {
|
|||
|
||||
private void checkConnected() {
|
||||
checkState(session != null && session.isConnected(), String.format(
|
||||
"%s@%s:%d: SFTP not connected!", username, host.getHostAddress(), port));
|
||||
"%s@%s:%d: SFTP not connected!", username, host, port));
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
@ -221,18 +219,17 @@ public class JschSshClient implements SshClient {
|
|||
|
||||
private void backoffForAttempt(int retryAttempt, String rootMessage) {
|
||||
backoffLimitedRetryHandler.imposeBackoffExponentialDelay(200L, 2, retryAttempt, sshRetries,
|
||||
String.format("%s@%s:%d: connection error: %s", username, host.getHostAddress(),
|
||||
port, rootMessage));
|
||||
String.format("%s@%s:%d: connection error: %s", username, host, port, rootMessage));
|
||||
}
|
||||
|
||||
private void newSession() throws JSchException {
|
||||
JSch jsch = new JSch();
|
||||
session = null;
|
||||
try {
|
||||
session = jsch.getSession(username, host.getHostAddress(), port);
|
||||
session = jsch.getSession(username, host, port);
|
||||
if (timeout != 0)
|
||||
session.setTimeout(timeout);
|
||||
logger.debug("%s@%s:%d: Session created.", username, host.getHostAddress(), port);
|
||||
logger.debug("%s@%s:%d: Session created.", username, host, port);
|
||||
if (password != null) {
|
||||
session.setPassword(password);
|
||||
} else {
|
||||
|
@ -241,19 +238,19 @@ public class JschSshClient implements SshClient {
|
|||
emptyPassPhrase);
|
||||
}
|
||||
} catch (JSchException e) {
|
||||
throw new SshException(String.format("%s@%s:%d: Error creating session.", username, host
|
||||
.getHostAddress(), port), e);
|
||||
throw new SshException(String.format("%s@%s:%d: Error creating session.", username, host,
|
||||
port), e);
|
||||
}
|
||||
java.util.Properties config = new java.util.Properties();
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
session.setConfig(config);
|
||||
session.connect();
|
||||
logger.debug("%s@%s:%d: Session connected.", username, host.getHostAddress(), port);
|
||||
logger.debug("%s@%s:%d: Session connected.", username, host, port);
|
||||
}
|
||||
|
||||
private SshException propagate(Exception e) {
|
||||
throw new SshException(String.format("%s@%s:%d: Error connecting to session.", username, host
|
||||
.getHostAddress(), port), e);
|
||||
throw new SshException(String.format("%s@%s:%d: Error connecting to session.", username,
|
||||
host, port), e);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
@ -272,7 +269,7 @@ public class JschSshClient implements SshClient {
|
|||
executor = (ChannelExec) session.openChannel("exec");
|
||||
} catch (JSchException e) {
|
||||
throw new SshException(String.format("%s@%s:%d: Error connecting to exec.", username,
|
||||
host.getHostAddress(), port), e);
|
||||
host, port), e);
|
||||
}
|
||||
executor.setCommand(command);
|
||||
ByteArrayOutputStream error = new ByteArrayOutputStream();
|
||||
|
@ -283,7 +280,7 @@ public class JschSshClient implements SshClient {
|
|||
.toString(), executor.getExitStatus());
|
||||
} catch (Exception e) {
|
||||
throw new SshException(String.format("%s@%s:%d: Error executing command: ", username,
|
||||
host.getHostAddress(), port, command), e);
|
||||
host, port, command), e);
|
||||
}
|
||||
} finally {
|
||||
if (executor != null)
|
||||
|
@ -293,7 +290,7 @@ public class JschSshClient implements SshClient {
|
|||
|
||||
@Override
|
||||
public String getHostAddress() {
|
||||
return this.host.getHostAddress();
|
||||
return this.host;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,16 +19,18 @@
|
|||
package org.jclouds.ssh.jsch.config;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.ssh.ConfiguresSshClient;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.jsch.JschSshClient;
|
||||
import org.jclouds.ssh.jsch.predicates.InetSocketAddressConnect;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -49,6 +51,7 @@ public class JschSshClientModule extends AbstractModule {
|
|||
|
||||
protected void configure() {
|
||||
bind(SshClient.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
|
||||
bind(SocketOpen.class).to(InetSocketAddressConnect.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
private static class Factory implements SshClient.Factory {
|
||||
|
@ -66,14 +69,14 @@ public class JschSshClientModule extends AbstractModule {
|
|||
this.injector = injector;
|
||||
}
|
||||
|
||||
public SshClient create(InetSocketAddress socket, String username, String password) {
|
||||
public SshClient create(IPSocket socket, String username, String password) {
|
||||
SshClient client = new JschSshClient(backoffLimitedRetryHandler, socket, timeout,
|
||||
username, password, null);
|
||||
injector.injectMembers(client);// add logger
|
||||
return client;
|
||||
}
|
||||
|
||||
public SshClient create(InetSocketAddress socket, String username, byte[] privateKey) {
|
||||
public SshClient create(IPSocket socket, String username, byte[] privateKey) {
|
||||
SshClient client = new JschSshClient(backoffLimitedRetryHandler, socket, timeout,
|
||||
username, null, privateKey);
|
||||
injector.injectMembers(client);// add logger
|
||||
|
|
|
@ -16,44 +16,62 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.predicates;
|
||||
package org.jclouds.ssh.jsch.predicates;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
* Tests to see if an address is reachable.
|
||||
* Tests to see if a socket is open.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class AddressReachable implements Predicate<InetAddress> {
|
||||
public class InetSocketAddressConnect implements SocketOpen {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject(optional = true)
|
||||
@Named("org.jclouds.address_timeout")
|
||||
@Named("org.jclouds.socket_timeout")
|
||||
private int timeout = 2000;
|
||||
|
||||
@Override
|
||||
public boolean apply(InetAddress address) {
|
||||
public boolean apply(IPSocket socketA) {
|
||||
InetSocketAddress socketAddress = new InetSocketAddress(socketA.getAddress(), socketA
|
||||
.getPort());
|
||||
Socket socket = null;
|
||||
try {
|
||||
logger.trace("testing address %s", address);
|
||||
return address.isReachable(timeout);
|
||||
logger.trace("testing socket %s", socketAddress);
|
||||
socket = new Socket();
|
||||
socket.setReuseAddress(false);
|
||||
socket.setSoLinger(false, 1);
|
||||
socket.setSoTimeout(timeout);
|
||||
socket.connect(socketAddress, timeout);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException ioe) {
|
||||
// no work to do
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -25,10 +25,8 @@ import java.io.FileInputStream;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.ssh.ExecResponse;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
|
@ -56,8 +54,6 @@ public class JschSshClientLiveTest {
|
|||
@BeforeGroups(groups = { "live" })
|
||||
public SshClient setupClient() throws NumberFormatException, FileNotFoundException, IOException {
|
||||
int port = (sshPort != null) ? Integer.parseInt(sshPort) : 22;
|
||||
InetAddress host = (sshHost != null) ? InetAddress.getByName(sshHost) : InetAddress
|
||||
.getLocalHost();
|
||||
if (sshUser == null
|
||||
|| ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile
|
||||
.trim().equals(""))) || sshUser.trim().equals("")) {
|
||||
|
@ -81,11 +77,7 @@ public class JschSshClientLiveTest {
|
|||
|
||||
public ExecResponse exec(String command) {
|
||||
if (command.equals("hostname")) {
|
||||
try {
|
||||
return new ExecResponse(InetAddress.getLocalHost().getHostName(), "", 0);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new ExecResponse(sshHost, "", 0);
|
||||
}
|
||||
throw new RuntimeException("command " + command + " not stubbed");
|
||||
}
|
||||
|
@ -111,10 +103,10 @@ public class JschSshClientLiveTest {
|
|||
SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
|
||||
SshClient connection;
|
||||
if (sshKeyFile != null && !sshKeyFile.trim().equals("")) {
|
||||
connection = factory.create(new InetSocketAddress(host, port), sshUser, Utils
|
||||
connection = factory.create(new IPSocket(sshHost, port), sshUser, Utils
|
||||
.toStringAndClose(new FileInputStream(sshKeyFile)).getBytes());
|
||||
} else {
|
||||
connection = factory.create(new InetSocketAddress(host, port), sshUser, sshPass);
|
||||
connection = factory.create(new IPSocket(sshHost, port), sshUser, sshPass);
|
||||
}
|
||||
connection.connect();
|
||||
return connection;
|
||||
|
@ -140,7 +132,7 @@ public class JschSshClientLiveTest {
|
|||
public void testExecHostname() throws IOException {
|
||||
ExecResponse response = setupClient().exec("hostname");
|
||||
assertEquals(response.getError(), "");
|
||||
assertEquals(response.getOutput().trim(), InetAddress.getLocalHost().getHostName());
|
||||
assertEquals(response.getOutput().trim(), sshHost);
|
||||
}
|
||||
|
||||
}
|
|
@ -20,10 +20,9 @@ package org.jclouds.ssh.jsch;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -51,8 +50,8 @@ public class JschSshClientTest {
|
|||
protected JschSshClient createClient() throws UnknownHostException {
|
||||
Injector i = Guice.createInjector(module());
|
||||
SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
|
||||
JschSshClient ssh = JschSshClient.class.cast(factory.create(new InetSocketAddress(InetAddress
|
||||
.getLocalHost(), 22), "username", "password"));
|
||||
JschSshClient ssh = JschSshClient.class.cast(factory.create(new IPSocket("localhost", 22),
|
||||
"username", "password"));
|
||||
return ssh;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,18 +18,18 @@
|
|||
*/
|
||||
package org.jclouds.ssh.jsch.config;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.jsch.JschSshClient;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the ability to configure a {@link JschSshClient}
|
||||
|
@ -43,8 +43,7 @@ public class JschSshClientModuleTest {
|
|||
|
||||
Injector i = Guice.createInjector(new JschSshClientModule());
|
||||
SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
|
||||
SshClient connection = factory.create(new InetSocketAddress(InetAddress.getLocalHost(), 22),
|
||||
"username", "password");
|
||||
SshClient connection = factory.create(new IPSocket("localhost", 22), "username", "password");
|
||||
assert connection instanceof JschSshClient;
|
||||
Map<String, String> keyPair = factory.generateRSAKeyPair("comment", "hola");
|
||||
assertEquals(keyPair.get("comment"), "comment");
|
||||
|
|
|
@ -18,18 +18,18 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.binders;
|
||||
|
||||
import org.jclouds.gogrid.domain.IpPortPair;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.REAL_IP_LIST_KEY;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.gogrid.domain.IpPortPair;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
/**
|
||||
* Binds a list of real IPs to the request.
|
||||
*
|
||||
|
@ -57,8 +57,7 @@ public class BindRealIpPortPairsToQueryParams implements Binder {
|
|||
"There must be an IP address defined in Ip object");
|
||||
checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");
|
||||
|
||||
generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp()
|
||||
.getHostAddress());
|
||||
generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp());
|
||||
generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".port", String.valueOf(ipPortPair
|
||||
.getPort()));
|
||||
i++;
|
||||
|
|
|
@ -51,8 +51,7 @@ public class BindVirtualIpPortPairToQueryParams implements Binder {
|
|||
checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
|
||||
checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");
|
||||
|
||||
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp()
|
||||
.getHostAddress());
|
||||
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp());
|
||||
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
|||
import static org.jclouds.compute.predicates.ImagePredicates.architectureIn;
|
||||
import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -230,22 +228,6 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
|
|||
NodeState.PENDING).build();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Function<String, InetAddress> provideStringIpToInetAddress() {
|
||||
return new Function<String, InetAddress>() {
|
||||
@Override
|
||||
public InetAddress apply(String from) {
|
||||
try {
|
||||
return InetAddress.getByName(from);
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO: log the failure.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds matches to required configurations. GoGrid's documentation only specifies how much RAM
|
||||
* one can get with different instance types. The # of cores and disk sizes are purely empyrical
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.gogrid.compute.functions;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
@ -92,7 +91,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
public NodeMetadata apply(Server from) {
|
||||
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
|
||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
||||
Set<InetAddress> ipSet = ImmutableSet.of(from.getIp().getIp());
|
||||
Set<String> ipSet = ImmutableSet.of(from.getIp().getIp());
|
||||
NodeState state = serverStateToNodeState.get(from.getState().getName());
|
||||
Credentials creds = client.getServerCredentialsList().get(from.getName());
|
||||
Image image = null;
|
||||
|
@ -105,6 +104,6 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
}
|
||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location,
|
||||
null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList
|
||||
.<InetAddress> of(), ImmutableMap.<String, String> of(), creds);
|
||||
.<String> of(), ImmutableMap.<String, String> of(), creds);
|
||||
}
|
||||
}
|
|
@ -43,7 +43,6 @@ package org.jclouds.gogrid.config;
|
|||
|
||||
import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_SESSIONINTERVAL;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -83,6 +82,7 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
@ -190,8 +190,8 @@ public class GoGridRestClientModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 1, TimeUnit.SECONDS);
|
||||
protected Predicate<IPSocket> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<IPSocket>(open, 130, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import com.google.common.primitives.Longs;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
@ -35,7 +33,7 @@ public class Ip implements Comparable<Ip> {
|
|||
|
||||
private long id;
|
||||
|
||||
private InetAddress ip;
|
||||
private String ip;
|
||||
private String subnet;
|
||||
@SerializedName("public")
|
||||
private boolean isPublic;
|
||||
|
@ -53,11 +51,11 @@ public class Ip implements Comparable<Ip> {
|
|||
* @param ip
|
||||
* ip address
|
||||
*/
|
||||
public Ip(InetAddress ip) {
|
||||
public Ip(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public Ip(long id, InetAddress ip, String subnet, boolean isPublic, IpState state) {
|
||||
public Ip(long id, String ip, String subnet, boolean isPublic, IpState state) {
|
||||
this.id = id;
|
||||
this.ip = ip;
|
||||
this.subnet = subnet;
|
||||
|
@ -69,7 +67,7 @@ public class Ip implements Comparable<Ip> {
|
|||
return id;
|
||||
}
|
||||
|
||||
public InetAddress getIp() {
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,11 +33,9 @@ import static org.jclouds.gogrid.reference.GoGridQueryParams.POWER_KEY;
|
|||
import static org.jclouds.gogrid.reference.GoGridQueryParams.SERVER_ID_OR_NAME_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.SERVER_RAM_KEY;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
|
@ -58,12 +56,10 @@ import org.jclouds.gogrid.options.AddServerOptions;
|
|||
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
|
@ -123,17 +119,7 @@ public interface GridServerAsyncClient {
|
|||
@Path("/grid/server/add")
|
||||
ListenableFuture<Server> addServer(@QueryParam(NAME_KEY) String name,
|
||||
@QueryParam(IMAGE_KEY) String image, @QueryParam(SERVER_RAM_KEY) String ram,
|
||||
@QueryParam(IP_KEY) @ParamParser(InetAddressHostName.class) InetAddress ip,
|
||||
AddServerOptions... addServerOptions);
|
||||
|
||||
@Singleton
|
||||
public static class InetAddressHostName implements Function<Object, String> {
|
||||
|
||||
public String apply(Object from) {
|
||||
return ((InetAddress) from).getHostAddress();
|
||||
}
|
||||
|
||||
}
|
||||
@QueryParam(IP_KEY) String ip, AddServerOptions... addServerOptions);
|
||||
|
||||
/**
|
||||
* @see GridServerClient#power(String, org.jclouds.gogrid.domain.PowerCommand)
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -39,116 +38,115 @@ import org.jclouds.gogrid.options.GetServerListOptions;
|
|||
/**
|
||||
* Provides synchronous access to GoGrid.
|
||||
* <p/>
|
||||
*
|
||||
*
|
||||
* @see GridServerAsyncClient
|
||||
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API" />
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GridServerClient {
|
||||
|
||||
/**
|
||||
* Returns the list of all servers.
|
||||
*
|
||||
* The result can be narrowed down by providing the options.
|
||||
* @param getServerListOptions options to narrow down the result
|
||||
* @return servers found by the request
|
||||
*/
|
||||
Set<Server> getServerList(GetServerListOptions... getServerListOptions);
|
||||
/**
|
||||
* Returns the list of all servers.
|
||||
*
|
||||
* The result can be narrowed down by providing the options.
|
||||
*
|
||||
* @param getServerListOptions
|
||||
* options to narrow down the result
|
||||
* @return servers found by the request
|
||||
*/
|
||||
Set<Server> getServerList(GetServerListOptions... getServerListOptions);
|
||||
|
||||
/**
|
||||
* Returns the server(s) by unique name(s).
|
||||
*
|
||||
* Given a name or a set of names, finds one or
|
||||
* multiple servers.
|
||||
* @param names to get the servers
|
||||
* @return server(s) matching the name(s)
|
||||
*/
|
||||
Set<Server> getServersByName(String... names);
|
||||
/**
|
||||
* Returns the server(s) by unique name(s).
|
||||
*
|
||||
* Given a name or a set of names, finds one or multiple servers.
|
||||
*
|
||||
* @param names
|
||||
* to get the servers
|
||||
* @return server(s) matching the name(s)
|
||||
*/
|
||||
Set<Server> getServersByName(String... names);
|
||||
|
||||
/**
|
||||
* Returns the server(s) by unique id(s).
|
||||
*
|
||||
* Given an id or a set of ids, finds one or
|
||||
* multiple servers.
|
||||
* @param ids to get the servers
|
||||
* @return server(s) matching the ids
|
||||
*/
|
||||
Set<Server> getServersById(Long... ids);
|
||||
/**
|
||||
* Returns the server(s) by unique id(s).
|
||||
*
|
||||
* Given an id or a set of ids, finds one or multiple servers.
|
||||
*
|
||||
* @param ids
|
||||
* to get the servers
|
||||
* @return server(s) matching the ids
|
||||
*/
|
||||
Set<Server> getServersById(Long... ids);
|
||||
|
||||
/**
|
||||
* Returns a map of running servers' names to the
|
||||
* log in credentials.
|
||||
* @return map <String server name => Credentials>
|
||||
*/
|
||||
Map<String, Credentials> getServerCredentialsList();
|
||||
/**
|
||||
* Returns a map of running servers' names to the log in credentials.
|
||||
*
|
||||
* @return map <String server name => Credentials>
|
||||
*/
|
||||
Map<String, Credentials> getServerCredentialsList();
|
||||
|
||||
/**
|
||||
* Adds a server with specified attributes
|
||||
*
|
||||
* @param name name of the server
|
||||
* @param image
|
||||
* image (id or name)
|
||||
* @param ram
|
||||
* ram type (id or name)
|
||||
* @param ip
|
||||
* ip address
|
||||
* @param addServerOptions
|
||||
* options to make it a sandbox instance or/and description
|
||||
* @return created server
|
||||
*/
|
||||
Server addServer(String name,
|
||||
String image,
|
||||
String ram,
|
||||
InetAddress ip,
|
||||
AddServerOptions... addServerOptions);
|
||||
/**
|
||||
* Adds a server with specified attributes
|
||||
*
|
||||
* @param name
|
||||
* name of the server
|
||||
* @param image
|
||||
* image (id or name)
|
||||
* @param ram
|
||||
* ram type (id or name)
|
||||
* @param ip
|
||||
* ip address
|
||||
* @param addServerOptions
|
||||
* options to make it a sandbox instance or/and description
|
||||
* @return created server
|
||||
*/
|
||||
Server addServer(String name, String image, String ram, String ip,
|
||||
AddServerOptions... addServerOptions);
|
||||
|
||||
/**
|
||||
* Changes the server's state according to {@link PowerCommand}
|
||||
*
|
||||
* @param idOrName
|
||||
* id or name of the server to apply the command
|
||||
* @param power
|
||||
* new desired state
|
||||
* @return server immediately after applying the command
|
||||
*/
|
||||
Server power(String idOrName, PowerCommand power);
|
||||
|
||||
/**
|
||||
* Changes the server's state according to {@link PowerCommand}
|
||||
*
|
||||
* @param idOrName
|
||||
* id or name of the server to apply the command
|
||||
* @param power
|
||||
* new desired state
|
||||
* @return server immediately after applying the command
|
||||
*/
|
||||
Server power(String idOrName,
|
||||
PowerCommand power);
|
||||
/**
|
||||
* Deletes the server by Id
|
||||
*
|
||||
* @param id
|
||||
* id of the server to delete
|
||||
* @return server before the command is executed
|
||||
*/
|
||||
Server deleteById(Long id);
|
||||
|
||||
/**
|
||||
* Deletes the server by Id
|
||||
*
|
||||
* @param id
|
||||
* id of the server to delete
|
||||
* @return server before the command is executed
|
||||
*/
|
||||
Server deleteById(Long id);
|
||||
/**
|
||||
* Deletes the server by name;
|
||||
*
|
||||
* NOTE: Using this parameter may generate an error if one or more servers share a non-unique
|
||||
* name.
|
||||
*
|
||||
* @param name
|
||||
* name of the server to be deleted
|
||||
*
|
||||
* @return server before the command is executed
|
||||
*/
|
||||
Server deleteByName(String name);
|
||||
|
||||
/**
|
||||
* Deletes the server by name;
|
||||
*
|
||||
* NOTE: Using this parameter may generate an
|
||||
* error if one or more servers share a non-unique name.
|
||||
*
|
||||
* @param name
|
||||
* name of the server to be deleted
|
||||
*
|
||||
* @return server before the command is executed
|
||||
*/
|
||||
Server deleteByName(String name);
|
||||
|
||||
/**
|
||||
* Retrieves the list of supported RAM configurations.
|
||||
* The objects will have RAM ID, name and description. In
|
||||
* most cases, id or name will be used for {@link #addServer}.
|
||||
*
|
||||
* To see how RAM maps to CPU and disk space (as of March 2010),
|
||||
* see {@link org.jclouds.gogrid.compute.config.GoGridComputeServiceContextModule#provideSizeToRam}.
|
||||
*
|
||||
* @return supported ram sizes
|
||||
*/
|
||||
Set<Option> getRamSizes();
|
||||
/**
|
||||
* Retrieves the list of supported RAM configurations. The objects will have RAM ID, name and
|
||||
* description. In most cases, id or name will be used for {@link #addServer}.
|
||||
*
|
||||
* To see how RAM maps to CPU and disk space (as of March 2010), see
|
||||
* {@link org.jclouds.gogrid.compute.config.GoGridComputeServiceContextModule#provideSizeToRam}.
|
||||
*
|
||||
* @return supported ram sizes
|
||||
*/
|
||||
Set<Option> getRamSizes();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import static org.testng.Assert.assertNotNull;
|
|||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
@ -55,10 +54,11 @@ import org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted;
|
|||
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
||||
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.jsch.JschSshClient;
|
||||
import org.jclouds.ssh.jsch.predicates.InetSocketAddressConnect;
|
||||
import org.testng.SkipException;
|
||||
import org.testng.TestException;
|
||||
import org.testng.annotations.AfterTest;
|
||||
|
@ -345,10 +345,10 @@ public class GoGridLiveTest {
|
|||
Credentials instanceCredentials = credsMap.get(createdServer.getName());
|
||||
assertNotNull(instanceCredentials);
|
||||
|
||||
InetSocketAddress socket = new InetSocketAddress(createdServer.getIp().getIp(), 22);
|
||||
IPSocket socket = new IPSocket(createdServer.getIp().getIp(), 22);
|
||||
|
||||
Predicate<InetSocketAddress> socketOpen = new RetryablePredicate<InetSocketAddress>(
|
||||
new SocketOpen(), 180, 5, TimeUnit.SECONDS);
|
||||
RetryablePredicate<IPSocket> socketOpen = new RetryablePredicate<IPSocket>(
|
||||
new InetSocketAddressConnect(), 180, 5, TimeUnit.SECONDS);
|
||||
|
||||
socketOpen.apply(socket);
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import static org.easymock.classextension.EasyMock.replay;
|
|||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -53,8 +52,7 @@ public class ServerToNodeMetadataTest {
|
|||
expect(client.getServerCredentialsList()).andReturn(credentialsMap);
|
||||
expect(credentialsMap.get("tag-ff")).andReturn(new Credentials("user", "pass"));
|
||||
|
||||
expect(server.getIp()).andReturn(
|
||||
new Ip(InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 })));
|
||||
expect(server.getIp()).andReturn(new Ip("127.0.0.1"));
|
||||
|
||||
ServerImage image = createMock(ServerImage.class);
|
||||
expect(server.getImage()).andReturn(image).atLeastOnce();
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.gogrid.functions;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
@ -64,14 +63,14 @@ public class ParseLoadBalancersFromJsonResponseTest {
|
|||
.getInstance(Gson.class));
|
||||
SortedSet<LoadBalancer> response = parser.apply(is);
|
||||
|
||||
LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null, new IpPortPair(new Ip(
|
||||
1313082L, InetAddress.getByName("204.51.240.181"), "204.51.240.176/255.255.255.240",
|
||||
true, IpState.ASSIGNED), 80), ImmutableSortedSet.of(new IpPortPair(new Ip(1313086L,
|
||||
InetAddress.getByName("204.51.240.185"), "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED), 80), new IpPortPair(new Ip(1313089L, InetAddress
|
||||
.getByName("204.51.240.188"), "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED), 80)), LoadBalancerType.ROUND_ROBIN,
|
||||
LoadBalancerPersistenceType.NONE, LoadBalancerOs.F5, LoadBalancerState.ON);
|
||||
LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null, new IpPortPair(
|
||||
new Ip(1313082L, "204.51.240.181", "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED), 80), ImmutableSortedSet.of(new IpPortPair(
|
||||
new Ip(1313086L, "204.51.240.185", "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED), 80), new IpPortPair(new Ip(1313089L, "204.51.240.188",
|
||||
"204.51.240.176/255.255.255.240", true, IpState.ASSIGNED), 80)),
|
||||
LoadBalancerType.ROUND_ROBIN, LoadBalancerPersistenceType.NONE, LoadBalancerOs.F5,
|
||||
LoadBalancerState.ON);
|
||||
assertEquals(Iterables.getOnlyElement(response), loadBalancer);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ package org.jclouds.gogrid.functions;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
@ -78,14 +77,13 @@ public class ParseServersFromJsonResponseTest {
|
|||
Server server = new Server(75245L, false, "PowerServer",
|
||||
"server to test the api. created by Alex", new Option(1L, "On",
|
||||
"Server is in active state."), webServer, new Option(1L, "512MB",
|
||||
"Server with 512MB RAM"), centOs, new Ip(1313079L, InetAddress
|
||||
.getByName("204.51.240.178"), "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED), new ServerImage(1946L,
|
||||
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0",
|
||||
"http://bitnami.org/stack/gallery", centOs, null,
|
||||
ServerImageType.WEB_APPLICATION_SERVER, ServerImageState.AVAILABLE, 0.0,
|
||||
"24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true, new Date(
|
||||
1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(
|
||||
"Server with 512MB RAM"), centOs, new Ip(1313079L, "204.51.240.178",
|
||||
"204.51.240.176/255.255.255.240", true, IpState.ASSIGNED), new ServerImage(
|
||||
1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||
"BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery", centOs,
|
||||
null, ServerImageType.WEB_APPLICATION_SERVER, ServerImageState.AVAILABLE,
|
||||
0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true,
|
||||
new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(
|
||||
new BillingToken(38L, "CentOS 5.2 32bit", 0.0), new BillingToken(
|
||||
56L, "BitNami: Gallery", 0.0)), new Customer(24732L,
|
||||
"BitRock")));
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -92,11 +91,10 @@ public class GridLoadBalancerAsyncClientTest extends RestClientTest<GridLoadBala
|
|||
Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer", String.class,
|
||||
IpPortPair.class, List.class, AddLoadBalancerOptions[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "BalanceIt", new IpPortPair(new Ip(InetAddress.getByName("127.0.0.1")), 80),
|
||||
Arrays.asList(new IpPortPair(new Ip(InetAddress.getByName("127.0.0.1")), 8080),
|
||||
new IpPortPair(new Ip(InetAddress.getByName("127.0.0.1")), 9090)),
|
||||
new AddLoadBalancerOptions.Builder().create(LoadBalancerType.LEAST_CONNECTED,
|
||||
LoadBalancerPersistenceType.SSL_STICKY));
|
||||
method, "BalanceIt", new IpPortPair(new Ip("127.0.0.1"), 80), Arrays.asList(
|
||||
new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(new Ip(
|
||||
"127.0.0.1"), 9090)), new AddLoadBalancerOptions.Builder().create(
|
||||
LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SSL_STICKY));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&"
|
||||
|
@ -128,9 +126,8 @@ public class GridLoadBalancerAsyncClientTest extends RestClientTest<GridLoadBala
|
|||
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", String.class,
|
||||
List.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "BalanceIt", Arrays.asList(new IpPortPair(new Ip(InetAddress
|
||||
.getByName("127.0.0.1")), 8080), new IpPortPair(new Ip(InetAddress
|
||||
.getByName("127.0.0.1")), 9090)));
|
||||
method, "BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
||||
new IpPortPair(new Ip("127.0.0.1"), 9090)));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&"
|
||||
|
|
|
@ -47,7 +47,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -188,9 +187,9 @@ public class GridServerAsyncClientTest extends RestClientTest<GridServerAsyncCli
|
|||
@Test
|
||||
public void testAddServerNoOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class,
|
||||
String.class, String.class, InetAddress.class, AddServerOptions[].class);
|
||||
String.class, String.class, String.class, AddServerOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"serverName", "img55", "memory", InetAddress.getByName("127.0.0.1"));
|
||||
"serverName", "img55", "memory", "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?v=1.3&"
|
||||
+ "name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 " + "HTTP/1.1");
|
||||
|
@ -214,9 +213,9 @@ public class GridServerAsyncClientTest extends RestClientTest<GridServerAsyncCli
|
|||
@Test
|
||||
public void testAddServerOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class,
|
||||
String.class, String.class, InetAddress.class, AddServerOptions[].class);
|
||||
String.class, String.class, String.class, AddServerOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"serverName", "img55", "memory", InetAddress.getByName("127.0.0.1"),
|
||||
"serverName", "img55", "memory", "127.0.0.1",
|
||||
new AddServerOptions().asSandboxType().withDescription("fooy"));
|
||||
|
||||
assertRequestLineEquals(
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.rackspace.cloudservers;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
@ -47,7 +46,6 @@ import org.jclouds.rackspace.cloudservers.domain.Image;
|
|||
import org.jclouds.rackspace.cloudservers.domain.RebootType;
|
||||
import org.jclouds.rackspace.cloudservers.domain.Server;
|
||||
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
|
||||
import org.jclouds.rackspace.cloudservers.functions.IpAddress;
|
||||
import org.jclouds.rackspace.cloudservers.functions.ParseAddressesFromJsonResponse;
|
||||
import org.jclouds.rackspace.cloudservers.functions.ParseBackupScheduleFromJsonResponse;
|
||||
import org.jclouds.rackspace.cloudservers.functions.ParseFlavorFromJsonResponse;
|
||||
|
@ -70,7 +68,6 @@ import org.jclouds.rest.annotations.Endpoint;
|
|||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
@ -187,8 +184,7 @@ public interface CloudServersAsyncClient {
|
|||
@PUT
|
||||
@Path("/servers/{id}/ips/public/{address}")
|
||||
@MapBinder(BindSharedIpGroupToJsonPayload.class)
|
||||
ListenableFuture<Void> shareIp(
|
||||
@PathParam("address") @ParamParser(IpAddress.class) InetAddress addressToShare,
|
||||
ListenableFuture<Void> shareIp(@PathParam("address") String addressToShare,
|
||||
@PathParam("id") int serverToTosignBindressTo,
|
||||
@MapPayloadParam("sharedIpGroupId") int sharedIpGroup,
|
||||
@MapPayloadParam("configureServer") boolean configureServer);
|
||||
|
@ -199,8 +195,7 @@ public interface CloudServersAsyncClient {
|
|||
@DELETE
|
||||
@Path("/servers/{id}/ips/public/{address}")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> unshareIp(
|
||||
@PathParam("address") @ParamParser(IpAddress.class) InetAddress addressToShare,
|
||||
ListenableFuture<Void> unshareIp(@PathParam("address") String addressToShare,
|
||||
@PathParam("id") int serverToTosignBindressTo);
|
||||
|
||||
/**
|
||||
|
@ -356,7 +351,7 @@ public interface CloudServersAsyncClient {
|
|||
@ResponseParser(ParseInetAddressListFromJsonResponse.class)
|
||||
@QueryParams(keys = "format", values = "json")
|
||||
@Path("/servers/{id}/ips/public")
|
||||
ListenableFuture<? extends List<InetAddress>> listPublicAddresses(@PathParam("id") int serverId);
|
||||
ListenableFuture<? extends List<String>> listPublicAddresses(@PathParam("id") int serverId);
|
||||
|
||||
/**
|
||||
* @see CloudServersClient#listPrivateAddresses
|
||||
|
@ -365,6 +360,6 @@ public interface CloudServersAsyncClient {
|
|||
@ResponseParser(ParseInetAddressListFromJsonResponse.class)
|
||||
@QueryParams(keys = "format", values = "json")
|
||||
@Path("/servers/{id}/ips/private")
|
||||
ListenableFuture<? extends List<InetAddress>> listPrivateAddresses(@PathParam("id") int serverId);
|
||||
ListenableFuture<? extends List<String>> listPrivateAddresses(@PathParam("id") int serverId);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.rackspace.cloudservers;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -194,7 +193,7 @@ public interface CloudServersClient {
|
|||
* (e.g. keepalived) can then be used within the servers to perform health checks and
|
||||
* manage IP failover.
|
||||
*/
|
||||
void shareIp(InetAddress addressToShare, int serverToTosignBindressTo, int sharedIpGroup,
|
||||
void shareIp(String addressToShare, int serverToTosignBindressTo, int sharedIpGroup,
|
||||
boolean configureServer);
|
||||
|
||||
/**
|
||||
|
@ -206,7 +205,7 @@ public interface CloudServersClient {
|
|||
* @param serverToTosignBindressTo
|
||||
* @return
|
||||
*/
|
||||
void unshareIp(InetAddress addressToShare, int serverToTosignBindressTo);
|
||||
void unshareIp(String addressToShare, int serverToTosignBindressTo);
|
||||
|
||||
/**
|
||||
* This operation allows you to change the administrative password.
|
||||
|
@ -370,7 +369,7 @@ public interface CloudServersClient {
|
|||
* @throws ResourceNotFoundException
|
||||
* , if the server doesn't exist
|
||||
*/
|
||||
List<InetAddress> listPublicAddresses(int serverId);
|
||||
List<String> listPublicAddresses(int serverId);
|
||||
|
||||
/**
|
||||
* List all private server addresses
|
||||
|
@ -378,6 +377,6 @@ public interface CloudServersClient {
|
|||
* @throws ResourceNotFoundException
|
||||
* , if the server doesn't exist
|
||||
*/
|
||||
List<InetAddress> listPrivateAddresses(int serverId);
|
||||
List<String> listPrivateAddresses(int serverId);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.rackspace.cloudservers.config;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -30,6 +29,7 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient;
|
||||
|
@ -73,8 +73,8 @@ public class CloudServersRestClientModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 1, TimeUnit.SECONDS);
|
||||
protected Predicate<IPSocket> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<IPSocket>(open, 130, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -89,7 +89,7 @@ public class CloudServersRestClientModule extends AbstractModule {
|
|||
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(CloudServersClient.class, client);
|
||||
}
|
||||
|
||||
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
|
||||
ParseCloudServersErrorFromHttpResponse.class);
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.rackspace.cloudservers.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
@ -31,31 +30,31 @@ import com.google.gson.annotations.SerializedName;
|
|||
public class Addresses {
|
||||
|
||||
@SerializedName("public")
|
||||
private Set<InetAddress> publicAddresses = Sets.newLinkedHashSet();
|
||||
private Set<String> publicAddresses = Sets.newLinkedHashSet();
|
||||
@SerializedName("private")
|
||||
private Set<InetAddress> privateAddresses = Sets.newLinkedHashSet();
|
||||
private Set<String> privateAddresses = Sets.newLinkedHashSet();
|
||||
|
||||
public Addresses() {
|
||||
}
|
||||
|
||||
public Addresses(Set<InetAddress> publicAddresses, Set<InetAddress> privateAddresses) {
|
||||
public Addresses(Set<String> publicAddresses, Set<String> privateAddresses) {
|
||||
this.publicAddresses = publicAddresses;
|
||||
this.privateAddresses = privateAddresses;
|
||||
}
|
||||
|
||||
public void setPublicAddresses(Set<InetAddress> publicAddresses) {
|
||||
public void setPublicAddresses(Set<String> publicAddresses) {
|
||||
this.publicAddresses = publicAddresses;
|
||||
}
|
||||
|
||||
public Set<InetAddress> getPublicAddresses() {
|
||||
public Set<String> getPublicAddresses() {
|
||||
return publicAddresses;
|
||||
}
|
||||
|
||||
public void setPrivateAddresses(Set<InetAddress> privateAddresses) {
|
||||
public void setPrivateAddresses(Set<String> privateAddresses) {
|
||||
this.privateAddresses = privateAddresses;
|
||||
}
|
||||
|
||||
public Set<InetAddress> getPrivateAddresses() {
|
||||
public Set<String> getPrivateAddresses() {
|
||||
return privateAddresses;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.rackspace.cloudservers.functions;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
@Singleton
|
||||
public class IpAddress implements Function<Object, String> {
|
||||
|
||||
public String apply(Object from) {
|
||||
return ((InetAddress) from).getHostAddress();
|
||||
}
|
||||
|
||||
}
|
|
@ -22,37 +22,37 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* This parses a list of {@link InetAddress} from a gson string.
|
||||
* This parses a list of {@link String} from a gson string.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseInetAddressListFromJsonResponse extends ParseJson<List<InetAddress>> {
|
||||
public class ParseInetAddressListFromJsonResponse extends ParseJson<List<String>> {
|
||||
|
||||
@Inject
|
||||
public ParseInetAddressListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
Map<String, List<InetAddress>> addressMap;
|
||||
Map<String, List<String>> addressMap;
|
||||
|
||||
public List<InetAddress> apply(InputStream stream) {
|
||||
Type flavor = new TypeToken<Map<String, List<InetAddress>>>() {
|
||||
public List<String> apply(InputStream stream) {
|
||||
Type flavor = new TypeToken<Map<String, List<String>>>() {
|
||||
}.getType();
|
||||
try {
|
||||
Map<String, List<InetAddress>> map = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
Map<String, List<String>> map = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
flavor);
|
||||
return map.values().iterator().next();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
|
|
@ -22,7 +22,6 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -89,7 +88,7 @@ public class CreateServerOptions extends BindToJsonPayload {
|
|||
private Map<String, String> metadata = Maps.newHashMap();
|
||||
private List<File> files = Lists.newArrayList();
|
||||
private Integer sharedIpGroupId;
|
||||
private InetAddress publicIp;
|
||||
private String publicIp;
|
||||
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
|
||||
|
@ -147,7 +146,7 @@ public class CreateServerOptions extends BindToJsonPayload {
|
|||
* Note: sharedIpGroupId is an optional parameter and for optimal performance, should ONLY be
|
||||
* specified when intending to share IPs between servers.
|
||||
*
|
||||
* @see #withSharedIp(InetAddress)
|
||||
* @see #withSharedIp(String)
|
||||
*/
|
||||
public CreateServerOptions withSharedIpGroup(int id) {
|
||||
checkArgument(id > 0, "id must be positive or zero. was: " + id);
|
||||
|
@ -196,7 +195,7 @@ public class CreateServerOptions extends BindToJsonPayload {
|
|||
* the public shared IP address in your request. This is optional and is only valid if
|
||||
* sharedIpGroupId is also supplied.
|
||||
*/
|
||||
public CreateServerOptions withSharedIp(InetAddress publicIp) {
|
||||
public CreateServerOptions withSharedIp(String publicIp) {
|
||||
checkState(sharedIpGroupId != null,
|
||||
"sharedIp is invalid unless a shared ip group is specified.");
|
||||
this.publicIp = checkNotNull(publicIp, "ip");
|
||||
|
@ -230,9 +229,9 @@ public class CreateServerOptions extends BindToJsonPayload {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CreateServerOptions#withSharedIp(InetAddress)
|
||||
* @see CreateServerOptions#withSharedIp(String)
|
||||
*/
|
||||
public static CreateServerOptions withSharedIp(InetAddress publicIp) {
|
||||
public static CreateServerOptions withSharedIp(String publicIp) {
|
||||
CreateServerOptions options = new CreateServerOptions();
|
||||
return options.withSharedIp(publicIp);
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ import static org.testng.Assert.assertTrue;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -38,6 +36,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rackspace.RackspacePropertiesBuilder;
|
||||
|
@ -61,6 +60,7 @@ import org.testng.annotations.AfterTest;
|
|||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Injector;
|
||||
|
@ -76,7 +76,7 @@ public class CloudServersClientLiveTest {
|
|||
|
||||
protected CloudServersClient client;
|
||||
protected SshClient.Factory sshFactory;
|
||||
private RetryablePredicate<InetSocketAddress> socketTester;
|
||||
private Predicate<IPSocket> socketTester;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
|
@ -88,7 +88,7 @@ public class CloudServersClientLiveTest {
|
|||
client = injector.getInstance(CloudServersClient.class);
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||
socketTester = new RetryablePredicate<InetSocketAddress>(socketOpen, 120, 1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS);
|
||||
injector.injectMembers(socketOpen); // add logger
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ public class CloudServersClientLiveTest {
|
|||
private int serverId;
|
||||
private String adminPass;
|
||||
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
|
||||
private InetAddress ip;
|
||||
private String ip;
|
||||
private int serverId2;
|
||||
private String adminPass2;
|
||||
private int imageId;
|
||||
|
@ -374,8 +374,8 @@ public class CloudServersClientLiveTest {
|
|||
}
|
||||
|
||||
private void doCheckPass(Server newDetails, String pass) throws IOException {
|
||||
InetSocketAddress socket = new InetSocketAddress(Iterables.get(newDetails.getAddresses()
|
||||
.getPublicAddresses(), 0), 22);
|
||||
IPSocket socket = new IPSocket(Iterables.get(newDetails.getAddresses().getPublicAddresses(),
|
||||
0), 22);
|
||||
socketTester.apply(socket);
|
||||
|
||||
SshClient client = sshFactory.create(socket, "root", pass);
|
||||
|
@ -391,8 +391,8 @@ public class CloudServersClientLiveTest {
|
|||
}
|
||||
|
||||
private ExecResponse exec(Server details, String pass, String command) throws IOException {
|
||||
InetSocketAddress socket = new InetSocketAddress(Iterables.get(details.getAddresses()
|
||||
.getPublicAddresses(), 0), 22);
|
||||
IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0),
|
||||
22);
|
||||
socketTester.apply(socket);
|
||||
SshClient client = sshFactory.create(socket, "root", pass);
|
||||
try {
|
||||
|
@ -452,7 +452,7 @@ public class CloudServersClientLiveTest {
|
|||
private void assertIpConfigured(Server server, String password) {
|
||||
try {
|
||||
ExecResponse response = exec(server, password, "ifconfig -a");
|
||||
assert response.getOutput().indexOf(ip.getHostAddress()) > 0 : String.format(
|
||||
assert response.getOutput().indexOf(ip) > 0 : String.format(
|
||||
"server %s didn't get ip %s%n%s", server, ip, response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -473,7 +473,7 @@ public class CloudServersClientLiveTest {
|
|||
private void assertIpNotConfigured(Server server, String password) {
|
||||
try {
|
||||
ExecResponse response = exec(server, password, "ifconfig -a");
|
||||
assert response.getOutput().indexOf(ip.getHostAddress()) == -1 : String.format(
|
||||
assert response.getOutput().indexOf(ip) == -1 : String.format(
|
||||
"server %s still has get ip %s%n%s", server, ip, response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -30,7 +30,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
|
@ -156,12 +155,7 @@ public class CloudServersClientTest {
|
|||
int.class, int.class, createServerOptionsVarargsClass);
|
||||
|
||||
GeneratedHttpRequest<CloudServersAsyncClient> httpMethod = processor.createRequest(method,
|
||||
new Object[] {
|
||||
"ralphie",
|
||||
2,
|
||||
1,
|
||||
withSharedIpGroup(2).withSharedIp(
|
||||
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })) });
|
||||
new Object[] { "ralphie", 2, 1, withSharedIpGroup(2).withSharedIp("127.0.0.1") });
|
||||
assertEquals(
|
||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2,\"addresses\":{\"public\":[\"127.0.0.1\"]}}}",
|
||||
httpMethod.getPayload().getRawContent());
|
||||
|
@ -479,11 +473,11 @@ public class CloudServersClientTest {
|
|||
|
||||
public void testShareIpNoConfig() throws SecurityException, NoSuchMethodException,
|
||||
UnknownHostException {
|
||||
Method method = CloudServersAsyncClient.class.getMethod("shareIp", InetAddress.class,
|
||||
int.class, int.class, boolean.class);
|
||||
Method method = CloudServersAsyncClient.class.getMethod("shareIp", String.class, int.class,
|
||||
int.class, boolean.class);
|
||||
|
||||
GeneratedHttpRequest<CloudServersAsyncClient> httpMethod = processor.createRequest(method,
|
||||
new Object[] { InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, false });
|
||||
new Object[] { "127.0.0.1", 2, 3, false });
|
||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
||||
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
|
||||
|
@ -503,11 +497,11 @@ public class CloudServersClientTest {
|
|||
|
||||
public void testShareIpConfig() throws SecurityException, NoSuchMethodException,
|
||||
UnknownHostException {
|
||||
Method method = CloudServersAsyncClient.class.getMethod("shareIp", InetAddress.class,
|
||||
int.class, int.class, boolean.class);
|
||||
Method method = CloudServersAsyncClient.class.getMethod("shareIp", String.class, int.class,
|
||||
int.class, boolean.class);
|
||||
|
||||
GeneratedHttpRequest<CloudServersAsyncClient> httpMethod = processor.createRequest(method,
|
||||
new Object[] { InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, true });
|
||||
new Object[] { "127.0.0.1", 2, 3, true });
|
||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
||||
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
|
||||
|
@ -528,11 +522,10 @@ public class CloudServersClientTest {
|
|||
|
||||
public void testUnshareIpNoConfig() throws SecurityException, NoSuchMethodException,
|
||||
UnknownHostException {
|
||||
Method method = CloudServersAsyncClient.class.getMethod("unshareIp", InetAddress.class,
|
||||
int.class);
|
||||
Method method = CloudServersAsyncClient.class.getMethod("unshareIp", String.class, int.class);
|
||||
|
||||
GeneratedHttpRequest<CloudServersAsyncClient> httpMethod = processor.createRequest(method,
|
||||
new Object[] { InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, false });
|
||||
new Object[] { "127.0.0.1", 2, 3, false });
|
||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
||||
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
|
||||
|
|
|
@ -6,7 +6,6 @@ import static org.easymock.classextension.EasyMock.replay;
|
|||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -53,10 +52,8 @@ public class ServerToNodeMetadataTest {
|
|||
Addresses addresses = createMock(Addresses.class);
|
||||
expect(server.getAddresses()).andReturn(addresses).atLeastOnce();
|
||||
|
||||
Set<InetAddress> publicAddresses = ImmutableSet.of(InetAddress.getByAddress(new byte[] { 12,
|
||||
10, 10, 1 }));
|
||||
Set<InetAddress> privateAddresses = ImmutableSet.of(InetAddress.getByAddress(new byte[] { 10,
|
||||
10, 10, 1 }));
|
||||
Set<String> publicAddresses = ImmutableSet.of("12.10.10.1");
|
||||
Set<String> privateAddresses = ImmutableSet.of("10.10.10.1");
|
||||
|
||||
expect(addresses.getPublicAddresses()).andReturn(publicAddresses);
|
||||
expect(addresses.getPrivateAddresses()).andReturn(privateAddresses);
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.rackspace.cloudservers.functions;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -50,12 +49,9 @@ public class ParseAddressesFromJsonResponseTest {
|
|||
ParseAddressesFromJsonResponse parser = new ParseAddressesFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
Addresses response = parser.apply(is);
|
||||
List<InetAddress> publicAddresses = ImmutableList.of(InetAddress.getByAddress(new byte[] {
|
||||
67, 23, 10, (byte) 131 }), InetAddress.getByAddress(new byte[] { 67, 23, 10,
|
||||
(byte) 132 }));
|
||||
List<String> publicAddresses = ImmutableList.of("67.23.10.132", "67.23.10.131");
|
||||
|
||||
List<InetAddress> privateAddresses = ImmutableList.of(InetAddress.getByAddress(new byte[] {
|
||||
10, (byte) 176, 42, 16 }));
|
||||
List<String> privateAddresses = ImmutableList.of("10.176.42.16");
|
||||
|
||||
assertEquals(response.getPublicAddresses(), publicAddresses);
|
||||
assertEquals(response.getPrivateAddresses(), privateAddresses);
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.rackspace.cloudservers.functions;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -49,9 +48,8 @@ public class ParseInetAddressListFromJsonResponseTest {
|
|||
|
||||
ParseInetAddressListFromJsonResponse parser = new ParseInetAddressListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
List<InetAddress> response = parser.apply(is);
|
||||
assertEquals(response, ImmutableList.of(InetAddress.getByAddress(new byte[] { 67, 23, 10,
|
||||
(byte) 132 }), InetAddress.getByAddress(new byte[] { 67, 23, 10, (byte) 131 })));
|
||||
List<String> response = parser.apply(is);
|
||||
assertEquals(response, ImmutableList.of("67.23.10.132", "67.23.10.131"));
|
||||
}
|
||||
|
||||
public void testPrivate() throws UnknownHostException {
|
||||
|
@ -60,8 +58,7 @@ public class ParseInetAddressListFromJsonResponseTest {
|
|||
|
||||
ParseInetAddressListFromJsonResponse parser = new ParseInetAddressListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
List<InetAddress> response = parser.apply(is);
|
||||
assertEquals(response, ImmutableList.of(InetAddress.getByAddress(new byte[] { 10, (byte) 176,
|
||||
42, 16 })));
|
||||
List<String> response = parser.apply(is);
|
||||
assertEquals(response, ImmutableList.of("10.176.42.16"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.rackspace.cloudservers.functions;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -60,10 +59,8 @@ public class ParseServerFromJsonResponseTest {
|
|||
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
||||
assertEquals(response.getProgress(), new Integer(60));
|
||||
List<InetAddress> publicAddresses = Lists.newArrayList(InetAddress.getByName("67.23.10.132"),
|
||||
InetAddress.getByName("67.23.10.131"));
|
||||
List<InetAddress> privateAddresses = Lists
|
||||
.newArrayList(InetAddress.getByName("10.176.42.16"));
|
||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||
Addresses addresses1 = new Addresses();
|
||||
addresses1.getPrivateAddresses().addAll(privateAddresses);
|
||||
addresses1.getPublicAddresses().addAll(publicAddresses);
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.rackspace.cloudservers.functions;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -73,10 +72,8 @@ public class ParseServerListFromJsonResponseTest {
|
|||
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
|
||||
assertEquals(response.get(0).getProgress(), new Integer(60));
|
||||
List<InetAddress> publicAddresses = Lists.newArrayList(InetAddress.getByName("67.23.10.132"),
|
||||
InetAddress.getByName("67.23.10.131"));
|
||||
List<InetAddress> privateAddresses = Lists
|
||||
.newArrayList(InetAddress.getByName("10.176.42.16"));
|
||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||
Addresses addresses1 = new Addresses();
|
||||
addresses1.getPrivateAddresses().addAll(privateAddresses);
|
||||
addresses1.getPublicAddresses().addAll(publicAddresses);
|
||||
|
@ -90,10 +87,8 @@ public class ParseServerListFromJsonResponseTest {
|
|||
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
|
||||
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
|
||||
assertEquals(response.get(1).getProgress(), null);
|
||||
List<InetAddress> publicAddresses2 = Lists
|
||||
.newArrayList(InetAddress.getByName("67.23.10.133"));
|
||||
List<InetAddress> privateAddresses2 = Lists.newArrayList(InetAddress
|
||||
.getByName("10.176.42.17"));
|
||||
List<String> publicAddresses2 = Lists.newArrayList("67.23.10.133");
|
||||
List<String> privateAddresses2 = Lists.newArrayList("10.176.42.17");
|
||||
Addresses addresses2 = new Addresses();
|
||||
addresses2.getPrivateAddresses().addAll(privateAddresses2);
|
||||
addresses2.getPublicAddresses().addAll(publicAddresses2);
|
||||
|
|
|
@ -23,9 +23,7 @@ import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Bui
|
|||
import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withSharedIpGroup;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
|
||||
|
@ -110,18 +108,16 @@ public class CreateServerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithSharedIp() throws UnknownHostException {
|
||||
public void testWithSharedIp() {
|
||||
CreateServerOptions options = new CreateServerOptions();
|
||||
options.withSharedIpGroup(3).withSharedIp(
|
||||
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||
options.withSharedIpGroup(3).withSharedIp("127.0.0.1");
|
||||
HttpRequest request = buildRequest(options);
|
||||
assertSharedIp(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSharedIpStatic() throws UnknownHostException {
|
||||
CreateServerOptions options = withSharedIpGroup(3).withSharedIp(
|
||||
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||
public void testWithSharedIpStatic() {
|
||||
CreateServerOptions options = withSharedIpGroup(3).withSharedIp("127.0.0.1");
|
||||
HttpRequest request = buildRequest(options);
|
||||
assertSharedIp(request);
|
||||
}
|
||||
|
@ -133,16 +129,15 @@ public class CreateServerOptionsTest {
|
|||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testWithSharedIpNoGroup() throws UnknownHostException {
|
||||
public void testWithSharedIpNoGroup() {
|
||||
CreateServerOptions options = new CreateServerOptions();
|
||||
options.withSharedIp(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||
options.withSharedIp("127.0.0.1");
|
||||
buildRequest(options);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testWithSharedIpNoGroupStatic() throws UnknownHostException {
|
||||
CreateServerOptions options = withSharedIp(InetAddress
|
||||
.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||
public void testWithSharedIpNoGroupStatic() {
|
||||
CreateServerOptions options = withSharedIp("127.0.0.1");
|
||||
buildRequest(options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||
import static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.PROPERTY_RIMUHOSTING_DEFAULT_DC;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
@ -116,7 +114,7 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
|
|||
.to(
|
||||
new TypeLiteral<ComputeServiceContextImpl<RimuHostingAsyncClient, RimuHostingClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(new TypeLiteral<Function<Server, Iterable<InetAddress>>>() {
|
||||
bind(new TypeLiteral<Function<Server, Iterable<String>>>() {
|
||||
}).to(ServerToPublicAddresses.class);
|
||||
bind(AddNodeWithTagStrategy.class).to(RimuHostingAddNodeWithTagStrategy.class);
|
||||
bind(ListNodesStrategy.class).to(RimuHostingListNodesStrategy.class);
|
||||
|
@ -182,13 +180,13 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
|
|||
public static class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
|
||||
private final RimuHostingClient client;
|
||||
private final Predicate<Server> serverRunning;
|
||||
private final Function<Server, Iterable<InetAddress>> getPublicAddresses;
|
||||
private final Function<Server, Iterable<String>> getPublicAddresses;
|
||||
private final Map<RunningState, NodeState> runningStateToNodeState;
|
||||
|
||||
@Inject
|
||||
protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client,
|
||||
@Named("RUNNING") Predicate<Server> serverRunning,
|
||||
Function<Server, Iterable<InetAddress>> getPublicAddresses,
|
||||
Function<Server, Iterable<String>> getPublicAddresses,
|
||||
Map<RunningState, NodeState> runningStateToNodeState) {
|
||||
this.client = client;
|
||||
this.serverRunning = serverRunning;
|
||||
|
@ -208,7 +206,7 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
|
|||
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId()
|
||||
.toString(), template.getLocation(), null, ImmutableMap.<String, String> of(),
|
||||
tag, template.getImage(), runningStateToNodeState.get(server.getState()),
|
||||
getPublicAddresses.apply(server), ImmutableList.<InetAddress> of(), ImmutableMap
|
||||
getPublicAddresses.apply(server), ImmutableList.<String> of(), ImmutableMap
|
||||
.<String, String> of(), new Credentials("root", serverResponse
|
||||
.getNewInstanceRequest().getCreateOptions().getPassword()));
|
||||
return node;
|
||||
|
@ -279,7 +277,7 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
|
|||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final Function<Server, Iterable<InetAddress>> getPublicAddresses;
|
||||
private final Function<Server, Iterable<String>> getPublicAddresses;
|
||||
private final Map<RunningState, NodeState> runningStateToNodeState;
|
||||
private final Set<? extends Image> images;
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -304,7 +302,7 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
@Inject
|
||||
ServerToNodeMetadata(Function<Server, Iterable<InetAddress>> getPublicAddresses,
|
||||
ServerToNodeMetadata(Function<Server, Iterable<String>> getPublicAddresses,
|
||||
Map<RunningState, NodeState> runningStateToNodeState, Set<? extends Image> images,
|
||||
Set<? extends Location> locations) {
|
||||
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
|
||||
|
@ -332,31 +330,19 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
|
|||
NodeState state = runningStateToNodeState.get(from.getState());
|
||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "",
|
||||
location, null, ImmutableMap.<String, String> of(), tag, image, state,
|
||||
getPublicAddresses.apply(from), ImmutableList.<InetAddress> of(), ImmutableMap
|
||||
getPublicAddresses.apply(from), ImmutableList.<String> of(), ImmutableMap
|
||||
.<String, String> of(), creds);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
private static class ServerToPublicAddresses implements Function<Server, Iterable<InetAddress>> {
|
||||
private static class ServerToPublicAddresses implements Function<Server, Iterable<String>> {
|
||||
@Override
|
||||
public Iterable<InetAddress> apply(Server server) {
|
||||
Iterable<String> addresses = server.getIpAddresses() == null ? ImmutableSet.<String> of()
|
||||
: Iterables.concat(ImmutableList.of(server.getIpAddresses().getPrimaryIp()),
|
||||
server.getIpAddresses().getSecondaryIps());
|
||||
return Iterables.transform(addresses, new Function<String, InetAddress>() {
|
||||
|
||||
@Override
|
||||
public InetAddress apply(String from) {
|
||||
try {
|
||||
return InetAddress.getByName(from);
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO: log the failure.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
public Iterable<String> apply(Server server) {
|
||||
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(
|
||||
ImmutableList.of(server.getIpAddresses().getPrimaryIp()), server.getIpAddresses()
|
||||
.getSecondaryIps());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.rimuhosting.miro.config;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -28,6 +27,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.concurrent.internal.SyncProxy;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
@ -70,8 +70,8 @@ public class RimuHostingRestClientModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 1, TimeUnit.SECONDS);
|
||||
protected Predicate<IPSocket> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<IPSocket>(open, 130, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,6 @@ package org.jclouds.tools.ant.taskdefs.compute;
|
|||
import static org.jclouds.rest.RestContextFactory.getPropertiesFromResource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
@ -169,9 +168,9 @@ public class ComputeTaskUtils {
|
|||
}
|
||||
}
|
||||
|
||||
static String ipOrEmptyString(Set<InetAddress> set) {
|
||||
static String ipOrEmptyString(Set<String> set) {
|
||||
if (set.size() > 0) {
|
||||
return Iterables.get(set, 0).getHostAddress();
|
||||
return Iterables.get(set, 0);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.vcloud.compute;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -204,12 +203,12 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<InetAddress> getPrivateAddresses(String id) {
|
||||
public Set<String> getPrivateAddresses(String id) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<InetAddress> getPublicAddresses(String id) {
|
||||
public Set<String> getPublicAddresses(String id) {
|
||||
VApp vApp = client.getVApp(id);
|
||||
return Sets.newHashSet(vApp.getNetworkToAddresses().values());
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.compute;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -66,12 +65,12 @@ public interface VCloudComputeClient {
|
|||
/**
|
||||
* returns a set of addresses that are only visible to the private network.
|
||||
*/
|
||||
Set<InetAddress> getPrivateAddresses(String vAppId);
|
||||
Set<String> getPrivateAddresses(String vAppId);
|
||||
|
||||
/**
|
||||
* returns a set of addresses that are publically visible
|
||||
*/
|
||||
Set<InetAddress> getPublicAddresses(String vAppId);
|
||||
Set<String> getPublicAddresses(String vAppId);
|
||||
|
||||
/**
|
||||
* reboots the vApp, blocking until the following state transition is complete:
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.compute.functions;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -63,10 +62,8 @@ public class GetExtra implements Function<VApp, Map<String, String>> {
|
|||
+ "");
|
||||
}
|
||||
|
||||
for (Entry<String, InetAddress> net : vApp.getNetworkToAddresses().entries()) {
|
||||
extra
|
||||
.put(String.format("network/%s/ip", net.getKey()), net.getValue()
|
||||
.getHostAddress());
|
||||
for (Entry<String, String> net : vApp.getNetworkToAddresses().entries()) {
|
||||
extra.put(String.format("network/%s/ip", net.getKey()), net.getValue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "error getting extra data for vApp: %s", vApp);
|
||||
|
|
|
@ -28,8 +28,6 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
|
|||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
@ -52,7 +50,7 @@ import org.jclouds.http.annotation.Redirection;
|
|||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.predicates.AddressReachable;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
@ -101,14 +99,8 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetAddress> addressTester(AddressReachable reachable) {
|
||||
return new RetryablePredicate<InetAddress>(reachable, 60, 5, TimeUnit.SECONDS);
|
||||
protected Predicate<IPSocket> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<IPSocket>(open, 130, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.jclouds.vcloud.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
|
@ -68,10 +66,10 @@ public class FirewallRule {
|
|||
|
||||
private final Policy policy;
|
||||
private final Protocol protocol;
|
||||
private final InetAddress sourceIP;
|
||||
private final String sourceIP;
|
||||
private final String sourcePort;
|
||||
|
||||
public FirewallRule(Policy policy, Protocol protocol, InetAddress sourceIP, String sourcePort) {
|
||||
public FirewallRule(Policy policy, Protocol protocol, String sourceIP, String sourcePort) {
|
||||
this.policy = policy;
|
||||
this.protocol = protocol;
|
||||
this.sourceIP = sourceIP;
|
||||
|
@ -95,7 +93,7 @@ public class FirewallRule {
|
|||
/**
|
||||
* An IP address to which this rule applies
|
||||
*/
|
||||
public InetAddress getSourceIP() {
|
||||
public String getSourceIP() {
|
||||
return sourceIP;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* Specifies a set of Network Address Translation rules using a pair of IP addresses and a pair of
|
||||
* IP port numbers.
|
||||
|
@ -27,12 +25,13 @@ import java.net.InetAddress;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class NatRule {
|
||||
private final InetAddress externalIP;
|
||||
private final String externalIP;
|
||||
private final Integer externalPort;
|
||||
private final InetAddress internalIP;
|
||||
private final String internalIP;
|
||||
private final Integer internalPort;
|
||||
|
||||
public NatRule(InetAddress externalIP, Integer externalPort, InetAddress IntegerernalIP, Integer IntegerernalPort) {
|
||||
public NatRule(String externalIP, Integer externalPort, String IntegerernalIP,
|
||||
Integer IntegerernalPort) {
|
||||
this.externalIP = externalIP;
|
||||
this.externalPort = externalPort;
|
||||
this.internalIP = IntegerernalIP;
|
||||
|
@ -42,7 +41,7 @@ public class NatRule {
|
|||
/**
|
||||
* The externally‐visible IP address.
|
||||
*/
|
||||
public InetAddress getExternalIP() {
|
||||
public String getExternalIP() {
|
||||
return externalIP;
|
||||
}
|
||||
|
||||
|
@ -56,7 +55,7 @@ public class NatRule {
|
|||
/**
|
||||
* The Integerernally‐visible (non‐routable) IP address.
|
||||
*/
|
||||
public InetAddress getInternalIP() {
|
||||
public String getInternalIP() {
|
||||
return internalIP;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -39,21 +38,21 @@ public interface Network extends NamedResource {
|
|||
/**
|
||||
* @return IP addresses of the network’s DNS servers.
|
||||
*/
|
||||
Set<InetAddress> getDnsServers();
|
||||
Set<String> getDnsServers();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return The IP address of the network’s primary gateway
|
||||
*/
|
||||
InetAddress getGateway();
|
||||
String getGateway();
|
||||
|
||||
/**
|
||||
* *
|
||||
*
|
||||
* @return the network’s subnet mask
|
||||
*/
|
||||
InetAddress getNetmask();
|
||||
String getNetmask();
|
||||
|
||||
/**
|
||||
* return the network’s fence modes.
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.vcloud.domain.internal.VAppImpl;
|
||||
|
@ -42,7 +41,7 @@ public interface VApp extends NamedResource {
|
|||
|
||||
Long getSize();
|
||||
|
||||
ListMultimap<String, InetAddress> getNetworkToAddresses();
|
||||
ListMultimap<String, String> getNetworkToAddresses();
|
||||
|
||||
String getOperatingSystemDescription();
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.domain.internal;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -43,9 +42,9 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
|
|||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
private final String description;
|
||||
private final Set<InetAddress> dnsServers = Sets.newHashSet();
|
||||
private final InetAddress gateway;
|
||||
private final InetAddress netmask;
|
||||
private final Set<String> dnsServers = Sets.newHashSet();
|
||||
private final String gateway;
|
||||
private final String netmask;
|
||||
private final Set<FenceMode> fenceModes = Sets.newHashSet();
|
||||
@Nullable
|
||||
private final Boolean dhcp;
|
||||
|
@ -53,9 +52,8 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
|
|||
private final Set<FirewallRule> firewallRules = Sets.newHashSet();
|
||||
|
||||
public NetworkImpl(String id, String name, URI location, String description,
|
||||
Set<InetAddress> dnsServers, InetAddress gateway, InetAddress netmask,
|
||||
Set<FenceMode> fenceModes, Boolean dhcp, Set<NatRule> natRules,
|
||||
Set<FirewallRule> firewallRules) {
|
||||
Set<String> dnsServers, String gateway, String netmask, Set<FenceMode> fenceModes,
|
||||
Boolean dhcp, Set<NatRule> natRules, Set<FirewallRule> firewallRules) {
|
||||
super(id, name, VCloudMediaType.NETWORK_XML, location);
|
||||
this.description = description;
|
||||
this.dnsServers.addAll(dnsServers);
|
||||
|
@ -77,21 +75,21 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<InetAddress> getDnsServers() {
|
||||
public Set<String> getDnsServers() {
|
||||
return dnsServers;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public InetAddress getGateway() {
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public InetAddress getNetmask() {
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.domain.internal;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -47,7 +46,7 @@ public class VAppImpl implements VApp {
|
|||
private final NamedResource vDC;
|
||||
private final VAppStatus status;
|
||||
private final Long size;
|
||||
private final ListMultimap<String, InetAddress> networkToAddresses;
|
||||
private final ListMultimap<String, String> networkToAddresses;
|
||||
private final String operatingSystemDescription;
|
||||
private final VirtualSystem system;
|
||||
private final Set<ResourceAllocation> resourceAllocations;
|
||||
|
@ -56,8 +55,8 @@ public class VAppImpl implements VApp {
|
|||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
|
||||
public VAppImpl(String id, String name, URI location, VAppStatus status, Long size, NamedResource vDC,
|
||||
ListMultimap<String, InetAddress> networkToAddresses,
|
||||
public VAppImpl(String id, String name, URI location, VAppStatus status, Long size,
|
||||
NamedResource vDC, ListMultimap<String, String> networkToAddresses,
|
||||
String operatingSystemDescription, VirtualSystem system,
|
||||
Set<ResourceAllocation> resourceAllocations) {
|
||||
this.id = id;
|
||||
|
@ -83,7 +82,7 @@ public class VAppImpl implements VApp {
|
|||
return status;
|
||||
}
|
||||
|
||||
public ListMultimap<String, InetAddress> getNetworkToAddresses() {
|
||||
public ListMultimap<String, String> getNetworkToAddresses() {
|
||||
return networkToAddresses;
|
||||
}
|
||||
|
||||
|
@ -114,21 +113,13 @@ public class VAppImpl implements VApp {
|
|||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((location == null) ? 0 : location.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime
|
||||
* result
|
||||
+ ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode());
|
||||
result = prime
|
||||
* result
|
||||
+ ((operatingSystemDescription == null) ? 0
|
||||
: operatingSystemDescription.hashCode());
|
||||
result = prime
|
||||
* result
|
||||
+ ((resourceAllocationByType == null) ? 0
|
||||
: resourceAllocationByType.hashCode());
|
||||
result = prime
|
||||
* result
|
||||
+ ((resourceAllocations == null) ? 0 : resourceAllocations
|
||||
.hashCode());
|
||||
result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode());
|
||||
result = prime * result
|
||||
+ ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode());
|
||||
result = prime * result
|
||||
+ ((resourceAllocationByType == null) ? 0 : resourceAllocationByType.hashCode());
|
||||
result = prime * result
|
||||
+ ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode());
|
||||
result = prime * result + ((size == null) ? 0 : size.hashCode());
|
||||
result = prime * result + ((status == null) ? 0 : status.hashCode());
|
||||
result = prime * result + ((system == null) ? 0 : system.hashCode());
|
||||
|
@ -168,14 +159,12 @@ public class VAppImpl implements VApp {
|
|||
if (operatingSystemDescription == null) {
|
||||
if (other.operatingSystemDescription != null)
|
||||
return false;
|
||||
} else if (!operatingSystemDescription
|
||||
.equals(other.operatingSystemDescription))
|
||||
} else if (!operatingSystemDescription.equals(other.operatingSystemDescription))
|
||||
return false;
|
||||
if (resourceAllocationByType == null) {
|
||||
if (other.resourceAllocationByType != null)
|
||||
return false;
|
||||
} else if (!resourceAllocationByType
|
||||
.equals(other.resourceAllocationByType))
|
||||
} else if (!resourceAllocationByType.equals(other.resourceAllocationByType))
|
||||
return false;
|
||||
if (resourceAllocations == null) {
|
||||
if (other.resourceAllocations != null)
|
||||
|
@ -223,13 +212,11 @@ public class VAppImpl implements VApp {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", location=" + location + ", name=" + name
|
||||
+ ", networkToAddresses=" + networkToAddresses
|
||||
+ ", operatingSystemDescription=" + operatingSystemDescription
|
||||
+ ", resourceAllocationByType=" + resourceAllocationByType
|
||||
+ ", resourceAllocations=" + resourceAllocations + ", size=" + size
|
||||
+ ", status=" + status + ", system=" + system + ", vDC=" + vDC
|
||||
+ "]";
|
||||
return "[id=" + id + ", location=" + location + ", name=" + name + ", networkToAddresses="
|
||||
+ networkToAddresses + ", operatingSystemDescription=" + operatingSystemDescription
|
||||
+ ", resourceAllocationByType=" + resourceAllocationByType
|
||||
+ ", resourceAllocations=" + resourceAllocations + ", size=" + size + ", status="
|
||||
+ status + ", system=" + system + ", vDC=" + vDC + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -54,22 +52,22 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
|
|||
|
||||
private String description;
|
||||
|
||||
private Set<InetAddress> dnsServers = Sets.newHashSet();
|
||||
private InetAddress gateway;
|
||||
private InetAddress netmask;
|
||||
private Set<String> dnsServers = Sets.newHashSet();
|
||||
private String gateway;
|
||||
private String netmask;
|
||||
private Set<FenceMode> fenceModes = Sets.newHashSet();
|
||||
private Boolean dhcp;
|
||||
private Set<NatRule> natRules = Sets.newHashSet();
|
||||
private Set<FirewallRule> firewallRules = Sets.newHashSet();
|
||||
|
||||
private InetAddress externalIP;
|
||||
private String externalIP;
|
||||
private Integer externalPort;
|
||||
private InetAddress internalIP;
|
||||
private String internalIP;
|
||||
private Integer internalPort;
|
||||
|
||||
private Policy policy;
|
||||
private Protocol protocol;
|
||||
private InetAddress sourceIP;
|
||||
private String sourceIP;
|
||||
private String sourcePort;
|
||||
|
||||
public Network getResult() {
|
||||
|
@ -89,11 +87,11 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
|
|||
if (qName.equals("Description")) {
|
||||
description = currentOrNull();
|
||||
} else if (qName.equals("Dns")) {
|
||||
dnsServers.add(parseInetAddress(currentOrNull()));
|
||||
dnsServers.add(currentOrNull());
|
||||
} else if (qName.equals("Gateway")) {
|
||||
gateway = parseInetAddress(currentOrNull());
|
||||
gateway = currentOrNull();
|
||||
} else if (qName.equals("Netmask")) {
|
||||
netmask = parseInetAddress(currentOrNull());
|
||||
netmask = currentOrNull();
|
||||
} else if (qName.equals("FenceMode")) {
|
||||
fenceModes.add(FenceMode.fromValue(currentOrNull()));
|
||||
} else if (qName.equals("Dhcp")) {
|
||||
|
@ -105,11 +103,11 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
|
|||
internalIP = null;
|
||||
internalPort = null;
|
||||
} else if (qName.equals("ExternalIP")) {
|
||||
externalIP = parseInetAddress(currentOrNull());
|
||||
externalIP = currentOrNull();
|
||||
} else if (qName.equals("ExternalPort")) {
|
||||
externalPort = Integer.parseInt(currentOrNull());
|
||||
} else if (qName.equals("InternalIP")) {
|
||||
internalIP = parseInetAddress(currentOrNull());
|
||||
internalIP = currentOrNull();
|
||||
} else if (qName.equals("InternalPort")) {
|
||||
internalPort = Integer.parseInt(currentOrNull());
|
||||
} else if (qName.equals("FirewallRule")) {
|
||||
|
@ -123,7 +121,7 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
|
|||
} else if (qName.equals("Policy")) {
|
||||
protocol = Protocol.fromValue(currentOrNull());
|
||||
} else if (qName.equals("SourceIp")) {
|
||||
sourceIP = parseInetAddress(currentOrNull());
|
||||
sourceIP = currentOrNull();
|
||||
} else if (qName.equals("SourcePort")) {
|
||||
sourcePort = currentOrNull();
|
||||
}
|
||||
|
@ -140,17 +138,4 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
|
|||
return returnVal.equals("") ? null : returnVal;
|
||||
}
|
||||
|
||||
private InetAddress parseInetAddress(String string) {
|
||||
String[] byteStrings = string.split("\\.");
|
||||
byte[] bytes = new byte[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.warn(e, "error parsing ipAddress", currentText);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -63,8 +61,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
|||
protected VirtualSystem system;
|
||||
protected Set<ResourceAllocation> allocations = Sets.newLinkedHashSet();
|
||||
protected VAppStatus status;
|
||||
protected final ListMultimap<String, InetAddress> networkToAddresses = ArrayListMultimap
|
||||
.create();
|
||||
protected final ListMultimap<String, String> networkToAddresses = ArrayListMultimap.create();
|
||||
protected StringBuilder currentText = new StringBuilder();
|
||||
protected String operatingSystemDescription;
|
||||
protected boolean inOs;
|
||||
|
@ -114,7 +111,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
|||
} else if (inOs && qName.equals("Description")) {
|
||||
operatingSystemDescription = currentText.toString().trim();
|
||||
} else if (qName.endsWith("IpAddress")) {
|
||||
networkToAddresses.put(networkName, parseInetAddress(currentText.toString().trim()));
|
||||
networkToAddresses.put(networkName, currentText.toString().trim());
|
||||
} else if (qName.equals("System")) {
|
||||
systemHandler.endElement(uri, localName, qName);
|
||||
system = systemHandler.getResult();
|
||||
|
@ -135,18 +132,4 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
|||
allocationHandler.characters(ch, start, length);
|
||||
}
|
||||
|
||||
private InetAddress parseInetAddress(String string) {
|
||||
String[] byteStrings = string.split("\\.");
|
||||
byte[] bytes = new byte[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.warn(e, "error parsing ipAddress", currentText);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -63,7 +62,7 @@ public class VCloudComputeClientLiveTest {
|
|||
protected VCloudClient client;
|
||||
|
||||
protected String id;
|
||||
protected InetAddress publicAddress;
|
||||
protected String publicAddress;
|
||||
protected String templateId;
|
||||
|
||||
public static class Expectation {
|
||||
|
@ -78,7 +77,7 @@ public class VCloudComputeClientLiveTest {
|
|||
|
||||
protected Map<OsFamily, Expectation> expectationMap;
|
||||
|
||||
protected Predicate<InetAddress> addressTester;
|
||||
protected Predicate<String> addressTester;
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
|
@ -151,7 +150,7 @@ public class VCloudComputeClientLiveTest {
|
|||
new JschSshClientModule()).buildInjector();
|
||||
computeClient = injector.getInstance(VCloudComputeClient.class);
|
||||
client = injector.getInstance(VCloudClient.class);
|
||||
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
|
||||
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<String>>() {
|
||||
}));
|
||||
expectationMap = ImmutableMap.<OsFamily, Expectation> builder().put(OsFamily.CENTOS,
|
||||
new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build();
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.easymock.classextension.EasyMock.replay;
|
|||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
|
@ -69,8 +68,8 @@ import com.google.inject.util.Providers;
|
|||
@Test(groups = "unit", testName = "vcloud.VCloudListNodesStrategyTest")
|
||||
public class VCloudListNodesStrategyTest {
|
||||
private VApp newVApp() throws UnknownHostException {
|
||||
ListMultimap<String, InetAddress> networkToAddresses = ImmutableListMultimap
|
||||
.<String, InetAddress> of("Network 1", InetAddress.getLocalHost());
|
||||
ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of(
|
||||
"Network 1", "127.0.0.1");
|
||||
|
||||
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "SimpleVM", "vmx-07");
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.vcloud.xml;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
|
@ -58,8 +57,7 @@ public class NetworkHandlerTest {
|
|||
Network result = factory.create(injector.getInstance(NetworkHandler.class)).parse(is);
|
||||
assertEquals(result, new NetworkImpl("1708", "10.114.34.128/26", URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"), null,
|
||||
ImmutableSet.<InetAddress> of(), InetAddress.getByName("10.114.34.129"), InetAddress
|
||||
.getByName("255.255.255.192"), ImmutableSet
|
||||
ImmutableSet.<String> of(), "10.114.34.129", "255.255.255.192", ImmutableSet
|
||||
.<FenceMode> of(FenceMode.ISOLATED), null, ImmutableSet.<NatRule> of(),
|
||||
ImmutableSet.<FirewallRule> of()));
|
||||
}
|
||||
|
@ -72,10 +70,9 @@ public class NetworkHandlerTest {
|
|||
is);
|
||||
assertEquals(result, new NetworkImpl("1183", "188849 trust", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/network/1183"), "188849 trust",
|
||||
ImmutableSet.<InetAddress> of(InetAddress.getByName("76.12.32.110"), InetAddress
|
||||
.getByName("208.112.89.187")), InetAddress.getByName("204.12.53.89"),
|
||||
InetAddress.getByName("255.255.255.248"), ImmutableSet.<FenceMode> of(), null,
|
||||
ImmutableSet.<NatRule> of(), ImmutableSet.<FirewallRule> of()));
|
||||
ImmutableSet.<String> of("76.12.32.110", "208.112.89.187"), "204.12.53.89",
|
||||
"255.255.255.248", ImmutableSet.<FenceMode> of(), null, ImmutableSet.<NatRule> of(),
|
||||
ImmutableSet.<FirewallRule> of()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.vcloud.xml;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.SortedSet;
|
||||
|
@ -54,8 +53,8 @@ public class VAppHandlerTest extends BaseHandlerTest {
|
|||
|
||||
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||
|
||||
ListMultimap<String, InetAddress> networkToAddresses = ImmutableListMultimap
|
||||
.<String, InetAddress> of("Network 1", InetAddress.getByName("204.12.11.167"));
|
||||
ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of(
|
||||
"Network 1", "204.12.11.167");
|
||||
|
||||
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "SimpleVM", "vmx-07");
|
||||
|
||||
|
@ -92,8 +91,7 @@ public class VAppHandlerTest extends BaseHandlerTest {
|
|||
.create("http://10.150.4.49/api/v0.8/vApp/10"), VAppStatus.RESOLVED, 123456789l,
|
||||
new NamedResourceImpl("4", null, "application/vnd.vmware.vcloud.vdc+xml", URI
|
||||
.create("http://10.150.4.49/api/v0.8/vdc/4")), ImmutableListMultimap
|
||||
.<String, InetAddress> of(), null, null, ImmutableSet
|
||||
.<ResourceAllocation> of());
|
||||
.<String, String> of(), null, null, ImmutableSet.<ResourceAllocation> of());
|
||||
assertEquals(result, expects);
|
||||
}
|
||||
|
||||
|
@ -102,8 +100,8 @@ public class VAppHandlerTest extends BaseHandlerTest {
|
|||
|
||||
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||
|
||||
ListMultimap<String, InetAddress> networkToAddresses = ImmutableListMultimap
|
||||
.<String, InetAddress> of("Public Network", InetAddress.getByName("10.150.4.93"));
|
||||
ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of(
|
||||
"Public Network", "10.150.4.93");
|
||||
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "centos53", "vmx-07");
|
||||
|
||||
SortedSet<ResourceAllocation> resourceAllocations = ImmutableSortedSet
|
||||
|
@ -148,8 +146,8 @@ public class VAppHandlerTest extends BaseHandlerTest {
|
|||
|
||||
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||
|
||||
ListMultimap<String, InetAddress> networkToAddresses = ImmutableListMultimap
|
||||
.<String, InetAddress> of("Public Network", InetAddress.getByName("10.23.119.221"));
|
||||
ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of(
|
||||
"Public Network", "10.23.119.221");
|
||||
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "m1", "vmx-07");
|
||||
|
||||
SortedSet<ResourceAllocation> resourceAllocations = ImmutableSortedSet
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.hostingdotcom.domain.internal;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -46,7 +45,7 @@ public class HostingDotComVAppImpl extends VAppImpl implements HostingDotComVApp
|
|||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
|
||||
public HostingDotComVAppImpl(String id, String name, URI location, VAppStatus status, Long size,
|
||||
NamedResource vDC, ListMultimap<String, InetAddress> networkToAddresses,
|
||||
NamedResource vDC, ListMultimap<String, String> networkToAddresses,
|
||||
String operatingSystemDescription, VirtualSystem system,
|
||||
Set<ResourceAllocation> resourceAllocations, String username, String password) {
|
||||
super(id, name, location, status, size, vDC, networkToAddresses, operatingSystemDescription,
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.jclouds.vcloud.hostingdotcom.compute;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
|
@ -56,7 +54,7 @@ public class HostingDotComVCloudComputeClientLiveTest extends VCloudComputeClien
|
|||
new Log4JLoggingModule(), new JschSshClientModule()).buildInjector();
|
||||
computeClient = injector.getInstance(HostingDotComVCloudComputeClient.class);
|
||||
client = injector.getInstance(HostingDotComVCloudClient.class);
|
||||
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
|
||||
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<String>>() {
|
||||
}));
|
||||
expectationMap = ImmutableMap.<OsFamily, Expectation> builder().put(OsFamily.CENTOS,
|
||||
new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build();
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.vcloud.hostingdotcom.xml;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
|
@ -53,10 +52,10 @@ public class HostingDotComVAppHandlerTest extends BaseHandlerTest {
|
|||
HostingDotComVApp expects = new HostingDotComVAppImpl("188849-33", "188849-33", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-33"),
|
||||
VAppStatus.RESOLVED, null, new NamedResourceImpl("188849", null,
|
||||
"application/vnd.vmware.vcloud.vdc+xml", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")),
|
||||
ImmutableListMultimap.<String, InetAddress> of(),
|
||||
null, null, ImmutableSortedSet.<ResourceAllocation> of(), "root", "meatisyummy");
|
||||
"application/vnd.vmware.vcloud.vdc+xml", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")),
|
||||
ImmutableListMultimap.<String, String> of(), null, null, ImmutableSortedSet
|
||||
.<ResourceAllocation> of(), "root", "meatisyummy");
|
||||
|
||||
assertEquals(result, expects);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
|
|||
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
|
@ -46,7 +45,6 @@ import org.jclouds.rest.annotations.ParamValidators;
|
|||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.InetAddressToHostAddress;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
|
@ -278,11 +276,9 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
@MapBinder(AddNodeOptions.class)
|
||||
ListenableFuture<? extends Node> addNode(
|
||||
@PathParam("internetServiceId") int internetServiceId,
|
||||
@MapPayloadParam("ipAddress") @ParamParser(InetAddressToHostAddress.class) InetAddress ipAddress,
|
||||
@MapPayloadParam("name") String name, @MapPayloadParam("port") int port,
|
||||
AddNodeOptions... options);
|
||||
ListenableFuture<? extends Node> addNode(@PathParam("internetServiceId") int internetServiceId,
|
||||
@MapPayloadParam("ipAddress") String ipAddress, @MapPayloadParam("name") String name,
|
||||
@MapPayloadParam("port") int port, AddNodeOptions... options);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#getNodes
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -120,7 +119,7 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
* @param options
|
||||
* @return
|
||||
*/
|
||||
Node addNode(int internetServiceId, InetAddress ipAddress, String name, int port,
|
||||
Node addNode(int internetServiceId, String ipAddress, String name, int port,
|
||||
AddNodeOptions... options);
|
||||
|
||||
Node getNode(int nodeId);
|
||||
|
@ -147,8 +146,10 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
* You can make more than one change in a single request. For example, you can increase the
|
||||
* number of virtual CPUs and the amount of virtual memory in the same request.
|
||||
*
|
||||
* @param vApp vApp to change in power state off
|
||||
* @param configuration(s) to change
|
||||
* @param vApp
|
||||
* vApp to change in power state off
|
||||
* @param configuration
|
||||
* (s) to change
|
||||
* @return task of configuration change
|
||||
*/
|
||||
Task configureVApp(VApp vApp, VAppConfiguration configuration);
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.vcloud.terremark.compute;
|
|||
|
||||
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -101,10 +100,10 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
|
|||
return response;
|
||||
}
|
||||
|
||||
public InetAddress createPublicAddressMappedToPorts(String vAppId, int... ports) {
|
||||
public String createPublicAddressMappedToPorts(String vAppId, int... ports) {
|
||||
VApp vApp = client.getVApp(vAppId);
|
||||
PublicIpAddress ip = null;
|
||||
InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values());
|
||||
String privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values());
|
||||
for (int port : ports) {
|
||||
InternetService is = null;
|
||||
Protocol protocol;
|
||||
|
@ -132,18 +131,16 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
|
|||
.getName())));
|
||||
ip = is.getPublicIpAddress();
|
||||
} else {
|
||||
logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress().getHostAddress(),
|
||||
protocol, port);
|
||||
logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress(), protocol, port);
|
||||
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port,
|
||||
protocol, port, withDescription(String.format(
|
||||
"port %d access to serverId: %s name: %s", port, vApp.getId(), vApp
|
||||
.getName())));
|
||||
}
|
||||
logger.debug("<< created InternetService(%s) %s:%s:%d", is.getId(), is
|
||||
.getPublicIpAddress().getAddress().getHostAddress(), is.getProtocol(), is
|
||||
.getPort());
|
||||
logger.debug(">> adding Node %s:%d -> %s:%d", is.getPublicIpAddress().getAddress()
|
||||
.getHostAddress(), is.getPort(), privateAddress.getHostAddress(), port);
|
||||
.getPublicIpAddress().getAddress(), is.getProtocol(), is.getPort());
|
||||
logger.debug(">> adding Node %s:%d -> %s:%d", is.getPublicIpAddress().getAddress(), is
|
||||
.getPort(), privateAddress, port);
|
||||
Node node = client.addNode(is.getId(), privateAddress, vApp.getName() + "-" + port, port);
|
||||
logger.debug("<< added Node(%s)", node.getId());
|
||||
}
|
||||
|
@ -158,14 +155,14 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
|
|||
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
|
||||
ipAddresses.add(service.getPublicIpAddress());
|
||||
logger.debug(">> deleting Node(%s) %s:%d -> %s:%d", node.getId(), service
|
||||
.getPublicIpAddress().getAddress().getHostAddress(), service.getPort(),
|
||||
node.getIpAddress().getHostAddress(), node.getPort());
|
||||
.getPublicIpAddress().getAddress(), service.getPort(), node.getIpAddress(),
|
||||
node.getPort());
|
||||
client.deleteNode(node.getId());
|
||||
logger.debug("<< deleted Node(%s)", node.getId());
|
||||
SortedSet<Node> nodes = client.getNodes(service.getId());
|
||||
if (nodes.size() == 0) {
|
||||
logger.debug(">> deleting InternetService(%s) %s:%d", service.getId(), service
|
||||
.getPublicIpAddress().getAddress().getHostAddress(), service.getPort());
|
||||
.getPublicIpAddress().getAddress(), service.getPort());
|
||||
client.deleteInternetService(service.getId());
|
||||
logger.debug("<< deleted InternetService(%s)", service.getId());
|
||||
continue SERVICE;
|
||||
|
@ -182,7 +179,7 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
|
|||
.getInternetServicesOnPublicIp(address.getId());
|
||||
if (services.size() == 0) {
|
||||
logger.debug(">> deleting PublicIpAddress(%s) %s", address.getId(), address
|
||||
.getAddress().getHostAddress());
|
||||
.getAddress());
|
||||
client.deletePublicIp(address.getId());
|
||||
logger.debug("<< deleted PublicIpAddress(%s)", address.getId());
|
||||
continue IPADDRESS;
|
||||
|
@ -217,15 +214,15 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<InetAddress> getPrivateAddresses(String id) {
|
||||
public Set<String> getPrivateAddresses(String id) {
|
||||
VApp vApp = client.getVApp(id);
|
||||
return Sets.newHashSet(vApp.getNetworkToAddresses().values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<InetAddress> getPublicAddresses(String id) {
|
||||
public Set<String> getPublicAddresses(String id) {
|
||||
VApp vApp = client.getVApp(id);
|
||||
Set<InetAddress> ipAddresses = Sets.newHashSet();
|
||||
Set<String> ipAddresses = Sets.newHashSet();
|
||||
for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC().getId())) {
|
||||
for (Node node : client.getNodes(service.getId())) {
|
||||
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.jclouds.vcloud.terremark.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
@ -49,18 +47,18 @@ public class IpAddress implements Comparable<IpAddress> {
|
|||
|
||||
}
|
||||
|
||||
private final InetAddress address;
|
||||
private final String address;
|
||||
private final Status status;
|
||||
@Nullable
|
||||
private final String server;
|
||||
|
||||
public IpAddress(InetAddress address, Status status, String server) {
|
||||
public IpAddress(String address, Status status, String server) {
|
||||
this.address = address;
|
||||
this.status = status;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public InetAddress getAddress() {
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
|
@ -79,8 +77,7 @@ public class IpAddress implements Comparable<IpAddress> {
|
|||
|
||||
@Override
|
||||
public int compareTo(IpAddress o) {
|
||||
return (this == o) ? 0 : getAddress().getHostAddress().compareTo(
|
||||
o.getAddress().getHostAddress());
|
||||
return (this == o) ? 0 : getAddress().compareTo(o.getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
|
@ -28,13 +27,13 @@ public class Node implements Comparable<Node> {
|
|||
private final int id;
|
||||
private final String name;
|
||||
private final URI location;
|
||||
private final InetAddress ipAddress;
|
||||
private final String ipAddress;
|
||||
private final int port;
|
||||
private final boolean enabled;
|
||||
private final String description;
|
||||
|
||||
public Node(int id, String name, URI location, InetAddress ipAddress, int port,
|
||||
boolean enabled, String description) {
|
||||
public Node(int id, String name, URI location, String ipAddress, int port, boolean enabled,
|
||||
String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
|
@ -68,10 +67,10 @@ public class Node implements Comparable<Node> {
|
|||
return location;
|
||||
}
|
||||
|
||||
public InetAddress getIpAddress() {
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
|
||||
public int compareTo(Node that) {
|
||||
if (this == that)
|
||||
return 0;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
|
@ -26,10 +25,10 @@ import java.net.URI;
|
|||
*/
|
||||
public class PublicIpAddress implements Comparable<PublicIpAddress> {
|
||||
private final int id;
|
||||
private final InetAddress address;
|
||||
private final String address;
|
||||
private final URI location;
|
||||
|
||||
public PublicIpAddress(int id, InetAddress address, URI location) {
|
||||
public PublicIpAddress(int id, String address, URI location) {
|
||||
this.id = id;
|
||||
this.address = address;
|
||||
this.location = location;
|
||||
|
@ -43,7 +42,7 @@ public class PublicIpAddress implements Comparable<PublicIpAddress> {
|
|||
return location;
|
||||
}
|
||||
|
||||
public InetAddress getAddress() {
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
@ -47,7 +45,7 @@ public class InternetServiceHandler extends HandlerWithResult<InternetService> {
|
|||
private URI location;
|
||||
private URI addressLocation;
|
||||
private String serviceName;
|
||||
private InetAddress address;
|
||||
private String address;
|
||||
private PublicIpAddress publicIpAddress;
|
||||
private int port;
|
||||
private String description;
|
||||
|
@ -87,7 +85,7 @@ public class InternetServiceHandler extends HandlerWithResult<InternetService> {
|
|||
location = URI.create(currentOrNull());
|
||||
} else if (qName.equals("Name")) {
|
||||
if (inPublicIpAddress)
|
||||
address = parseInetAddress(currentOrNull());
|
||||
address = currentOrNull();
|
||||
else
|
||||
serviceName = currentOrNull();
|
||||
} else if (qName.equals("PublicIpAddress")) {
|
||||
|
@ -110,20 +108,6 @@ public class InternetServiceHandler extends HandlerWithResult<InternetService> {
|
|||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
private InetAddress parseInetAddress(String string) {
|
||||
String[] byteStrings = string.split("\\.");
|
||||
byte[] bytes = new byte[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.warn(e, "error parsing ipAddress", currentText);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -44,7 +42,7 @@ public class IpAddressesHandler extends ParseSax.HandlerWithResult<SortedSet<IpA
|
|||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private SortedSet<IpAddress> addresses = Sets.newTreeSet();
|
||||
private InetAddress address;
|
||||
private String address;
|
||||
private Status status;
|
||||
@Nullable
|
||||
private String server;
|
||||
|
@ -67,7 +65,7 @@ public class IpAddressesHandler extends ParseSax.HandlerWithResult<SortedSet<IpA
|
|||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (qName.equals("Name")) {
|
||||
address = parseInetAddress(currentOrNull());
|
||||
address = currentOrNull();
|
||||
} else if (qName.equals("Status")) {
|
||||
status = IpAddress.Status.fromValue(currentOrNull());
|
||||
} else if (!skip && qName.equals("Server")) {
|
||||
|
@ -90,18 +88,4 @@ public class IpAddressesHandler extends ParseSax.HandlerWithResult<SortedSet<IpA
|
|||
return returnVal.equals("") ? null : returnVal;
|
||||
}
|
||||
|
||||
private InetAddress parseInetAddress(String string) {
|
||||
String[] byteStrings = string.split("\\.");
|
||||
byte[] bytes = new byte[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.warn(e, "error parsing ipAddress", currentText);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
@ -40,7 +38,7 @@ public class NodeHandler extends HandlerWithResult<Node> {
|
|||
private int id;
|
||||
private URI location;
|
||||
private String serviceName;
|
||||
private InetAddress address;
|
||||
private String address;
|
||||
private int port;
|
||||
private String description;
|
||||
private boolean enabled;
|
||||
|
@ -67,27 +65,13 @@ public class NodeHandler extends HandlerWithResult<Node> {
|
|||
} else if (qName.equals("Enabled")) {
|
||||
enabled = Boolean.parseBoolean(currentOrNull());
|
||||
} else if (qName.equals("IpAddress")) {
|
||||
address = parseInetAddress(currentOrNull());
|
||||
address = currentOrNull();
|
||||
} else if (qName.equals("Description")) {
|
||||
description = currentOrNull();
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
private InetAddress parseInetAddress(String string) {
|
||||
String[] byteStrings = string.split("\\.");
|
||||
byte[] bytes = new byte[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.warn(e, "error parsing ipAddress", currentText);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue