[jbosstools-commits] JBoss Tools SVN: r24047 - in trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core: src/org/jboss/tools/deltacloud/core and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Aug 11 10:39:58 EDT 2010


Author: jjohnstn
Date: 2010-08-11 10:39:58 -0400 (Wed, 11 Aug 2010)
New Revision: 24047

Modified:
   trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
   trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
   trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java
Log:
2010-08-11  Jeff Johnston  <jjohnstn at redhat.com>

	* src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getInstances): Make
	instances a private field instead of local to the method. 
	(refreshInstance): New method.
	(createInstance): Add notification to IInstanceListListeners.
	* src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java: Add static
	strings for the various states.



Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog	2010-08-11 14:36:49 UTC (rev 24046)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog	2010-08-11 14:39:58 UTC (rev 24047)
@@ -1,3 +1,12 @@
+2010-08-11  Jeff Johnston  <jjohnstn at redhat.com>
+
+	* src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getInstances): Make
+	instances a private field instead of local to the method. 
+	(refreshInstance): New method.
+	(createInstance): Add notification to IInstanceListListeners.
+	* src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java: Add static
+	strings for the various states.
+
 2010-08-09  Jeff Johnston  <jjohnstn at redhat.com>
 
 	* src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java (getHostName): New method. 

Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java	2010-08-11 14:36:49 UTC (rev 24046)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java	2010-08-11 14:39:58 UTC (rev 24047)
@@ -21,8 +21,8 @@
 	private String username;
 	private URL url;
 	private DeltaCloudClient client;
+	private ArrayList<DeltaCloudInstance> instances;
 	
-	
 	ListenerList instanceListeners = new ListenerList();
 	ListenerList imageListeners = new ListenerList();
 	
@@ -74,7 +74,7 @@
 	}
 
 	public DeltaCloudInstance[] getInstances() {
-		ArrayList<DeltaCloudInstance> instances = new ArrayList<DeltaCloudInstance>();
+		instances = new ArrayList<DeltaCloudInstance>();
 		try {
 			List<Instance> list = client.listInstances();
 			for (Iterator<Instance> i = list.iterator(); i.hasNext();) {
@@ -89,6 +89,18 @@
 		notifyInstanceListListeners(instanceArray);
 		return instanceArray;
 	}
+	
+	public DeltaCloudInstance refreshInstance(String instanceId) {
+		DeltaCloudInstance retVal = null;
+		try {
+			Instance instance = client.listInstances(instanceId);
+			retVal = new DeltaCloudInstance(instance);
+		} catch (DeltaCloudClientException e) {
+			// do nothing and return null
+		}
+		return retVal;
+	}
+	
 
 	public DeltaCloudHardwareProfile[] getProfiles() {
 		ArrayList<DeltaCloudHardwareProfile> profiles = new ArrayList<DeltaCloudHardwareProfile>();
@@ -146,13 +158,20 @@
 		return realms.toArray(new DeltaCloudRealm[realms.size()]);
 	}
 
-	public boolean createInstance(String name, String imageId, String realmId, String profileId) throws DeltaCloudException {
+	public DeltaCloudInstance createInstance(String name, String imageId, String realmId, String profileId) throws DeltaCloudException {
 		try {
-			if (client.createInstance(imageId, profileId, realmId, name) != null)
-				return true;
+			Instance instance = client.createInstance(imageId, profileId, realmId, name);
+			if (instance != null) {
+				DeltaCloudInstance newInstance = new DeltaCloudInstance(instance);
+				instances.add(newInstance);
+				DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
+				instanceArray = instances.toArray(instanceArray);
+				notifyInstanceListListeners(instanceArray);
+				return newInstance;
+			}
 		} catch (DeltaCloudClientException e) {
 			throw new DeltaCloudException(e);
 		}
-		return false;
+		return null;
 	}
 }

Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java	2010-08-11 14:36:49 UTC (rev 24046)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java	2010-08-11 14:39:58 UTC (rev 24047)
@@ -7,6 +7,10 @@
 
 public class DeltaCloudInstance {
 
+	public final static String PENDING = Instance.State.PENDING.toString();
+	public final static String RUNNING = Instance.State.RUNNING.toString();
+	public final static String STOPPED = Instance.State.STOPPED.toString();
+	
 	private Instance instance;
 	
 	public DeltaCloudInstance(Instance instance) {



More information about the jbosstools-commits mailing list