mirror of https://github.com/apache/jclouds.git
Issue 130: added server state
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2462 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
9253e755bd
commit
ce1b6dea27
|
@ -37,6 +37,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.aws.AWSResponseException;
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.domain.InstanceState;
|
||||
import org.jclouds.aws.ec2.domain.InstanceType;
|
||||
import org.jclouds.aws.ec2.domain.IpProtocol;
|
||||
import org.jclouds.aws.ec2.domain.KeyPair;
|
||||
|
@ -49,6 +50,7 @@ import org.jclouds.compute.domain.LoginType;
|
|||
import org.jclouds.compute.domain.Profile;
|
||||
import org.jclouds.compute.domain.ServerIdentity;
|
||||
import org.jclouds.compute.domain.ServerMetadata;
|
||||
import org.jclouds.compute.domain.ServerState;
|
||||
import org.jclouds.compute.domain.internal.CreateServerResponseImpl;
|
||||
import org.jclouds.compute.domain.internal.ServerIdentityImpl;
|
||||
import org.jclouds.compute.domain.internal.ServerMetadataImpl;
|
||||
|
@ -87,6 +89,12 @@ public class EC2ComputeService implements ComputeService {
|
|||
private Map<Profile, InstanceType> profileInstanceTypeMap = ImmutableMap
|
||||
.<Profile, InstanceType> builder().put(Profile.SMALLEST, InstanceType.M1_SMALL).build();
|
||||
|
||||
private Map<InstanceState, ServerState> instanceToServerState = ImmutableMap
|
||||
.<InstanceState, ServerState> builder().put(InstanceState.PENDING, ServerState.PENDING)
|
||||
.put(InstanceState.RUNNING, ServerState.RUNNING).put(InstanceState.SHUTTING_DOWN,
|
||||
ServerState.PENDING).put(InstanceState.TERMINATED, ServerState.TERMINATED)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public CreateServerResponse createServer(String name, Profile profile, Image image) {
|
||||
String ami = checkNotNull(imageAmiIdMap.get(image), "image not supported: " + image);
|
||||
|
@ -117,7 +125,8 @@ public class EC2ComputeService implements ComputeService {
|
|||
Set<InetAddress> privateAddresses = runningInstance.getPrivateIpAddress() == null ? ImmutableSet
|
||||
.<InetAddress> of()
|
||||
: ImmutableSet.<InetAddress> of(runningInstance.getPrivateIpAddress());
|
||||
return new CreateServerResponseImpl(runningInstance.getInstanceId(), name, publicAddresses,
|
||||
return new CreateServerResponseImpl(runningInstance.getInstanceId(), name,
|
||||
instanceToServerState.get(runningInstance.getInstanceState()), publicAddresses,
|
||||
privateAddresses, 22, LoginType.SSH, new Credentials("root", keyPair
|
||||
.getKeyMaterial()));
|
||||
}
|
||||
|
@ -166,10 +175,10 @@ public class EC2ComputeService implements ComputeService {
|
|||
@Override
|
||||
public ServerMetadata getServerMetadata(String id) {
|
||||
RunningInstance runningInstance = getRunningInstance(id);
|
||||
return new ServerMetadataImpl(runningInstance.getInstanceId(), runningInstance
|
||||
.getInstanceId(), ImmutableSet.<InetAddress> of(runningInstance.getIpAddress()),
|
||||
ImmutableSet.<InetAddress> of(runningInstance.getPrivateIpAddress()), 22,
|
||||
LoginType.SSH);
|
||||
return new ServerMetadataImpl(runningInstance.getInstanceId(), runningInstance.getKeyName(),
|
||||
instanceToServerState.get(runningInstance.getInstanceState()), ImmutableSet
|
||||
.<InetAddress> of(runningInstance.getIpAddress()), ImmutableSet
|
||||
.<InetAddress> of(runningInstance.getPrivateIpAddress()), 22, LoginType.SSH);
|
||||
}
|
||||
|
||||
private RunningInstance getRunningInstance(String id) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.google.inject.ImplementedBy;
|
|||
*/
|
||||
@ImplementedBy(ServerMetadataImpl.class)
|
||||
public interface ServerMetadata extends ServerIdentity {
|
||||
ServerState getState();
|
||||
|
||||
SortedSet<InetAddress> getPublicAddresses();
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package org.jclouds.compute.domain;
|
||||
|
||||
/**
|
||||
* Indicates the status of a server
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum ServerState {
|
||||
/**
|
||||
* The server is in transition
|
||||
*/
|
||||
PENDING,
|
||||
/**
|
||||
* The server is not running
|
||||
*/
|
||||
TERMINATED,
|
||||
/**
|
||||
* The server is deployed, but suspended
|
||||
*/
|
||||
SUSPENDED,
|
||||
/**
|
||||
* The server is available for requests
|
||||
*/
|
||||
RUNNING;
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ import java.net.InetAddress;
|
|||
|
||||
import org.jclouds.compute.domain.CreateServerResponse;
|
||||
import org.jclouds.compute.domain.LoginType;
|
||||
import org.jclouds.compute.domain.ServerState;
|
||||
import org.jclouds.domain.Credentials;
|
||||
|
||||
/**
|
||||
|
@ -34,23 +35,20 @@ import org.jclouds.domain.Credentials;
|
|||
* @author Ivan Meredith
|
||||
*/
|
||||
public class CreateServerResponseImpl extends ServerMetadataImpl implements CreateServerResponse {
|
||||
|
||||
|
||||
private final Credentials credentials;
|
||||
|
||||
|
||||
public CreateServerResponseImpl(String id, String name, Iterable<InetAddress> publicAddresses,
|
||||
Iterable<InetAddress> privateAddresses, int loginPort, LoginType loginType,
|
||||
Credentials credentials) {
|
||||
super(id, name, publicAddresses, privateAddresses, loginPort, loginType);
|
||||
public CreateServerResponseImpl(String id, String name, ServerState state,
|
||||
Iterable<InetAddress> publicAddresses, Iterable<InetAddress> privateAddresses,
|
||||
int loginPort, LoginType loginType, Credentials credentials) {
|
||||
super(id, name, state, publicAddresses, privateAddresses, loginPort, loginType);
|
||||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
|
||||
public Credentials getCredentials() {
|
||||
return credentials;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -59,7 +57,6 @@ public class CreateServerResponseImpl extends ServerMetadataImpl implements Crea
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
|
@ -77,5 +74,4 @@ public class CreateServerResponseImpl extends ServerMetadataImpl implements Crea
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.SortedSet;
|
|||
|
||||
import org.jclouds.compute.domain.LoginType;
|
||||
import org.jclouds.compute.domain.ServerMetadata;
|
||||
import org.jclouds.compute.domain.ServerState;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
@ -46,14 +47,17 @@ public class ServerMetadataImpl extends ServerIdentityImpl implements ServerMeta
|
|||
}
|
||||
|
||||
};
|
||||
private final ServerState state;
|
||||
private final SortedSet<InetAddress> publicAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR);
|
||||
private final SortedSet<InetAddress> privateAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR);
|
||||
private final int loginPort;
|
||||
private final LoginType loginType;
|
||||
|
||||
public ServerMetadataImpl(String id, String name, Iterable<InetAddress> publicAddresses,
|
||||
Iterable<InetAddress> privateAddresses, int loginPort, LoginType loginType) {
|
||||
public ServerMetadataImpl(String id, String name, ServerState state,
|
||||
Iterable<InetAddress> publicAddresses, Iterable<InetAddress> privateAddresses,
|
||||
int loginPort, LoginType loginType) {
|
||||
super(id, name);
|
||||
this.state = state;
|
||||
Iterables.addAll(this.publicAddresses, publicAddresses);
|
||||
Iterables.addAll(this.privateAddresses, privateAddresses);
|
||||
this.loginPort = loginPort;
|
||||
|
@ -128,4 +132,8 @@ public class ServerMetadataImpl extends ServerIdentityImpl implements ServerMeta
|
|||
return true;
|
||||
}
|
||||
|
||||
public ServerState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.compute.domain.LoginType;
|
||||
import org.jclouds.compute.domain.ServerState;
|
||||
import org.jclouds.compute.domain.internal.CreateServerResponseImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
|
||||
|
@ -44,10 +45,11 @@ public class RimuHostingCreateServerResponse extends CreateServerResponseImpl {
|
|||
|
||||
public RimuHostingCreateServerResponse(NewServerResponse rhServerResponse) {
|
||||
super(rhServerResponse.getServer().getId().toString(),
|
||||
rhServerResponse.getServer().getName(), getPublicAddresses(rhServerResponse
|
||||
.getServer()), ImmutableList.<InetAddress> of(), 22, LoginType.SSH,
|
||||
new Credentials("root", rhServerResponse.getNewInstanceRequest().getCreateOptions()
|
||||
.getPassword()));
|
||||
rhServerResponse.getServer().getName(),
|
||||
ServerState.PENDING,// TODO need a real state!
|
||||
getPublicAddresses(rhServerResponse.getServer()), ImmutableList.<InetAddress> of(),
|
||||
22, LoginType.SSH, new Credentials("root", rhServerResponse.getNewInstanceRequest()
|
||||
.getCreateOptions().getPassword()));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.jclouds.compute.domain.LoginType;
|
|||
import org.jclouds.compute.domain.Profile;
|
||||
import org.jclouds.compute.domain.ServerIdentity;
|
||||
import org.jclouds.compute.domain.ServerMetadata;
|
||||
import org.jclouds.compute.domain.ServerState;
|
||||
import org.jclouds.compute.domain.internal.CreateServerResponseImpl;
|
||||
import org.jclouds.compute.domain.internal.ServerMetadataImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
|
@ -45,9 +46,11 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.rest.domain.NamedResource;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.internal.ImmutableSet;
|
||||
|
@ -60,12 +63,18 @@ public class HostingDotComVCloudComputeService implements ComputeService {
|
|||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final HostingDotComVCloudComputeClient computeClient;
|
||||
private final HostingDotComVCloudClient tmClient;
|
||||
private final HostingDotComVCloudClient hostingClient;
|
||||
|
||||
private static final Map<VAppStatus, ServerState> vAppStatusToServerState = ImmutableMap
|
||||
.<VAppStatus, ServerState> builder().put(VAppStatus.OFF, ServerState.TERMINATED).put(
|
||||
VAppStatus.ON, ServerState.RUNNING).put(VAppStatus.RESOLVED,
|
||||
ServerState.PENDING).put(VAppStatus.SUSPENDED, ServerState.SUSPENDED).put(
|
||||
VAppStatus.UNRESOLVED, ServerState.PENDING).build();
|
||||
|
||||
@Inject
|
||||
public HostingDotComVCloudComputeService(HostingDotComVCloudClient tmClient,
|
||||
HostingDotComVCloudComputeClient computeClient) {
|
||||
this.tmClient = tmClient;
|
||||
this.hostingClient = tmClient;
|
||||
this.computeClient = computeClient;
|
||||
|
||||
}
|
||||
|
@ -73,17 +82,19 @@ public class HostingDotComVCloudComputeService implements ComputeService {
|
|||
@Override
|
||||
public CreateServerResponse createServer(String name, Profile profile, Image image) {
|
||||
Map<String, String> metaMap = computeClient.start(name, 1, 512, image);
|
||||
VApp vApp = tmClient.getVApp(metaMap.get("id"));
|
||||
return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), vApp
|
||||
.getNetworkToAddresses().values(), ImmutableSet.<InetAddress> of(), 22,
|
||||
LoginType.SSH, new Credentials(metaMap.get("username"), metaMap.get("password")));
|
||||
VApp vApp = hostingClient.getVApp(metaMap.get("id"));
|
||||
return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), vAppStatusToServerState
|
||||
.get(vApp.getStatus()), vApp.getNetworkToAddresses().values(), ImmutableSet
|
||||
.<InetAddress> of(), 22, LoginType.SSH, new Credentials(metaMap.get("username"),
|
||||
metaMap.get("password")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerMetadata getServerMetadata(String id) {
|
||||
VApp vApp = tmClient.getVApp(id);
|
||||
return new ServerMetadataImpl(vApp.getId(), vApp.getName(), vApp.getNetworkToAddresses()
|
||||
.values(), ImmutableSet.<InetAddress> of(), 22, LoginType.SSH);
|
||||
VApp vApp = hostingClient.getVApp(id);
|
||||
return new ServerMetadataImpl(vApp.getId(), vApp.getName(), vAppStatusToServerState.get(vApp
|
||||
.getStatus()), vApp.getNetworkToAddresses().values(), ImmutableSet
|
||||
.<InetAddress> of(), 22, LoginType.SSH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,7 +110,7 @@ public class HostingDotComVCloudComputeService implements ComputeService {
|
|||
@Override
|
||||
public SortedSet<ServerIdentity> listServers() {
|
||||
SortedSet<ServerIdentity> servers = Sets.newTreeSet();
|
||||
for (NamedResource resource : tmClient.getDefaultVDC().getResourceEntities().values()) {
|
||||
for (NamedResource resource : hostingClient.getDefaultVDC().getResourceEntities().values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
servers.add(getServerMetadata(resource.getId()));
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.jclouds.vcloud.terremark.compute;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
|
@ -38,6 +39,7 @@ import org.jclouds.compute.domain.LoginType;
|
|||
import org.jclouds.compute.domain.Profile;
|
||||
import org.jclouds.compute.domain.ServerIdentity;
|
||||
import org.jclouds.compute.domain.ServerMetadata;
|
||||
import org.jclouds.compute.domain.ServerState;
|
||||
import org.jclouds.compute.domain.internal.CreateServerResponseImpl;
|
||||
import org.jclouds.compute.domain.internal.ServerMetadataImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
|
@ -45,10 +47,12 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.rest.domain.NamedResource;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.internal.ImmutableSet;
|
||||
|
@ -63,6 +67,12 @@ public class TerremarkVCloudComputeService implements ComputeService {
|
|||
private final TerremarkVCloudComputeClient computeClient;
|
||||
private final TerremarkVCloudClient tmClient;
|
||||
|
||||
private static final Map<VAppStatus, ServerState> vAppStatusToServerState = ImmutableMap
|
||||
.<VAppStatus, ServerState> builder().put(VAppStatus.OFF, ServerState.TERMINATED).put(
|
||||
VAppStatus.ON, ServerState.RUNNING).put(VAppStatus.RESOLVED,
|
||||
ServerState.PENDING).put(VAppStatus.SUSPENDED, ServerState.SUSPENDED).put(
|
||||
VAppStatus.UNRESOLVED, ServerState.PENDING).build();
|
||||
|
||||
@Inject
|
||||
public TerremarkVCloudComputeService(TerremarkVCloudClient tmClient,
|
||||
TerremarkVCloudComputeClient computeClient) {
|
||||
|
@ -78,9 +88,10 @@ public class TerremarkVCloudComputeService implements ComputeService {
|
|||
// bug creating more than one internet service returns 503 or 500
|
||||
// InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22, 80, 8080);
|
||||
InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22);
|
||||
return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), ImmutableSet
|
||||
.<InetAddress> of(publicIp), vApp.getNetworkToAddresses().values(), 22,
|
||||
LoginType.SSH, new Credentials("vcloud", "p4ssw0rd"));
|
||||
return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), vAppStatusToServerState
|
||||
.get(vApp.getStatus()), ImmutableSet.<InetAddress> of(publicIp), vApp
|
||||
.getNetworkToAddresses().values(), 22, LoginType.SSH, new Credentials("vcloud",
|
||||
"p4ssw0rd"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,8 +99,9 @@ public class TerremarkVCloudComputeService implements ComputeService {
|
|||
VApp vApp = tmClient.getVApp(id);
|
||||
// TODO
|
||||
Set<InetAddress> publicAddresses = ImmutableSet.<InetAddress> of();
|
||||
return new ServerMetadataImpl(vApp.getId(), vApp.getName(), publicAddresses, vApp
|
||||
.getNetworkToAddresses().values(), 22, LoginType.SSH);
|
||||
return new ServerMetadataImpl(vApp.getId(), vApp.getName(), vAppStatusToServerState.get(vApp
|
||||
.getStatus()), publicAddresses, vApp.getNetworkToAddresses().values(), 22,
|
||||
LoginType.SSH);
|
||||
}
|
||||
|
||||
public SortedSet<InternetService> getInternetServicesByName(final String name) {
|
||||
|
|
Loading…
Reference in New Issue