Author: jjohnstn
Date: 2010-08-23 18:41:25 -0400 (Mon, 23 Aug 2010)
New Revision: 24369
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
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java
Log:
2010-08-23 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/Instance.java (getKey): New method.
(setKey): Ditto.
* src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getCurrInstances): Fix to
call getInstances if there aren't any instances yet.
(getCurrImages): New method.
(refreshInstance): Pass any instance key into the new instance.
(getImages): Synchronize on imageLock.
(loadChildren): New method that loads the children in a thread.
(createInstance): Save the key if generated into the instance.
* src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java (getKey): New method.
* src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java (loadClouds): Ditto.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-08-23 22:38:22
UTC (rev 24368)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-08-23 22:41:25
UTC (rev 24369)
@@ -1,3 +1,17 @@
+2010-08-23 Jeff Johnston <jjohnstn(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/client/Instance.java (getKey): New method.
+ (setKey): Ditto.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getCurrInstances): Fix to
+ call getInstances if there aren't any instances yet.
+ (getCurrImages): New method.
+ (refreshInstance): Pass any instance key into the new instance.
+ (getImages): Synchronize on imageLock.
+ (loadChildren): New method that loads the children in a thread.
+ (createInstance): Save the key if generated into the instance.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java (getKey): New method.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java (loadClouds): Ditto.
+
2010-08-20 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java (DCNS): Add KEYS.
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-23
22:38:22 UTC (rev 24368)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-08-23
22:41:25 UTC (rev 24369)
@@ -29,7 +29,9 @@
private String type;
private DeltaCloudClient client;
private ArrayList<DeltaCloudInstance> instances;
+ private ArrayList<DeltaCloudImage> images;
private Map<String, String> keys = new HashMap<String, String>();
+ private Object imageLock = new Object();
ListenerList instanceListeners = new ListenerList();
ListenerList imageListeners = new ListenerList();
@@ -78,6 +80,19 @@
return type;
}
+ public void loadChildren() {
+ Thread t = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ getImages();
+ getInstances();
+ }
+
+ });
+ t.start();
+ }
+
public void addInstanceListListener(IInstanceListListener listener) {
instanceListeners.add(listener);
}
@@ -124,6 +139,8 @@
}
public DeltaCloudInstance[] getCurrInstances() {
+ if (instances == null)
+ return getInstances();
DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
instanceArray = instances.toArray(instanceArray);
return instanceArray;
@@ -156,6 +173,7 @@
for (int i = 0; i < instances.size(); ++i) {
DeltaCloudInstance inst = instances.get(i);
if (inst.getId().equals(instanceId)) {
+ instance.setKey(inst.getKey());
// FIXME: remove BOGUS state when server fixes state problems
if (!(instance.getState().equals(DeltaCloudInstance.BOGUS)) &&
!(inst.getState().equals(instance.getState()))) {
instances.set(i, retVal);
@@ -199,19 +217,34 @@
}
public DeltaCloudImage[] getImages() {
- ArrayList<DeltaCloudImage> images = new ArrayList<DeltaCloudImage>();
- try {
- List<Image> list = client.listImages();
- for (Iterator<Image> i = list.iterator(); i.hasNext();) {
- DeltaCloudImage image = new DeltaCloudImage(i.next());
- images.add(image);
+ synchronized (imageLock) {
+ images = new ArrayList<DeltaCloudImage>();
+ try {
+ List<Image> list = client.listImages();
+ for (Iterator<Image> i = list.iterator(); i.hasNext();) {
+ DeltaCloudImage image = new DeltaCloudImage(i.next());
+ images.add(image);
+ }
+ } catch (DeltaCloudClientException e) {
+ Activator.log(e);
}
- } catch (DeltaCloudClientException e) {
- Activator.log(e);
+ DeltaCloudImage[] imageArray = new DeltaCloudImage[images.size()];
+ imageArray = images.toArray(imageArray);
+ notifyImageListListeners(imageArray);
+ return imageArray;
}
- return images.toArray(new DeltaCloudImage[images.size()]);
}
+ public DeltaCloudImage[] getCurrImages() {
+ synchronized(imageLock) {
+ if (images == null)
+ return getImages();
+ DeltaCloudImage[] imageArray = new DeltaCloudImage[images.size()];
+ imageArray = images.toArray(imageArray);
+ return imageArray;
+ }
+ }
+
public boolean testConnection() {
String instanceId = "madeupValue"; //$NON-NLS-1$
try {
@@ -246,6 +279,7 @@
if (DeltaCloudInstance.EC2_TYPE.equals(type)) {
client.createKey(keyname, Activator.getDefault().getStateLocation());
instance = client.createInstance(imageId, profileId, realmId, name, keyname, memory,
storage);
+ instance.setKey(keyname);
keys.put(instance.getId(), keyname);
} else {
instance = client.createInstance(imageId, profileId, realmId, name, memory,
storage);
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-23
22:38:22 UTC (rev 24368)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-08-23
22:41:25 UTC (rev 24369)
@@ -51,6 +51,10 @@
return instance.getState().toString();
}
+ public String getKey() {
+ return instance.getKey();
+ }
+
public List<String> getActions() {
return instance.getActionNames();
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java 2010-08-23
22:38:22 UTC (rev 24368)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java 2010-08-23
22:41:25 UTC (rev 24369)
@@ -63,6 +63,7 @@
try {
password = node.get("password", null); //$NON-NLS-1$
DeltaCloud cloud = new DeltaCloud(name, url, username, password, type, false);
+ cloud.loadChildren();
clouds.add(cloud);
} catch (Exception e1) {
Activator.log(e1);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-08-23
22:38:22 UTC (rev 24368)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-08-23
22:41:25 UTC (rev 24369)
@@ -31,6 +31,8 @@
private String realmId;
+ private String keyname;
+
@XmlElement
private State state;
@@ -99,6 +101,14 @@
}
}
+ public void setKey(String keyname) {
+ this.keyname = keyname;
+ }
+
+ public String getKey() {
+ return keyname;
+ }
+
@SuppressWarnings("unused")
private void setPrivateAddresses(AddressList privateAddresses)
{