Author: adietish
Date: 2010-11-16 12:28:30 -0500 (Tue, 16 Nov 2010)
New Revision: 26631
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudPersistedConnectionsException.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/DeltaCloudManager.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/ErrorUtils.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java
Log:
[JBIDE-7597] removed implicit loading of persisted connections. moved to explicit loading.
Collecting exceptions and returning them as errors that occurred. Reporting them to the
user.
This is an initial non-optimal but working implementation (kinda POC)
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-11-16 17:21:41
UTC (rev 26630)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-11-16 17:28:30
UTC (rev 26631)
@@ -1,5 +1,9 @@
2010-11-16 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java (DeltaCloudManager):
+ [JBIDE-7597] removed implicit loading of persisted connections. moved to explicit
loading.
+ (loadClouds):
+ [JBIDE-7597] collecting exceptions are returning them as errors.
* src/org/jboss/tools/deltacloud/core/client/Image.java:
* src/org/jboss/tools/deltacloud/core/DeltaCloudImage.java:
* src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java
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-11-16
17:21:41 UTC (rev 26630)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java 2010-11-16
17:28:30 UTC (rev 26631)
@@ -15,36 +15,36 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.equinox.security.storage.ISecurePreferences;
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
public class DeltaCloudManager {
+ private static final DeltaCloudManager INSTANCE = new DeltaCloudManager();
+
public final static String CLOUDFILE_NAME = "clouds.xml"; //$NON-NLS-1$
-
- private static DeltaCloudManager cloudManager;
private ArrayList<DeltaCloud> clouds = new ArrayList<DeltaCloud>();
private ListenerList cloudManagerListeners;
private DeltaCloudManager() {
- loadClouds();
}
- private void loadClouds() {
+ public DeltaCloudPersistedConnectionsException loadClouds() {
+ DeltaCloudPersistedConnectionsException connectionException = new
DeltaCloudPersistedConnectionsException();
IPath stateLocation = Activator.getDefault().getStateLocation();
File cloudFile = stateLocation.append(CLOUDFILE_NAME).toFile();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -52,26 +52,27 @@
DocumentBuilder db = dbf.newDocumentBuilder();
if (cloudFile.exists()) {
Document d = db.parse(cloudFile);
- Element e = d.getDocumentElement();
+ Element element = d.getDocumentElement();
// Get the stored configuration data
- NodeList cloudNodes = e.getElementsByTagName("cloud"); // $NON-NLS-1$
+ NodeList cloudNodes = element.getElementsByTagName("cloud"); //
$NON-NLS-1$
for (int x = 0; x < cloudNodes.getLength(); ++x) {
Node n = cloudNodes.item(x);
- loadCloud(n);
+ try {
+ String name = getCloudName(n);
+ loadCloud(name, n);
+ } catch (StorageException e) {
+ connectionException.addError(e);
+ }
}
}
- } catch (ParserConfigurationException e) {
- Activator.log(e);
- } catch (SAXException e) {
- Activator.log(e);
- } catch (IOException e) {
- Activator.log(e);
+ } catch (Exception e) {
+ connectionException.addError(e);
}
+ return connectionException;
}
- private void loadCloud(Node n) {
+ private void loadCloud(String name, Node n) throws StorageException,
MalformedURLException, DeltaCloudException {
NamedNodeMap attrs = n.getAttributes();
- String name = attrs.getNamedItem("name").getNodeValue(); // $NON-NLS-1$
String url = attrs.getNamedItem("url").getNodeValue(); // $NON-NLS-1$
String username = attrs.getNamedItem("username").getNodeValue(); //
$NON-NLS-1$
String type = attrs.getNamedItem("type").getNodeValue(); // $NON-NLS-1$
@@ -82,20 +83,20 @@
String lastImageId = getLastKeyName(attrs.getNamedItem("lastimage")); //
$NON-NLS-1$
ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node(key);
- try {
- String password = node.get("password", null); //$NON-NLS-1$
- DeltaCloud cloud = new DeltaCloud(name, url, username, password, type,
- false, imageFilterRules, instanceFilterRules);
- cloud.setLastImageId(lastImageId);
- cloud.setLastKeyname(lastKeyName);
- cloud.loadChildren();
- clouds.add(cloud);
- } catch (Exception e1) {
- Activator.log(e1);
- return;
- }
+ String password = node.get("password", null); //$NON-NLS-1$
+ DeltaCloud cloud = new DeltaCloud(
+ name, url, username, password, type, false, imageFilterRules, instanceFilterRules);
+ cloud.setLastImageId(lastImageId);
+ cloud.setLastKeyname(lastKeyName);
+ cloud.loadChildren();
+ clouds.add(cloud);
}
+ private String getCloudName(Node n) {
+ String name = n.getAttributes().getNamedItem("name").getNodeValue(); //
$NON-NLS-1$
+ return name;
+ }
+
private String getLastKeyName(Node lastKeyNameNode) {
String lastKeyName = "";
if (lastKeyNameNode != null) {
@@ -160,9 +161,7 @@
}
public static DeltaCloudManager getDefault() {
- if (cloudManager == null)
- cloudManager = new DeltaCloudManager();
- return cloudManager;
+ return INSTANCE;
}
public DeltaCloud[] getClouds() {
@@ -204,9 +203,11 @@
/**
* Checks if any cloud uses the given url and username
- *
- * @param url the url
- * @param userName the user name
+ *
+ * @param url
+ * the url
+ * @param userName
+ * the user name
* @return true, if is checks for any cloud
*/
private boolean isHasAnyCloud(String url, String userName) {
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudPersistedConnectionsException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudPersistedConnectionsException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudPersistedConnectionsException.java 2010-11-16
17:28:30 UTC (rev 26631)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An exception that holds all errors that occured when loading persisted
+ * connections to deltacloud servers.
+ */
+public class DeltaCloudPersistedConnectionsException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ private ArrayList<Throwable> throwables;
+
+ public DeltaCloudPersistedConnectionsException() {
+ super();
+ this.throwables = new ArrayList<Throwable>();
+ }
+
+ public void addError(Throwable throwable) {
+ throwables.add(throwable);
+ }
+
+ public List<Throwable> getErrors() {
+ return throwables;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudPersistedConnectionsException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-16 17:21:41
UTC (rev 26630)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-16 17:28:30
UTC (rev 26631)
@@ -1,5 +1,7 @@
2010-11-16 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java (CVRootElement):
+ [JBIDE-7597] removed implicit loading of persisted connections. moved to explicit
loading.
* src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
(inputChanged):
* src/org/jboss/tools/deltacloud/ui/views/InstancePropertySource.java (getKey):
[JBIDE-7597] errors while loading images/instances are now reported (exceptions are not
swallowed any longer)
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/ErrorUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/ErrorUtils.java 2010-11-16
17:21:41 UTC (rev 26630)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/ErrorUtils.java 2010-11-16
17:28:30 UTC (rev 26631)
@@ -10,14 +10,17 @@
******************************************************************************/
package org.jboss.tools.deltacloud.ui;
+import java.util.Collection;
+
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jboss.tools.common.log.StatusFactory;
public class ErrorUtils {
- public static IStatus openErrorDialog(final String title, final String message,
Exception e, final Shell shell) {
+ public static IStatus openErrorDialog(final String title, final String message,
Throwable e, final Shell shell) {
final IStatus status = StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
e.getMessage(), e);
Display.getDefault().syncExec(new Runnable() {
public void run() {
@@ -26,4 +29,25 @@
});
return status;
}
+
+ public static IStatus openErrorDialog(final String title, final String message,
Collection<Throwable> throwables, final Shell shell) {
+ final IStatus status = createMultiStatus(message, throwables);
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ ErrorDialog.openError(shell, title, message, status);
+ }
+ });
+ return status;
+ }
+
+ // TODO: move to appropriate util class
+ private static IStatus createMultiStatus(String message, Collection<Throwable>
throwables) {
+ MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 0, message, null);
+ for(Throwable e : throwables) {
+ IStatus childStatus = StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
e.getMessage(), e);
+ multiStatus.add(childStatus );
+ }
+ return multiStatus;
+ }
+
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-11-16
17:21:41 UTC (rev 26630)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-11-16
17:28:30 UTC (rev 26631)
@@ -76,6 +76,7 @@
initialized = true;
cloud.addInstanceListListener(this);
} catch (Exception e) {
+ // TODO: internationalize strings
ErrorUtils.openErrorDialog(
"Error",
"Colud not get instances from cloud " + cloud.getName(),
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java 2010-11-16
17:21:41 UTC (rev 26630)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java 2010-11-16
17:28:30 UTC (rev 26631)
@@ -15,7 +15,9 @@
import org.eclipse.ui.views.properties.IPropertySource;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
+import org.jboss.tools.deltacloud.core.DeltaCloudPersistedConnectionsException;
import org.jboss.tools.deltacloud.core.ICloudManagerListener;
+import org.jboss.tools.deltacloud.ui.ErrorUtils;
public class CVRootElement extends CloudViewElement implements ICloudManagerListener {
@@ -25,8 +27,13 @@
public CVRootElement(TreeViewer viewer) {
super(DeltaCloudManager.getDefault(), "root"); //$NON-NLS-1$
this.viewer = viewer;
+ DeltaCloudPersistedConnectionsException loadCloudsErrors =
DeltaCloudManager.getDefault().loadClouds();
+ ErrorUtils.openErrorDialog(
+ "Error",
+ "Colud load clouds",
+ loadCloudsErrors.getErrors(), Display.getDefault().getActiveShell());
}
-
+
@Override
public IPropertySource getPropertySource() {
// no property source for the root element
@@ -54,7 +61,7 @@
DeltaCloudManager.getDefault().removeCloudManagerListener(this);
super.finalize();
}
-
+
public void changeEvent(int type) {
DeltaCloudManager m = DeltaCloudManager.getDefault();
m.removeCloudManagerListener(this);
@@ -69,7 +76,7 @@
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- ((TreeViewer)viewer).refresh(this, false);
+ ((TreeViewer) viewer).refresh(this, false);
}
});
}