Issue 130, Issue 129: revised compute abstraction to be more resource oriented. added GET to ant

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2443 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-16 00:42:40 +00:00
parent 2ee25b9629
commit 9518a67228
18 changed files with 378 additions and 192 deletions

View File

@ -26,23 +26,42 @@ package org.jclouds.compute;
import java.util.SortedSet;
import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Profile;
import org.jclouds.compute.domain.ServerIdentity;
import org.jclouds.compute.domain.ServerMetadata;
/**
* TODO: better name?
*
* @author Ivan Meredith
* @author Adrian Cole
*/
public interface ComputeService {
SortedSet<Server> listServers();
/**
* List all servers available to the current user
*/
SortedSet<ServerIdentity> listServers();
/**
* Find all servers matching the specified name
*/
SortedSet<ServerIdentity> getServerByName(String name);
/**
* Create a new server given the name, profile, and image.
*
* @see Image
*/
CreateServerResponse createServer(String name, Profile profile, Image image);
Server getServerById(String id);
SortedSet<Server> getServerByName(String id);
/**
* destroy the server.
*/
void destroyServer(String id);
/**
* Find a server by its id
*/
ServerMetadata getServerMetadata(String id);
}

View File

@ -23,36 +23,13 @@
*/
package org.jclouds.compute.domain;
import java.net.InetAddress;
import java.util.SortedSet;
import org.jclouds.domain.Credentials;
/**
* @author Adrian Cole
* @author Ivan Meredith
*/
public interface CreateServerResponse {
/**
* unique id of the server. potentially generated by the service.
*
*/
String getId();
/**
* user defined name of the server.
*
*/
String getName();
SortedSet<InetAddress> getPublicAddresses();
SortedSet<InetAddress> getPrivateAddresses();
int getLoginPort();
LoginType getLoginType();
public interface CreateServerResponse extends ServerMetadata {
Credentials getCredentials();

View File

@ -21,7 +21,7 @@
* under the License.
* ====================================================================
*/
package org.jclouds.compute;
package org.jclouds.compute.domain;
/**
* @author Adrian Cole

View File

@ -21,7 +21,7 @@
* under the License.
* ====================================================================
*/
package org.jclouds.compute;
package org.jclouds.compute.domain;
/**
* @author Adrian Cole

View File

@ -21,12 +21,18 @@
* under the License.
* ====================================================================
*/
package org.jclouds.compute;
package org.jclouds.compute.domain;
import org.jclouds.compute.domain.internal.ServerIdentityImpl;
import com.google.inject.ImplementedBy;
/**
* @author Ivan Meredith
* @author Adrian Cole
*/
public interface Server extends Comparable<Server> {
@ImplementedBy(ServerIdentityImpl.class)
public interface ServerIdentity extends Comparable<ServerIdentity> {
/**
* unique id of the server. potentially generated by the service.
@ -40,5 +46,4 @@ public interface Server extends Comparable<Server> {
*/
public String getName();
public Boolean destroy();
}

View File

@ -21,42 +21,28 @@
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.compute;
package org.jclouds.compute.domain;
import org.jclouds.compute.Server;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import java.net.InetAddress;
import java.util.SortedSet;
import org.jclouds.compute.domain.internal.ServerMetadataImpl;
import com.google.inject.ImplementedBy;
/**
*
* @author Adrian Cole
* @author Ivan Meredith
*/
public class TerremarkVCloudServer implements Server {
@ImplementedBy(ServerMetadataImpl.class)
public interface ServerMetadata extends ServerIdentity {
private final TerremarkVCloudComputeClient computeClient;
SortedSet<InetAddress> getPublicAddresses();
private final TerremarkVApp vApp;
SortedSet<InetAddress> getPrivateAddresses();
public TerremarkVCloudServer(TerremarkVCloudComputeClient computeClient, TerremarkVApp vApp) {
this.vApp = vApp;
this.computeClient = computeClient;
}
int getLoginPort();
public String getId() {
return vApp.getId();
}
LoginType getLoginType();
public Boolean destroy() {
computeClient.stop(getId());
return Boolean.TRUE;
}
@Override
public String getName() {
return vApp.getName();
}
@Override
public int compareTo(Server o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
}
}
}

View File

@ -24,96 +24,47 @@
package org.jclouds.compute.domain.internal;
import java.net.InetAddress;
import java.util.Comparator;
import java.util.SortedSet;
import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.compute.domain.LoginType;
import org.jclouds.domain.Credentials;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
* @author Ivan Meredith
*/
public class CreateServerResponseImpl implements CreateServerResponse {
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());
}
};
private final String id;
private final String name;
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 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) {
this.id = id;
this.name = name;
Iterables.addAll(this.publicAddresses, publicAddresses);
Iterables.addAll(this.privateAddresses, privateAddresses);
this.loginPort = loginPort;
this.loginType = loginType;
super(id, name, publicAddresses, privateAddresses, loginPort, loginType);
this.credentials = credentials;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public SortedSet<InetAddress> getPublicAddresses() {
return publicAddresses;
}
public SortedSet<InetAddress> getPrivateAddresses() {
return privateAddresses;
}
public int getLoginPort() {
return loginPort;
}
public LoginType getLoginType() {
return loginType;
}
public Credentials getCredentials() {
return credentials;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
int result = super.hashCode();
result = prime * result + ((credentials == null) ? 0 : credentials.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + loginPort;
result = prime * result + ((loginType == null) ? 0 : loginType.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
@ -123,34 +74,8 @@ public class CreateServerResponseImpl implements CreateServerResponse {
return false;
} else if (!credentials.equals(other.credentials))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (loginPort != other.loginPort)
return false;
if (loginType == null) {
if (other.loginType != null)
return false;
} else if (!loginType.equals(other.loginType))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (privateAddresses == null) {
if (other.privateAddresses != null)
return false;
} else if (!privateAddresses.equals(other.privateAddresses))
return false;
if (publicAddresses == null) {
if (other.publicAddresses != null)
return false;
} else if (!publicAddresses.equals(other.publicAddresses))
return false;
return true;
}
}

View File

@ -0,0 +1,96 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.compute.domain.internal;
import org.jclouds.compute.domain.ServerIdentity;
/**
* @author Adrian Cole
* @author Ivan Meredith
*/
public class ServerIdentityImpl implements ServerIdentity {
private final String id;
private final String name;
public ServerIdentityImpl(String id, String name) {
this.id = id;
this.name = name;
}
/**
* {@inheritDoc}
*/
public String getId() {
return id;
}
/**
* {@inheritDoc}
*/
public String getName() {
return name;
}
/**
* {@inheritDoc}
*/
public int compareTo(ServerIdentity o) {
if (getName() == null)
return -1;
return (this == o) ? 0 : getName().compareTo(o.getName());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ServerIdentityImpl other = (ServerIdentityImpl) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}

View File

@ -0,0 +1,131 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.compute.domain.internal;
import java.net.InetAddress;
import java.util.Comparator;
import java.util.SortedSet;
import org.jclouds.compute.domain.LoginType;
import org.jclouds.compute.domain.ServerMetadata;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
* @author Ivan Meredith
*/
public class ServerMetadataImpl extends ServerIdentityImpl implements ServerMetadata {
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());
}
};
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) {
super(id, name);
Iterables.addAll(this.publicAddresses, publicAddresses);
Iterables.addAll(this.privateAddresses, privateAddresses);
this.loginPort = loginPort;
this.loginType = loginType;
}
/**
* {@inheritDoc}
*/
public SortedSet<InetAddress> getPublicAddresses() {
return publicAddresses;
}
/**
* {@inheritDoc}
*/
public SortedSet<InetAddress> getPrivateAddresses() {
return privateAddresses;
}
/**
* {@inheritDoc}
*/
public int getLoginPort() {
return loginPort;
}
/**
* {@inheritDoc}
*/
public LoginType getLoginType() {
return loginType;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + loginPort;
result = prime * result + ((loginType == null) ? 0 : loginType.hashCode());
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ServerMetadataImpl other = (ServerMetadataImpl) obj;
if (loginPort != other.loginPort)
return false;
if (loginType == null) {
if (other.loginType != null)
return false;
} else if (!loginType.equals(other.loginType))
return false;
if (privateAddresses == null) {
if (other.privateAddresses != null)
return false;
} else if (!privateAddresses.equals(other.privateAddresses))
return false;
if (publicAddresses == null) {
if (other.publicAddresses != null)
return false;
} else if (!publicAddresses.equals(other.publicAddresses))
return false;
return true;
}
}

