Author: jjohnstn
Date: 2010-08-04 12:49:52 -0400 (Wed, 04 Aug 2010)
New Revision: 23924
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudRealm.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthException.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/Activator.java
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/client/DeltaCloudClient.java
Log:
2010-08-04 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthException.java: New file.
* src/org/jboss/tools/deltacloud/core/DeltaCloudException.java: New file.
* src/org/jboss/tools/deltacloud/core/DeltaCloudRealm.java: New file.
* src/org/jboss/tools/deltacloud/core/Activator.java (logErrorMessage): Ditto.
(log): Ditto.
* src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
(listDeltaCloudObjects):
Check for errors.
(checkForErrors): New method to check for connection errors.
(buildHardwareProfile): Check for errors and change so method throws exceptions.
(buildInstance): Ditto.
* src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getInstances): Log error instead
of
printing stack trace.
(getImages): Ditto.
(getRealms): New method.
(testConnection): Ditto.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-08-04 16:45:53
UTC (rev 23923)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-08-04 16:49:52
UTC (rev 23924)
@@ -1,3 +1,21 @@
+2010-08-04 Jeff Johnston <jjohnstn(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthException.java: New file.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudException.java: New file.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudRealm.java: New file.
+ * src/org/jboss/tools/deltacloud/core/Activator.java (logErrorMessage): Ditto.
+ (log): Ditto.
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
(listDeltaCloudObjects):
+ Check for errors.
+ (checkForErrors): New method to check for connection errors.
+ (buildHardwareProfile): Check for errors and change so method throws exceptions.
+ (buildInstance): Ditto.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getInstances): Log error instead
of
+ printing stack trace.
+ (getImages): Ditto.
+ (getRealms): New method.
+ (testConnection): Ditto.
+
2010-08-03 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java (getClouds): Remove
default
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/Activator.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/Activator.java 2010-08-04
16:45:53 UTC (rev 23923)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/Activator.java 2010-08-04
16:49:52 UTC (rev 23924)
@@ -1,6 +1,11 @@
package org.jboss.tools.deltacloud.core;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;
/**
@@ -47,4 +52,23 @@
return plugin;
}
+ public static void log(IStatus status) {
+ Activator.getDefault().getLog().log(status);
+ }
+
+ public static void logErrorMessage(String message) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, null));
+ }
+
+ public static void log(Throwable e) {
+ if (e instanceof InvocationTargetException)
+ e = ((InvocationTargetException) e).getTargetException();
+ IStatus status = null;
+ if (e instanceof CoreException)
+ status = ((CoreException) e).getStatus();
+ else
+ status = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, e.getMessage(), e);
+ log(status);
+ }
+
}
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-04
16:45:53 UTC (rev 23923)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-08-04
16:49:52 UTC (rev 23924)
@@ -7,10 +7,12 @@
import java.util.List;
import org.eclipse.core.runtime.ListenerList;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudAuthException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.Image;
import org.jboss.tools.deltacloud.core.client.Instance;
+import org.jboss.tools.deltacloud.core.client.Realm;
public class DeltaCloud {
@@ -79,8 +81,7 @@
instances.add(instance);
}
} catch (DeltaCloudClientException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Activator.log(e);
}
DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
instanceArray = instances.toArray(instanceArray);
@@ -97,10 +98,35 @@
images.add(image);
}
} catch (DeltaCloudClientException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Activator.log(e);
}
return images.toArray(new DeltaCloudImage[images.size()]);
}
+ public boolean testConnection() {
+ String instanceId = "madeupValue"; //$NON-NLS-1$
+ try {
+ client.listInstances(instanceId);
+ return true;
+ } catch (DeltaCloudAuthException e) {
+ return false;
+ } catch (DeltaCloudClientException e) {
+ return true;
+ }
+ }
+
+ public DeltaCloudRealm[] getRealms() {
+ ArrayList<DeltaCloudRealm> realms = new ArrayList<DeltaCloudRealm>();
+ try {
+ List<Realm> list = client.listRealms();
+ for (Iterator<Realm> i = list.iterator(); i.hasNext();) {
+ DeltaCloudRealm realm = new DeltaCloudRealm(i.next());
+ realms.add(realm);
+ }
+ } catch (DeltaCloudClientException e) {
+ Activator.log(e);
+ }
+ return realms.toArray(new DeltaCloudRealm[realms.size()]);
+ }
+
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudException.java 2010-08-04
16:49:52 UTC (rev 23924)
@@ -0,0 +1,22 @@
+package org.jboss.tools.deltacloud.core;
+
+public class DeltaCloudException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudException(String message, Throwable clause)
+ {
+ super(message, clause);
+ }
+
+ public DeltaCloudException(Throwable clause)
+ {
+ super(clause);
+ }
+
+ public DeltaCloudException(String message)
+ {
+ super(message);
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudRealm.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudRealm.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudRealm.java 2010-08-04
16:49:52 UTC (rev 23924)
@@ -0,0 +1,25 @@
+package org.jboss.tools.deltacloud.core;
+
+import org.jboss.tools.deltacloud.core.client.Realm;
+
+public class DeltaCloudRealm {
+
+ private Realm realm;
+
+ public DeltaCloudRealm(Realm realm) {
+ this.realm = realm;
+ }
+
+ public String getId() {
+ return realm.getId();
+ }
+
+ public String getName() {
+ return realm.getName();
+ }
+
+ public String getState() {
+ return realm.getState();
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthException.java 2010-08-04
16:49:52 UTC (rev 23924)
@@ -0,0 +1,22 @@
+package org.jboss.tools.deltacloud.core.client;
+
+public class DeltaCloudAuthException extends DeltaCloudClientException {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudAuthException(String message, Throwable clause)
+ {
+ super(message, clause);
+ }
+
+ public DeltaCloudAuthException(Throwable clause)
+ {
+ super(clause);
+ }
+
+ public DeltaCloudAuthException(String message)
+ {
+ super(message);
+ }
+
+}
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-04
16:45:53 UTC (rev 23923)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-08-04
16:49:52 UTC (rev 23924)
@@ -233,8 +233,22 @@
sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.DESTROY,
RequestType.GET);
}
- private Instance buildInstance(String xml)
+ private void checkForErrors(Document d) throws DeltaCloudClientException
{
+ NodeList n = d.getElementsByTagName("error");
+ for (int i = 0; i < n.getLength();)
+ {
+ Node node = n.item(i);
+ String status = node.getAttributes().getNamedItem("status").getNodeValue();
+ if (status.equals("403"))
+ throw new DeltaCloudAuthException("Authorization error");
+ else
+ throw new DeltaCloudClientException("Connection error");
+ }
+ }
+
+ private Instance buildInstance(String xml) throws DeltaCloudClientException
+ {
try
{
Instance instance = JAXB.unmarshal(new StringReader(xml), Instance.class);
@@ -242,15 +256,17 @@
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new InputSource(new StringReader(xml)));
-
- instance.setImageId(getIdFromHref(getAttributeValues(document, "image",
"href").get(0)));
- instance.setProfileId(getIdFromHref(getAttributeValues(document,
"hardware_profile", "href").get(0)));
- getProfileProperties(instance, getPropertyNodes(document,
"hardware_profile"));
- instance.setRealmId(getIdFromHref(getAttributeValues(document, "realm",
"href").get(0)));
- instance.setState(getElementText(document, "state").get(0));
+
+ checkForErrors(document);
+ instance.setImageId(getIdFromHref(getAttributeValues(document, "image",
"href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
+ instance.setProfileId(getIdFromHref(getAttributeValues(document,
"hardware_profile", "href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
+ 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$
+
ArrayList<Instance.Action> actions = new ArrayList<Instance.Action>();
- for(String s : getAttributeValues(document, "link", "rel"))
+ for(String s : getAttributeValues(document, "link", "rel"))
//$NON-NLS-1$ //$NON-NLS-2$
{
actions.add(Instance.Action.valueOf(s.toUpperCase()));
}
@@ -258,14 +274,16 @@
return instance;
}
+ catch (DeltaCloudClientException e) {
+ throw e;
+ }
catch(Exception e)
{
- e.printStackTrace();
+ return null;
}
- return null;
}
- private HardwareProfile buildHardwareProfile(String xml)
+ private HardwareProfile buildHardwareProfile(String xml) throws
DeltaCloudClientException
{
try
{
@@ -274,36 +292,38 @@
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new InputSource(new StringReader(xml)));
-
- List<Node> nodes = getPropertyNodes(document, "hardware_profile");
+
+ checkForErrors(document);
+ List<Node> nodes = getPropertyNodes(document, "hardware_profile");
//$NON-NLS-1$
+
for (Node n : nodes) {
Property p = new Property();
- p.setName(n.getAttributes().getNamedItem("name").getNodeValue());
- p.setValue(n.getAttributes().getNamedItem("value").getNodeValue());
- p.setUnit(n.getAttributes().getNamedItem("unit").getNodeValue());
- p.setKind(n.getAttributes().getNamedItem("kind").getNodeValue());
- if (p.getKind().equals("range")) {
+ p.setName(n.getAttributes().getNamedItem("name").getNodeValue());
//$NON-NLS-1$
+ p.setValue(n.getAttributes().getNamedItem("value").getNodeValue());
//$NON-NLS-1$
+ p.setUnit(n.getAttributes().getNamedItem("unit").getNodeValue());
//$NON-NLS-1$
+ p.setKind(n.getAttributes().getNamedItem("kind").getNodeValue()) ;
//$NON-NLS-1$
+ if (p.getKind().equals("range")) { //$NON-NLS-1$
NodeList children = n.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
Node child = children.item(i);
- if (child.getNodeName().equals("range")) {
- String first =
child.getAttributes().getNamedItem("first").getNodeValue();
- String last =
child.getAttributes().getNamedItem("last").getNodeValue();
+ if (child.getNodeName().equals("range")) { //$NON-NLS-1$
+ String first =
child.getAttributes().getNamedItem("first").getNodeValue(); //$NON-NLS-1$
+ String last = child.getAttributes().getNamedItem("last").getNodeValue();
//$NON-NLS-1$
p.setRange(first, last);
}
}
}
- else if (p.getKind().equals("enum")) {
+ else if (p.getKind().equals("enum")) { //$NON-NLS-1$
ArrayList<String> enums = new ArrayList<String>();
NodeList children = n.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
Node child = children.item(i);
- if (child.getNodeName().equals("enum")) {
+ if (child.getNodeName().equals("enum")) { //$NON-NLS-1$
NodeList enumChildren = child.getChildNodes();
for (int j = 0; j < enumChildren.getLength(); ++j) {
Node enumChild = enumChildren.item(j);
- enums.add(enumChild.getAttributes().getNamedItem("value").getNodeValue());
+ enums.add(enumChild.getAttributes().getNamedItem("value").getNodeValue());
//$NON-NLS-1$
}
}
}
@@ -400,6 +420,8 @@
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(is);
+ checkForErrors(document);
+
document.getElementsByTagName(path).toString();
ArrayList<T> dco = new ArrayList<T>();
@@ -410,6 +432,9 @@
dco.add(buildDeltaCloudObject(clazz, nodeList.item(i)));
}
return dco;
+ } catch (DeltaCloudClientException e)
+ {
+ throw e;
}
catch(Exception e)
{