mirror of https://github.com/apache/jclouds.git
deltacloud now operates on rackspace
This commit is contained in:
parent
53c735fdff
commit
1a51fbc8ad
|
@ -52,7 +52,6 @@ public class InstanceStateStopped implements Predicate<RunningInstance> {
|
||||||
|
|
||||||
public boolean apply(RunningInstance instance) {
|
public boolean apply(RunningInstance instance) {
|
||||||
logger.trace("looking for state on instance %s", instance);
|
logger.trace("looking for state on instance %s", instance);
|
||||||
|
|
||||||
instance = refresh(instance);
|
instance = refresh(instance);
|
||||||
logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(),
|
logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(),
|
||||||
InstanceState.STOPPED, instance.getInstanceState());
|
InstanceState.STOPPED, instance.getInstanceState());
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class TransitionOnAction implements Transition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TransitionOnAction [action=" + action + ", to=" + to + "]";
|
return "[action=" + action + ", to=" + to + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 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.deltacloud.predicates;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.deltacloud.DeltacloudClient;
|
||||||
|
import org.jclouds.deltacloud.domain.Instance;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Tests to see if a instance is terminated
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class InstanceFinished extends InstanceState {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public InstanceFinished(DeltacloudClient client) {
|
||||||
|
super(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Instance.State getState() {
|
||||||
|
return Instance.State.FINISH;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 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.deltacloud.predicates;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.deltacloud.DeltacloudClient;
|
||||||
|
import org.jclouds.deltacloud.domain.Instance;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Tests to see if a instance is running
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class InstanceRunning extends InstanceState {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public InstanceRunning(DeltacloudClient client) {
|
||||||
|
super(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Instance.State getState() {
|
||||||
|
return Instance.State.RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 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.deltacloud.predicates;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.deltacloud.DeltacloudClient;
|
||||||
|
import org.jclouds.deltacloud.domain.Instance;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Tests to see if a instance is at a specific state
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public abstract class InstanceState implements Predicate<Instance> {
|
||||||
|
|
||||||
|
private final DeltacloudClient client;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public InstanceState(DeltacloudClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean apply(Instance instance) {
|
||||||
|
logger.trace("looking for state on instance %s", checkNotNull(instance, "instance"));
|
||||||
|
instance = refresh(instance);
|
||||||
|
if (instance == null || instance.getState() == Instance.State.FINISH)
|
||||||
|
return false;
|
||||||
|
logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(), getState(), instance
|
||||||
|
.getState());
|
||||||
|
return instance.getState() == getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Instance.State getState();
|
||||||
|
|
||||||
|
private Instance refresh(Instance instance) {
|
||||||
|
return client.getInstance(instance.getHref());
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,13 +27,15 @@ import java.util.logging.Logger;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.deltacloud.domain.Image;
|
import org.jclouds.deltacloud.domain.Image;
|
||||||
import org.jclouds.deltacloud.domain.Instance;
|
import org.jclouds.deltacloud.domain.Instance;
|
||||||
|
import org.jclouds.deltacloud.domain.PasswordAuthentication;
|
||||||
|
import org.jclouds.deltacloud.domain.Transition;
|
||||||
|
import org.jclouds.deltacloud.domain.TransitionOnAction;
|
||||||
import org.jclouds.deltacloud.options.CreateInstanceOptions;
|
import org.jclouds.deltacloud.options.CreateInstanceOptions;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.net.IPSocket;
|
import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||||
import org.testng.annotations.AfterGroups;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -51,6 +53,7 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest {
|
||||||
|
|
||||||
protected String prefix = System.getProperty("user.name") + ".test";
|
protected String prefix = System.getProperty("user.name") + ".test";
|
||||||
protected Instance instance;
|
protected Instance instance;
|
||||||
|
protected Credentials creds;
|
||||||
|
|
||||||
public void testCreateInstance() throws Exception {
|
public void testCreateInstance() throws Exception {
|
||||||
Logger.getAnonymousLogger().info("starting instance");
|
Logger.getAnonymousLogger().info("starting instance");
|
||||||
|
@ -62,12 +65,13 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
}).getId(), CreateInstanceOptions.Builder.named(prefix));
|
}).getId(), CreateInstanceOptions.Builder.named(prefix));
|
||||||
instance = client.getInstance(instance.getHref());
|
if (instance.getAuthentication() != null && instance.getAuthentication() instanceof PasswordAuthentication)
|
||||||
|
creds = PasswordAuthentication.class.cast(instance.getAuthentication()).getLoginCredentials();
|
||||||
|
refreshInstance();
|
||||||
checkStartedInstance();
|
checkStartedInstance();
|
||||||
|
|
||||||
Instance newInfo = client.getInstance(instance.getHref());
|
Instance newInfo = client.getInstance(instance.getHref());
|
||||||
checkInstanceMatchesGet(newInfo);
|
checkInstanceMatchesGet(newInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkInstanceMatchesGet(Instance newInfo) {
|
protected void checkInstanceMatchesGet(Instance newInfo) {
|
||||||
|
@ -77,49 +81,57 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest {
|
||||||
protected void checkStartedInstance() {
|
protected void checkStartedInstance() {
|
||||||
System.out.println(new Gson().toJson(instance));
|
System.out.println(new Gson().toJson(instance));
|
||||||
assertEquals(instance.getName(), prefix);
|
assertEquals(instance.getName(), prefix);
|
||||||
|
assert stateChanges.get(Instance.State.RUNNING).apply(instance) : instance;
|
||||||
|
refreshInstance();
|
||||||
assertEquals(instance.getState(), Instance.State.RUNNING);
|
assertEquals(instance.getState(), Instance.State.RUNNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Instance refreshInstance() {
|
||||||
|
if (instance != null)
|
||||||
|
return instance = client.getInstance(instance.getHref());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateInstance")
|
@Test(dependsOnMethods = "testCreateInstance")
|
||||||
public void testConnectivity() throws Exception {
|
public void testConnectivity() throws Exception {
|
||||||
Logger.getAnonymousLogger().info("awaiting ssh");
|
Logger.getAnonymousLogger().info("awaiting ssh");
|
||||||
// TODO
|
assert socketTester.apply(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), 22)) : instance;
|
||||||
// assert socketTester.apply(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0),
|
if (creds != null) {
|
||||||
// 22)) : instance;
|
Logger.getAnonymousLogger().info("will connect ssh");
|
||||||
// doConnectViaSsh(instance, getSshCredentials(instance));
|
doConnectViaSsh(instance, creds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Credentials getSshCredentials(Instance instance2) {
|
public HttpRequest getAction(Instance.Action action) {
|
||||||
// TODO
|
return instance.getActions().get(action);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpRequest refreshInstanceAndGetAction(Instance.Action action) {
|
|
||||||
return client.getInstance(instance.getHref()).getActions().get(action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testConnectivity")
|
@Test(dependsOnMethods = "testConnectivity")
|
||||||
public void testLifeCycle() {
|
public void testLifeCycle() {
|
||||||
client.performAction(refreshInstanceAndGetAction(Instance.Action.STOP));
|
|
||||||
assertEquals(client.getInstance(instance.getHref()).getState(), Instance.State.STOPPED);
|
|
||||||
|
|
||||||
client.performAction(refreshInstanceAndGetAction(Instance.Action.START));
|
|
||||||
assertEquals(client.getInstance(instance.getHref()).getState(), Instance.State.RUNNING);
|
|
||||||
|
|
||||||
client.performAction(refreshInstanceAndGetAction(Instance.Action.REBOOT));
|
|
||||||
assertEquals(client.getInstance(instance.getHref()).getState(), Instance.State.RUNNING);
|
|
||||||
|
|
||||||
|
HttpRequest rebootUri = getAction(Instance.Action.REBOOT);
|
||||||
|
if (rebootUri != null) {
|
||||||
|
client.performAction(rebootUri);
|
||||||
|
assert stateChanges.get(Instance.State.RUNNING).apply(instance) : instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testLifeCycle")
|
@Test(dependsOnMethods = "testLifeCycle")
|
||||||
public void testDestroyInstance() {
|
public void testDestroyInstance() {
|
||||||
try {
|
for (Transition transition : findChainTo(Instance.State.FINISH, refreshInstance().getState(), client
|
||||||
client.performAction(refreshInstanceAndGetAction(Instance.Action.STOP));
|
.getInstanceStates())) {
|
||||||
assertEquals(client.getInstance(instance.getHref()).getState(), Instance.State.STOPPED);
|
if (refreshInstance() == null)
|
||||||
} catch (IllegalArgumentException e) {
|
break;
|
||||||
|
if (transition instanceof TransitionOnAction) {
|
||||||
|
client.performAction(getAction(TransitionOnAction.class.cast(transition).getAction()));
|
||||||
|
}
|
||||||
|
Predicate<Instance> stateTester = stateChanges.get(transition.getTo());
|
||||||
|
if (stateTester != null)
|
||||||
|
assert stateTester.apply(instance) : transition + " : " + instance;
|
||||||
|
else
|
||||||
|
Logger.getAnonymousLogger().warning(String.format("no state tester for: %s", transition));
|
||||||
}
|
}
|
||||||
client.performAction(refreshInstanceAndGetAction(Instance.Action.DESTROY));
|
assert refreshInstance() == null;
|
||||||
assertEquals(client.getInstance(instance.getHref()), null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doConnectViaSsh(Instance instance, Credentials creds) throws IOException {
|
protected void doConnectViaSsh(Instance instance, Credentials creds) throws IOException {
|
||||||
|
@ -138,14 +150,9 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups(groups = "live")
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() {
|
protected void tearDown() {
|
||||||
try {
|
testDestroyInstance();
|
||||||
testDestroyInstance();
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
// no need to check null or anything as we swallow all
|
|
||||||
}
|
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@ import org.jclouds.deltacloud.domain.Image;
|
||||||
import org.jclouds.deltacloud.domain.Instance;
|
import org.jclouds.deltacloud.domain.Instance;
|
||||||
import org.jclouds.deltacloud.domain.Realm;
|
import org.jclouds.deltacloud.domain.Realm;
|
||||||
import org.jclouds.deltacloud.domain.Transition;
|
import org.jclouds.deltacloud.domain.Transition;
|
||||||
|
import org.jclouds.deltacloud.domain.Instance.State;
|
||||||
|
import org.jclouds.deltacloud.predicates.InstanceFinished;
|
||||||
|
import org.jclouds.deltacloud.predicates.InstanceRunning;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.net.IPSocket;
|
import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||||
|
@ -46,6 +49,7 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
@ -68,6 +72,7 @@ public class ReadOnlyDeltacloudClientLiveTest {
|
||||||
protected String endpoint;
|
protected String endpoint;
|
||||||
protected String apiversion;
|
protected String apiversion;
|
||||||
protected Predicate<IPSocket> socketTester;
|
protected Predicate<IPSocket> socketTester;
|
||||||
|
protected ImmutableMap<State, Predicate<Instance>> stateChanges;
|
||||||
|
|
||||||
protected void setupCredentials() {
|
protected void setupCredentials() {
|
||||||
identity = System.getProperty("test." + provider + ".identity", "mockuser");
|
identity = System.getProperty("test." + provider + ".identity", "mockuser");
|
||||||
|
@ -99,6 +104,12 @@ public class ReadOnlyDeltacloudClientLiveTest {
|
||||||
|
|
||||||
client = context.getApi();
|
client = context.getApi();
|
||||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
|
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
|
||||||
|
stateChanges = ImmutableMap.<Instance.State, Predicate<Instance>> of(//
|
||||||
|
Instance.State.RUNNING, new RetryablePredicate<Instance>(new InstanceRunning(client), 600, 1,
|
||||||
|
TimeUnit.SECONDS),//
|
||||||
|
Instance.State.FINISH, new RetryablePredicate<Instance>(new InstanceFinished(client), 30, 1,
|
||||||
|
TimeUnit.SECONDS)//
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue