mirror of https://github.com/apache/jclouds.git
Changed Addresses and Server domain objects do deserialize current nova response. Updated tests.
This commit is contained in:
parent
eb4dedca62
commit
b17b860279
|
@ -18,38 +18,31 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.compute.functions;
|
package org.jclouds.openstack.nova.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import com.google.common.base.Function;
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import java.util.Map;
|
import com.google.common.collect.Iterables;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.openstack.nova.domain.Server;
|
|
||||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
|
||||||
import org.jclouds.collect.Memoized;
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.*;
|
||||||
import org.jclouds.compute.domain.Image;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationBuilder;
|
import org.jclouds.domain.LocationBuilder;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.openstack.nova.domain.Server;
|
||||||
|
import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import javax.annotation.Resource;
|
||||||
import com.google.common.base.Predicate;
|
import javax.inject.Inject;
|
||||||
import com.google.common.base.Supplier;
|
import javax.inject.Named;
|
||||||
import com.google.common.collect.Iterables;
|
import javax.inject.Singleton;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -75,7 +68,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImageId() + "");
|
return input.getProviderId().equals(instance.getImageRef() + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +81,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Hardware input) {
|
public boolean apply(Hardware input) {
|
||||||
return input.getProviderId().equals(instance.getFlavorId() + "");
|
return input.getProviderId().equals(instance.getFlavorRef() + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +105,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
from.getHostId()).parent(location.get()).build());
|
from.getHostId()).parent(location.get()).build());
|
||||||
builder.userMetadata(from.getMetadata());
|
builder.userMetadata(from.getMetadata());
|
||||||
builder.group(parseGroupFromName(from.getName()));
|
builder.group(parseGroupFromName(from.getName()));
|
||||||
builder.imageId(from.getImageId() + "");
|
builder.imageId(from.getImageRef() + "");
|
||||||
builder.operatingSystem(parseOperatingSystem(from));
|
builder.operatingSystem(parseOperatingSystem(from));
|
||||||
builder.hardware(parseHardware(from));
|
builder.hardware(parseHardware(from));
|
||||||
builder.state(serverToNodeState.get(from.getStatus()));
|
builder.state(serverToNodeState.get(from.getStatus()));
|
||||||
|
|
|
@ -18,44 +18,76 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Addresses {
|
public class Addresses {
|
||||||
|
|
||||||
@SerializedName("public")
|
@SerializedName("public")
|
||||||
private Set<String> publicAddresses = Sets.newLinkedHashSet();
|
private Set<Map<String, String>> publicAddresses = Sets.newHashSet();
|
||||||
@SerializedName("private")
|
@SerializedName("private")
|
||||||
private Set<String> privateAddresses = Sets.newLinkedHashSet();
|
private Set<Map<String, String>> privateAddresses = Sets.newHashSet();
|
||||||
|
|
||||||
public Addresses() {
|
public Addresses() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public Addresses(Set<Map<String, String>> publicAddresses, Set<Map<String, String>> privateAddresses) {
|
||||||
|
// this.publicAddresses = publicAddresses;
|
||||||
|
// this.privateAddresses = privateAddresses;
|
||||||
|
// }
|
||||||
|
|
||||||
public Addresses(Set<String> publicAddresses, Set<String> privateAddresses) {
|
public Addresses(Set<String> publicAddresses, Set<String> privateAddresses) {
|
||||||
this.publicAddresses = publicAddresses;
|
this.publicAddresses.clear();
|
||||||
this.privateAddresses = privateAddresses;
|
this.privateAddresses.clear();
|
||||||
|
for (String address : publicAddresses) {
|
||||||
|
HashMap<String, String> addressMap = new HashMap<String, String>();
|
||||||
|
addressMap.put("version", "4");
|
||||||
|
addressMap.put("addr", "address");
|
||||||
|
this.publicAddresses.add(addressMap);
|
||||||
|
}
|
||||||
|
for (String address : privateAddresses) {
|
||||||
|
HashMap<String, String> addressMap = new HashMap<String, String>();
|
||||||
|
addressMap.put("version", "4");
|
||||||
|
addressMap.put("addr", "address");
|
||||||
|
this.privateAddresses.add(addressMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPublicAddresses(Set<String> publicAddresses) {
|
}
|
||||||
|
|
||||||
|
public void setPublicAddresses(Set<Map<String, String>> publicAddresses) {
|
||||||
this.publicAddresses = publicAddresses;
|
this.publicAddresses = publicAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getPublicAddresses() {
|
public Set<String> getPublicAddresses() {
|
||||||
return publicAddresses;
|
HashSet<String> addresses = new HashSet<String>();
|
||||||
|
for (Map<String, String> address : publicAddresses) {
|
||||||
|
if (address.containsKey("addr")) {
|
||||||
|
addresses.add(address.get("addr"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrivateAddresses(Set<String> privateAddresses) {
|
public void setPrivateAddresses(Set<Map<String, String>> privateAddresses) {
|
||||||
this.privateAddresses = privateAddresses;
|
this.privateAddresses = privateAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getPrivateAddresses() {
|
public Set<String> getPrivateAddresses() {
|
||||||
return privateAddresses;
|
HashSet<String> addresses = new HashSet<String>();
|
||||||
|
for (Map<String, String> address : privateAddresses) {
|
||||||
|
if (address.containsKey("addr")) {
|
||||||
|
addresses.add(address.get("addr"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are
|
* A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are
|
||||||
* requisite elements when creating a server.
|
* requisite elements when creating a server.
|
||||||
|
@ -32,13 +32,34 @@ public class Server extends Resource {
|
||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
// private Map<String, Map<String,String>> metadata = Maps.newHashMap();
|
||||||
|
|
||||||
|
public Map<String, String> getMetadata() {
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadata(Map<String, String> metadata) {
|
||||||
|
this.metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, String> metadata = Maps.newHashMap();
|
private Map<String, String> metadata = Maps.newHashMap();
|
||||||
|
|
||||||
private Addresses addresses;
|
private Addresses addresses;
|
||||||
|
|
||||||
private String adminPass;
|
private String adminPass;
|
||||||
private Integer flavorId;
|
private String flavorRef;
|
||||||
private String hostId;
|
private String hostId;
|
||||||
private Integer imageId;
|
private String imageRef;
|
||||||
|
|
||||||
|
public String getAffinityId() {
|
||||||
|
return affinityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAffinityId(String affinityId) {
|
||||||
|
this.affinityId = affinityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String affinityId;
|
||||||
|
|
||||||
private Integer progress;
|
private Integer progress;
|
||||||
private ServerStatus status;
|
private ServerStatus status;
|
||||||
|
@ -51,13 +72,13 @@ public class Server extends Resource {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMetadata(Map<String, String> metadata) {
|
// public void setMetadata(Map<String, String> metadata) {
|
||||||
this.metadata = metadata;
|
// this.metadata.put("values", metadata);
|
||||||
}
|
// }
|
||||||
|
|
||||||
public Map<String, String> getMetadata() {
|
// public Map<String, String> getMetadata() {
|
||||||
return metadata;
|
// return metadata.get("values");
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void setAddresses(Addresses addresses) {
|
public void setAddresses(Addresses addresses) {
|
||||||
this.addresses = addresses;
|
this.addresses = addresses;
|
||||||
|
@ -75,12 +96,12 @@ public class Server extends Resource {
|
||||||
return adminPass;
|
return adminPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFlavorId(Integer flavorId) {
|
public void setFlavorRef(String flavorRef) {
|
||||||
this.flavorId = flavorId;
|
this.flavorRef = flavorRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getFlavorId() {
|
public String getFlavorRef() {
|
||||||
return flavorId;
|
return flavorRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHostId(String hostId) {
|
public void setHostId(String hostId) {
|
||||||
|
@ -103,12 +124,12 @@ public class Server extends Resource {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImageId(Integer imageId) {
|
public void getImageRef(String imageRef) {
|
||||||
this.imageId = imageId;
|
this.imageRef = imageRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getImageId() {
|
public String getImageRef() {
|
||||||
return imageId;
|
return imageRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -141,10 +162,10 @@ public class Server extends Resource {
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
|
result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
|
||||||
result = prime * result + ((adminPass == null) ? 0 : adminPass.hashCode());
|
result = prime * result + ((adminPass == null) ? 0 : adminPass.hashCode());
|
||||||
result = prime * result + ((flavorId == null) ? 0 : flavorId.hashCode());
|
result = prime * result + ((flavorRef == null) ? 0 : flavorRef.hashCode());
|
||||||
result = prime * result + ((hostId == null) ? 0 : hostId.hashCode());
|
result = prime * result + ((hostId == null) ? 0 : hostId.hashCode());
|
||||||
result = prime * result + id;
|
result = prime * result + id;
|
||||||
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
|
result = prime * result + ((imageRef == null) ? 0 : imageRef.hashCode());
|
||||||
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
return result;
|
return result;
|
||||||
|
@ -169,10 +190,10 @@ public class Server extends Resource {
|
||||||
return false;
|
return false;
|
||||||
} else if (!adminPass.equals(other.adminPass))
|
} else if (!adminPass.equals(other.adminPass))
|
||||||
return false;
|
return false;
|
||||||
if (flavorId == null) {
|
if (flavorRef == null) {
|
||||||
if (other.flavorId != null)
|
if (other.flavorRef != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!flavorId.equals(other.flavorId))
|
} else if (!flavorRef.equals(other.flavorRef))
|
||||||
return false;
|
return false;
|
||||||
if (hostId == null) {
|
if (hostId == null) {
|
||||||
if (other.hostId != null)
|
if (other.hostId != null)
|
||||||
|
@ -181,10 +202,10 @@ public class Server extends Resource {
|
||||||
return false;
|
return false;
|
||||||
if (id != other.id)
|
if (id != other.id)
|
||||||
return false;
|
return false;
|
||||||
if (imageId == null) {
|
if (imageRef == null) {
|
||||||
if (other.imageId != null)
|
if (other.imageRef != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!imageId.equals(other.imageId))
|
} else if (!imageRef.equals(other.imageRef))
|
||||||
return false;
|
return false;
|
||||||
if (metadata == null) {
|
if (metadata == null) {
|
||||||
if (other.metadata != null)
|
if (other.metadata != null)
|
||||||
|
@ -205,8 +226,8 @@ public class Server extends Resource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Server [addresses=" + addresses + ", adminPass=" + adminPass + ", flavorId="
|
return "Server [addresses=" + addresses + ", adminPass=" + adminPass + ", flavorRef="
|
||||||
+ flavorId + ", hostId=" + hostId + ", id=" + id + ", imageId=" + imageId
|
+ flavorRef + ", hostId=" + hostId + ", id=" + id + ", imageRef=" + imageRef
|
||||||
+ ", metadata=" + metadata + ", name=" + name + "]";
|
+ ", metadata=" + metadata + ", name=" + name + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,11 +275,11 @@ public class NovaClientLiveTest {
|
||||||
"rackspace".getBytes()).withMetadata(metadata));
|
"rackspace".getBytes()).withMetadata(metadata));
|
||||||
|
|
||||||
assertNotNull(server.getAdminPass());
|
assertNotNull(server.getAdminPass());
|
||||||
|
assertEquals(server.getStatus(), ServerStatus.BUILD);
|
||||||
serverId = server.getId();
|
serverId = server.getId();
|
||||||
adminPass = server.getAdminPass();
|
adminPass = server.getAdminPass();
|
||||||
ip = server.getAddresses().getPublicAddresses().iterator().next();
|
|
||||||
assertEquals(server.getStatus(), ServerStatus.BUILD);
|
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
|
ip = client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void blockUntilServerActive(int serverId) throws InterruptedException {
|
private void blockUntilServerActive(int serverId) throws InterruptedException {
|
||||||
|
@ -316,8 +316,8 @@ public class NovaClientLiveTest {
|
||||||
assertNotNull(server.getHostId());
|
assertNotNull(server.getHostId());
|
||||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||||
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
||||||
assertEquals(new Integer(14362), server.getImageId());
|
assertEquals("14362", server.getImageRef());
|
||||||
assertEquals(new Integer(1), server.getFlavorId());
|
assertEquals("1", server.getFlavorRef());
|
||||||
assertNotNull(server.getAddresses());
|
assertNotNull(server.getAddresses());
|
||||||
// listAddresses tests..
|
// listAddresses tests..
|
||||||
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
||||||
|
@ -328,21 +328,12 @@ public class NovaClientLiveTest {
|
||||||
|
|
||||||
// check metadata
|
// check metadata
|
||||||
assertEquals(server.getMetadata(), metadata);
|
assertEquals(server.getMetadata(), metadata);
|
||||||
|
assertPassword(server, adminPass);
|
||||||
checkPassOk(server, adminPass);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this tests "personality" as the file looked up was sent during server creation
|
|
||||||
*/
|
|
||||||
|
|
||||||
private void checkPassOk(Server newDetails, String pass) throws IOException {
|
|
||||||
doCheckPass(newDetails, pass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void doCheckPass(Server newDetails, String pass) throws IOException {
|
private void assertPassword(Server server, String pass) throws IOException {
|
||||||
IPSocket socket = new IPSocket(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0), 22);
|
IPSocket socket = new IPSocket(Iterables.get(server.getAddresses().getPublicAddresses(), 0), 22);
|
||||||
socketTester.apply(socket);
|
socketTester.apply(socket);
|
||||||
|
|
||||||
SshClient client = sshFactory.create(socket, new Credentials("root", pass));
|
SshClient client = sshFactory.create(socket, new Credentials("root", pass));
|
||||||
|
@ -383,7 +374,7 @@ public class NovaClientLiveTest {
|
||||||
public void testChangePassword() throws Exception {
|
public void testChangePassword() throws Exception {
|
||||||
client.changeAdminPass(serverId, "elmo");
|
client.changeAdminPass(serverId, "elmo");
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
checkPassOk(client.getServer(serverId), "elmo");
|
assertPassword(client.getServer(serverId), "elmo");
|
||||||
this.adminPass = "elmo";
|
this.adminPass = "elmo";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,7 +411,7 @@ public class NovaClientLiveTest {
|
||||||
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
|
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
// issue Web Hosting #119580 imageId comes back incorrect after rebuild
|
// issue Web Hosting #119580 imageId comes back incorrect after rebuild
|
||||||
assertEquals(new Integer(imageId), client.getServer(serverId).getImageId());
|
assertEquals(imageId, client.getServer(serverId).getImageRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
||||||
|
@ -441,7 +432,7 @@ public class NovaClientLiveTest {
|
||||||
blockUntilServerVerifyResize(serverId);
|
blockUntilServerVerifyResize(serverId);
|
||||||
client.revertResizeServer(serverId);
|
client.revertResizeServer(serverId);
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
assertEquals(new Integer(1), client.getServer(serverId).getFlavorId());
|
assertEquals(new Integer(1), client.getServer(serverId).getFlavorRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
||||||
|
@ -450,7 +441,7 @@ public class NovaClientLiveTest {
|
||||||
blockUntilServerVerifyResize(serverId2);
|
blockUntilServerVerifyResize(serverId2);
|
||||||
client.confirmResizeServer(serverId2);
|
client.confirmResizeServer(serverId2);
|
||||||
blockUntilServerActive(serverId2);
|
blockUntilServerActive(serverId2);
|
||||||
assertEquals(new Integer(2), client.getServer(serverId2).getFlavorId());
|
assertEquals(new Integer(2), client.getServer(serverId2).getFlavorRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = {"testRebootSoft", "testRevertResize",
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = {"testRebootSoft", "testRevertResize",
|
||||||
|
|
|
@ -18,37 +18,26 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.compute.functions;
|
package org.jclouds.openstack.nova.compute.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import com.google.common.base.Suppliers;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import org.jclouds.compute.domain.*;
|
||||||
|
import org.jclouds.domain.Credentials;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.domain.LocationBuilder;
|
||||||
|
import org.jclouds.domain.LocationScope;
|
||||||
|
import org.jclouds.openstack.nova.compute.config.NovaComputeServiceDependenciesModule;
|
||||||
|
import org.jclouds.openstack.nova.domain.Server;
|
||||||
|
import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||||
|
import org.jclouds.openstack.nova.functions.ParseServerFromJsonResponseTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.openstack.nova.compute.config.NovaComputeServiceDependenciesModule;
|
import static org.testng.Assert.assertEquals;
|
||||||
import org.jclouds.openstack.nova.domain.Server;
|
|
||||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
|
||||||
import org.jclouds.openstack.nova.functions.ParseServerFromJsonResponseTest;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
|
||||||
import org.jclouds.compute.domain.HardwareBuilder;
|
|
||||||
import org.jclouds.compute.domain.Image;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.OperatingSystemBuilder;
|
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
|
||||||
import org.jclouds.compute.domain.Processor;
|
|
||||||
import org.jclouds.compute.domain.Volume;
|
|
||||||
import org.jclouds.compute.domain.VolumeBuilder;
|
|
||||||
import org.jclouds.domain.Credentials;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.domain.LocationBuilder;
|
|
||||||
import org.jclouds.domain.LocationScope;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -58,7 +47,7 @@ public class ServerToNodeMetadataTest {
|
||||||
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
|
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws UnknownHostException {
|
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||||
Credentials creds = new Credentials("root", "abdce");
|
Credentials creds = new Credentials("root", "abdce");
|
||||||
|
|
||||||
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
||||||
|
@ -67,8 +56,8 @@ public class ServerToNodeMetadataTest {
|
||||||
Server server = ParseServerFromJsonResponseTest.parseServer();
|
Server server = ParseServerFromJsonResponseTest.parseServer();
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
||||||
.<String, Credentials> of("node#1234", creds), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials>of("node#1234", creds), Suppliers.<Set<? extends Image>>ofInstance(images),
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>>ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
|
|
||||||
|
@ -81,15 +70,15 @@ public class ServerToNodeMetadataTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException {
|
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||||
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||||
Server server = ParseServerFromJsonResponseTest.parseServer();
|
Server server = ParseServerFromJsonResponseTest.parseServer();
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
||||||
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
.<String, Credentials>of(), Suppliers.<Set<? extends Image>>ofInstance(images), Suppliers
|
||||||
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>>ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
|
|
||||||
|
@ -103,7 +92,7 @@ public class ServerToNodeMetadataTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException {
|
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||||
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
||||||
org.jclouds.compute.domain.Image jcImage = NovaImageToImageTest.convertImage();
|
org.jclouds.compute.domain.Image jcImage = NovaImageToImageTest.convertImage();
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
|
||||||
|
@ -111,8 +100,8 @@ public class ServerToNodeMetadataTest {
|
||||||
Server server = ParseServerFromJsonResponseTest.parseServer();
|
Server server = ParseServerFromJsonResponseTest.parseServer();
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
||||||
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
.<String, Credentials>of(), Suppliers.<Set<? extends Image>>ofInstance(images), Suppliers
|
||||||
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>>ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
|
|
||||||
|
@ -128,15 +117,15 @@ public class ServerToNodeMetadataTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException {
|
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||||
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(NovaImageToImageTest.convertImage());
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(NovaImageToImageTest.convertImage());
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
|
||||||
Server server = ParseServerFromJsonResponseTest.parseServer();
|
Server server = ParseServerFromJsonResponseTest.parseServer();
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
||||||
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
.<String, Credentials>of(), Suppliers.<Set<? extends Image>>ofInstance(images), Suppliers
|
||||||
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>>ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
|
|
||||||
|
|
|
@ -49,37 +49,35 @@ import static org.testng.Assert.assertEquals;
|
||||||
public class ParseServerFromJsonResponseTest {
|
public class ParseServerFromJsonResponseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
public void testApplyInputStreamDetails() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||||
Server response = parseServer();
|
Server response = parseServer();
|
||||||
|
|
||||||
assertEquals(response.getId(), 1234);
|
assertEquals(response.getId(), 1234);
|
||||||
assertEquals(response.getName(), "sample-server");
|
assertEquals(response.getName(), "sample-server");
|
||||||
assertEquals(response.getImageId().intValue(), 1234);
|
assertEquals(response.getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234");
|
||||||
assertEquals(response.getFlavorId().intValue(), 1);
|
assertEquals(response.getFlavorRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
||||||
assertEquals(response.getImageId(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234");
|
|
||||||
assertEquals(response.getFlavorId(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
|
||||||
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
assertEquals(true, false, "Uncomment next line");
|
assertEquals(response.getAffinityId(), "fc88bcf8394db9c8d0564e08ca6a9724188a84d1");
|
||||||
//assertEquals(response.getAffinityId(), "fc88bcf8394db9c8d0564e08ca6a9724188a84d1");
|
|
||||||
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
||||||
assertEquals(response.getProgress(), new Integer(60));
|
assertEquals(response.getProgress(), new Integer(60));
|
||||||
|
|
||||||
List<String> publicAddresses = ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83");
|
List<String> publicAddresses = ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83");
|
||||||
List<String> privateAddresses = ImmutableList.of("10.176.42.16", "::babe:10.176.42.16");
|
List<String> privateAddresses = ImmutableList.of("10.176.42.16", "::babe:10.176.42.16");
|
||||||
Addresses addresses1 = new Addresses(new HashSet<String>(publicAddresses), new HashSet<String>(privateAddresses));
|
Addresses addresses1 = new Addresses(new HashSet<String>(publicAddresses), new HashSet<String>(privateAddresses));
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
|
||||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Server parseServer() {
|
public static Server parseServer() throws NoSuchMethodException, ClassNotFoundException {
|
||||||
Injector i = Guice.createInjector(new GsonModule());
|
Injector i = Guice.createInjector(new GsonModule());
|
||||||
|
|
||||||
InputStream is = ParseServerFromJsonResponseTest.class.getResourceAsStream("/test_get_server_detail.json");
|
InputStream is = ParseServerFromJsonResponseTest.class.getResourceAsStream("/test_get_server_detail.json");
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
|
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
|
||||||
}));
|
}));
|
||||||
Server response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
|
||||||
return response;
|
//Function<HttpResponse, ?> parser = i.getInstance(getParserOrThrowException(NovaClient.class.getMethod("getServer", int.class)));
|
||||||
|
return (Server) parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,8 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
|
|
||||||
assertEquals(response.get(0).getId(), 1234);
|
assertEquals(response.get(0).getId(), 1234);
|
||||||
assertEquals(response.get(0).getName(), "sample-server");
|
assertEquals(response.get(0).getName(), "sample-server");
|
||||||
assertEquals(response.get(0).getImageId().intValue(), 1234);
|
assertEquals(response.get(0).getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234");
|
||||||
assertEquals(response.get(0).getFlavorId().intValue(), 1);
|
assertEquals(response.get(0).getFlavorRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
||||||
assertEquals(response.get(0).getImageId(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234");
|
|
||||||
assertEquals(response.get(0).getFlavorId(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
|
||||||
assertEquals(true, false, "Uncomment next line");
|
assertEquals(true, false, "Uncomment next line");
|
||||||
//assertEquals(response.getAffinityId(), "fc88bcf8394db9c8d0564e08ca6a9724188a84d1");
|
//assertEquals(response.getAffinityId(), "fc88bcf8394db9c8d0564e08ca6a9724188a84d1");
|
||||||
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
|
@ -93,8 +91,8 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
assertEquals(response.get(1).getId(), 5678);
|
assertEquals(response.get(1).getId(), 5678);
|
||||||
assertEquals(response.get(1).getName(), "sample-server2");
|
assertEquals(response.get(1).getName(), "sample-server2");
|
||||||
assertEquals(response.get(0).getImageId(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1");
|
assertEquals(response.get(0).getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1");
|
||||||
assertEquals(response.get(0).getFlavorId(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
assertEquals(response.get(0).getFlavorRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
||||||
assertEquals(true, false, "Uncomment next line");
|
assertEquals(true, false, "Uncomment next line");
|
||||||
//assertEquals(response.getAffinityId(), "b414fa41cb37b97dcb58d6c76112af1258e9eae2");
|
//assertEquals(response.getAffinityId(), "b414fa41cb37b97dcb58d6c76112af1258e9eae2");
|
||||||
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
|
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
|
||||||
|
|
Loading…
Reference in New Issue