Author: adietish
Date: 2010-10-27 09:18:27 -0400 (Wed, 27 Oct 2010)
New Revision: 26088
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java
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/client/DeltaCloudClient.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnection.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java
Log:
[JBIDE-7431] catched only DeltaCloudNotFoundException (== only case that indicates auth
succeeded), added error reporting dialog for all other errors in the UI, added tests
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-10-27
12:45:49 UTC (rev 26087)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-10-27
13:18:27 UTC (rev 26088)
@@ -28,16 +28,17 @@
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.DeltaCloudNotFoundException;
import org.jboss.tools.deltacloud.core.client.HardwareProfile;
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 {
-
+
public final static String MOCK_TYPE = "MOCK"; //$NON-NLS-1$
public final static String EC2_TYPE = "EC2"; //$NON-NLS-1$
-
+
private String name;
private String username;
private String url;
@@ -53,21 +54,21 @@
private Object imageLock = new Object();
private Object instanceLock = new Object();
private Object actionLock = new Object();
-
+
ListenerList instanceListeners = new ListenerList();
ListenerList imageListeners = new ListenerList();
-
+
public DeltaCloud(String name, String url, String username, String passwd) throws
MalformedURLException {
this(name, url, username, passwd, null, false, IImageFilter.ALL_STRING,
IInstanceFilter.ALL_STRING);
}
- public DeltaCloud(String name, String url, String username, String passwd,
+ public DeltaCloud(String name, String url, String username, String passwd,
String type, boolean persistent) throws MalformedURLException {
this(name, url, username, passwd, type, persistent, IImageFilter.ALL_STRING,
IInstanceFilter.ALL_STRING);
}
- public DeltaCloud(String name, String url, String username, String passwd,
- String type, boolean persistent,
+ public DeltaCloud(String name, String url, String username, String passwd,
+ String type, boolean persistent,
String imageFilterRules, String instanceFilterRules) throws MalformedURLException {
this.client = new DeltaCloudClient(new URL(url), username, passwd); //$NON-NLS-1$
this.url = url;
@@ -90,8 +91,9 @@
storePassword(url, username, passwd);
}
}
-
- public void editCloud(String name, String url, String username, String passwd, String
type) throws MalformedURLException {
+
+ public void editCloud(String name, String url, String username, String passwd, String
type)
+ throws MalformedURLException {
this.client = new DeltaCloudClient(new URL(url + "/api"), username, passwd);
//$NON-NLS-1$
this.url = url;
this.name = name;
@@ -105,7 +107,7 @@
String key = DeltaCloud.getPreferencesKey(url, username);
ISecurePreferences node = root.node(key);
try {
- node.put("password", passwd, true /*encrypt*/);
+ node.put("password", passwd, true /* encrypt */);
} catch (StorageException e) {
e.printStackTrace();
}
@@ -116,43 +118,43 @@
key += url + "/" + username; //$NON-NLS-1$
return EncodingUtils.encodeSlashes(key);
}
-
+
public String getName() {
return name;
}
-
+
public String getURL() {
return url;
}
-
+
public String getUsername() {
return username;
}
-
+
public String getType() {
return type;
}
-
+
public String getLastImageId() {
return lastImageId;
}
-
+
public void setLastImageId(String lastImageId) {
this.lastImageId = lastImageId;
}
-
+
public String getLastKeyname() {
return lastKeyname;
}
-
+
public void setLastKeyname(String lastKeyname) {
this.lastKeyname = lastKeyname;
}
-
+
public IInstanceFilter getInstanceFilter() {
return instanceFilter;
}
-
+
public void createInstanceFilter(String ruleString) {
String rules = getInstanceFilter().toString();
if (IInstanceFilter.ALL_STRING.equals(ruleString))
@@ -166,11 +168,11 @@
notifyInstanceListListeners(getCurrInstances());
}
}
-
+
public IImageFilter getImageFilter() {
return imageFilter;
}
-
+
public void createImageFilter(String ruleString) {
String rules = getImageFilter().toString();
if (IImageFilter.ALL_STRING.equals(ruleString))
@@ -184,7 +186,7 @@
notifyImageListListeners(getCurrImages());
}
}
-
+
public void loadChildren() {
Thread t = new Thread(new Runnable() {
@@ -193,20 +195,20 @@
getImages();
getInstances();
}
-
+
});
t.start();
}
-
+
public void save() {
// Currently we have to save all clouds instead of just this one
DeltaCloudManager.getDefault().saveClouds();
}
-
+
public void addInstanceListListener(IInstanceListListener listener) {
instanceListeners.add(listener);
}
-
+
public void removeInstanceListListener(IInstanceListListener listener) {
instanceListeners.remove(listener);
}
@@ -214,21 +216,21 @@
public void notifyInstanceListListeners(DeltaCloudInstance[] array) {
Object[] listeners = instanceListeners.getListeners();
for (int i = 0; i < listeners.length; ++i)
- ((IInstanceListListener)listeners[i]).listChanged(this, array);
+ ((IInstanceListListener) listeners[i]).listChanged(this, array);
}
-
+
public void addImageListListener(IImageListListener listener) {
imageListeners.add(listener);
}
-
+
public void removeImageListListener(IImageListListener listener) {
imageListeners.remove(listener);
}
-
+
public void notifyImageListListeners(DeltaCloudImage[] array) {
Object[] listeners = imageListeners.getListeners();
for (int i = 0; i < listeners.length; ++i)
- ((IImageListListener)listeners[i]).listChanged(this, array);
+ ((IImageListListener) listeners[i]).listChanged(this, array);
}
public Job getActionJob(String id) {
@@ -255,7 +257,7 @@
actionJobs.remove(id);
}
}
-
+
public DeltaCloudInstance[] getInstances() {
synchronized (instanceLock) {
instances = new ArrayList<DeltaCloudInstance>();
@@ -274,7 +276,7 @@
return instanceArray;
}
}
-
+
public DeltaCloudInstance[] getCurrInstances() {
synchronized (instanceLock) {
if (instances == null)
@@ -284,7 +286,7 @@
return instanceArray;
}
}
-
+
public DeltaCloudInstance[] destroyInstance(String instanceId) {
try {
client.destroyInstance(instanceId);
@@ -311,7 +313,7 @@
throw new DeltaCloudException(e);
}
}
-
+
public void deleteKey(String keyname) throws DeltaCloudException {
try {
client.deleteKey(keyname);
@@ -339,7 +341,7 @@
notifyInstanceListListeners(instanceArray);
}
}
-
+
public DeltaCloudInstance refreshInstance(String instanceId) {
DeltaCloudInstance retVal = null;
try {
@@ -348,8 +350,10 @@
for (int i = 0; i < instances.size(); ++i) {
DeltaCloudInstance inst = instances.get(i);
if (inst.getId().equals(instanceId)) {
- // FIXME: remove BOGUS state when server fixes state problems
- if (!(retVal.getState().equals(DeltaCloudInstance.BOGUS)) &&
!(inst.getState().equals(retVal.getState()))) {
+ // FIXME: remove BOGUS state when server fixes state
+ // problems
+ if (!(retVal.getState().equals(DeltaCloudInstance.BOGUS))
+ && !(inst.getState().equals(retVal.getState()))) {
instances.set(i, retVal);
DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
instanceArray = instances.toArray(instanceArray);
@@ -363,7 +367,7 @@
}
return retVal;
}
-
+
public boolean performInstanceAction(String instanceId, String action) throws
DeltaCloudException {
try {
return client.performInstanceAction(instanceId, action);
@@ -387,7 +391,7 @@
profileArray = profiles.toArray(profileArray);
return profileArray;
}
-
+
public DeltaCloudImage[] getImages() {
synchronized (imageLock) {
images = new ArrayList<DeltaCloudImage>();
@@ -408,7 +412,7 @@
}
public DeltaCloudImage[] getCurrImages() {
- synchronized(imageLock) {
+ synchronized (imageLock) {
if (images == null)
return getImages();
DeltaCloudImage[] imageArray = new DeltaCloudImage[images.size()];
@@ -416,7 +420,7 @@
return imageArray;
}
}
-
+
public DeltaCloudImage getImage(String imageId) {
DeltaCloudImage retVal = null;
try {
@@ -428,15 +432,17 @@
}
return retVal;
}
-
+
public boolean testConnection() throws DeltaCloudClientException {
- String instanceId = "madeupValue"; //$NON-NLS-1$
+ String instanceId = "nonexistingInstance"; //$NON-NLS-1$
try {
client.listInstances(instanceId);
return true;
+ } catch( DeltaCloudNotFoundException e) {
+ return true;
} catch (DeltaCloudAuthException e) {
return false;
- }
+ }
}
public DeltaCloudRealm[] getRealms() {
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-10-27
12:45:49 UTC (rev 26087)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-10-27
13:18:27 UTC (rev 26088)
@@ -53,6 +53,8 @@
public class DeltaCloudClient implements API {
+ private static final int HTTP_STATUSCODE_NOTFOUND = 404;
+ private static final int HTTP_STATUSCODE_FORBIDDEN = 403;
private static final String DOCUMENT_ELEMENT_DRIVER = "driver"; //$NON-NLS-1$
private static final String DOCUMENT_ELEMENT_API = "api"; //$NON-NLS-1$
private static final int HTTP_STATUSCODE_SERVERERROR = 500;
@@ -142,17 +144,24 @@
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (isHttpForbiddenError(statusCode)) {
throw new DeltaCloudAuthException(
- MessageFormat.format("the server reported an authorization error
\"{0}\" on requesting \"{1}\"",
+ MessageFormat.format("The server reported an authorization error
\"{0}\" on requesting \"{1}\"",
httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
+ } else if (isHttpNotFoundError(statusCode)) {
+ throw new DeltaCloudNotFoundException(
+ MessageFormat.format("The server could not find the resource
\"{0}\"", requestUrl));
} else if (isHttpClientError(statusCode) || isHttpServerError(statusCode)) {
throw new DeltaCloudClientException(
- MessageFormat.format("the server reported an error \"{0}\" on
requesting \"{1}\"",
+ MessageFormat.format("The server reported an error \"{0}\" on
requesting \"{1}\"",
httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
}
}
+ private boolean isHttpNotFoundError(int statusCode) {
+ return statusCode == HTTP_STATUSCODE_NOTFOUND;
+ }
+
private boolean isHttpForbiddenError(int statusCode) {
- return statusCode == 403;
+ return statusCode == HTTP_STATUSCODE_FORBIDDEN;
}
private boolean isHttpClientError(int statusCode) {
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java 2010-10-27
13:18:27 UTC (rev 26088)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are 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 Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+public class DeltaCloudNotFoundException extends DeltaCloudClientException {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudNotFoundException(String message, Throwable clause)
+ {
+ super(message, clause);
+ }
+
+ public DeltaCloudNotFoundException(Throwable clause)
+ {
+ super(clause);
+ }
+
+ public DeltaCloudNotFoundException(String message)
+ {
+ super(message);
+ }
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnection.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnection.java 2010-10-27
12:45:49 UTC (rev 26087)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnection.java 2010-10-27
13:18:27 UTC (rev 26088)
@@ -51,7 +51,7 @@
cloud.getType(), this);
addPage(mainPage);
} catch (MalformedURLException e) {
- Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
e.getMessage(), e);
+ IStatus status = StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
e.getMessage(), e);
ErrorDialog.openError(getShell(),
WizardMessages.getString("EditCloudConnectionError.title"),
WizardMessages.getString("EditCloudConnectionError.message"), status);
}
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java 2010-10-27
12:45:49 UTC (rev 26087)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java 2010-10-27
13:18:27 UTC (rev 26088)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.internal.deltacloud.test.core;
+import static org.junit.Assert.assertFalse;
+
import java.io.IOException;
import java.net.MalformedURLException;
@@ -45,21 +47,23 @@
}
@Test
- public void testConnectionDoesNotThrowOnForbidden() throws MalformedURLException,
DeltaCloudClientException {
+ public void testConnectionReportsFalseOnAuthFailure() throws MalformedURLException,
DeltaCloudClientException {
ServerFake serverFake = setupServerFake("HTTP/1.1 403 Forbidden\n\n\n");
try {
- DeltaCloud deltaCloud = new DeltaCloud("aName",
"http://localhost:" + ServerFake.DEFAULT_PORT, "badUser",
"badPassword");
- deltaCloud.testConnection();
+ DeltaCloud deltaCloud = new DeltaCloud("aName",
"http://localhost:" + ServerFake.DEFAULT_PORT, "badUser",
+ "badPassword");
+ assertFalse(deltaCloud.testConnection());
} finally {
serverFake.stop();
}
}
- @Test(expected=DeltaCloudClientException.class)
- public void testConnectionDoesThrowOnGeneralError() throws MalformedURLException,
DeltaCloudClientException {
+ @Test(expected = DeltaCloudClientException.class)
+ public void testConnectionThrowsOnGeneralFailure() throws MalformedURLException,
DeltaCloudClientException {
ServerFake serverFake = setupServerFake("HTTP/1.1 501 Some Error\ndummy dummy
dummy\n\n");
try {
- DeltaCloud deltaCloud = new DeltaCloud("aName",
"http://localhost:" + ServerFake.DEFAULT_PORT, "badUser",
"badPassword");
+ DeltaCloud deltaCloud = new DeltaCloud("aName",
"http://localhost:" + ServerFake.DEFAULT_PORT, "badUser",
+ "badPassword");
deltaCloud.testConnection();
} finally {
serverFake.stop();