Author: jjohnstn
Date: 2010-08-27 14:54:33 -0400 (Fri, 27 Aug 2010)
New Revision: 24521
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/client/DeltaCloudClient.java
Log:
2010-08-27 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java (buildInstance): Add
call to getAuthentication method.
(getAuthentication): New method to get authentication items such as keyname.
* src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getCurrInstances): Synchronize on
new instanceLock object.
(getInstances): Ditto.
(performInstanceAction): Do not do any special actions for EC2 clouds, namely
deleting a key if stopping.
(refreshInstance): Do not reset the key.
(createInstance): Do not look for EC2 type, do not create a key, but just check if a
keyname is specified.
Do not save the key if specified as this is done when creating the instance.
* src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java: Add MOCK type.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-08-27 18:47:54
UTC (rev 24520)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-08-27 18:54:33
UTC (rev 24521)
@@ -1,3 +1,18 @@
+2010-08-27 Jeff Johnston <jjohnstn(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java (buildInstance): Add
+ call to getAuthentication method.
+ (getAuthentication): New method to get authentication items such as keyname.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getCurrInstances): Synchronize
on
+ new instanceLock object.
+ (getInstances): Ditto.
+ (performInstanceAction): Do not do any special actions for EC2 clouds, namely
+ deleting a key if stopping.
+ (refreshInstance): Do not reset the key.
+ (createInstance): Do not look for EC2 type, do not create a key, but just check if a
keyname is specified.
+ Do not save the key if specified as this is done when creating the instance.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java: Add MOCK type.
+
2010-08-26 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java (createKey): Remove
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-27
18:47:54 UTC (rev 24520)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-08-27
18:54:33 UTC (rev 24521)
@@ -3,12 +3,12 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.Path;
import org.eclipse.equinox.security.storage.EncodingUtils;
import org.eclipse.equinox.security.storage.ISecurePreferences;
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
@@ -30,8 +30,8 @@
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();
+ private Object instanceLock = new Object();
ListenerList instanceListeners = new ListenerList();
ListenerList imageListeners = new ListenerList();
@@ -122,28 +122,32 @@
}
public DeltaCloudInstance[] getInstances() {
- instances = new ArrayList<DeltaCloudInstance>();
- try {
- List<Instance> list = client.listInstances();
- for (Iterator<Instance> i = list.iterator(); i.hasNext();) {
- DeltaCloudInstance instance = new DeltaCloudInstance(i.next());
- instances.add(instance);
+ synchronized (instanceLock) {
+ instances = new ArrayList<DeltaCloudInstance>();
+ try {
+ List<Instance> list = client.listInstances();
+ for (Iterator<Instance> i = list.iterator(); i.hasNext();) {
+ DeltaCloudInstance instance = new DeltaCloudInstance(i.next());
+ instances.add(instance);
+ }
+ } catch (DeltaCloudClientException e) {
+ Activator.log(e);
}
- } catch (DeltaCloudClientException e) {
- Activator.log(e);
+ DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
+ instanceArray = instances.toArray(instanceArray);
+ notifyInstanceListListeners(instanceArray);
+ return instanceArray;
}
- DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
- instanceArray = instances.toArray(instanceArray);
- notifyInstanceListListeners(instanceArray);
- return instanceArray;
}
public DeltaCloudInstance[] getCurrInstances() {
- if (instances == null)
- return getInstances();
- DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
- instanceArray = instances.toArray(instanceArray);
- return instanceArray;
+ synchronized (instanceLock) {
+ if (instances == null)
+ return getInstances();
+ DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
+ instanceArray = instances.toArray(instanceArray);
+ return instanceArray;
+ }
}
public DeltaCloudInstance[] destroyInstance(String instanceId) {
@@ -173,7 +177,6 @@
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 (!(retVal.getState().equals(DeltaCloudInstance.BOGUS)) &&
!(inst.getState().equals(retVal.getState()))) {
instances.set(i, retVal);
@@ -192,8 +195,6 @@
public boolean performInstanceAction(String instanceId, String action) throws
DeltaCloudException {
try {
- if (action.equals(DeltaCloudInstance.STOP) && keys.get(instanceId) != null)
- client.deleteKey(keys.get(instanceId), Activator.getDefault().getStateLocation());
return client.performInstanceAction(instanceId, action);
} catch (DeltaCloudClientException e) {
throw new DeltaCloudException(e);
@@ -272,15 +273,11 @@
}
public DeltaCloudInstance createInstance(String name, String imageId, String realmId,
String profileId,
- String memory, String storage) throws DeltaCloudException {
+ String keyname, String memory, String storage) throws DeltaCloudException {
try {
- String keyname = "key-" + name + "-" + System.nanoTime();
//$NON-NLS-1 //$NON-NLS-2$
Instance instance = null;
- if (DeltaCloudInstance.EC2_TYPE.equals(type)) {
- client.createKey(keyname, Activator.getDefault().getStateLocation());
+ if (keyname != null) {
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-27
18:47:54 UTC (rev 24520)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-08-27
18:54:33 UTC (rev 24521)
@@ -19,6 +19,7 @@
public final static String DESTROY = Instance.Action.DESTROY.toString();
public final static String EC2_TYPE = "EC2"; //$NON-NLS-1$
+ public final static String MOCK_TYPE = "MOCK"; //$NON-NLS-1$
private Instance instance;
private String givenName;
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-08-27
18:47:54 UTC (rev 24520)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-08-27
18:54:33 UTC (rev 24521)
@@ -339,6 +339,7 @@
getProfileProperties(instance, getPropertyNodes(document,
"hardware_profile")); //$NON-NLS-1$
instance.setRealmId(getIdFromHref(getAttributeValues(document, "realm",
"href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
instance.setState(getElementText(document, "state").get(0)); //$NON-NLS-1$
+ getAuthentication(document, instance);
ArrayList<Instance.Action> actions = new ArrayList<Instance.Action>();
for(String s : getAttributeValues(document, "link", "rel"))
//$NON-NLS-1$ //$NON-NLS-2$
@@ -458,6 +459,31 @@
return values;
}
+ private void getAuthentication(Document document, Instance instance) {
+ NodeList elements = document.getElementsByTagName("authentication");
+ for (int i = 0; i < elements.getLength(); i++)
+ {
+ Node element = elements.item(i);
+ NamedNodeMap attrs = element.getAttributes();
+ Node type = attrs.getNamedItem("type"); //$NON-NLS-1$
+ if (type.getNodeValue().equals("key")) { //$NON-NLS-1$
+ NodeList children = element.getChildNodes();
+ for (int j = 0; j < children.getLength(); ++j) {
+ Node child = children.item(j);
+ if (child.getNodeName().equals("login")) { //$NON-NLS-1$
+ NodeList loginChildren = child.getChildNodes();
+ for (int k = 0; k < loginChildren.getLength(); ++k) {
+ Node loginChild = loginChildren.item(k);
+ if (loginChild.getNodeName().equals("keyname")) { //$NON-NLS-1$
+ instance.setKey(loginChild.getTextContent());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
private void getProfileProperties(Instance instance, List<Node> propertyNodes) {
if (propertyNodes != null) {
for (Iterator<Node> i = propertyNodes.iterator(); i.hasNext();) {