Author: adietish
Date: 2010-12-17 14:10:10 -0500 (Fri, 17 Dec 2010)
New Revision: 27593
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/AbstractDeltaCloudResourceAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IDeltaCloudResourceAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IInstanceAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IKeyAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyActionXmlAdapter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
Removed:
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/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
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
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/InstanceAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java
Log:
[JBIDE-7371] implementing key related methods in the DeltaCloudClient (created a method
that returns a key instance compared to a string as it was before). Implementing tests for
it.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-17 16:43:44
UTC (rev 27592)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-17 19:10:10
UTC (rev 27593)
@@ -1,3 +1,8 @@
+2010-12-17 André Dietisheim <adietish(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java (createKey):
+ [JBIDE-7371] added #createKey method that now returns a key instance
+
2010-12-16 André Dietisheim <adietish(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.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/DeltaCloud.java 2010-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -18,7 +18,7 @@
import java.util.regex.PatternSyntaxException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudAuthException;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudAuthClientException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
@@ -147,7 +147,7 @@
throws DeltaCloudException {
try {
return new DeltaCloudClientImpl(url, username, password);
- } catch (MalformedURLException e) {
+ } catch (Exception e) {
throw new DeltaCloudException(MessageFormat.format("Could not access cloud at
{0}", url), e);
}
}
@@ -589,11 +589,11 @@
return true;
} catch (DeltaCloudNotFoundClientException e) {
return true;
- } catch (DeltaCloudAuthException e) {
+ } catch (DeltaCloudAuthClientException e) {
return false;
- } catch(DeltaCloudClientException e){
+ } catch (DeltaCloudClientException e) {
throw new DeltaCloudException("Could not connection to ", e);
}
-
+
}
}
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-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -14,6 +14,7 @@
import java.util.List;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.IInstanceAction;
import org.jboss.tools.deltacloud.core.client.Instance;
import org.jboss.tools.deltacloud.core.client.Instance.InstanceState;
import org.jboss.tools.deltacloud.core.client.InstanceAction;
@@ -56,9 +57,9 @@
public enum Action {
- START(InstanceAction.START),
- STOP(InstanceAction.STOP),
- REBOOT(InstanceAction.REBOOT),
+ START(IInstanceAction.START),
+ STOP(IInstanceAction.STOP),
+ REBOOT(IInstanceAction.REBOOT),
DESTROY(InstanceAction.DESTROY);
private String name;
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/AbstractDeltaCloudResourceAction.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/AbstractDeltaCloudResourceAction.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/AbstractDeltaCloudResourceAction.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.client;
+
+import org.jboss.tools.deltacloud.core.client.request.DeltaCloudRequest.HttpMethod;
+
+/**
+ * An action that is executable on a deltacloud resource
+ *
+ * @author André Dietisheim
+ *
+ */
+public abstract class AbstractDeltaCloudResourceAction implements
IDeltaCloudResourceAction {
+
+ private String name;
+ private String url;
+ private HttpMethod method;
+
+ protected AbstractDeltaCloudResourceAction() {
+ }
+
+ protected AbstractDeltaCloudResourceAction(String name, String url, String method) {
+ this.url = url;
+ this.method = HttpMethod.valueOf(method.toUpperCase());
+ this.name = name;
+ }
+
+ protected void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ protected void setUrl(String url) {
+ this.url = url;
+ }
+
+ @Override
+ public String getUrl() {
+ return url;
+ }
+
+ protected void setMethod(HttpMethod method) {
+ this.method = method;
+ }
+
+ protected void setMethod(String method) {
+ this.method = HttpMethod.valueOf(method.toUpperCase());
+ }
+
+
+ @Override
+ public HttpMethod getMethod() {
+ return method;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/AbstractDeltaCloudResourceAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthClientException.java
(from rev 27584,
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/DeltaCloudAuthClientException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthClientException.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class DeltaCloudAuthClientException extends DeltaCloudClientException {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudAuthClientException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public DeltaCloudAuthClientException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public DeltaCloudAuthClientException(String message)
+ {
+ super(message);
+ }
+
+}
Deleted:
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 2010-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthException.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * 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;
-
-/**
- * @author Andre Dietisheim
- */
-public class DeltaCloudAuthException extends DeltaCloudClientException {
-
- private static final long serialVersionUID = 1L;
-
- public DeltaCloudAuthException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- public DeltaCloudAuthException(Throwable cause)
- {
- super(cause);
- }
-
- 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-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -125,9 +125,9 @@
String memory, String storage) throws DeltaCloudClientException;
/**
- * Creates a key for a given name on the deltacloud server and stores it
- * in the file at the given path. The file gets created if the file path
- * does not exist yet.
+ * Creates a key for a given name on the deltacloud server and stores it in
+ * the file at the given path. The file gets created if the file path does
+ * not exist yet.
*
* @param keyname
* the name of the key to retrieve from the server
@@ -138,7 +138,7 @@
*/
public void createKey(String keyname, String keystoreLocation) throws
DeltaCloudClientException;
- public String createKey(String keyname) throws DeltaCloudClientException;
+ public Key createKey(String keyname) throws DeltaCloudClientException;
/**
* Deletes the key with the given name on the deltacloud server
@@ -147,6 +147,12 @@
* @throws DeltaCloudClientException
*/
public void deleteKey(String keyname) throws DeltaCloudClientException;
-
+
public List<Key> listKeys() throws DeltaCloudClientException;
+
+ /**
+ * Returns a key with the given name if it is available on the server.
+ * Throws a DeltaCloudException if it is not available.
+ */
+ public Key listKey(String name) throws DeltaCloudClientException;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2010-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -61,6 +61,7 @@
import org.jboss.tools.deltacloud.core.client.request.ListImagesRequest;
import org.jboss.tools.deltacloud.core.client.request.ListInstanceRequest;
import org.jboss.tools.deltacloud.core.client.request.ListInstancesRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListKeyRequest;
import org.jboss.tools.deltacloud.core.client.request.ListKeysRequest;
import org.jboss.tools.deltacloud.core.client.request.ListRealmRequest;
import org.jboss.tools.deltacloud.core.client.request.ListRealmsRequest;
@@ -86,6 +87,8 @@
public static Logger logger = Logger.getLogger(DeltaCloudClientImpl.class);
+ private DocumentBuilder documentBuilder;
+
public static enum DeltaCloudServerType {
UNKNOWN, MOCK, EC2
}
@@ -94,19 +97,36 @@
private String username;
private String password;
- public DeltaCloudClientImpl(String url) throws MalformedURLException {
+ public DeltaCloudClientImpl(String url) throws MalformedURLException,
DeltaCloudClientException {
this(url, null, null);
}
- public DeltaCloudClientImpl(String url, String username, String password) throws
MalformedURLException {
+ public DeltaCloudClientImpl(String url, String username, String password) throws
DeltaCloudClientException {
logger.debug("Creating new Delta Cloud Client for Server: " + url);
- this.baseUrl = new URL(url);
+ this.baseUrl = createUrl(url);
this.username = username;
this.password = password;
+ documentBuilder = createDocumentBuilder();
}
+ private URL createUrl(String url) throws DeltaCloudClientException {
+ try {
+ return new URL(url);
+ } catch (MalformedURLException e) {
+ throw new DeltaCloudClientException(MessageFormat.format("Could not create url
for {0}", url), e);
+ }
+ }
+
+ private DocumentBuilder createDocumentBuilder() throws DeltaCloudClientException {
+ try {
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ throw new DeltaCloudClientException("Could not create document builder",
e);
+ }
+ }
+
protected String sendRequest(DeltaCloudRequest deltaCloudRequest) throws
DeltaCloudClientException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
@@ -133,7 +153,7 @@
if (HttpStatusCode.OK.isStatus(statusCode)) {
return;
} else if (HttpStatusCode.FORBIDDEN.isStatus(statusCode)) {
- throw new DeltaCloudAuthException(
+ throw new DeltaCloudAuthClientException(
MessageFormat.format("The server reported an authorization error
\"{0}\" on requesting \"{1}\"",
httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
} else if (HttpStatusCode.NOT_FOUND.isStatus(statusCode)) {
@@ -230,9 +250,7 @@
DeltaCloudServerType serverType = DeltaCloudServerType.UNKNOWN;
try {
String apiResponse = sendRequest(new TypeRequest(baseUrl));
- DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document document = db.parse(new InputSource(new StringReader(apiResponse)));
-
+ Document document = getDocument(apiResponse);
NodeList elements = document.getElementsByTagName(DOCUMENT_ELEMENT_API);
if (elements.getLength() > 0) {
Node n = elements.item(0);
@@ -250,7 +268,14 @@
@Override
public Instance createInstance(String imageId) throws DeltaCloudClientException {
- return buildInstance(sendRequest(new CreateInstanceRequest(baseUrl, imageId)));
+ try {
+ return buildInstance(sendRequest(new CreateInstanceRequest(baseUrl, imageId)));
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+
}
@Override
@@ -266,14 +291,26 @@
public Instance createInstance(String imageId, String profileId, String realmId, String
name, String keyname,
String memory, String storage) throws DeltaCloudClientException {
- return buildInstance(sendRequest(new CreateInstanceRequest(baseUrl, imageId, profileId,
realmId, name, keyname,
- memory, storage)));
+ try {
+ return buildInstance(sendRequest(new CreateInstanceRequest(baseUrl, imageId,
profileId, realmId, name,
+ keyname, memory, storage)));
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
}
@Override
public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException {
- return buildDeltaCloudObject(HardwareProfile.class, sendRequest(new
ListHardwareProfileRequest(baseUrl,
- profileId)));
+ try {
+ return buildDeltaCloudObject(HardwareProfile.class, sendRequest(new
ListHardwareProfileRequest(baseUrl,
+ profileId)));
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
}
@Override
@@ -301,7 +338,13 @@
public Instance listInstances(String instanceId) throws DeltaCloudClientException {
// return JAXB.unmarshal(new StringReader(sendRequest(new
// ListInstanceRequest(baseUrl, instanceId))), Instance.class);
- return buildInstance(sendRequest(new ListInstanceRequest(baseUrl, instanceId)));
+ try {
+ return buildInstance(sendRequest(new ListInstanceRequest(baseUrl, instanceId)));
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
}
@Override
@@ -314,21 +357,40 @@
return JAXB.unmarshal(new StringReader(sendRequest(new ListRealmRequest(baseUrl,
realmId))), Realm.class);
}
- public String createKey(String keyname) throws DeltaCloudClientException {
- return sendRequest(new CreateKeyRequest(baseUrl, keyname));
- }
-
- public void createKey(String keyname, String keyStoreLocation) throws
DeltaCloudClientException {
- String xml = createKey(keyname);
+ public Key createKey(String keyname) throws DeltaCloudClientException {
try {
- String key = trimKey(getKey(xml));
- File keyFile = createKeyFile(keyname, keyStoreLocation);
- storeKey(key, keyFile);
+ String response = sendRequest(new CreateKeyRequest(baseUrl, keyname));
+ Key key = new Key();
+ return updatekey(getDocument(response), key);
+ } catch (DeltaCloudClientException e) {
+ throw e;
} catch (Exception e) {
throw new DeltaCloudClientException(e);
}
}
+ private Key updatekey(Document document, Key key) throws Exception {
+ key.setId(getAttributeValues(document, "key", "id").get(0));
//$NON-NLS-1$ //$NON-NLS-2$
+ key.setUrl(getAttributeValues(document, "key", "href").get(0));
//$NON-NLS-1$ //$NON-NLS-2$
+ key.setState(getFirstElementTextValue(document, "state")); //$NON-NLS-1$
+ key.setFingerPrint(getFirstElementTextValue(document, "fingerprint"));
//$NON-NLS-1$
+ key.setPem(getFirstElementTextValue(document, "pem")); //$NON-NLS-1$
+ key.setActions(createKeyActions(key, document));
+ return key;
+ }
+
+ public void createKey(String keyname, String keyStoreLocation) throws
DeltaCloudClientException {
+ Key key = createKey(keyname);
+ throw new UnsupportedOperationException("not implemented yet");
+ // try {
+ // String key = trimKey(getKey(xml));
+ // File keyFile = createKeyFile(keyname, keyStoreLocation);
+ // storeKey(key, keyFile);
+ // } catch (Exception e) {
+ // throw new DeltaCloudClientException(e);
+ // }
+ }
+
private void storeKey(String key, File keyFile) throws IOException {
FileWriter w = new FileWriter(keyFile);
w.write(key);
@@ -351,10 +413,7 @@
}
private List<String> getKey(String xml) throws ParserConfigurationException,
SAXException, IOException {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document document = db.parse(new InputSource(new StringReader(xml)));
- List<String> keyText = getElementTextValues(document, PEM_FILE_SUFFIX);
//$NON-NLS-1$
+ List<String> keyText = getElementTextValues(getDocument(xml), PEM_FILE_SUFFIX);
//$NON-NLS-1$
return keyText;
}
@@ -375,60 +434,79 @@
public void deleteKey(String keyname) throws DeltaCloudClientException {
sendRequest(new DeleteKeyRequest(baseUrl, keyname));
}
-
+
public List<Key> listKeys() throws DeltaCloudClientException {
String xml = sendRequest(new ListKeysRequest(baseUrl));
- Key instance = JAXB.unmarshal(new StringReader(xml), Key.class);
+ Key key = JAXB.unmarshal(new StringReader(xml), Key.class);
throw new UnsupportedOperationException();
}
- private Instance updateInstance(String xml, Instance instance) throws
DeltaCloudClientException {
- try {
+ public Key listKey(String name) throws DeltaCloudClientException {
+ String xml = sendRequest(new ListKeyRequest(baseUrl, name));
+ Key key = JAXB.unmarshal(new StringReader(xml), Key.class);
+ return key;
+ }
- 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))); //$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(getElementTextValues(document, "state").get(0));
//$NON-NLS-1$
- getAuthentication(document, instance);
- instance.setActions(createInstanceActions(instance, document));
- instance.setPublicAddresses(new AddressList(getElementTextValues(document,
"public_addresses")));
- instance.setPrivateAddresses(new AddressList(getElementTextValues(document,
"private_addresses")));
- return instance;
- } catch (DeltaCloudClientException e) {
- throw e;
- } catch (Exception e) {
- DeltaCloudClientException newException = new
DeltaCloudClientException(e.getLocalizedMessage());
- throw newException;
- }
+ private Instance updateInstance(String xml, Instance instance) throws Exception {
+ Document document = getDocument(xml);
+ 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(getElementTextValues(document, "state").get(0));
//$NON-NLS-1$
+ getAuthentication(document, instance);
+ instance.setActions(createInstanceActions(instance, document));
+ instance.setPublicAddresses(new AddressList(getElementTextValues(document,
"public_addresses")));
+ instance.setPrivateAddresses(new AddressList(getElementTextValues(document,
"private_addresses")));
+ return instance;
}
- private Instance buildInstance(String xml) throws DeltaCloudClientException {
+ private Instance buildInstance(String xml) throws Exception {
Instance instance = JAXB.unmarshal(new StringReader(xml), Instance.class);
return updateInstance(xml, instance);
}
- private List<InstanceAction> createInstanceActions(final Instance instance,
Document document)
- throws DeltaCloudClientException {
+ private List<InstanceAction> createInstanceActions(final Instance instance,
Document document) throws Exception {
final List<InstanceAction> actions = new ArrayList<InstanceAction>();
forEachNode(document, "link", new INodeVisitor() {
@Override
public void visit(Node node) throws Exception {
- NamedNodeMap attributes = node.getAttributes();
- String name = getAttributeTextContent("rel", attributes, node);
- String url = getAttributeTextContent("href", attributes, node);
- String method = getAttributeTextContent("method", attributes, node);
- actions.add(new InstanceAction(name, url, method, instance));
+ InstanceAction action = new InstanceAction();
+ setActionProperties(action, node);
+ action.setInstance(instance);
+ actions.add(action);
}
});
return actions;
}
+ private List<KeyAction> createKeyActions(final Key key, Document document) throws
Exception {
+ final List<KeyAction> actions = new ArrayList<KeyAction>();
+ forEachNode(document, "link", new INodeVisitor() {
+
+ @Override
+ public void visit(Node node) throws Exception {
+ KeyAction action = new KeyAction();
+ setActionProperties(action, node);
+ action.setKey(key);
+ actions.add(action);
+ }
+ });
+ return actions;
+ }
+
+ private void setActionProperties(final AbstractDeltaCloudResourceAction action, Node
node)
+ throws DeltaCloudClientException {
+ NamedNodeMap attributes = node.getAttributes();
+ String name = getAttributeTextContent("rel", attributes, node);
+ action.setName(name);
+ String url = getAttributeTextContent("href", attributes, node);
+ action.setUrl(url);
+ String method = getAttributeTextContent("method", attributes, node);
+ action.setMethod(method);
+ }
+
private String getAttributeTextContent(String attributeName, NamedNodeMap namedNodeMap,
Node node)
throws DeltaCloudClientException {
Node attributeNode = namedNodeMap.getNamedItem(attributeName);
@@ -444,9 +522,7 @@
try {
HardwareProfile profile = JAXB.unmarshal(new StringReader(xml),
HardwareProfile.class);
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document document = db.parse(new InputSource(new StringReader(xml)));
+ Document document = getDocument(xml);
List<Node> nodes = getPropertyNodes(document, "hardware_profile");
//$NON-NLS-1$
@@ -492,14 +568,10 @@
return null;
}
- private void forEachNode(Document document, String tagName, INodeVisitor visitor) throws
DeltaCloudClientException {
+ private void forEachNode(Document document, String tagName, INodeVisitor visitor) throws
Exception {
NodeList elements = document.getElementsByTagName(tagName);
for (int i = 0; i < elements.getLength(); i++) {
- try {
- visitor.visit(elements.item(i));
- } catch (Exception e) {
- throw new DeltaCloudClientException(e.getMessage());
- }
+ visitor.visit(elements.item(i));
}
}
@@ -512,6 +584,14 @@
return values;
}
+ private String getFirstElementTextValue(Document document, String elementName) {
+ List<String> values = getElementTextValues(document, elementName);
+ if (values.size() == 0) {
+ return null;
+ }
+ return values.get(0);
+ }
+
private List<String> getElementTextValues(Document document, String elementName)
{
NodeList elements = document.getElementsByTagName(elementName);
ArrayList<String> values = new ArrayList<String>();
@@ -616,14 +696,12 @@
private Document getDocument(String response) throws ParserConfigurationException,
SAXException, IOException {
InputSource is = new InputSource(new StringReader(response));
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document document = db.parse(is);
+ Document document = documentBuilder.parse(is);
return document;
}
@SuppressWarnings("unchecked")
- private <T extends Object> T buildDeltaCloudObject(Class<T> clazz, String
node) throws DeltaCloudClientException {
+ private <T extends Object> T buildDeltaCloudObject(Class<T> clazz, String
node) throws Exception {
if (clazz.equals(Instance.class)) {
return (T) buildInstance(node);
} else if (clazz.equals(HardwareProfile.class)) {
@@ -646,6 +724,10 @@
throw new DeltaCloudClientException(MessageFormat.format(
"Could not perform action {0} on instance {1}", action.getName(),
action.getInstance()
.getName()), e);
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
}
return true;
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IDeltaCloudResourceAction.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IDeltaCloudResourceAction.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IDeltaCloudResourceAction.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.client;
+
+import org.jboss.tools.deltacloud.core.client.request.DeltaCloudRequest.HttpMethod;
+
+/**
+ * @author André Dietisheim
+ */
+public interface IDeltaCloudResourceAction {
+
+ public static final String DESTROY = "destroy";
+
+ public String getName();
+
+ public String getUrl();
+
+ public HttpMethod getMethod();
+
+}
\ No newline at end of file
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IDeltaCloudResourceAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IInstanceAction.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IInstanceAction.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IInstanceAction.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * 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.client;
+
+public interface IInstanceAction extends IDeltaCloudResourceAction {
+
+ public static final String START = "start";
+ public static final String STOP = "stop";
+ public static final String REBOOT = "reboot";
+
+ public Instance getInstance();
+
+}
\ No newline at end of file
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IInstanceAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IKeyAction.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IKeyAction.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IKeyAction.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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.client;
+
+/**
+ * @author André Dietisheim
+ */
+public interface IKeyAction extends IDeltaCloudResourceAction {
+
+ public Key getKey();
+
+}
\ No newline at end of file
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/IKeyAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -185,15 +185,15 @@
}
public boolean canStart() {
- return getAction(InstanceAction.START) != null;
+ return getAction(IInstanceAction.START) != null;
}
public boolean canStop() {
- return getAction(InstanceAction.STOP) != null;
+ return getAction(IInstanceAction.STOP) != null;
}
public boolean canReboot() {
- return getAction(InstanceAction.REBOOT) != null;
+ return getAction(IInstanceAction.REBOOT) != null;
}
public boolean canDestroy() {
@@ -213,11 +213,11 @@
}
public boolean start(DeltaCloudClient client) throws DeltaCloudClientException {
- return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(InstanceAction.START));
+ return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(IInstanceAction.START));
}
public boolean stop(DeltaCloudClient client) throws DeltaCloudClientException {
- return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(InstanceAction.STOP));
+ return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(IInstanceAction.STOP));
}
public boolean destroy(DeltaCloudClient client) throws DeltaCloudClientException {
@@ -225,7 +225,7 @@
}
public boolean reboot(DeltaCloudClient client) throws DeltaCloudClientException {
- return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(InstanceAction.REBOOT));
+ return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(IInstanceAction.REBOOT));
}
@Override
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java 2010-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core.client;
-import org.jboss.tools.deltacloud.core.client.request.DeltaCloudRequest.HttpMethod;
/**
* An action that is executable on an instance
@@ -21,47 +20,30 @@
* @see DeltaCloudClient#performInstanceAction(String, String);
*
*/
-public class InstanceAction {
+public class InstanceAction extends AbstractDeltaCloudResourceAction implements
IInstanceAction {
- public static final String START = "start";
- public static final String STOP = "stop";
- public static final String DESTROY = "destroy";
- public static final String REBOOT = "reboot";
-
- private String name;
- private String url;
- private HttpMethod method;
private Instance instance;
- protected InstanceAction(String name, String url, String method, Instance instance) {
- this(name, url, HttpMethod.valueOf(method.toUpperCase()), instance);
+ protected InstanceAction() {
+ super();
}
- protected InstanceAction(String name, String url, HttpMethod method, Instance instance)
{
- this.name = name;
- this.url = url;
- this.method = method;
+ protected InstanceAction(String name, String url, String method, Instance instance) {
+ super(name, url, method);
this.instance = instance;
}
- public String getName() {
- return name;
+ protected void setInstance(Instance instance) {
+ this.instance = instance;
}
- public String getUrl() {
- return url;
+ @Override
+ public Instance getInstance() {
+ return instance;
}
- public HttpMethod getMethod() {
- return method;
- }
-
@Override
public String toString() {
- return "InstanceAction [name=" + name + ", url=" + url + ",
method=" + method + "]";
+ return "InstanceAction [name=" + getName() + ", url=" + getUrl() +
", method=" + getMethod() + "]";
}
-
- public Instance getInstance() {
- return instance;
- }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java 2010-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -10,7 +10,9 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.core.client;
-import javax.xml.bind.annotation.XmlElement;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
/**
* @author Andre Dietisheim
@@ -19,20 +21,63 @@
private static final long serialVersionUID = 1L;
- public static enum InstanceState {
- RUNNING, STOPPED, PENDING, TERMINATED, BOGUS
- };
+ private URL url;
+ private String id;
+ private String pem;
+ private String fingerPrint;
+ private String state;
+ private List<KeyAction> actions;
- @XmlElement
- private String name;
+ public String getId() {
+ return id;
+ }
- public String getName() {
- return name;
+ protected void setUrl(String url) throws MalformedURLException {
+ this.url = new URL(url);
}
- @SuppressWarnings("unused")
- private void setName(String name) {
- this.name = name;
+ protected void setUrl(URL url) {
+ this.url = url;
}
-
+
+ protected void setId(String id) {
+ this.id = id;
+ }
+
+ protected void setPem(String pem) {
+ this.pem = pem;
+ }
+
+ protected void setFingerPrint(String fingerPrint) {
+ this.fingerPrint = fingerPrint;
+ }
+
+ protected void setState(String state) {
+ this.state = state;
+ }
+
+ protected void setActions(List<KeyAction> actions) {
+ this.actions = actions;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public String getFingerPrint() {
+ return fingerPrint;
+ }
+
+ public String getPem() {
+ return pem;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public List<KeyAction> getActions() {
+ return actions;
+ }
+
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyAction.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyAction.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyAction.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -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.client;
+
+/**
+ * An action that is executable on a deltacloud key
+ *
+ * @author André Dietisheim
+ */
+public class KeyAction extends AbstractDeltaCloudResourceAction implements IKeyAction {
+
+ private Key key;
+
+ protected KeyAction() {
+ }
+
+ protected KeyAction(String name, Key key, String url, String method) {
+ super(name, url, method);
+ this.key = key;
+ }
+
+ protected void setKey(Key key) {
+ this.key = key;
+ }
+
+ @Override
+ public Key getKey() {
+ return key;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyActionXmlAdapter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyActionXmlAdapter.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyActionXmlAdapter.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -0,0 +1,18 @@
+package org.jboss.tools.deltacloud.core.client;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+public class KeyActionXmlAdapter extends XmlAdapter<String, KeyAction> {
+
+ @Override
+ public KeyAction unmarshal(String v) throws Exception {
+ return null;
+ }
+
+ @Override
+ public String marshal(KeyAction v) throws Exception {
+ return null;
+ }
+
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/KeyActionXmlAdapter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java 2010-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -14,7 +14,6 @@
import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
-
/**
* Creates a key on the deltacloud server
*
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.client.request;
+
+import java.net.URL;
+
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+
+/**
+ * List a key with a given name that is available on the deltacloud server
+ *
+ * @author André Dietisheim
+ */
+public class ListKeyRequest extends AbstractDeltaCloudRequest {
+
+ private String name;
+
+ public ListKeyRequest(URL baseUrl, String name) {
+ super(baseUrl, HttpMethod.GET);
+ this.name = name;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("keys").path(name).toString();
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java 2010-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -10,15 +10,19 @@
******************************************************************************/
package org.jboss.tools.internal.deltacloud.test.core.client;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
+import org.jboss.tools.deltacloud.core.client.Key;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -44,15 +48,38 @@
testSetup.tearDown();
}
+ /**
+ * checks if the client throws a {@link DeltaCloudNotFoundClientException} if an
+ * unknown key is requested.
+ *
+ * @throws DeltaCloudClientException
+ */
+ @Ignore
+ @Test(expected = DeltaCloudNotFoundClientException.class)
+ public void listUnknownKeyThrowsException() throws DeltaCloudClientException {
+ String keyName = String.valueOf(System.currentTimeMillis());
+ testSetup.getClient().listKey(keyName);
+ }
+
@Test
public void canCreateKey() throws DeltaCloudClientException {
- String key = testSetup.getClient().createKey("test");
+ String keyName = "test" + System.currentTimeMillis();
+ Key key = testSetup.getClient().createKey(keyName);
assertNotNull(key);
+ assertEquals(keyName, key.getId());
+ }
+ @Ignore
+ @Test
+ public void canListKey() throws DeltaCloudClientException {
+ String keyName = String.valueOf(System.currentTimeMillis());
+ Key createdKey = testSetup.getClient().createKey(keyName);
+ Key listedKey = testSetup.getClient().listKey(keyName);
+ assertEquals(createdKey.getId(), listedKey.getId());
}
-
+
@Test
public void canListKeys() {
-
+
}
}
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java 2010-12-17
16:43:44 UTC (rev 27592)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java 2010-12-17
19:10:10 UTC (rev 27593)
@@ -57,22 +57,27 @@
assertEquals(DeltaCloudClientImpl.DeltaCloudServerType.MOCK,
testSetup.getClient().getServerType());
}
-/**
+ /**
*
* #getServerType reports {@link DeltaCloudClient.DeltaCloudType#UNKNOWN) if it queries
a fake server that responds with a unknown answer.
*
* @throws IOException
* Signals that an I/O exception has occurred.
+ * @throws DeltaCloudClientException
*/
@Test
- public void reportsUnknownUrl() throws IOException {
- ServerFake serverFake = new ServerFake(new
URL(MockIntegrationTestContext.SERVERFAKE_URL).getPort(),
- "<dummy></dummy>");
+ public void reportsUnknownUrl() throws IOException, DeltaCloudClientException {
+ ServerFake serverFake =
+ new ServerFake(
+ new URL(MockIntegrationTestContext.SERVERFAKE_URL).getPort(),
+ "<dummy></dummy>");
serverFake.start();
try {
- assertEquals(DeltaCloudClientImpl.DeltaCloudServerType.UNKNOWN, new
DeltaCloudClientImpl(
- MockIntegrationTestContext.SERVERFAKE_URL,
MockIntegrationTestContext.DELTACLOUD_USER,
- MockIntegrationTestContext.DELTACLOUD_PASSWORD).getServerType());
+ assertEquals(
+ DeltaCloudClientImpl.DeltaCloudServerType.UNKNOWN,
+ new DeltaCloudClientImpl(
+ MockIntegrationTestContext.SERVERFAKE_URL,
MockIntegrationTestContext.DELTACLOUD_USER,
+ MockIntegrationTestContext.DELTACLOUD_PASSWORD).getServerType());
} finally {
serverFake.stop();
}
@@ -101,7 +106,8 @@
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.GET;
- } }
+ }
+ }
);
return Collections.emptyList();
}