From 7a7ab9ecf269ebb49afe2a0db46b001e4e1a46fa Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 29 Mar 2011 16:59:04 -0700 Subject: [PATCH] progress on deltacloud --- sandbox-apis/deltacloud/README.txt | 1 + sandbox-apis/deltacloud/pom.xml | 2 +- .../DeltacloudPropertiesBuilder.java | 2 +- .../config/DeltacloudRestClientModule.java | 4 +-- .../deltacloud/domain/InstanceState.java | 6 +++- .../deltacloud/xml/InstanceStatesHandler.java | 31 ++++++++++++++----- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/sandbox-apis/deltacloud/README.txt b/sandbox-apis/deltacloud/README.txt index 73c9795028..6d968a0e08 100644 --- a/sandbox-apis/deltacloud/README.txt +++ b/sandbox-apis/deltacloud/README.txt @@ -33,6 +33,7 @@ To run a local deltacloud server, do the following: # export SSL_CERT_DIR=$HOME/certs # export SSL_CERT_FILE=$HOME/certs/cacert.pem # jruby -S deltacloudd -i mock + * or if you are running from a src tree: jruby -S ./server/bin/deltacloudd -i Here are some notes about specific cloud providers * terremark diff --git a/sandbox-apis/deltacloud/pom.xml b/sandbox-apis/deltacloud/pom.xml index 3cd3076eb0..e84ceefffb 100644 --- a/sandbox-apis/deltacloud/pom.xml +++ b/sandbox-apis/deltacloud/pom.xml @@ -53,7 +53,7 @@ trmkrun-ccc,test.trmk-924 http://localhost:3001/api - 0.1.0 + 0.1.2 mockuser mockpassword diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java index ab23178211..3a9fc0af22 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java @@ -34,7 +34,7 @@ public class DeltacloudPropertiesBuilder extends PropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "0.1.0"); + properties.setProperty(PROPERTY_API_VERSION, "0.1.2"); return properties; } diff --git a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java index 0258b57f30..33bef56bd4 100644 --- a/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java +++ b/sandbox-apis/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java @@ -48,7 +48,7 @@ import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; -import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; +import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import com.google.common.base.Predicate; import com.google.common.base.Supplier; @@ -86,7 +86,7 @@ public class DeltacloudRestClientModule extends RestClientModule> provideCollections( @Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( authException, seconds, new Supplier>() { @Override public Set get() { 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 index 2609b9f582..2deee73ecc 100644 --- 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 @@ -45,6 +45,10 @@ public enum InstanceState { * the instance is stopped */ STOPPED, + /** + * the instance is shutting down + */ + SHUTTING_DOWN, /** * the instance is terminated */ @@ -56,7 +60,7 @@ public enum InstanceState { public static InstanceState fromValue(String state) { try { - return valueOf(checkNotNull(state, "state")); + return valueOf(checkNotNull(state, "state").toUpperCase()); } catch (IllegalArgumentException e) { return UNRECOGNIZED; } 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 5d7219e561..8575fa29cd 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 @@ -21,12 +21,15 @@ package org.jclouds.deltacloud.xml; 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.http.functions.ParseSax; +import org.jclouds.logging.Logger; import org.jclouds.util.SaxUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -39,6 +42,9 @@ import com.google.common.collect.Multimap; */ public class InstanceStatesHandler extends ParseSax.HandlerWithResult> { + @Resource + protected Logger logger = Logger.NULL; + private Multimap states = LinkedHashMultimap.create(); private InstanceState state; @@ -50,17 +56,28 @@ public class InstanceStatesHandler extends ParseSax.HandlerWithResult attributes = SaxUtils.cleanseAttributes(attrs); if (qName.equals("state")) { - state = InstanceState.valueOf(attributes.get("name").toUpperCase()); + state = instanceStateWarningOnUnrecognized(attributes.get("name")); } else if (qName.equals("transition")) { if (attributes.containsKey("auto")) - states.put(state, new TransitionAutomatically(InstanceState.valueOf(attributes.get("to").toUpperCase()))); + states.put(state, new TransitionAutomatically(instanceStateWarningOnUnrecognized(attributes.get("to")))); else - states.put( - state, - new TransitionOnAction(InstanceAction.fromValue(attributes.get("action")), InstanceState - .valueOf(attributes.get("to").toUpperCase()))); - + states.put(state, new TransitionOnAction(instanceActionWarningOnUnrecognized(attributes.get("action")), + instanceStateWarningOnUnrecognized(attributes.get("to")))); } } + InstanceState instanceStateWarningOnUnrecognized(String input) { + InstanceState state = InstanceState.fromValue(input); + if (state == InstanceState.UNRECOGNIZED) + logger.warn("unrecognized state: %s", input); + return state; + } + + InstanceAction instanceActionWarningOnUnrecognized(String input) { + InstanceAction action = InstanceAction.fromValue(input); + if (action == InstanceAction.UNRECOGNIZED) + logger.warn("unrecognized action: %s", input); + return action; + } + }