View File

@ -33,9 +33,10 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.Image;
import org.jclouds.compute.Profile;
import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Profile;
import org.jclouds.compute.domain.ServerMetadata;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
import org.jclouds.rimuhosting.miro.domain.Server;
@ -67,8 +68,8 @@ public class RimuHostingComputeService implements ComputeService {
return new RimuHostingCreateServerResponse(serverResponse);
}
public SortedSet<org.jclouds.compute.Server> listServers() {
SortedSet<org.jclouds.compute.Server> servers = new TreeSet<org.jclouds.compute.Server>();
public SortedSet<org.jclouds.compute.domain.ServerIdentity> listServers() {
SortedSet<org.jclouds.compute.domain.ServerIdentity> servers = new TreeSet<org.jclouds.compute.domain.ServerIdentity>();
SortedSet<Server> rhServers = rhClient.getInstanceList();
for (Server rhServer : rhServers) {
servers.add(new RimuHostingServer(rhServer, rhClient));
@ -76,16 +77,21 @@ public class RimuHostingComputeService implements ComputeService {
return servers;
}
public org.jclouds.compute.Server getServerById(String id) {
return new RimuHostingServer(rhClient.getInstance(Long.valueOf(id)), rhClient);
public ServerMetadata getServerMetadata(String id) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public SortedSet<org.jclouds.compute.Server> getServerByName(String id) {
SortedSet<org.jclouds.compute.Server> serverSet = new TreeSet<org.jclouds.compute.Server>();
public SortedSet<org.jclouds.compute.domain.ServerIdentity> getServerByName(String id) {
SortedSet<org.jclouds.compute.domain.ServerIdentity> serverSet = new TreeSet<org.jclouds.compute.domain.ServerIdentity>();
for (Server rhServer : rhClient.getInstanceList()) {
serverSet.add(new RimuHostingServer(rhServer, rhClient));
}
return serverSet;
}
@Override
public void destroyServer(String id) {
rhClient.destroyInstance(new Long(id));
}
}

View File

@ -23,10 +23,10 @@
*/
package org.jclouds.rimuhosting.miro.servers;
import org.jclouds.compute.Server;
import org.jclouds.compute.domain.ServerIdentity;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
public class RimuHostingServer implements Server {
public class RimuHostingServer implements ServerIdentity {
org.jclouds.rimuhosting.miro.domain.Server rhServer;
RimuHostingClient rhClient;
@ -52,7 +52,7 @@ public class RimuHostingServer implements Server {
}
@Override
public int compareTo(Server o) {
public int compareTo(ServerIdentity o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
}
}

View File

@ -26,9 +26,9 @@ package org.jclouds.rimuhosting.miro.servers;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertNotNull;
import org.jclouds.compute.Image;
import org.jclouds.compute.Profile;
import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Profile;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
import org.jclouds.rimuhosting.miro.RimuHostingContextBuilder;
@ -63,6 +63,6 @@ public class RimuHostingComputeServiceLiveTest {
CreateServerResponse server = rhServerService.createServer("test.com", Profile.SMALLEST,
Image.CENTOS_53);
assertNotNull(rhClient.getInstance(Long.valueOf(server.getId())));
rhServerService.getServerById(server.getId()).destroy();
rhServerService.destroyServer(server.getId());
}
}

View File

@ -23,7 +23,7 @@
====================================================================
-->
<project name="ex6" default="list" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<project name="compute" default="list" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<artifact:localRepository id="local.repository" path="${user.home}/.m2/repository" />
<artifact:remoteRepository id="jclouds-snapshot.repository" url="http://jclouds.rimuhosting.com/maven2/snapshots" />
@ -37,21 +37,27 @@
<typedef name="compute" classname="org.jclouds.tools.ant.ComputeTask" classpathref="jclouds.classpath" />
<property name="jclouds.compute.provider" value="compute://${jclouds.compute.account}:${jclouds.compute.key}@${jclouds.compute.provider}" />
<property name="jclouds.compute.url" value="compute://${jclouds.compute.account}:${jclouds.compute.key}@${jclouds.compute.provider}" />
<property name="jclouds.compute.servername" value="testforjcloud2" />
<target name="list">
<compute action="list" provider="${jclouds.compute.provider}" />
<compute action="list" provider="${jclouds.compute.url}" />
</target>
<target name="clean">
<compute action="destroy" provider="${jclouds.compute.provider}" >
<compute action="destroy" provider="${jclouds.compute.url}" >
<server name="${jclouds.compute.servername}"/>
</compute>
</target>
<target name="get">
<compute action="get" provider="${jclouds.compute.url}" >
<server name="${jclouds.compute.servername}"/>
</compute>
</target>
<target name="create">
<compute action="create" provider="${jclouds.compute.provider}" >
<compute action="create" provider="${jclouds.compute.url}" >
<server name="${jclouds.compute.servername}" image="CENTOS_53" profile="SMALLEST" />
</compute>
</target>

View File

@ -34,16 +34,17 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceFactory;
import org.jclouds.compute.Image;
import org.jclouds.compute.Profile;
import org.jclouds.compute.Server;
import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Profile;
import org.jclouds.compute.domain.ServerIdentity;
import org.jclouds.http.HttpUtils;
import org.jclouds.tools.ant.logging.config.AntLoggingModule;
import com.google.common.base.Function;
import com.google.common.collect.MapMaker;
import com.google.common.io.Resources;
import com.google.gson.Gson;
import com.google.inject.Module;
import com.google.inject.Provider;
@ -94,7 +95,7 @@ public class ComputeTask extends Task {
}
public static enum Action {
CREATE, LIST, DESTROY
CREATE, GET, LIST, DESTROY
}
private String provider;
@ -122,12 +123,16 @@ public class ComputeTask extends Task {
ComputeService computeService = computeMap.get(HttpUtils.createUri(provider));
switch (action) {
case CREATE:
case GET:
case DESTROY:
if (serverElement != null) {
switch (action) {
case CREATE:
create(computeService);
break;
case GET:
get(computeService);
break;
case DESTROY:
destroy(computeService);
break;
@ -138,7 +143,7 @@ public class ComputeTask extends Task {
break;
case LIST:
log("list");
for (Server server : computeService.listServers()) {
for (ServerIdentity server : computeService.listServers()) {
log(String.format(" id=%s, name=%s", server.getId(), server.getName()));
}
break;
@ -162,14 +167,25 @@ public class ComputeTask extends Task {
private void destroy(ComputeService computeService) {
log(String.format("destroy name: %s", serverElement.getName()));
SortedSet<Server> serversThatMatch = computeService.getServerByName(serverElement.getName());
SortedSet<ServerIdentity> serversThatMatch = computeService.getServerByName(serverElement
.getName());
if (serversThatMatch.size() > 0) {
for (Server server : serversThatMatch) {
for (ServerIdentity server : serversThatMatch) {
log(String.format(" destroying id=%s, name=%s", server.getId(), server.getName()));
if (!server.destroy()) {
log(String.format(" could not destroy id=%s, name=%s", server.getId(), server
.getName()), Project.MSG_ERR);
}
computeService.destroyServer(server.getId());
}
}
}
private void get(ComputeService computeService) {
log(String.format("get name: %s", serverElement.getName()));
SortedSet<ServerIdentity> serversThatMatch = computeService.getServerByName(serverElement
.getName());
if (serversThatMatch.size() > 0) {
for (ServerIdentity server : serversThatMatch) {
log(String.format(" server id=%s, name=%s, value=%s", server.getId(), server
.getName(), new Gson()
.toJson(computeService.getServerMetadata(server.getId()))));
}
}
}

View File

@ -36,7 +36,7 @@ import java.util.SortedSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.compute.Image;
import org.jclouds.compute.domain.Image;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;

View File

@ -24,6 +24,7 @@
package org.jclouds.vcloud.terremark.compute;
import java.net.InetAddress;
import java.util.Set;
import java.util.SortedSet;
import javax.annotation.Resource;
@ -31,12 +32,14 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.Image;
import org.jclouds.compute.Profile;
import org.jclouds.compute.Server;
import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.compute.domain.Image;
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.internal.CreateServerResponseImpl;
import org.jclouds.compute.domain.internal.ServerMetadataImpl;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.rest.domain.NamedResource;
@ -81,8 +84,12 @@ public class TerremarkVCloudComputeService implements ComputeService {
}
@Override
public Server getServerById(String id) {
return new TerremarkVCloudServer(computeClient, tmClient.getVApp(id));
public ServerMetadata getServerMetadata(String id) {
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);
}
public SortedSet<InternetService> getInternetServicesByName(final String name) {
@ -96,23 +103,28 @@ public class TerremarkVCloudComputeService implements ComputeService {
}
@Override
public SortedSet<Server> getServerByName(final String name) {
return Sets.newTreeSet(Iterables.filter(listServers(), new Predicate<Server>() {
public SortedSet<ServerIdentity> getServerByName(final String name) {
return Sets.newTreeSet(Iterables.filter(listServers(), new Predicate<ServerIdentity>() {
@Override
public boolean apply(Server input) {
public boolean apply(ServerIdentity input) {
return input.getName().equalsIgnoreCase(name);
}
}));
}
@Override
public SortedSet<Server> listServers() {
SortedSet<Server> servers = Sets.newTreeSet();
public SortedSet<ServerIdentity> listServers() {
SortedSet<ServerIdentity> servers = Sets.newTreeSet();
for (NamedResource resource : tmClient.getDefaultVDC().getResourceEntities().values()) {
if (resource.getType().equals(VCloudMediaType.VAPP_XML)) {
servers.add(getServerById(resource.getId()));
servers.add(getServerMetadata(resource.getId()));
}
}
return servers;
}
@Override
public void destroyServer(String id) {
computeClient.stop(id);
}
}

View File

@ -40,6 +40,7 @@ import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.domain.NamedResource;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
@ -58,6 +59,7 @@ import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.inject.Injector;
/**
@ -141,6 +143,10 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
System.out.printf("%d: done deploying vApp%n", System.currentTimeMillis());
vApp = tmClient.getVApp(vApp.getId());
NamedResource vAppResource = tmClient.getDefaultVDC().getResourceEntities().get(serverName);
assertEquals(vAppResource.getId(), vApp.getId());
verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.OFF);
@ -162,7 +168,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
@Test(dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" })
public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
node = tmClient.addNode(is.getId(), vApp.getNetworkToAddresses().values().iterator().next(),
node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()),
vApp.getName() + "-SSH", 22);
publicIp = is.getPublicIpAddress().getAddress();
doCheckPass(publicIp);
@ -187,6 +193,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
assert successTester.apply(tmClient.resetVApp(vApp.getId()).getLocation());
vApp = tmClient.getVApp(vApp.getId());
assertEquals(vApp.getStatus(), VAppStatus.ON);
// TODO we need to determine whether shutdown is supported before invoking it.

View File

@ -32,7 +32,7 @@ import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.jclouds.compute.Image;
import org.jclouds.compute.domain.Image;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.domain.ResourceType;