mirror of https://github.com/apache/jclouds.git
Issue 230: more progress on ibm
This commit is contained in:
parent
9dcaa272ec
commit
9b9f9c4e9c
|
@ -108,10 +108,10 @@ public abstract class BaseJettyTest {
|
||||||
@SuppressWarnings( { "unchecked" })
|
@SuppressWarnings( { "unchecked" })
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<IntegrationTestAsyncClient, IntegrationTestClient> provideContext(Closer closer,
|
RestContext<IntegrationTestClient, IntegrationTestAsyncClient> provideContext(Closer closer,
|
||||||
IntegrationTestAsyncClient aclient, IntegrationTestClient client,
|
IntegrationTestClient aclient, IntegrationTestAsyncClient client,
|
||||||
@Localhost URI endPoint) {
|
@Localhost URI endPoint) {
|
||||||
return new RestContextImpl(closer, aclient, client, endPoint, System
|
return new RestContextImpl(closer, client, aclient, endPoint, System
|
||||||
.getProperty("user.name"));
|
.getProperty("user.name"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.jclouds.ibmdev.domain.Instance;
|
||||||
import org.jclouds.ibmdev.domain.Key;
|
import org.jclouds.ibmdev.domain.Key;
|
||||||
import org.jclouds.ibmdev.domain.Location;
|
import org.jclouds.ibmdev.domain.Location;
|
||||||
import org.jclouds.ibmdev.domain.Volume;
|
import org.jclouds.ibmdev.domain.Volume;
|
||||||
|
import org.jclouds.ibmdev.functions.GetFirstInstanceInList;
|
||||||
import org.jclouds.ibmdev.functions.ParseAddressFromJson;
|
import org.jclouds.ibmdev.functions.ParseAddressFromJson;
|
||||||
import org.jclouds.ibmdev.functions.ParseAddressesFromJson;
|
import org.jclouds.ibmdev.functions.ParseAddressesFromJson;
|
||||||
import org.jclouds.ibmdev.functions.ParseExpirationTimeFromJson;
|
import org.jclouds.ibmdev.functions.ParseExpirationTimeFromJson;
|
||||||
|
@ -181,10 +182,11 @@ public interface IBMDeveloperCloudAsyncClient {
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/instances")
|
@Path("/instances")
|
||||||
@ResponseParser(ParseInstanceFromJson.class)
|
@ResponseParser(GetFirstInstanceInList.class)
|
||||||
ListenableFuture<Instance> createInstanceInLocation(@FormParam("location") String location,
|
ListenableFuture<Instance> createInstanceInLocation(
|
||||||
@FormParam("name") String name, @FormParam("imageID") String imageID,
|
@FormParam("location") String location, @FormParam("name") String name,
|
||||||
@FormParam("instanceType") String instanceType, CreateInstanceOptions... options);
|
@FormParam("imageID") String imageID, @FormParam("instanceType") String instanceType,
|
||||||
|
CreateInstanceOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see IBMDeveloperCloudClient#deleteInstance
|
* @see IBMDeveloperCloudClient#deleteInstance
|
||||||
|
|
|
@ -60,6 +60,7 @@ import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
|
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
|
||||||
import org.jclouds.compute.util.ComputeUtils;
|
import org.jclouds.compute.util.ComputeUtils;
|
||||||
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
|
@ -438,12 +439,14 @@ public class IBMDeveloperCloudComputeServiceContextModule extends IBMDeveloperCl
|
||||||
public IBMImage(org.jclouds.ibmdev.domain.Image in, Location location) {
|
public IBMImage(org.jclouds.ibmdev.domain.Image in, Location location) {
|
||||||
// TODO parse correct OS
|
// TODO parse correct OS
|
||||||
// TODO manifest fails to parse due to encoding issues in the path
|
// TODO manifest fails to parse due to encoding issues in the path
|
||||||
|
// TODO get correct default credentials
|
||||||
|
// http://www-180.ibm.com/cloud/enterprise/beta/ram/community/_rlvid.jsp.faces?_rap=pc_DiscussionForum.doDiscussionTopic&_rvip=/community/discussionForum.jsp&guid={DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&submission=false&fid=1068&tid=1527
|
||||||
super(in.getId(), in.getName(), in.getId(), location, null, ImmutableMap
|
super(in.getId(), in.getName(), in.getId(), location, null, ImmutableMap
|
||||||
.<String, String> of(), in.getDescription(), in.getCreatedTime().getTime() + "",
|
.<String, String> of(), in.getDescription(), in.getCreatedTime().getTime() + "",
|
||||||
(in.getPlatform().indexOf("Redhat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, in
|
(in.getPlatform().indexOf("Redhat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, in
|
||||||
.getPlatform(),
|
.getPlatform(),
|
||||||
(in.getPlatform().indexOf("32") != -1) ? Architecture.X86_32
|
(in.getPlatform().indexOf("32") != -1) ? Architecture.X86_32
|
||||||
: Architecture.X86_64, null);
|
: Architecture.X86_64, new Credentials("root", null));
|
||||||
this.rawImage = in;
|
this.rawImage = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,12 +74,14 @@ public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata>
|
||||||
public NodeMetadata apply(Instance from) {
|
public NodeMetadata apply(Instance from) {
|
||||||
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
|
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
|
||||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
final String tag = matcher.find() ? matcher.group(1) : null;
|
||||||
Set<String> ipSet = ImmutableSet.of(from.getIp());
|
Set<String> ipSet = from.getIp() != null ? ImmutableSet.of(from.getIp()) : ImmutableSet
|
||||||
|
.<String> of();
|
||||||
NodeState state = instanceStateToNodeState.get(from.getStatus());
|
NodeState state = instanceStateToNodeState.get(from.getStatus());
|
||||||
Image image = images.get(from.getImageId());
|
Image image = images.get(from.getImageId());
|
||||||
|
String key = tag != null ? credentialsMap.get(tag) : null;
|
||||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations
|
||||||
.get(image.getLocation()), null, ImmutableMap.<String, String> of(), tag, image,
|
.get(image.getLocation()), null, ImmutableMap.<String, String> of(), tag, image,
|
||||||
state, ipSet, ImmutableList.<String> of(), ImmutableMap.<String, String> of(),
|
state, ipSet, ImmutableList.<String> of(), ImmutableMap.<String, String> of(),
|
||||||
new Credentials(image.getDefaultCredentials().account, credentialsMap.get(tag)));
|
new Credentials(image.getDefaultCredentials().account, key));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -69,7 +69,7 @@ public class Instance {
|
||||||
private String type;
|
private String type;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public Software(String version, String type, String name) {
|
public Software(String name, String type, String version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.ibmdev.functions;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.ibmdev.domain.Instance;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class GetFirstInstanceInList implements Function<HttpResponse, Instance> {
|
||||||
|
private ParseInstancesFromJson listParser;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public GetFirstInstanceInList(ParseInstancesFromJson gson) {
|
||||||
|
this.listParser = gson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Instance apply(HttpResponse from) {
|
||||||
|
return Iterables.getOnlyElement(listParser.apply(from));
|
||||||
|
}
|
||||||
|
}
|
|
@ -62,6 +62,8 @@ public class ParseUtils {
|
||||||
public static final Predicate<Address> CLEAN_ADDRESS = new Predicate<Address>() {
|
public static final Predicate<Address> CLEAN_ADDRESS = new Predicate<Address>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Address input) {
|
public boolean apply(Address input) {
|
||||||
|
if ("0".equals(input.getInstanceId()))
|
||||||
|
input.setInstanceId(null);
|
||||||
if ("".equals(input.getIp()))
|
if ("".equals(input.getIp()))
|
||||||
input.setIp(null);
|
input.setIp(null);
|
||||||
return true;
|
return true;
|
||||||
|
@ -69,11 +71,16 @@ public class ParseUtils {
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final Set<String> emptyString = ImmutableSet.of("");
|
private static final Set<String> emptyString = ImmutableSet.of("");
|
||||||
|
/**
|
||||||
|
* sometimes the service incorrectly returns an id of "0"
|
||||||
|
* http://www-180.ibm.com/cloud/enterprise/
|
||||||
|
* beta/ram/community/discussionTopic.faces?guid={DA689AEE
|
||||||
|
* -783C-6FE7-6F9F-DFEE9763F806}&v=1&fid=1068&tid=1526
|
||||||
|
*/
|
||||||
public static final Predicate<Volume> CLEAN_VOLUME = new Predicate<Volume>() {
|
public static final Predicate<Volume> CLEAN_VOLUME = new Predicate<Volume>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Volume input) {
|
public boolean apply(Volume input) {
|
||||||
if (new Long(0).equals(input.getInstanceId()))
|
if ("0".equals(input.getInstanceId()))
|
||||||
input.setInstanceId(null);
|
input.setInstanceId(null);
|
||||||
if (emptyString.equals(input.getProductCodes()))
|
if (emptyString.equals(input.getProductCodes()))
|
||||||
input.getProductCodes().clear();
|
input.getProductCodes().clear();
|
||||||
|
@ -95,6 +102,8 @@ public class ParseUtils {
|
||||||
public boolean apply(Instance input) {
|
public boolean apply(Instance input) {
|
||||||
if (emptyString.equals(input.getProductCodes()))
|
if (emptyString.equals(input.getProductCodes()))
|
||||||
input.getProductCodes().clear();
|
input.getProductCodes().clear();
|
||||||
|
if ("".equals(input.getIp()))
|
||||||
|
input.setIp(null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class CreateInstanceOptions extends BaseHttpRequestOptions {
|
||||||
formParameters.removeAll("volumeID");
|
formParameters.removeAll("volumeID");
|
||||||
formParameters.put("volumeID", id + "");
|
formParameters.put("volumeID", id + "");
|
||||||
|
|
||||||
String mountParam = String.format("oss.storage.id.%s.mnt", id);
|
String mountParam = String.format("oss.storage.id.0.mnt", id);
|
||||||
formParameters.removeAll(mountParam);
|
formParameters.removeAll(mountParam);
|
||||||
formParameters.put(mountParam, mountPoint);
|
formParameters.put(mountParam, mountPoint);
|
||||||
return this;
|
return this;
|
||||||
|
@ -129,4 +129,5 @@ public class CreateInstanceOptions extends BaseHttpRequestOptions {
|
||||||
return options.authorizePublicKey(publicKeyName);
|
return options.authorizePublicKey(publicKeyName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class InstanceActive implements Predicate<Instance> {
|
||||||
public boolean apply(Instance instance) {
|
public boolean apply(Instance instance) {
|
||||||
logger.trace("looking for state on instance %s", instance);
|
logger.trace("looking for state on instance %s", instance);
|
||||||
instance = client.getInstance(instance.getId());
|
instance = client.getInstance(instance.getId());
|
||||||
if (instance == null)
|
if (instance == null || instance.getStatus() == Instance.Status.FAILED)
|
||||||
return false;
|
return false;
|
||||||
logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(),
|
logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(),
|
||||||
Instance.Status.ACTIVE, instance.getStatus());
|
Instance.Status.ACTIVE, instance.getStatus());
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.http.functions.CloseContentAndReturn;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.ibmdev.config.IBMDeveloperCloudRestClientModule;
|
import org.jclouds.ibmdev.config.IBMDeveloperCloudRestClientModule;
|
||||||
import org.jclouds.ibmdev.domain.Image;
|
import org.jclouds.ibmdev.domain.Image;
|
||||||
|
import org.jclouds.ibmdev.functions.GetFirstInstanceInList;
|
||||||
import org.jclouds.ibmdev.functions.ParseAddressFromJson;
|
import org.jclouds.ibmdev.functions.ParseAddressFromJson;
|
||||||
import org.jclouds.ibmdev.functions.ParseAddressesFromJson;
|
import org.jclouds.ibmdev.functions.ParseAddressesFromJson;
|
||||||
import org.jclouds.ibmdev.functions.ParseExpirationTimeFromJson;
|
import org.jclouds.ibmdev.functions.ParseExpirationTimeFromJson;
|
||||||
|
@ -514,7 +515,7 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
||||||
assertHeadersEqual(httpRequest,
|
assertHeadersEqual(httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 57\nContent-Type: application/x-www-form-urlencoded\n");
|
"Accept: application/json\nContent-Length: 57\nContent-Type: application/x-www-form-urlencoded\n");
|
||||||
assertPayloadEquals(httpRequest, "location=1&imageID=22&name=name&instanceType=instanceType");
|
assertPayloadEquals(httpRequest, "location=1&imageID=22&name=name&instanceType=instanceType");
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseInstanceFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, GetFirstInstanceInList.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -540,9 +541,9 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
||||||
"Accept: application/json\nContent-Length: 221\nContent-Type: application/x-www-form-urlencoded\n");
|
"Accept: application/json\nContent-Length: 221\nContent-Type: application/x-www-form-urlencoded\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"location=location&imageID=22&name=name&instanceType=instanceType&ip=1&publicKey=MOO&volumeID=2&oss.storage.id.2.mnt=%2Fmnt&insight_admin_password=myPassword1&db2_admin_password=myPassword2&report_user_password=myPassword3");
|
"location=location&imageID=22&name=name&instanceType=instanceType&ip=1&publicKey=MOO&volumeID=2&oss.storage.id.0.mnt=%2Fmnt&insight_admin_password=myPassword1&db2_admin_password=myPassword2&report_user_password=myPassword3");
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseInstanceFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, GetFirstInstanceInList.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.jclouds.ibmdev;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.ibmdev.options.CreateInstanceOptions.Builder.attachIp;
|
import static org.jclouds.ibmdev.options.CreateInstanceOptions.Builder.attachIp;
|
||||||
|
import static org.jclouds.ibmdev.options.CreateInstanceOptions.Builder.configurationData;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
|
@ -32,6 +33,7 @@ import static org.testng.Assert.assertNull;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -44,6 +46,8 @@ import org.jclouds.ibmdev.domain.Location;
|
||||||
import org.jclouds.ibmdev.domain.Volume;
|
import org.jclouds.ibmdev.domain.Volume;
|
||||||
import org.jclouds.ibmdev.domain.Instance.Software;
|
import org.jclouds.ibmdev.domain.Instance.Software;
|
||||||
import org.jclouds.ibmdev.predicates.AddressFree;
|
import org.jclouds.ibmdev.predicates.AddressFree;
|
||||||
|
import org.jclouds.ibmdev.predicates.InstanceActive;
|
||||||
|
import org.jclouds.ibmdev.predicates.InstanceRemovedOrNotFound;
|
||||||
import org.jclouds.ibmdev.predicates.VolumeUnmounted;
|
import org.jclouds.ibmdev.predicates.VolumeUnmounted;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
|
@ -66,14 +70,18 @@ import com.google.common.io.Files;
|
||||||
@Test(groups = "live", testName = "ibmdevelopercloud.IBMDeveloperCloudClientLiveTest")
|
@Test(groups = "live", testName = "ibmdevelopercloud.IBMDeveloperCloudClientLiveTest")
|
||||||
public class IBMDeveloperCloudClientLiveTest {
|
public class IBMDeveloperCloudClientLiveTest {
|
||||||
|
|
||||||
|
private static final ImmutableSet<Software> SOFTWARE = ImmutableSet.<Software> of(new Software(
|
||||||
|
"SUSE Linux Enterprise", "OS", "10 SP2"));
|
||||||
|
private static final String SIZE = "LARGE";
|
||||||
private IBMDeveloperCloudClient connection;
|
private IBMDeveloperCloudClient connection;
|
||||||
private Location location;
|
private Location location;
|
||||||
private Address ip;
|
private Address ip;
|
||||||
private ImmutableMap<String, String> keyPair;
|
private ImmutableMap<String, String> keyPair;
|
||||||
private Key key;
|
private Key key;
|
||||||
private Volume volume;
|
private Volume volume;
|
||||||
private Instance instance;
|
|
||||||
private String user;
|
private String user;
|
||||||
|
private Instance instance2;
|
||||||
|
private Instance instance;
|
||||||
|
|
||||||
private static final String TAG = System.getProperty("user.name");
|
private static final String TAG = System.getProperty("user.name");
|
||||||
|
|
||||||
|
@ -182,13 +190,29 @@ public class IBMDeveloperCloudClientLiveTest {
|
||||||
public void testAddPublicKey() throws Exception {
|
public void testAddPublicKey() throws Exception {
|
||||||
try {
|
try {
|
||||||
connection.addPublicKey(TAG, keyPair.get("public"));
|
connection.addPublicKey(TAG, keyPair.get("public"));
|
||||||
|
key = connection.getKey(TAG);
|
||||||
|
try {
|
||||||
|
assert key.getInstanceIds().equals(ImmutableSet.<String> of()) : key;
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
// inconsistency in the key api when recreating a key
|
||||||
|
// http://www-180.ibm.com/cloud/enterprise/beta/ram/community/discussionTopic.faces?guid={DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&fid=1068&tid=1528
|
||||||
|
}
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
// must not have been found
|
// must have been found
|
||||||
connection.updatePublicKey(TAG, keyPair.get("public"));
|
connection.updatePublicKey(TAG, keyPair.get("public"));
|
||||||
|
key = connection.getKey(TAG);
|
||||||
|
for (String instanceId : key.getInstanceIds()) {
|
||||||
|
Instance instance = connection.getInstance(instanceId);
|
||||||
|
System.out.println("deleting instance: " + instance);
|
||||||
|
if (instance.getStatus() == Instance.Status.FAILED
|
||||||
|
|| instance.getStatus() == Instance.Status.ACTIVE) {
|
||||||
|
connection.deleteInstance(instanceId);
|
||||||
|
assert new RetryablePredicate<Instance>(new InstanceRemovedOrNotFound(connection),
|
||||||
|
30, 2, TimeUnit.SECONDS).apply(instance) : instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
key = connection.getKey(TAG);
|
|
||||||
assertEquals(key.getName(), TAG);
|
assertEquals(key.getName(), TAG);
|
||||||
assertEquals(key.getInstanceIds(), ImmutableSet.<Long> of());
|
|
||||||
assert keyPair.get("public").indexOf(key.getKeyMaterial()) > 0;
|
assert keyPair.get("public").indexOf(key.getKeyMaterial()) > 0;
|
||||||
assertNotNull(key.getLastModifiedTime());
|
assertNotNull(key.getLastModifiedTime());
|
||||||
}
|
}
|
||||||
|
@ -199,8 +223,10 @@ public class IBMDeveloperCloudClientLiveTest {
|
||||||
ip = connection.allocateAddressInLocation(location.getId());
|
ip = connection.allocateAddressInLocation(location.getId());
|
||||||
assertEquals(ip.getIp(), null);
|
assertEquals(ip.getIp(), null);
|
||||||
// wait up to 30 seconds for this to become "free"
|
// wait up to 30 seconds for this to become "free"
|
||||||
assert new RetryablePredicate<Address>(new AddressFree(connection), 30, 2,
|
new RetryablePredicate<Address>(new AddressFree(connection), 30, 2, TimeUnit.SECONDS)
|
||||||
TimeUnit.SECONDS).apply(ip);
|
.apply(ip);
|
||||||
|
refreshIpAndReturnAllAddresses();
|
||||||
|
assertEquals(ip.getInstanceId(), null);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
if (HttpResponseException.class.cast(e.getCause()).getResponse().getStatusCode() == 409) {
|
if (HttpResponseException.class.cast(e.getCause()).getResponse().getStatusCode() == 409) {
|
||||||
ip = Iterables.find(connection.listAddresses(), new Predicate<Address>() {
|
ip = Iterables.find(connection.listAddresses(), new Predicate<Address>() {
|
||||||
|
@ -215,27 +241,15 @@ public class IBMDeveloperCloudClientLiveTest {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals(ip.getInstanceId(), "0");
|
assertEquals(ip.getInstanceId(), null);
|
||||||
assertEquals(ip.getLocation(), location.getId());
|
assertEquals(ip.getLocation(), location.getId());
|
||||||
|
|
||||||
final String id = ip.getId();
|
Set<? extends Address> allAddresses = refreshIpAndReturnAllAddresses();
|
||||||
|
|
||||||
Set<? extends Address> allAddresses = connection.listAddresses();
|
|
||||||
|
|
||||||
// refresh address as it may have been just created
|
|
||||||
ip = Iterables.find(allAddresses, new Predicate<Address>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Address input) {
|
|
||||||
return input.getId().equals(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
assert (allAddresses.contains(ip)) : String.format("ip %s not in %s", ip, allAddresses);
|
assert (allAddresses.contains(ip)) : String.format("ip %s not in %s", ip, allAddresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testGetLocation")
|
@Test(enabled = false, dependsOnMethods = "testGetLocation")
|
||||||
public void testCreateVolume() throws Exception {
|
public void testCreateVolume() throws Exception {
|
||||||
try {
|
try {
|
||||||
volume = connection.createVolumeInLocation(location.getId(), TAG, "EXT3", "SMALL");
|
volume = connection.createVolumeInLocation(location.getId(), TAG, "EXT3", "SMALL");
|
||||||
|
@ -244,19 +258,24 @@ public class IBMDeveloperCloudClientLiveTest {
|
||||||
TimeUnit.SECONDS).apply(volume);
|
TimeUnit.SECONDS).apply(volume);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
if (HttpResponseException.class.cast(e.getCause()).getResponse().getStatusCode() == 409) {
|
if (HttpResponseException.class.cast(e.getCause()).getResponse().getStatusCode() == 409) {
|
||||||
volume = Iterables.find(connection.listVolumes(), new Predicate<Volume>() {
|
Set<? extends Volume> volumes = connection.listVolumes();
|
||||||
|
try {
|
||||||
|
volume = Iterables.find(volumes, new Predicate<Volume>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Volume input) {
|
public boolean apply(Volume input) {
|
||||||
return input.getState() == Volume.State.UNMOUNTED;
|
return input.getState() == Volume.State.UNMOUNTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
} catch (NoSuchElementException ex) {
|
||||||
|
throw new RuntimeException("no unmounted volumes in: " + volumes, e);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals(volume.getInstanceId(), "0");
|
assertEquals(volume.getInstanceId(), null);
|
||||||
assertEquals(volume.getLocation(), location.getId());
|
assertEquals(volume.getLocation(), location.getId());
|
||||||
|
|
||||||
final String id = volume.getId();
|
final String id = volume.getId();
|
||||||
|
@ -277,45 +296,98 @@ public class IBMDeveloperCloudClientLiveTest {
|
||||||
|
|
||||||
private static final String IMAGE_ID = "11";// Rational Insight
|
private static final String IMAGE_ID = "11";// Rational Insight
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testAddPublicKey")
|
||||||
|
public void testCreateInstance() throws Exception {
|
||||||
|
instance = connection.createInstanceInLocation(location.getId(), TAG, IMAGE_ID, SIZE,
|
||||||
|
configurationData(
|
||||||
|
ImmutableMap.of("insight_admin_password", "myPassword1",
|
||||||
|
"db2_admin_password", "myPassword2", "report_user_password",
|
||||||
|
"myPassword3")).authorizePublicKey(key.getName()));
|
||||||
|
try {
|
||||||
|
assertIpHostAndStatusNEW(instance);
|
||||||
|
assertConsistent(instance, TAG);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
System.err.println(instance);
|
||||||
|
throw e;
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
System.err.println(instance);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
assert new RetryablePredicate<Instance>(new InstanceActive(connection), 600, 2,
|
||||||
|
TimeUnit.SECONDS).apply(instance) : connection.getInstance(instance.getId());
|
||||||
|
|
||||||
|
System.out.println(((System.currentTimeMillis() - start) / 1000) + " seconds");
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertIpHostAndStatusACTIVE(instance);
|
||||||
|
assertConsistent(instance, TAG);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
System.err.println(instance);
|
||||||
|
throw e;
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
System.err.println(instance);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertConsistent(Instance instance, String TAG) {
|
||||||
|
assertNotNull(instance.getId());
|
||||||
|
assertEquals(instance.getName(), TAG);
|
||||||
|
assertEquals(instance.getInstanceType(), SIZE);
|
||||||
|
assertEquals(instance.getLocation(), location.getId());
|
||||||
|
assertEquals(instance.getImageId(), IMAGE_ID);
|
||||||
|
assertEquals(instance.getSoftware(), SOFTWARE);
|
||||||
|
assertEquals(instance.getKeyName(), key.getName());
|
||||||
|
assertNotNull(instance.getLaunchTime());
|
||||||
|
assertNotNull(instance.getExpirationTime());
|
||||||
|
assertEquals(instance.getOwner(), user);
|
||||||
|
assertEquals(instance.getProductCodes(), ImmutableSet.<String> of());
|
||||||
|
assertEquals(instance.getRequestName(), TAG);
|
||||||
|
assertNotNull(instance.getRequestId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertIpHostAndStatusNEW(Instance instance) {
|
||||||
|
assertEquals(instance.getIp(), null);
|
||||||
|
assertEquals(instance.getHostname(), null);
|
||||||
|
assertEquals(instance.getStatus(), Instance.Status.NEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertIpHostAndStatusACTIVE(Instance instance) {
|
||||||
|
assertNotNull(instance.getIp());
|
||||||
|
assertNotNull(instance.getHostname());
|
||||||
|
assertEquals(instance.getStatus(), Instance.Status.ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cannot run an instance due to 500 errors:
|
* cannot run an instance due to 500 errors:
|
||||||
*
|
*
|
||||||
* http://www-180.ibm.com/cloud/enterprise/beta/ram/community/discussionTopic.faces?guid={
|
* http://www-180.ibm.com/cloud/enterprise/beta/ram/community/discussionTopic.faces?guid={
|
||||||
* DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&fid=1068&tid=1523#topic
|
* DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&fid=1068&tid=1523#topic
|
||||||
*/
|
*/
|
||||||
@Test(expectedExceptions = HttpResponseException.class, dependsOnMethods = { "testAddPublicKey",
|
@Test(enabled = false, dependsOnMethods = { "testAddPublicKey", "testAllocateIpAddress",
|
||||||
"testAllocateIpAddress", "testCreateVolume" })
|
"testCreateVolume" })
|
||||||
public void testCreateInstanceWithOptions() throws Exception {
|
public void testCreateInstanceWithVolume() throws Exception {
|
||||||
instance = connection.createInstanceInLocation(location.getId(), TAG, IMAGE_ID, "LARGE",
|
instance2 = connection.createInstanceInLocation(location.getId(), TAG, IMAGE_ID, SIZE,
|
||||||
attachIp(ip.getId()).authorizePublicKey(key.getName()).mountVolume(volume.getId(),
|
attachIp(ip.getId()).authorizePublicKey(key.getName()).mountVolume(volume.getId(),
|
||||||
"/mnt").configurationData(
|
"/mnt").configurationData(
|
||||||
ImmutableMap.of("insight_admin_password", "myPassword1",
|
ImmutableMap.of("insight_admin_password", "myPassword1",
|
||||||
"db2_admin_password", "myPassword2", "report_user_password",
|
"db2_admin_password", "myPassword2", "report_user_password",
|
||||||
"myPassword3")));
|
"myPassword3")));
|
||||||
assertEquals(instance.getLocation(), location.getId());
|
//
|
||||||
assertNotNull(instance.getHostname());
|
|
||||||
assertEquals(instance.getIp(), ip.getIp());
|
|
||||||
assertEquals(instance.getKeyName(), key.getName());
|
|
||||||
assertNotNull(instance.getExpirationTime());
|
|
||||||
assertNotNull(instance.getLaunchTime());
|
|
||||||
assertEquals(instance.getInstanceType(), "SMALL");
|
|
||||||
assertNotNull(instance.getName());
|
|
||||||
assertEquals(instance.getOwner(), user);
|
|
||||||
assertEquals(instance.getImageId(), IMAGE_ID);
|
|
||||||
assertEquals(instance.getSoftware(), ImmutableSet.<Software> of());
|
|
||||||
assertEquals(instance.getProductCodes(), ImmutableSet.<String> of());
|
|
||||||
assertEquals(instance.getStatus(), Instance.Status.NEW);
|
|
||||||
assertNotNull(instance.getRequestName());
|
|
||||||
|
|
||||||
volume = connection.getVolume(volume.getId());
|
volume = connection.getVolume(volume.getId());
|
||||||
assertEquals(volume.getInstanceId(), instance.getId());
|
assertEquals(volume.getInstanceId(), instance2.getId());
|
||||||
|
|
||||||
refreshIp();
|
refreshIpAndReturnAllAddresses();
|
||||||
assertEquals(ip.getInstanceId(), ip.getId());
|
assertEquals(ip.getInstanceId(), instance2.getId());
|
||||||
|
assertEquals(ip.getIp(), instance2.getIp());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshIp() {
|
private Set<? extends Address> refreshIpAndReturnAllAddresses() {
|
||||||
Set<? extends Address> allAddresses = connection.listAddresses();
|
Set<? extends Address> allAddresses = connection.listAddresses();
|
||||||
final String id = ip.getId();
|
final String id = ip.getId();
|
||||||
// refresh address as it may have been just created
|
// refresh address as it may have been just created
|
||||||
|
@ -327,6 +399,7 @@ public class IBMDeveloperCloudClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
return allAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterTest(groups = { "live" })
|
@AfterTest(groups = { "live" })
|
||||||
|
@ -354,6 +427,12 @@ public class IBMDeveloperCloudClientLiveTest {
|
||||||
connection.deleteInstance(instance.getId());
|
connection.deleteInstance(instance.getId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if (instance2 != null)
|
||||||
|
try {
|
||||||
|
connection.deleteInstance(instance2.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,10 @@ public class ParseInstanceFromJsonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
Instance instance = new Instance(new Date(1260472231726l), ImmutableSet.of(new Software(
|
Instance instance = new Instance(new Date(1260472231726l), ImmutableSet.<Software> of(new Software(
|
||||||
"10 SP2", "OS", "SUSE Linux Enterprise")), "129.33.197.78", "7430", "DEFAULT", "ABC",
|
"SUSE Linux Enterprise", "OS", "10 SP2")), "129.33.197.78", "7430", "DEFAULT",
|
||||||
"MEDIUM", 5, "aadelucc@us.ibm.com", "vm723.developer.ihost.com", "1", "3", ImmutableSet
|
"ABC", "MEDIUM", 5, "aadelucc@us.ibm.com", "vm723.developer.ihost.com", "1", "3",
|
||||||
.<String> of(), "ABC", "7430", new Date(1263064240837l));
|
ImmutableSet.<String> of(), "ABC", "7430", new Date(1263064240837l));
|
||||||
|
|
||||||
Instance compare = handler.apply(new HttpResponse(ParseInstanceFromJsonTest.class
|
Instance compare = handler.apply(new HttpResponse(ParseInstanceFromJsonTest.class
|
||||||
.getResourceAsStream("/instance.json")));
|
.getResourceAsStream("/instance.json")));
|
||||||
|
|
|
@ -58,12 +58,12 @@ public class ParseInstancesFromJsonTest {
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
Instance instance1 = new Instance(new Date(1260472231726l), ImmutableSet.of(new Software(
|
Instance instance1 = new Instance(new Date(1260472231726l), ImmutableSet.of(new Software(
|
||||||
"10 SP2", "OS", "SUSE Linux Enterprise")), "129.33.197.78", "7430", "DEFAULT",
|
"SUSE Linux Enterprise", "OS", "10 SP2")), "129.33.197.78", "7430", "DEFAULT",
|
||||||
"ABC", "MEDIUM", 5, "aadelucc@us.ibm.com", "vm723.developer.ihost.com", "1", "3",
|
"ABC", "MEDIUM", 5, "aadelucc@us.ibm.com", "vm723.developer.ihost.com", "1", "3",
|
||||||
ImmutableSet.<String> of(), "ABC", "7430", new Date(1263064240837l));
|
ImmutableSet.<String> of(), "ABC", "7430", new Date(1263064240837l));
|
||||||
|
|
||||||
Instance instance2 = new Instance(new Date(1260472231727l), ImmutableSet.of(new Software(
|
Instance instance2 = new Instance(new Date(1260472231727l), ImmutableSet.of(new Software(
|
||||||
"10 SP3", "OS", "SUSE Linux Enterprise")), "129.33.197.79", "7431", "DEFAULT",
|
"SUSE Linux Enterprise", "OS", "10 SP3")), "129.33.197.79", "7431", "DEFAULT",
|
||||||
"ABC", "MEDIUM", 6, "aadelucc@us.ibm.com", "vm723.developer.ihost.com", "2", "4",
|
"ABC", "MEDIUM", 6, "aadelucc@us.ibm.com", "vm723.developer.ihost.com", "2", "4",
|
||||||
ImmutableSet.<String> of(), "ABC", "7431", new Date(1263064240838l));
|
ImmutableSet.<String> of(), "ABC", "7431", new Date(1263064240838l));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue