diff --git a/sandbox-apis/deltacloud/README.txt b/sandbox-apis/deltacloud/README.txt index 6d968a0e08..77e08b4524 100644 --- a/sandbox-apis/deltacloud/README.txt +++ b/sandbox-apis/deltacloud/README.txt @@ -7,6 +7,7 @@ To install deltacloud, do the following: * OS/X and jruby # use homebrew or equiv to install jruby * brew install jruby + * note testing took place w/ 1.6.0 # install and configure openssl to avoid "certificate verify failed" errors # install and link openssl * brew install openssl @@ -24,7 +25,9 @@ To install deltacloud, do the following: * jruby -ropen-uri -e 'p open("https://encrypted.google.com")' * should see something like # # install specific version of rack that doesn't conflict with deltacloud - * jruby -S gem --version 1.1.0 install rack + * jruby -S gem install rack --version 1.1.0 + # install net-ssh + * jruby -S gem install net-ssh # install deltacloud core * jruby -S gem install deltacloud-core @@ -40,12 +43,15 @@ Here are some notes about specific cloud providers # install fog gem * jruby -S gem install fog * rackspace - # install cloudfiles gem + # install cloudfiles, cloudservers gem + * jruby -S gem install cloudservers * jruby -S gem install cloudfiles * ec2 - # install amazon-ec2 gem - * jruby -S gem install amazon-ec2 - + * using jruby --1.8, 'gem install aws' will fail with ArrayIndexOutOfBoundsException per http://jira.codehaus.org/browse/JRUBY-5581 + * using jruby --1.9, 'gem install aws' works, but running './server/bin/deltacloudd -i ec2' fails per http://jira.codehaus.org/browse/JRUBY-5529 + # install i18n, aws gem + * jruby -S gem install i18n + * jruby -S gem install aws Local Development of Delta * jruby -S gem install rack-test cucumber diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java index 4d92458e61..36f99ab9e4 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java @@ -37,9 +37,9 @@ import org.jclouds.deltacloud.domain.DeltacloudCollection; import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.domain.Instance; -import org.jclouds.deltacloud.domain.InstanceState; import org.jclouds.deltacloud.domain.Realm; import org.jclouds.deltacloud.domain.Transition; +import org.jclouds.deltacloud.domain.Instance.State; import org.jclouds.deltacloud.functions.ReturnVoidOnRedirectedDelete; import org.jclouds.deltacloud.options.CreateInstanceOptions; import org.jclouds.deltacloud.xml.DeltacloudCollectionsHandler; @@ -93,7 +93,7 @@ public interface DeltacloudAsyncClient { @Endpoint(InstanceStates.class) @ExceptionParser(ReturnEmptyMultimapOnNotFoundOr404.class) @XMLResponseParser(InstanceStatesHandler.class) - ListenableFuture> getInstanceStates(); + ListenableFuture> getInstanceStates(); /** * @see DeltacloudClient#listRealms diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java index 997120ed3f..0ad720ec60 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java @@ -28,9 +28,9 @@ import org.jclouds.deltacloud.domain.DeltacloudCollection; import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.domain.Instance; -import org.jclouds.deltacloud.domain.InstanceState; import org.jclouds.deltacloud.domain.Realm; import org.jclouds.deltacloud.domain.Transition; +import org.jclouds.deltacloud.domain.Instance.State; import org.jclouds.deltacloud.options.CreateInstanceOptions; import org.jclouds.http.HttpRequest; @@ -58,7 +58,7 @@ public interface DeltacloudClient { * * @return The possible states of an instance, and how to traverse between them */ - Multimap getInstanceStates(); + Multimap getInstanceStates(); /** * The realms collection will return a set of all realms available to the current user. diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/HardwareProperty.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/HardwareProperty.java index b5aae40959..7c5c022afd 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/HardwareProperty.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/HardwareProperty.java @@ -1,3 +1,28 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.deltacloud.domain; + /** * * Copyright (C) 2010 Cloud Conscious, LLC. @@ -17,8 +42,6 @@ * ==================================================================== */ -package org.jclouds.deltacloud.domain; - import static com.google.common.base.Preconditions.checkNotNull; /** @@ -44,7 +67,7 @@ public interface HardwareProperty { */ UNRECOGNIZED; - public static Kind fromValue(String kind) { + public static HardwareProperty.Kind fromValue(String kind) { try { return valueOf(checkNotNull(kind, "kind").toUpperCase()); } catch (IllegalArgumentException e) { @@ -57,7 +80,7 @@ public interface HardwareProperty { * * @return describes the values to chose from. */ - Kind getKind(); + HardwareProperty.Kind getKind(); /** * @@ -76,4 +99,4 @@ public interface HardwareProperty { * @return the actual value of the property. It depends on the specified unit: 1024, 2 on x86_64 */ Object getValue(); -} +} \ No newline at end of file diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Instance.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Instance.java index d89ce944f9..9363c6920e 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Instance.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Instance.java @@ -38,6 +38,83 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ public class Instance { + public static interface Authentication { + + } + + public static enum State { + /** + * initial state, before instance is created. + */ + START, + /** + * the instance is in the process of being launched + */ + PENDING, + /** + * the instance launched (although the boot process might not be completed) + */ + RUNNING, + /** + * the instance is shutting down + */ + SHUTTING_DOWN, + /** + * the instance is stopped + */ + STOPPED, + /** + * the instance is terminated + */ + FINISH, + /** + * state returned as something besides the above. + */ + UNRECOGNIZED; + + public static State fromValue(String state) { + try { + return valueOf(checkNotNull(state, "state").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public static enum Action { + + CREATE, + + RUN, + + REBOOT, + + START, + + STOP, + + DESTROY, + + UNRECOGNIZED; + + public String value() { + return name().toLowerCase(); + } + + @Override + public String toString() { + return value(); + } + + public static Action fromValue(String action) { + try { + return valueOf(checkNotNull(action, "action").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + private final URI href; private final String id; private final String ownerId; @@ -46,14 +123,16 @@ public class Instance { private final URI image; private final URI hardwareProfile; private final URI realm; - private final InstanceState state; - private final Map actions; + private final State state; + private final Map actions; + @Nullable + private final Authentication authentication; private final Set publicAddresses; private final Set privateAddresses; public Instance(URI href, String id, String ownerId, @Nullable String name, URI image, URI hardwareProfile, - URI realm, InstanceState state, Map actions, Set publicAddresses, - Set privateAddresses) { + URI realm, State state, Map actions, @Nullable Authentication authentication, + Set publicAddresses, Set privateAddresses) { this.href = checkNotNull(href, "href"); this.id = checkNotNull(id, "id"); this.ownerId = checkNotNull(ownerId, "ownerId"); @@ -63,6 +142,7 @@ public class Instance { this.realm = checkNotNull(realm, "realm"); this.state = checkNotNull(state, "state"); this.actions = ImmutableMap.copyOf(checkNotNull(actions, "actions")); + this.authentication = authentication; this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses")); this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses")); } @@ -128,7 +208,7 @@ public class Instance { * * @return indicator of the instance's current state */ - public InstanceState getState() { + public State getState() { return state; } @@ -137,10 +217,19 @@ public class Instance { * @return valid actions for the instance, along with the URL which may be used to perform the * action */ - public Map getActions() { + public Map getActions() { return actions; } + /** + * + * @return authentication of the instance or null + */ + @Nullable + public Authentication getAuthentication() { + return authentication; + } + /** * * @return publicly routable IP addresses or names for the instance @@ -161,16 +250,7 @@ public class Instance { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((actions == null) ? 0 : actions.hashCode()); - result = prime * result + ((hardwareProfile == null) ? 0 : hardwareProfile.hashCode()); result = prime * result + ((href == null) ? 0 : href.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((image == null) ? 0 : image.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode()); - result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode()); - result = prime * result + ((realm == null) ? 0 : realm.hashCode()); - result = prime * result + ((state == null) ? 0 : state.hashCode()); return result; } @@ -183,61 +263,21 @@ public class Instance { if (getClass() != obj.getClass()) return false; Instance other = (Instance) obj; - if (actions == null) { - if (other.actions != null) - return false; - } else if (!actions.equals(other.actions)) - return false; - if (hardwareProfile == null) { - if (other.hardwareProfile != null) - return false; - } else if (!hardwareProfile.equals(other.hardwareProfile)) - return false; if (href == null) { if (other.href != null) return false; } else if (!href.equals(other.href)) return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (image == null) { - if (other.image != null) - return false; - } else if (!image.equals(other.image)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (privateAddresses == null) { - if (other.privateAddresses != null) - return false; - } else if (!privateAddresses.equals(other.privateAddresses)) - return false; - if (publicAddresses == null) { - if (other.publicAddresses != null) - return false; - } else if (!publicAddresses.equals(other.publicAddresses)) - return false; - if (realm == null) { - if (other.realm != null) - return false; - } else if (!realm.equals(other.realm)) - return false; - if (state != other.state) - return false; return true; } @Override public String toString() { - return "[href=" + href + ", id=" + id + ", name=" + name + ", image=" + image + ", hardwareProfile=" - + hardwareProfile + ", realm=" + realm + ", state=" + state + ", actions=" + actions + ", publicAddresses=" - + publicAddresses + ", privateAddresses=" + privateAddresses + "]"; + return String + .format( + "[id=%s, href=%s, image=%s, name=%s, state=%s, realm=%s, ownerId=%s, hardwareProfile=%s, actions=%s, authentication=%s, privateAddresses=%s, publicAddresses=%s]", + id, href, image, name, state, realm, ownerId, hardwareProfile, actions, authentication, + privateAddresses, publicAddresses); } } diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/InstanceAction.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/InstanceAction.java deleted file mode 100644 index 44393a6d11..0000000000 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/InstanceAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * - * Indicator of the instance's current action - * - * @author Adrian Cole - * - */ -public enum InstanceAction { - - CREATE, - - REBOOT, - - START, - - STOP, - - DESTROY, - - UNRECOGNIZED; - - public String value() { - return name().toLowerCase(); - } - - @Override - public String toString() { - return value(); - } - - public static InstanceAction fromValue(String action) { - try { - return valueOf(checkNotNull(action, "action").toUpperCase()); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } -} \ No newline at end of file diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/InstanceState.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/InstanceState.java deleted file mode 100644 index 4159dfd5c4..0000000000 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/InstanceState.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * - * Indicator of the instance's current state - * - * @author Adrian Cole - * - */ -public enum InstanceState { - /** - * initial state, before instance is created. - */ - START, - /** - * the instance is in the process of being launched - */ - PENDING, - /** - * the instance launched (although the boot process might not be completed) - */ - RUNNING, - /** - * the instance is shutting down - */ - SHUTTING_DOWN, - /** - * the instance is stopped - */ - STOPPED, - /** - * the instance is terminated - */ - FINISH, - /** - * state returned as something besides the above. - */ - UNRECOGNIZED; - - public static InstanceState fromValue(String state) { - try { - return valueOf(checkNotNull(state, "state").toUpperCase()); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } -} \ No newline at end of file diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/KeyAuthentication.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/KeyAuthentication.java new file mode 100644 index 0000000000..c846d4d30c --- /dev/null +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/KeyAuthentication.java @@ -0,0 +1,79 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.Serializable; + +/** + * + * @author Adrian Cole + */ +public class KeyAuthentication implements Instance.Authentication, Serializable { + + /** The serialVersionUID */ + private static final long serialVersionUID = 7669076186483470376L; + private final String keyName; + + public KeyAuthentication(String keyName) { + this.keyName = checkNotNull(keyName, "keyName"); + } + + public String getKeyName() { + return keyName; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((keyName == null) ? 0 : keyName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + KeyAuthentication other = (KeyAuthentication) obj; + if (keyName == null) { + if (other.keyName != null) + return false; + } else if (!keyName.equals(other.keyName)) + return false; + return true; + } + + @Override + public String toString() { + return String.format("[keyName=%s]", keyName); + } + +} \ No newline at end of file diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/PasswordAuthentication.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/PasswordAuthentication.java new file mode 100644 index 0000000000..4a19c5fb89 --- /dev/null +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/PasswordAuthentication.java @@ -0,0 +1,81 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.Serializable; + +import org.jclouds.domain.Credentials; + +/** + * + * @author Adrian Cole + */ +public class PasswordAuthentication implements Instance.Authentication, Serializable { + + /** The serialVersionUID */ + private static final long serialVersionUID = 7669076186483470376L; + private final Credentials login; + + public PasswordAuthentication(Credentials login) { + this.login = checkNotNull(login, "login"); + } + + public Credentials getLoginCredentials() { + return login; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((login == null) ? 0 : login.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PasswordAuthentication other = (PasswordAuthentication) obj; + if (login == null) { + if (other.login != null) + return false; + } else if (!login.equals(other.login)) + return false; + return true; + } + + @Override + public String toString() { + return String.format("[login=%s]", login); + } + +} \ No newline at end of file diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Realm.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Realm.java index 288ea9422c..7f71acab13 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Realm.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Realm.java @@ -36,14 +36,39 @@ import javax.annotation.Nullable; * @author Adrian Cole */ public class Realm { + public enum State { + + /** + * the realm is available + */ + AVAILABLE, + + /** + * the realm is unavailable + */ + UNAVAILABLE, + + /** + * state returned as something besides the above. + */ + UNRECOGNIZED; + + public static State fromValue(String state) { + try { + return valueOf(checkNotNull(state, "state")); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } private final URI href; private final String id; @Nullable private final String limit; private final String name; - private final RealmState state; + private final State state; - public Realm(URI href, String id, String name, @Nullable String limit, RealmState state) { + public Realm(URI href, String id, String name, @Nullable String limit, State state) { this.href = checkNotNull(href, "href"); this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name"); @@ -90,7 +115,7 @@ public class Realm { * * @return indicator of the realm's current state */ - public RealmState getState() { + public State getState() { return state; } diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/RealmState.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/RealmState.java deleted file mode 100644 index a8fc7331be..0000000000 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/RealmState.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * - * Indicator of the realm's current state - * - * @author Adrian Cole - * - */ -public enum RealmState { - - /** - * the realm is available - */ - AVAILABLE, - - /** - * the realm is unavailable - */ - UNAVAILABLE, - - /** - * state returned as something besides the above. - */ - UNRECOGNIZED; - - public static RealmState fromValue(String state) { - try { - return valueOf(checkNotNull(state, "state")); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } -} \ No newline at end of file diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Transition.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Transition.java index c9e01453bf..f16b6b5371 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Transition.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Transition.java @@ -24,5 +24,5 @@ package org.jclouds.deltacloud.domain; * @author Adrian Cole */ public interface Transition { - InstanceState getTo(); + Instance.State getTo(); } \ No newline at end of file diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/TransitionAutomatically.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/TransitionAutomatically.java index 544238c3a5..eaf3aec17a 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/TransitionAutomatically.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/TransitionAutomatically.java @@ -26,13 +26,13 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Adrian Cole */ public class TransitionAutomatically implements Transition { - private final InstanceState to; + private final Instance.State to; - public TransitionAutomatically(InstanceState to) { + public TransitionAutomatically(Instance.State to) { this.to = checkNotNull(to, "to"); } - public InstanceState getTo() { + public Instance.State getTo() { return to; } diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/TransitionOnAction.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/TransitionOnAction.java index d933f9ffcd..42b230961e 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/TransitionOnAction.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/domain/TransitionOnAction.java @@ -26,19 +26,19 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Adrian Cole */ public class TransitionOnAction implements Transition { - private final InstanceAction action; - private final InstanceState to; + private final Instance.Action action; + private final Instance.State to; - public TransitionOnAction(InstanceAction action, InstanceState to) { + public TransitionOnAction(Instance.Action action, Instance.State to) { this.to = checkNotNull(to, "to"); this.action = checkNotNull(action, "action"); } - public InstanceState getTo() { + public Instance.State getTo() { return to; } - public InstanceAction getAction() { + public Instance.Action getAction() { return action; } diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/HardwarePropertyHandler.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/HardwarePropertyHandler.java index bbfbf9ec38..98d9195e64 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/HardwarePropertyHandler.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/HardwarePropertyHandler.java @@ -30,8 +30,8 @@ import org.jclouds.deltacloud.domain.EnumHardwareProperty; import org.jclouds.deltacloud.domain.FixedHardwareProperty; import org.jclouds.deltacloud.domain.HardwareParameter; import org.jclouds.deltacloud.domain.HardwareProperty; -import org.jclouds.deltacloud.domain.HardwareProperty.Kind; import org.jclouds.deltacloud.domain.RangeHardwareProperty; +import org.jclouds.deltacloud.domain.HardwareProperty.Kind; import org.jclouds.http.functions.ParseSax; import org.jclouds.util.SaxUtils; import org.xml.sax.Attributes; diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/InstanceHandler.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/InstanceHandler.java index 632ea2d235..6c9e21686c 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/InstanceHandler.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/InstanceHandler.java @@ -19,6 +19,8 @@ package org.jclouds.deltacloud.xml; +import static org.jclouds.util.SaxUtils.currentOrNull; + import java.net.URI; import java.util.Map; import java.util.Set; @@ -26,8 +28,10 @@ import java.util.Set; import javax.annotation.Resource; import org.jclouds.deltacloud.domain.Instance; -import org.jclouds.deltacloud.domain.InstanceAction; -import org.jclouds.deltacloud.domain.InstanceState; +import org.jclouds.deltacloud.domain.KeyAuthentication; +import org.jclouds.deltacloud.domain.PasswordAuthentication; +import org.jclouds.deltacloud.domain.Instance.Authentication; +import org.jclouds.domain.Credentials; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.logging.Logger; @@ -54,8 +58,8 @@ public class InstanceHandler extends ParseSax.HandlerWithResult { private URI image; private URI hardwareProfile; private URI realm; - private InstanceState state; - private Map actions = Maps.newLinkedHashMap(); + private Instance.State state; + private Map actions = Maps.newLinkedHashMap(); private Set publicAddresses = Sets.newLinkedHashSet(); private Set privateAddresses = Sets.newLinkedHashSet(); @@ -64,6 +68,10 @@ public class InstanceHandler extends ParseSax.HandlerWithResult { private Instance instance; + private Credentials.Builder credentialsBuilder = new Credentials.Builder(); + private String keyName; + private Authentication authentication; + public Instance getResult() { return instance; } @@ -83,10 +91,10 @@ public class InstanceHandler extends ParseSax.HandlerWithResult { this.id = attributes.get("id"); } else if (qName.equals("link")) { try { - InstanceAction action = InstanceAction.fromValue(attributes.get("rel")); - if (action != InstanceAction.UNRECOGNIZED) { + Instance.Action action = Instance.Action.fromValue(attributes.get("rel")); + if (action != Instance.Action.UNRECOGNIZED) { HttpRequest request = new HttpRequest(attributes.get("method").toUpperCase(), URI.create(attributes - .get("href"))); + .get("href"))); actions.put(action, request); } } catch (RuntimeException e) { @@ -112,19 +120,35 @@ public class InstanceHandler extends ParseSax.HandlerWithResult { inPrivateAddresses = false; } if (qName.equalsIgnoreCase("owner_id")) { - this.ownerId = currentText.toString().trim(); + this.ownerId = currentOrNull(currentText); } else if (qName.equalsIgnoreCase("name")) { - this.name = currentText.toString().trim(); + this.name = currentOrNull(currentText); + } else if (qName.equalsIgnoreCase("keyname")) { + this.keyName = currentOrNull(currentText); + } else if (qName.equalsIgnoreCase("username")) { + this.credentialsBuilder.identity(currentOrNull(currentText)); + } else if (qName.equalsIgnoreCase("password")) { + this.credentialsBuilder.credential(currentOrNull(currentText)); + } else if (qName.equalsIgnoreCase("authentication")) { + if (keyName != null) { + this.authentication = new KeyAuthentication(keyName); + } else { + Credentials creds = credentialsBuilder.build(); + if (creds.identity != null) + this.authentication = new PasswordAuthentication(creds); + } + this.keyName = null; + this.credentialsBuilder = new Credentials.Builder(); } else if (qName.equalsIgnoreCase("state")) { - this.state = InstanceState.fromValue(currentText.toString().trim()); + this.state = Instance.State.fromValue(currentOrNull(currentText)); } else if (qName.equalsIgnoreCase("address")) { if (inPublicAddresses) - this.publicAddresses.add(currentText.toString().trim()); + this.publicAddresses.add(currentOrNull(currentText)); else if (inPrivateAddresses) - this.privateAddresses.add(currentText.toString().trim()); + this.privateAddresses.add(currentOrNull(currentText)); } else if (qName.equalsIgnoreCase("instance")) { this.instance = new Instance(href, id, ownerId, name, image, hardwareProfile, realm, state, actions, - publicAddresses, privateAddresses); + authentication, publicAddresses, privateAddresses); this.href = null; this.id = null; this.ownerId = null; @@ -133,6 +157,7 @@ public class InstanceHandler extends ParseSax.HandlerWithResult { this.hardwareProfile = null; this.realm = null; this.state = null; + this.authentication = null; this.actions = Maps.newLinkedHashMap(); this.publicAddresses = Sets.newLinkedHashSet(); this.privateAddresses = Sets.newLinkedHashSet(); diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/InstanceStatesHandler.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/InstanceStatesHandler.java index 8575fa29cd..cc49c1fea1 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/InstanceStatesHandler.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/xml/InstanceStatesHandler.java @@ -23,11 +23,11 @@ import java.util.Map; import javax.annotation.Resource; -import org.jclouds.deltacloud.domain.InstanceAction; -import org.jclouds.deltacloud.domain.InstanceState; import org.jclouds.deltacloud.domain.Transition; import org.jclouds.deltacloud.domain.TransitionAutomatically; import org.jclouds.deltacloud.domain.TransitionOnAction; +import org.jclouds.deltacloud.domain.Instance.Action; +import org.jclouds.deltacloud.domain.Instance.State; import org.jclouds.http.functions.ParseSax; import org.jclouds.logging.Logger; import org.jclouds.util.SaxUtils; @@ -40,15 +40,15 @@ import com.google.common.collect.Multimap; /** * @author Adrian Cole */ -public class InstanceStatesHandler extends ParseSax.HandlerWithResult> { +public class InstanceStatesHandler extends ParseSax.HandlerWithResult> { @Resource protected Logger logger = Logger.NULL; - private Multimap states = LinkedHashMultimap.create(); - private InstanceState state; + private Multimap states = LinkedHashMultimap.create(); + private State state; - public Multimap getResult() { + public Multimap getResult() { return states; } @@ -66,16 +66,16 @@ public class InstanceStatesHandler extends ParseSax.HandlerWithResult { private String id; private String name; private String limit; - private RealmState state; + private State state; private Realm realm; @@ -65,7 +65,7 @@ public class RealmHandler extends ParseSax.HandlerWithResult { } else if (qName.equalsIgnoreCase("name")) { this.name = currentText.toString().trim(); } else if (qName.equalsIgnoreCase("state")) { - this.state = RealmState.fromValue(currentText.toString().trim()); + this.state = State.fromValue(currentText.toString().trim()); } else if (qName.equalsIgnoreCase("realm")) { this.realm = new Realm(href, id, name, limit, state); this.href = null; diff --git a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java index 2d0a4fbd9e..18d5516651 100644 --- a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java +++ b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java @@ -234,7 +234,7 @@ public class DeltacloudAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "imageId-1"); assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api/instances HTTP/1.1"); @@ -251,9 +251,9 @@ public class DeltacloudAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "imageId-1", - CreateInstanceOptions.Builder.named("foo")); + CreateInstanceOptions.Builder.named("foo")); assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api/instances HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n"); @@ -269,8 +269,8 @@ public class DeltacloudAsyncClientTest extends RestClientTest() { + + @Override + public boolean apply(Image input) { + return input.getDescription().toLowerCase().indexOf("fedora") != -1; + } + + }).getId(), CreateInstanceOptions.Builder.named(prefix)); instance = client.getInstance(instance.getHref()); checkStartedInstance(); @@ -71,7 +77,7 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest { protected void checkStartedInstance() { System.out.println(new Gson().toJson(instance)); assertEquals(instance.getName(), prefix); - assertEquals(instance.getState(), InstanceState.RUNNING); + assertEquals(instance.getState(), Instance.State.RUNNING); } @Test(dependsOnMethods = "testCreateInstance") @@ -88,37 +94,37 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest { return null; } - public HttpRequest refreshInstanceAndGetAction(InstanceAction action) { + public HttpRequest refreshInstanceAndGetAction(Instance.Action action) { return client.getInstance(instance.getHref()).getActions().get(action); } @Test(dependsOnMethods = "testConnectivity") - public void testLifeCycle() throws Exception { - client.performAction(refreshInstanceAndGetAction(InstanceAction.STOP)); - assertEquals(client.getInstance(instance.getHref()).getState(), InstanceState.STOPPED); + public void testLifeCycle() { + client.performAction(refreshInstanceAndGetAction(Instance.Action.STOP)); + assertEquals(client.getInstance(instance.getHref()).getState(), Instance.State.STOPPED); - client.performAction(refreshInstanceAndGetAction(InstanceAction.START)); - assertEquals(client.getInstance(instance.getHref()).getState(), InstanceState.RUNNING); + client.performAction(refreshInstanceAndGetAction(Instance.Action.START)); + assertEquals(client.getInstance(instance.getHref()).getState(), Instance.State.RUNNING); - client.performAction(refreshInstanceAndGetAction(InstanceAction.REBOOT)); - assertEquals(client.getInstance(instance.getHref()).getState(), InstanceState.RUNNING); + client.performAction(refreshInstanceAndGetAction(Instance.Action.REBOOT)); + assertEquals(client.getInstance(instance.getHref()).getState(), Instance.State.RUNNING); } @Test(dependsOnMethods = "testLifeCycle") - public void testDestroyInstance() throws Exception { + public void testDestroyInstance() { try { - client.performAction(refreshInstanceAndGetAction(InstanceAction.STOP)); - assertEquals(client.getInstance(instance.getHref()).getState(), InstanceState.STOPPED); + client.performAction(refreshInstanceAndGetAction(Instance.Action.STOP)); + assertEquals(client.getInstance(instance.getHref()).getState(), Instance.State.STOPPED); } catch (IllegalArgumentException e) { } - client.performAction(refreshInstanceAndGetAction(InstanceAction.DESTROY)); + client.performAction(refreshInstanceAndGetAction(Instance.Action.DESTROY)); assertEquals(client.getInstance(instance.getHref()), null); } protected void doConnectViaSsh(Instance instance, Credentials creds) throws IOException { - SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class) - .create(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), 22), creds); + SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class).create( + new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); @@ -137,7 +143,7 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest { protected void tearDown() { try { testDestroyInstance(); - } catch (Exception e) { + } catch (NullPointerException e) { // no need to check null or anything as we swallow all } super.tearDown(); diff --git a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java index 928653a99d..5e5bb16a66 100644 --- a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java +++ b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java @@ -32,7 +32,6 @@ import org.jclouds.deltacloud.domain.DeltacloudCollection; import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.domain.Instance; -import org.jclouds.deltacloud.domain.InstanceState; import org.jclouds.deltacloud.domain.Realm; import org.jclouds.deltacloud.domain.Transition; import org.jclouds.logging.log4j.config.Log4JLoggingModule; @@ -57,7 +56,7 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@Test(groups = "live", sequential = true, testName ="ReadOnlyDeltacloudClientLiveTest") +@Test(groups = "live", sequential = true, testName = "ReadOnlyDeltacloudClientLiveTest") public class ReadOnlyDeltacloudClientLiveTest { protected DeltacloudClient client; @@ -96,7 +95,7 @@ public class ReadOnlyDeltacloudClientLiveTest { setupCredentials(); Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides); + overrides); client = context.getApi(); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS); @@ -110,20 +109,20 @@ public class ReadOnlyDeltacloudClientLiveTest { @Test public void testGetInstanceStatesCanGoFromStartToFinish() throws Exception { - Multimap states = client.getInstanceStates(); + Multimap states = client.getInstanceStates(); assertNotNull(states); - Iterable toFinishFromStart = findChainTo(InstanceState.FINISH, InstanceState.START, states); + Iterable toFinishFromStart = findChainTo(Instance.State.FINISH, Instance.State.START, states); assert Iterables.size(toFinishFromStart) > 0 : toFinishFromStart; - Iterable toRunningFromStart = findChainTo(InstanceState.RUNNING, InstanceState.START, states); + Iterable toRunningFromStart = findChainTo(Instance.State.RUNNING, Instance.State.START, states); assert Iterables.size(toRunningFromStart) > 0 : toRunningFromStart; - Iterable toFinishFromRunning = findChainTo(InstanceState.FINISH, InstanceState.RUNNING, states); + Iterable toFinishFromRunning = findChainTo(Instance.State.FINISH, Instance.State.RUNNING, states); assert Iterables.size(toFinishFromRunning) > 0 : toFinishFromRunning; - assertEquals(ImmutableList.copyOf(Iterables.concat(toRunningFromStart, toFinishFromRunning)), - ImmutableList.copyOf(toFinishFromStart)); + assertEquals(ImmutableList.copyOf(Iterables.concat(toRunningFromStart, toFinishFromRunning)), ImmutableList + .copyOf(toFinishFromStart)); } - Iterable findChainTo(InstanceState desired, InstanceState currentState, - Multimap states) { + Iterable findChainTo(Instance.State desired, Instance.State currentState, + Multimap states) { for (Transition transition : states.get(currentState)) { if (currentState.ordinal() >= transition.getTo().ordinal()) continue; diff --git a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstanceHandlerTest.java b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstanceHandlerTest.java index e5976489b7..806d9c82cb 100644 --- a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstanceHandlerTest.java +++ b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstanceHandlerTest.java @@ -25,8 +25,10 @@ import java.io.InputStream; import java.net.URI; import org.jclouds.deltacloud.domain.Instance; -import org.jclouds.deltacloud.domain.InstanceAction; -import org.jclouds.deltacloud.domain.InstanceState; +import org.jclouds.deltacloud.domain.KeyAuthentication; +import org.jclouds.deltacloud.domain.PasswordAuthentication; +import org.jclouds.deltacloud.domain.Instance.Authentication; +import org.jclouds.domain.Credentials; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.config.SaxParserModule; @@ -48,7 +50,7 @@ public class InstanceHandlerTest { static ParseSax createParser() { Injector injector = Guice.createInjector(new SaxParserModule()); ParseSax parser = injector.getInstance(ParseSax.Factory.class).create( - injector.getInstance(InstanceHandler.class)); + injector.getInstance(InstanceHandler.class)); return parser; } @@ -61,17 +63,37 @@ public class InstanceHandlerTest { return createParser().parse(is); } - public void test() { - Instance expects = new Instance(URI.create("http://fancycloudprovider.com/api/instances/inst1"), "inst1", - "larry", "Production JBoss Instance", URI.create("http://fancycloudprovider.com/api/images/img3"), - URI.create("http://fancycloudprovider.com/api/hardware_profiles/m1-small"), - URI.create("http://fancycloudprovider.com/api/realms/us"), InstanceState.RUNNING, ImmutableMap.of( - InstanceAction.REBOOT, - new HttpRequest("POST", URI.create("http://fancycloudprovider.com/api/instances/inst1/reboot")), - InstanceAction.STOP, - new HttpRequest("POST", URI.create("http://fancycloudprovider.com/api/instances/inst1/stop"))), - ImmutableSet.of("inst1.larry.fancycloudprovider.com"), ImmutableSet.of("inst1.larry.internal")); - assertEquals(parseInstance(), expects); + public void testWithNoAuthentication() { + Instance expects = instanceWithAuthentication(null); + assertEquals(parseInstance("/test_get_instance.xml").toString(), expects.toString()); + } + + public void testWithPasswordAuthentication() { + Instance expects = instanceWithAuthentication(new PasswordAuthentication(new Credentials("root", "FOO"))); + assertEquals(parseInstance("/test_get_instance_pw.xml").toString(), expects.toString()); + } + + public void testWithKeyAuthentication() { + Instance expects = instanceWithAuthentication(new KeyAuthentication("keyname")); + assertEquals(parseInstance("/test_get_instance_key.xml").toString(), expects.toString()); + } + + public void testWithKeyAuthenticationBlank() { + Instance expects = instanceWithAuthentication(null); + assertEquals(parseInstance("/test_get_instance_nokey.xml").toString(), expects.toString()); + } + + private Instance instanceWithAuthentication(Authentication authentication) { + return new Instance(URI.create("http://fancycloudprovider.com/api/instances/inst1"), "inst1", "larry", + "Production JBoss Instance", URI.create("http://fancycloudprovider.com/api/images/img3"), URI + .create("http://fancycloudprovider.com/api/hardware_profiles/m1-small"), URI + .create("http://fancycloudprovider.com/api/realms/us"), Instance.State.RUNNING, ImmutableMap + .of(Instance.Action.REBOOT, new HttpRequest("POST", URI + .create("http://fancycloudprovider.com/api/instances/inst1/reboot")), + Instance.Action.STOP, new HttpRequest("POST", URI + .create("http://fancycloudprovider.com/api/instances/inst1/stop"))), + authentication, ImmutableSet.of("inst1.larry.fancycloudprovider.com"), ImmutableSet + .of("inst1.larry.internal")); } } diff --git a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstanceStatesHandlerTest.java b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstanceStatesHandlerTest.java index 680fab6e13..7e54cad0e4 100644 --- a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstanceStatesHandlerTest.java +++ b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstanceStatesHandlerTest.java @@ -23,11 +23,11 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; -import org.jclouds.deltacloud.domain.InstanceAction; -import org.jclouds.deltacloud.domain.InstanceState; import org.jclouds.deltacloud.domain.Transition; import org.jclouds.deltacloud.domain.TransitionAutomatically; import org.jclouds.deltacloud.domain.TransitionOnAction; +import org.jclouds.deltacloud.domain.Instance.Action; +import org.jclouds.deltacloud.domain.Instance.State; import org.jclouds.http.functions.BaseHandlerTest; import org.testng.annotations.Test; @@ -35,26 +35,25 @@ import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; /** - * Tests behavior of {@code InstanceStatesHandler} + * Tests behavior of {@code StatesHandler} * * @author Adrian Cole */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", testName = "InstanceStatesHandlerTest") +@Test(groups = "unit", testName = "StatesHandlerTest") public class InstanceStatesHandlerTest extends BaseHandlerTest { public void test() { InputStream is = getClass().getResourceAsStream("/test_get_states.xml"); - Multimap expects = ImmutableMultimap - . builder() - .put(InstanceState.START, new TransitionOnAction(InstanceAction.CREATE, InstanceState.PENDING)) - .put(InstanceState.PENDING, new TransitionAutomatically(InstanceState.RUNNING)) - .putAll(InstanceState.RUNNING, new TransitionOnAction(InstanceAction.REBOOT, InstanceState.RUNNING), - new TransitionOnAction(InstanceAction.STOP, InstanceState.STOPPED)) - .putAll(InstanceState.STOPPED, new TransitionOnAction(InstanceAction.START, InstanceState.RUNNING), - new TransitionOnAction(InstanceAction.DESTROY, InstanceState.FINISH)).build(); - assertEquals(factory.create(injector.getInstance(InstanceStatesHandler.class)).parse(is).entries(), - expects.entries()); + Multimap expects = ImmutableMultimap. builder().put(State.START, + new TransitionOnAction(Action.CREATE, State.PENDING)).put(State.PENDING, + new TransitionAutomatically(State.RUNNING)) + .putAll(State.RUNNING, new TransitionOnAction(Action.REBOOT, State.RUNNING), + new TransitionOnAction(Action.STOP, State.STOPPED)).putAll(State.STOPPED, + new TransitionOnAction(Action.START, State.RUNNING), + new TransitionOnAction(Action.DESTROY, State.FINISH)).build(); + assertEquals(factory.create(injector.getInstance(InstanceStatesHandler.class)).parse(is).entries(), expects + .entries()); } } diff --git a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstancesHandlerTest.java b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstancesHandlerTest.java index f52a0e363b..5525f09256 100644 --- a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstancesHandlerTest.java +++ b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/InstancesHandlerTest.java @@ -26,8 +26,6 @@ import java.net.URI; import java.util.Set; import org.jclouds.deltacloud.domain.Instance; -import org.jclouds.deltacloud.domain.InstanceAction; -import org.jclouds.deltacloud.domain.InstanceState; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.BaseHandlerTest; import org.testng.annotations.Test; @@ -48,15 +46,15 @@ public class InstancesHandlerTest extends BaseHandlerTest { public void test() { InputStream is = getClass().getResourceAsStream("/test_list_instances.xml"); Set expects = ImmutableSet.of(new Instance(URI - .create("http://fancycloudprovider.com/api/instances/inst1"), "inst1", "larry", - "Production JBoss Instance", URI.create("http://fancycloudprovider.com/api/images/img3"), URI - .create("http://fancycloudprovider.com/api/hardware_profiles/m1-small"), URI - .create("http://fancycloudprovider.com/api/realms/us"), InstanceState.RUNNING, ImmutableMap.of( - InstanceAction.REBOOT, - new HttpRequest("POST", URI.create("http://fancycloudprovider.com/api/instances/inst1/reboot")), - InstanceAction.STOP, - new HttpRequest("POST", URI.create("http://fancycloudprovider.com/api/instances/inst1/stop"))), - ImmutableSet.of("inst1.larry.fancycloudprovider.com"), ImmutableSet.of("inst1.larry.internal"))); - assertEquals(factory.create(injector.getInstance(InstancesHandler.class)).parse(is), expects); + .create("http://fancycloudprovider.com/api/instances/inst1"), "inst1", "larry", + "Production JBoss Instance", URI.create("http://fancycloudprovider.com/api/images/img3"), URI + .create("http://fancycloudprovider.com/api/hardware_profiles/m1-small"), URI + .create("http://fancycloudprovider.com/api/realms/us"), Instance.State.RUNNING, ImmutableMap + .of(Instance.Action.REBOOT, new HttpRequest("POST", URI + .create("http://fancycloudprovider.com/api/instances/inst1/reboot")), + Instance.Action.STOP, new HttpRequest("POST", URI + .create("http://fancycloudprovider.com/api/instances/inst1/stop"))), null, + ImmutableSet.of("inst1.larry.fancycloudprovider.com"), ImmutableSet.of("inst1.larry.internal"))); + assertEquals(factory.create(injector.getInstance(InstancesHandler.class)).parse(is).toString(), expects.toString()); } } diff --git a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/RealmHandlerTest.java b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/RealmHandlerTest.java index d6b9d52190..3d47579340 100644 --- a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/RealmHandlerTest.java +++ b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/RealmHandlerTest.java @@ -25,7 +25,6 @@ import java.io.InputStream; import java.net.URI; import org.jclouds.deltacloud.domain.Realm; -import org.jclouds.deltacloud.domain.RealmState; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.config.SaxParserModule; import org.testng.annotations.Test; @@ -44,7 +43,7 @@ public class RealmHandlerTest { static ParseSax createParser() { Injector injector = Guice.createInjector(new SaxParserModule()); ParseSax parser = injector.getInstance(ParseSax.Factory.class).create( - injector.getInstance(RealmHandler.class)); + injector.getInstance(RealmHandler.class)); return parser; } @@ -59,7 +58,7 @@ public class RealmHandlerTest { public void test() { Realm expects = new Realm(URI.create("http://fancycloudprovider.com/api/realms/us"), "us", "United States", null, - RealmState.AVAILABLE); + Realm.State.AVAILABLE); assertEquals(parseRealm(), expects); } diff --git a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/RealmsHandlerTest.java b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/RealmsHandlerTest.java index b603712118..52a5af8caf 100644 --- a/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/RealmsHandlerTest.java +++ b/sandbox-apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/RealmsHandlerTest.java @@ -26,7 +26,6 @@ import java.net.URI; import java.util.Set; import org.jclouds.deltacloud.domain.Realm; -import org.jclouds.deltacloud.domain.RealmState; import org.jclouds.http.functions.BaseHandlerTest; import org.testng.annotations.Test; @@ -44,10 +43,10 @@ public class RealmsHandlerTest extends BaseHandlerTest { @Test public void test() { InputStream is = getClass().getResourceAsStream("/test_list_realms.xml"); - Set expects = ImmutableSet.of( - new Realm(URI.create("http://fancycloudprovider.com/api/realms/us"), "us", "United States", null, - RealmState.AVAILABLE), new Realm(URI.create("http://fancycloudprovider.com/api/realms/eu"), "eu", - "Europe", null, RealmState.AVAILABLE)); + Set expects = ImmutableSet.of(new Realm(URI + .create("http://fancycloudprovider.com/api/realms/us"), "us", "United States", null, + Realm.State.AVAILABLE), new Realm(URI.create("http://fancycloudprovider.com/api/realms/eu"), "eu", + "Europe", null, Realm.State.AVAILABLE)); assertEquals(factory.create(injector.getInstance(RealmsHandler.class)).parse(is), expects); } } diff --git a/sandbox-apis/deltacloud/src/test/resources/test_get_instance_key.xml b/sandbox-apis/deltacloud/src/test/resources/test_get_instance_key.xml new file mode 100644 index 0000000000..6a20a01e9e --- /dev/null +++ b/sandbox-apis/deltacloud/src/test/resources/test_get_instance_key.xml @@ -0,0 +1,24 @@ + + + larry + Production JBoss Instance + + + + + RUNNING + + + + + +
inst1.larry.fancycloudprovider.com
+
+ + +
inst1.larry.internal
+
+ + keyname + +
diff --git a/sandbox-apis/deltacloud/src/test/resources/test_get_instance_nokey.xml b/sandbox-apis/deltacloud/src/test/resources/test_get_instance_nokey.xml new file mode 100644 index 0000000000..b74de30913 --- /dev/null +++ b/sandbox-apis/deltacloud/src/test/resources/test_get_instance_nokey.xml @@ -0,0 +1,24 @@ + + + larry + Production JBoss Instance + + + + + RUNNING + + + + + +
inst1.larry.fancycloudprovider.com
+
+ + +
inst1.larry.internal
+
+ + + +
diff --git a/sandbox-apis/deltacloud/src/test/resources/test_get_instance_pw.xml b/sandbox-apis/deltacloud/src/test/resources/test_get_instance_pw.xml new file mode 100644 index 0000000000..f557f080a9 --- /dev/null +++ b/sandbox-apis/deltacloud/src/test/resources/test_get_instance_pw.xml @@ -0,0 +1,27 @@ + + + larry + Production JBoss Instance + + + + + RUNNING + + + + + +
inst1.larry.fancycloudprovider.com
+
+ + +
inst1.larry.internal
+
+ + + root + FOO + + +
\ No newline at end of file