Author: adietish
Date: 2010-11-04 09:37:05 -0400 (Thu, 04 Nov 2010)
New Revision: 26252
Added:
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/DeltaCloudNotFoundClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/API.java
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/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/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.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudTypeValidator.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/context/MockIntegrationTestContext.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ImageMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.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/ProfileMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/RealmMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java
Log:
[JBIDE-7484] removed instance related methods from client, unified funtionality in
#performAction and offered additional methods on Instance (#start, #stop, #destroy,
#reboot). Furthermore update instance upon action responses from server.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-11-04 13:35:05
UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-11-04 13:37:05
UTC (rev 26252)
@@ -1,3 +1,12 @@
+2010-11-04 André Dietisheim <adietish(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java:
+ * src/org/jboss/tools/deltacloud/core/client/InstanceAction.java:
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java:
+ * src/org/jboss/tools/deltacloud/core/client/Instance.java (start), (stop), (destroy),
(reboot):
+ [JBIDE-7484] removed instance related methods from client, unified funtionality in
#performAction and offered additional methods on
+ Instance (#start, #stop, #destroy, #reboot). Furthermore update instance upon action
responses from server.
+
2010-10-29 André Dietisheim <adietish(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/HttpStatusCode.java: extracted and put in a
2 enums:
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-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -25,9 +25,9 @@
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
import org.eclipse.equinox.security.storage.StorageException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudAuthException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundException;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
import org.jboss.tools.deltacloud.core.client.HardwareProfile;
import org.jboss.tools.deltacloud.core.client.Image;
import org.jboss.tools.deltacloud.core.client.Instance;
@@ -44,7 +44,7 @@
private String type;
private String lastKeyname = "";
private String lastImageId = "";
- private DeltaCloudClient client;
+ private DeltaCloudClientImpl client;
private ArrayList<DeltaCloudInstance> instances;
private ArrayList<DeltaCloudImage> images;
private IImageFilter imageFilter;
@@ -69,7 +69,7 @@
public DeltaCloud(String name, String url, String username, String passwd,
String type, boolean persistent,
String imageFilterRules, String instanceFilterRules) throws MalformedURLException {
- this.client = new DeltaCloudClient(url, username, passwd); //$NON-NLS-1$
+ this.client = new DeltaCloudClientImpl(url, username, passwd); //$NON-NLS-1$
this.url = url;
this.name = name;
this.username = username;
@@ -93,7 +93,7 @@
public void editCloud(String name, String url, String username, String passwd, String
type)
throws MalformedURLException {
- this.client = new DeltaCloudClient(url, username, passwd); //$NON-NLS-1$
+ this.client = new DeltaCloudClientImpl(url, username, passwd); //$NON-NLS-1$
this.url = url;
this.name = name;
this.username = username;
@@ -288,15 +288,10 @@
public DeltaCloudInstance[] destroyInstance(String instanceId) {
try {
- client.destroyInstance(instanceId);
- for (int i = 0; i < instances.size(); ++i) {
- DeltaCloudInstance instance = instances.get(i);
- if (instance.getId().equals(instanceId)) {
- instances.remove(i);
- break;
- }
- }
- } catch (DeltaCloudClientException e) {
+ DeltaCloudInstance instance = getInstance(instanceId);
+ performInstanceAction(instance, DeltaCloudInstance.DESTROY);
+ instances.remove(instance);
+ } catch (DeltaCloudException e) {
return null;
}
DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
@@ -367,14 +362,31 @@
return retVal;
}
- public boolean performInstanceAction(String instanceId, String action) throws
DeltaCloudException {
+ public boolean performInstanceAction(String instanceId, String actionId) throws
DeltaCloudException {
+ return performInstanceAction(getInstance(instanceId), actionId);
+ }
+
+ protected boolean performInstanceAction(DeltaCloudInstance instance, String actionId)
throws DeltaCloudException {
try {
- return client.performInstanceAction(instanceId, action);
+ if (instance == null) {
+ return false;
+ }
+ return instance.performInstanceAction(actionId, client);
+
} catch (DeltaCloudClientException e) {
throw new DeltaCloudException(e);
}
}
+ private DeltaCloudInstance getInstance(String instanceId) {
+ for (DeltaCloudInstance instance : instances) {
+ if (instance.getId().equals(instanceId)) {
+ return instance;
+ }
+ }
+ return null;
+ }
+
public DeltaCloudHardwareProfile[] getProfiles() {
ArrayList<DeltaCloudHardwareProfile> profiles = new
ArrayList<DeltaCloudHardwareProfile>();
try {
@@ -437,11 +449,11 @@
try {
client.listInstances(instanceId);
return true;
- } catch( DeltaCloudNotFoundException e) {
+ } catch (DeltaCloudNotFoundClientException 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/DeltaCloudInstance.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -12,6 +12,8 @@
import java.util.List;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.Instance;
import org.jboss.tools.deltacloud.core.client.InstanceAction;
@@ -90,4 +92,12 @@
return hostNames.get(0);
return null;
}
+
+ protected boolean performInstanceAction(String actionId, DeltaCloudClientImpl client)
throws DeltaCloudClientException {
+ InstanceAction action = instance.getAction(actionId);
+ if (action == null) {
+ return false;
+ }
+ return client.performInstanceAction(action);
+ }
}
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/API.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/API.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/API.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -1,119 +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;
-
-import java.util.List;
-
-public interface API
-{
- /**
- * Returns a list of Delta Cloud Realms
- * @return List of Delta Cloud Realms
- * @throws DeltaCloudClientException
- */
- public List<Realm> listRealms() throws DeltaCloudClientException;
-
- /**
- * Returns a single Delta Cloud Realm given its ID
- * @param realmId
- * @return Delta Cloud Realm
- * @throws DeltaCloudClientException
- */
- public Realm listRealms(String realmId) throws DeltaCloudClientException;
-
- public List<HardwareProfile> listProfiles() throws DeltaCloudClientException;
-
- /**
- * Returns a Delta Cloud Flavors
- * @param flavorId
- * @return Delta Cloud Flavor
- * @throws DeltaCloudClientException
- */
- public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException;
-
- /**
- * Returns a List of Delta Cloud Images
- * @return List of Delta Cloud Images
- * @throws DeltaCloudClientException
- */
- public List<Image> listImages() throws DeltaCloudClientException;
-
- /**
- * Returns a Delta Cloud Image given its ID
- * @param imageId
- * @return
- * @throws DeltaCloudClientException
- */
- public Image listImages(String imageId) throws DeltaCloudClientException;
-
- /**
- * Returns a list of all Instances from the Delta Cloud Provider
- * @return
- * @throws DeltaCloudClientException
- */
- public List<Instance> listInstances() throws DeltaCloudClientException;
-
- /**
- * Returns an Instance from the Delta Cloud Provider given on the Instances ID
- * @param instanceId
- * @return
- * @throws DeltaCloudClientException
- */
- public Instance listInstances(String instanceId) throws DeltaCloudClientException;
-
- /**
- * Creates a new Delta Cloud Instance based on the Image specified by the Image ID.
Default parameters are used for the
- * Flavor, Realm and Name. These are specified by the Delta Cloud Provider
- * @param imageId
- * @return The newly created Delta Cloud Instance
- * @throws DeltaCloudClientException
- */
- public Instance createInstance(String imageId) throws DeltaCloudClientException;
-
- /**
- * Creates a new Delta Cloud Instance, the instance will be based on the Image specified
by the instance ID. It will be of
- * type flavor and in the location realm
- * @param imageId
- * @param flavor
- * @param realm
- * @param name
- * @return
- * @throws DeltaCloudClientException
- */
- public Instance createInstance(String imageId, String flavor, String realm, String name)
throws DeltaCloudClientException;
-
- /**
- * Starts a previously stopped Instance given the Instance ID
- * @param instanceId
- * @throws DeltaCloudClientException
- */
- public void startInstance(String instanceId) throws DeltaCloudClientException;
-
- /**
- * Reboots a running Instance
- * @param instanceId
- * @throws DeltaCloudClientException
- */
- public void rebootInstance(String instanceId) throws DeltaCloudClientException;
-
- /** Shuts down a running instance
- * @param instanceId
- * @throws DeltaCloudClientException
- */
- public void shutdownInstance(String instanceId) throws DeltaCloudClientException;
-
- /** Destroys a previously Stopped Instance
- *
- * @param instanceId
- * @throws DeltaCloudClientException
- */
- public void destroyInstance(String instanceId) throws DeltaCloudClientException;
-}
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-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -10,706 +10,107 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.core.client;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import javax.xml.bind.JAXB;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.log4j.Logger;
-import org.eclipse.core.runtime.Path;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
+public interface DeltaCloudClient {
-public class DeltaCloudClient implements API {
+ /**
+ * Returns the server type this client is connected to.
+ *
+ * @return the server type
+ *
+ * @see DeltaCloudServerType
+ */
+ public DeltaCloudServerType getServerType();
- private static final String BASEURL_API = "/api";
- private static final String PEM_FILE_SUFFIX = "pem";
- private static final String DOCUMENT_ELEMENT_DRIVER = "driver";
- private static final String DOCUMENT_ELEMENT_API = "api";
+ /**
+ * Returns a list of Delta Cloud Realms
+ *
+ * @return List of Delta Cloud Realms
+ * @throws DeltaCloudClientException
+ */
+ public List<Realm> listRealms() throws DeltaCloudClientException;
- public static Logger logger = Logger.getLogger(DeltaCloudClient.class);
+ /**
+ * Returns a single Delta Cloud Realm given its ID
+ *
+ * @param realmId
+ * @return Delta Cloud Realm
+ * @throws DeltaCloudClientException
+ */
+ public Realm listRealms(String realmId) throws DeltaCloudClientException;
- public static enum DeltaCloudType {
- UNKNOWN, MOCK, EC2
- }
+ public List<HardwareProfile> listProfiles() throws DeltaCloudClientException;
- private static enum DCNS {
- TYPE {
- public String getResourceName() {
- return "";
- }
- }
- ,
- INSTANCES
- , REALMS
- , IMAGES
- , HARDWARE_PROFILES
- , KEYS
- , START
- , STOP
- , REBOOT
- , DESTROY;
+ /**
+ * Returns a Delta Cloud Flavors
+ *
+ * @param flavorId
+ * @return Delta Cloud Flavor
+ * @throws DeltaCloudClientException
+ */
+ public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException;
- @Override
- public String toString() {
- return "/" + getResourceName();
- }
-
- public String getResourceName() {
- return name().toLowerCase();
- }
- }
-
- private URL baseUrl;
- private String username;
- private String password;
-
- public DeltaCloudClient(String url) throws MalformedURLException {
- this(url, null, null);
- }
-
- public DeltaCloudClient(String url, String username, String password) throws
MalformedURLException {
-
- logger.debug("Creating new Delta Cloud Client for Server: " + url);
-
- this.baseUrl = new URL(url + BASEURL_API);
- this.username = username;
- this.password = password;
- }
-
- private String sendRequest(String path, HttpMethod httpMethod) throws
DeltaCloudClientException {
- DefaultHttpClient httpClient = addCredentials(new DefaultHttpClient());
- String requestUrl = baseUrl.toString() + path;
- logger.debug("Sending Request to: " + requestUrl);
-
- try {
- HttpUriRequest request = getRequest(httpMethod, requestUrl);
- HttpResponse httpResponse = httpClient.execute(request);
- throwOnHttpErrors(requestUrl, httpResponse);
- return getResponse(httpResponse.getEntity());
- } catch (DeltaCloudClientException e) {
- throw e;
- } catch (IOException e) {
- logger.error("Error processing request to: " + requestUrl, e);
- throw new DeltaCloudClientException("Error processing request to: " +
requestUrl, e);
- } catch (Exception e) {
- throw new DeltaCloudClientException(e.getMessage());
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
- }
-
- private void throwOnHttpErrors(String requestUrl, HttpResponse httpResponse) throws
DeltaCloudClientException {
- int statusCode = httpResponse.getStatusLine().getStatusCode();
- if (HttpStatusCode.OK.isStatus(statusCode)) {
- return;
- } else if (HttpStatusCode.FORBIDDEN.isStatus(statusCode)) {
- throw new DeltaCloudAuthException(
- MessageFormat.format("The server reported an authorization error
\"{0}\" on requesting \"{1}\"",
- httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
- } else if (HttpStatusCode.NOT_FOUND.isStatus(statusCode)) {
- throw new DeltaCloudNotFoundException(
- MessageFormat.format("The server could not find the resource
\"{0}\"", requestUrl));
- } else if (HttpStatusRange.CLIENT_ERROR.isInRange(statusCode)
- || HttpStatusRange.SERVER_ERROR.isInRange(statusCode)) {
- throw new DeltaCloudClientException(
- MessageFormat.format("The server reported an error \"{0}\" on
requesting \"{1}\"",
- httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
- }
- }
-
- private String getResponse(HttpEntity entity) throws IOException,
- DeltaCloudClientException {
- if (entity == null) {
- return null;
- }
- String xml = readInputStreamToString(entity.getContent());
- logger.debug("Response\n" + xml);
- return xml;
- }
-
/**
- * Returns a request instance for the given request type and url.
+ * Returns a List of Delta Cloud Images
*
- * @param httpMethod
- * the request type to use
- * @param requestUrl
- * the requested url
- * @return the request instance
+ * @return List of Delta Cloud Images
+ * @throws DeltaCloudClientException
*/
- protected HttpUriRequest getRequest(HttpMethod httpMethod, String requestUrl) {
- HttpUriRequest request = null;
- switch (httpMethod) {
- case POST:
- request = new HttpPost(requestUrl);
- break;
- case DELETE:
- request = new HttpDelete(requestUrl);
- break;
- case GET:
- default:
- request = new HttpGet(requestUrl);
- }
- request.setHeader("Accept", "application/xml;q=1");
- return request;
- }
+ public List<Image> listImages() throws DeltaCloudClientException;
/**
- * Adds the credentials to the given http client.
+ * Returns a Delta Cloud Image given its ID
*
- * @param httpClient
- * the http client
- * @return the default http client
+ * @param imageId
+ * @return
+ * @throws DeltaCloudClientException
*/
- private DefaultHttpClient addCredentials(DefaultHttpClient httpClient) {
- if (username != null && password != null) {
- httpClient.getCredentialsProvider().setCredentials(
- new AuthScope(baseUrl.getHost(), baseUrl.getPort()),
- new UsernamePasswordCredentials(username, password));
- }
- return httpClient;
- }
+ public Image listImages(String imageId) throws DeltaCloudClientException;
- private static String readInputStreamToString(InputStream is) throws
DeltaCloudClientException {
- try {
- try {
- if (is != null) {
- StringBuilder sb = new StringBuilder();
- String line;
-
- BufferedReader reader = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
- while ((line = reader.readLine()) != null) {
- sb.append(line).append("\n");
- }
- return sb.toString();
- }
- } finally {
- is.close();
- }
- } catch (Exception e) {
- throw new DeltaCloudClientException("Error converting Response to String",
e);
- }
- return "";
- }
-
- public DeltaCloudType getServerType() {
- DeltaCloudType serverType = DeltaCloudType.UNKNOWN;
- try {
- String query = "?format=xml";
- String apiResponse = sendRequest(DCNS.TYPE + query, HttpMethod.GET);
- DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document document = db.parse(new InputSource(new StringReader(apiResponse)));
-
- NodeList elements = document.getElementsByTagName(DOCUMENT_ELEMENT_API);
- if (elements.getLength() > 0) {
- Node n = elements.item(0);
- Node driver = n.getAttributes().getNamedItem(DOCUMENT_ELEMENT_DRIVER);
- if (driver != null) {
- String driverValue = driver.getNodeValue();
- serverType = DeltaCloudType.valueOf(driverValue.toUpperCase());
- }
- }
- } catch (Exception e) {
- serverType = DeltaCloudType.UNKNOWN;
- }
- return serverType;
- }
-
- @Override
- public Instance createInstance(String imageId) throws DeltaCloudClientException {
- String query = "?image_id=" + imageId;
- return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
- }
-
- @Override
- public Instance createInstance(String imageId, String profileId, String realmId, String
name)
- throws DeltaCloudClientException {
- return createInstance(imageId, profileId, realmId, name, null, null, null);
- }
-
- public Instance createInstance(String imageId, String profileId, String realmId, String
name, String memory,
- String storage) throws DeltaCloudClientException {
- return createInstance(imageId, profileId, realmId, name, null, memory, storage);
- }
-
- public Instance createInstance(String imageId, String profileId, String realmId, String
name, String keyname,
- String memory, String storage) throws DeltaCloudClientException {
- String query = "?image_id=" + imageId + "&hwp_id=" + profileId
+ "&realm_id=" + realmId + "&name=" + name;
- if (memory != null)
- query += "&hwp_memory=" + memory;
- if (storage != null)
- query += "&hwp_storage=" + storage;
- if (keyname != null)
- query += "&keyname=" + keyname;
- query += "&commit=create";
- return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
- }
-
- @Override
- public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException {
- String request = DCNS.HARDWARE_PROFILES + "/" + profileId;
- return buildDeltaCloudObject(HardwareProfile.class, sendRequest(request,
HttpMethod.GET));
- }
-
- @Override
- public List<HardwareProfile> listProfiles() throws DeltaCloudClientException {
- return listDeltaCloudObjects(HardwareProfile.class, DCNS.HARDWARE_PROFILES.toString(),
"hardware_profile");
- }
-
- @Override
- public List<Image> listImages() throws DeltaCloudClientException {
- return listDeltaCloudObjects(Image.class, DCNS.IMAGES.toString(), "image");
- }
-
- @Override
- public Image listImages(String imageId) throws DeltaCloudClientException {
- return JAXB.unmarshal(new StringReader(sendRequest(DCNS.IMAGES + "/" +
imageId, HttpMethod.GET)), Image.class);
- }
-
- @Override
- public List<Instance> listInstances() throws DeltaCloudClientException {
- return listDeltaCloudObjects(Instance.class, DCNS.INSTANCES.toString(),
"instance");
- }
-
- @Override
- public Instance listInstances(String instanceId) throws DeltaCloudClientException {
- return buildInstance(sendRequest(DCNS.INSTANCES + "/" + instanceId,
HttpMethod.GET));
- }
-
- @Override
- public List<Realm> listRealms() throws DeltaCloudClientException {
- return listDeltaCloudObjects(Realm.class, DCNS.REALMS.toString(), "realm");
- }
-
- @Override
- public Realm listRealms(String realmId) throws DeltaCloudClientException {
- return JAXB.unmarshal(new StringReader(sendRequest(DCNS.REALMS + "/" +
realmId, HttpMethod.GET)), Realm.class);
- }
-
/**
- * Retrieves 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.
+ * Returns a list of all Instances from the Delta Cloud Provider
*
- * @param keyname
- * the name of the key to retrieve from the server
- * @param keyStoreLocation
- * the path to the file to store the key in
+ * @return
* @throws DeltaCloudClientException
- * the delta cloud client exception
*/
- public void createKey(String keyname, String keyStoreLocation) throws
DeltaCloudClientException {
- String xml = sendRequest(DCNS.KEYS + "?name=" + keyname, HttpMethod.POST);
- try {
- String key = trimKey(getKey(xml));
- File keyFile = createKeyFile(keyname, keyStoreLocation);
- storeKey(key, keyFile);
- } catch (Exception e) {
- throw new DeltaCloudClientException(e);
- }
- }
+ public List<Instance> listInstances() throws DeltaCloudClientException;
- private void storeKey(String key, File keyFile) throws IOException {
- FileWriter w = new FileWriter(keyFile);
- w.write(key);
- w.close();
- }
-
- private String trimKey(List<String> keyText) throws IOException {
- StringBuffer sb = new StringBuffer();
- String line;
- BufferedReader reader = new BufferedReader(new StringReader(keyText.get(0)));
- while ((line = reader.readLine()) != null) {
- // We must trim off the white-space from the xml
- // Complete white-space lines are to be ignored.
- String trimmedLine = line.trim();
- if (trimmedLine.length() > 0) {
- sb.append(trimmedLine).append("\n");
- }
- }
- return sb.toString();
- }
-
- 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 = getElementText(document, PEM_FILE_SUFFIX); //$NON-NLS-1$
- return keyText;
- }
-
- private File createKeyFile(String keyname, String keyStoreLocation) throws IOException
{
- File keyFile = Path.fromOSString(keyStoreLocation).append(keyname + "." +
PEM_FILE_SUFFIX).toFile(); //$NON-NLS-1$
- if (!keyFile.exists()) {
- keyFile.createNewFile();
- }
- keyFile.setReadable(false, false);
- keyFile.setWritable(true, true);
- keyFile.setReadable(true, true);
- return keyFile;
- }
-
- public void deleteKey(String keyname) throws DeltaCloudClientException {
- sendRequest(DCNS.KEYS + "/" + keyname, HttpMethod.DELETE);
- }
-
- @Override
- public void rebootInstance(String instanceId) throws DeltaCloudClientException {
- /**
- * shouldn't that be PUT? changing resource states == PUT!
- */
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.REBOOT,
HttpMethod.GET);
- }
-
- @Override
- public void shutdownInstance(String instanceId) throws DeltaCloudClientException {
- /**
- * shouldn't that be PUT? changing resource states == PUT!
- */
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.STOP, HttpMethod.POST);
- }
-
- @Override
- public void startInstance(String instanceId) throws DeltaCloudClientException {
- /**
- * shouldn't that be PUT? changing resource states == PUT!
- */
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.START,
HttpMethod.POST);
- }
-
- @Override
- public void destroyInstance(String instanceId) throws DeltaCloudClientException {
- sendRequest(DCNS.INSTANCES + "/" + instanceId, HttpMethod.DELETE);
- }
-
- private Instance buildInstance(String xml) throws DeltaCloudClientException {
- try {
- Instance instance = JAXB.unmarshal(new StringReader(xml), Instance.class);
-
- 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(getElementText(document, "state").get(0)); //$NON-NLS-1$
- getAuthentication(document, instance);
- instance.setActions(createInstanceActions(instance, document));
-
- return instance;
- } catch (DeltaCloudClientException e) {
- throw e;
- } catch (Exception e) {
- DeltaCloudClientException newException = new
DeltaCloudClientException(e.getLocalizedMessage());
- throw newException;
- }
- }
-
- private List<InstanceAction> createInstanceActions(Instance instance, Document
document)
- throws DeltaCloudClientException {
- 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, stripBaseUrl(url), method));
- }
- });
- return actions;
- }
-
- private String stripBaseUrl(String url) throws DeltaCloudClientException {
- String baseUrlString = baseUrl.toString();
- if (url.indexOf(baseUrlString) != 0) {
- throw new DeltaCloudClientException(MessageFormat.format(
- "Resource at {0} is not child resource of root resource at {1}", url,
baseUrl));
- }
-
- return url.substring(baseUrlString.length());
- }
-
- private String getAttributeTextContent(String attributeName, NamedNodeMap namedNodeMap,
Node node)
- throws DeltaCloudClientException {
- Node attributeNode = namedNodeMap.getNamedItem(attributeName);
- if (attributeNode == null) {
- throw new DeltaCloudClientException(MessageFormat.format("Could not find
attribute {0} in node {1}",
- attributeName, node.getNodeName()));
- }
-
- return attributeNode.getTextContent();
- }
-
- private HardwareProfile buildHardwareProfile(String xml) throws
DeltaCloudClientException {
- 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)));
-
- 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());
//$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")) { //$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")) { //$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")) { //$NON-NLS-1$
- NodeList enumChildren = child.getChildNodes();
- for (int j = 0; j < enumChildren.getLength(); ++j) {
- Node enumChild = enumChildren.item(j);
- if (enumChild.getNodeName().equals("entry")) {
- enums.add(enumChild.getAttributes().getNamedItem("value").getNodeValue());
//$NON-NLS-1$
- }
- }
- }
- }
- p.setEnums(enums);
- }
- profile.getProperties().add(p);
- }
- return profile;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private void forEachNode(Document document, String tagName, INodeVisitor visitor) throws
DeltaCloudClientException {
- 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());
- }
- }
- }
-
- private List<String> getAttributeValues(Document document, String elementName,
String attributeName) {
- NodeList elements = document.getElementsByTagName(elementName);
- ArrayList<String> values = new ArrayList<String>();
- for (int i = 0; i < elements.getLength(); i++) {
- values.add(elements.item(i).getAttributes().getNamedItem(attributeName).getTextContent());
- }
- return values;
- }
-
- private List<String> getElementText(Document document, String elementName) {
- NodeList elements = document.getElementsByTagName(elementName);
- ArrayList<String> values = new ArrayList<String>();
- for (int i = 0; i < elements.getLength(); i++) {
- values.add(elements.item(i).getTextContent());
- }
- return values;
- }
-
- private List<Node> getPropertyNodes(Document document, String elementName) {
- NodeList elements = document.getElementsByTagName(elementName);
- ArrayList<Node> values = new ArrayList<Node>();
- for (int i = 0; i < elements.getLength(); i++) {
- NodeList children = elements.item(i).getChildNodes();
- for (int j = 0; j < children.getLength(); ++j) {
- Node child = children.item(j);
- if (child.getNodeName().equals("property")) { //$NON-NLS-1$
- values.add(child);
- }
- }
- }
- return values;
- }
-
- private void getAuthentication(Document document, Instance instance) {
- NodeList elements = document.getElementsByTagName("authentication");
- for (int i = 0; i < elements.getLength(); i++) {
- Node element = elements.item(i);
- NamedNodeMap attrs = element.getAttributes();
- Node type = attrs.getNamedItem("type"); //$NON-NLS-1$
- if (type.getNodeValue().equals("key")) { //$NON-NLS-1$
- NodeList children = element.getChildNodes();
- for (int j = 0; j < children.getLength(); ++j) {
- Node child = children.item(j);
- if (child.getNodeName().equals("login")) { //$NON-NLS-1$
- NodeList loginChildren = child.getChildNodes();
- for (int k = 0; k < loginChildren.getLength(); ++k) {
- Node loginChild = loginChildren.item(k);
- if (loginChild.getNodeName().equals("keyname")) { //$NON-NLS-1$
- instance.setKey(loginChild.getTextContent());
- }
- }
- }
- }
- }
- }
- }
-
- private void getProfileProperties(Instance instance, List<Node> propertyNodes) {
- if (propertyNodes != null) {
- for (Iterator<Node> i = propertyNodes.iterator(); i.hasNext();) {
- Node n = i.next();
- NamedNodeMap attrs = n.getAttributes();
- String name = attrs.getNamedItem("name").getNodeValue(); //$NON-NLS-1$
- if (name.equals("memory")) { //$NON-NLS-1$
- String memory = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
- if (attrs.getNamedItem("unit") != null) { //$NON-NLS-1$
- memory += " " + attrs.getNamedItem("unit").getNodeValue();
//$NON-NLS-1$
- }
- instance.setMemory(memory);
- } else if (name.equals("storage")) { //$NON-NLS-1$
- String storage = attrs.getNamedItem("value").getNodeValue();
//$NON-NLS-1$
- if (attrs.getNamedItem("unit") != null) { //$NON-NLS-1$
- storage += " " + attrs.getNamedItem("unit").getNodeValue();
//$NON-NLS-1$
- }
- instance.setStorage(storage);
- } else if (name.equals("cpu")) { //$NON-NLS-1$
- String cpu = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
- instance.setCPU(cpu);
- }
- }
- }
- }
-
- private String getIdFromHref(String href) {
- return href.substring(href.lastIndexOf("/") + 1, href.length());
- }
-
- private <T extends DeltaCloudObject> List<T>
listDeltaCloudObjects(Class<T> clazz, String path, String elementName)
- throws DeltaCloudClientException {
- try {
- Document document = getDocument(path);
- ArrayList<T> dco = new ArrayList<T>();
- NodeList nodeList = document.getElementsByTagName(elementName);
- for (int i = 0; i < nodeList.getLength(); i++) {
- dco.add(buildDeltaCloudObject(clazz, nodeToString(nodeList.item(i))));
- }
- return dco;
- } catch (DeltaCloudClientException e) {
- throw e;
- } catch (Exception e) {
- throw new DeltaCloudClientException("Could not list object of type " +
clazz, e);
- }
- }
-
- private Document getDocument(String path) throws DeltaCloudClientException,
ParserConfigurationException,
- SAXException, IOException {
- InputSource is = new InputSource(new StringReader(sendRequest(path, HttpMethod.GET)));
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document document = db.parse(is);
- return document;
- }
-
- @SuppressWarnings("unchecked")
- private <T extends Object> T buildDeltaCloudObject(Class<T> clazz, String
node) throws DeltaCloudClientException {
- if (clazz.equals(Instance.class)) {
- return (T) buildInstance(node);
- } else if (clazz.equals(HardwareProfile.class)) {
- return (T) buildHardwareProfile(node);
- } else {
- return JAXB.unmarshal(new StringReader(node), clazz);
- }
- }
-
/**
- * Performs an action, indicated by a given action id, on a instance with a
- * given instance id.
- * <p>
- * Retrieves the instance with the given id, checks for the actions that are
- * available to it and performs the given action only if it is available. It
- * is important to note that this method performs several REST calls to the
- * server.
+ * Returns an Instance from the Delta Cloud Provider given on the Instances
+ * ID
*
* @param instanceId
- * the id of the instance to perfom the action on
- * @param action
- * the action id to perform
- * @return true, if the action was performed successfully
+ * @return
* @throws DeltaCloudClientException
- * indicates that an error occured while performing the action
+ */
+ public Instance listInstances(String instanceId) throws DeltaCloudClientException;
+
+ /**
+ * Creates a new Delta Cloud Instance based on the Image specified by the
+ * Image ID. Default parameters are used for the Flavor, Realm and Name.
+ * These are specified by the Delta Cloud Provider
*
- * @see #startInstance(String)
- * @see #shutdownInstance(String)
- * @see #destroyInstance(String)
- * @see #rebootInstance(String)
+ * @param imageId
+ * @return The newly created Delta Cloud Instance
+ * @throws DeltaCloudClientException
*/
- public boolean performInstanceAction(String instanceId, String actionName) throws
DeltaCloudClientException {
- Instance instance = listInstances(instanceId);
- InstanceAction action = instance.getAction(actionName);
- if (action != null) {
- sendRequest(action.getUrl(), action.getMethod());
- return true;
- }
- return false;
- }
+ public Instance createInstance(String imageId) throws DeltaCloudClientException;
- private String nodeToString(Node node) throws DeltaCloudClientException {
- try {
- StringWriter writer = new StringWriter();
- Transformer t = TransformerFactory.newInstance().newTransformer();
- t.transform(new DOMSource(node), new StreamResult(writer));
- return writer.toString();
- } catch (TransformerException e) {
- throw new DeltaCloudClientException("Error transforming node to string",
e);
- }
- }
-
- private interface INodeVisitor {
- public void visit(Node node) throws Exception;
- }
-
+ /**
+ * Creates a new Delta Cloud Instance, the instance will be based on the
+ * Image specified by the instance ID. It will be of type flavor and in the
+ * location realm
+ *
+ * @param imageId
+ * @param flavor
+ * @param realm
+ * @param name
+ * @return
+ * @throws DeltaCloudClientException
+ */
+ public Instance createInstance(String imageId, String flavor, String realm, String
name)
+ throws DeltaCloudClientException;
}
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
(from rev 26235,
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
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -0,0 +1,670 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.bind.JAXB;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.Path;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class DeltaCloudClientImpl implements InternalDeltaCloudClient {
+
+ private static final String BASEURL_API = "/api";
+ private static final String PEM_FILE_SUFFIX = "pem";
+ private static final String DOCUMENT_ELEMENT_DRIVER = "driver";
+ private static final String DOCUMENT_ELEMENT_API = "api";
+
+ public static Logger logger = Logger.getLogger(DeltaCloudClientImpl.class);
+
+ public static enum DeltaCloudServerType {
+ UNKNOWN, MOCK, EC2
+ }
+
+ private static enum DCNS {
+ TYPE {
+ public String getResourceName() {
+ return "";
+ }
+ }
+ ,
+ INSTANCES
+ , REALMS
+ , IMAGES
+ , HARDWARE_PROFILES
+ , KEYS
+ , START
+ , STOP
+ , REBOOT
+ , DESTROY;
+
+ @Override
+ public String toString() {
+ return "/" + getResourceName();
+ }
+
+ public String getResourceName() {
+ return name().toLowerCase();
+ }
+ }
+
+ private URL baseUrl;
+ private String username;
+ private String password;
+
+ public DeltaCloudClientImpl(String url) throws MalformedURLException {
+ this(url, null, null);
+ }
+
+ public DeltaCloudClientImpl(String url, String username, String password) throws
MalformedURLException {
+
+ logger.debug("Creating new Delta Cloud Client for Server: " + url);
+
+ this.baseUrl = new URL(url + BASEURL_API);
+ this.username = username;
+ this.password = password;
+ }
+
+ private String sendRequest(String path, HttpMethod httpMethod) throws
DeltaCloudClientException {
+ DefaultHttpClient httpClient = addCredentials(new DefaultHttpClient());
+ String requestUrl = baseUrl.toString() + path;
+ logger.debug("Sending Request to: " + requestUrl);
+
+ try {
+ HttpUriRequest request = getRequest(httpMethod, requestUrl);
+ HttpResponse httpResponse = httpClient.execute(request);
+ throwOnHttpErrors(requestUrl, httpResponse);
+ return getResponse(httpResponse.getEntity());
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (IOException e) {
+ logger.error("Error processing request to: " + requestUrl, e);
+ throw new DeltaCloudClientException("Error processing request to: " +
requestUrl, e);
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e.getMessage());
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ }
+
+ private void throwOnHttpErrors(String requestUrl, HttpResponse httpResponse) throws
DeltaCloudClientException {
+ int statusCode = httpResponse.getStatusLine().getStatusCode();
+ if (HttpStatusCode.OK.isStatus(statusCode)) {
+ return;
+ } else if (HttpStatusCode.FORBIDDEN.isStatus(statusCode)) {
+ throw new DeltaCloudAuthException(
+ MessageFormat.format("The server reported an authorization error
\"{0}\" on requesting \"{1}\"",
+ httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
+ } else if (HttpStatusCode.NOT_FOUND.isStatus(statusCode)) {
+ throw new DeltaCloudNotFoundClientException(
+ MessageFormat.format("The server could not find the resource
\"{0}\"", requestUrl));
+ } else if (HttpStatusRange.CLIENT_ERROR.isInRange(statusCode)
+ || HttpStatusRange.SERVER_ERROR.isInRange(statusCode)) {
+ throw new DeltaCloudClientException(
+ MessageFormat.format("The server reported an error \"{0}\" on
requesting \"{1}\"",
+ httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
+ }
+ }
+
+ private String getResponse(HttpEntity entity) throws IOException,
+ DeltaCloudClientException {
+ if (entity == null) {
+ return null;
+ }
+ String xml = readInputStreamToString(entity.getContent());
+ logger.debug("Response\n" + xml);
+ return xml;
+ }
+
+ /**
+ * Returns a request instance for the given request type and url.
+ *
+ * @param httpMethod
+ * the request type to use
+ * @param requestUrl
+ * the requested url
+ * @return the request instance
+ */
+ protected HttpUriRequest getRequest(HttpMethod httpMethod, String requestUrl) {
+ HttpUriRequest request = null;
+ switch (httpMethod) {
+ case POST:
+ request = new HttpPost(requestUrl);
+ break;
+ case DELETE:
+ request = new HttpDelete(requestUrl);
+ break;
+ case GET:
+ default:
+ request = new HttpGet(requestUrl);
+ }
+ request.setHeader("Accept", "application/xml;q=1");
+ return request;
+ }
+
+ /**
+ * Adds the credentials to the given http client.
+ *
+ * @param httpClient
+ * the http client
+ * @return the default http client
+ */
+ private DefaultHttpClient addCredentials(DefaultHttpClient httpClient) {
+ if (username != null && password != null) {
+ httpClient.getCredentialsProvider().setCredentials(
+ new AuthScope(baseUrl.getHost(), baseUrl.getPort()),
+ new UsernamePasswordCredentials(username, password));
+ }
+ return httpClient;
+ }
+
+ private static String readInputStreamToString(InputStream is) throws
DeltaCloudClientException {
+ try {
+ try {
+ if (is != null) {
+ StringBuilder sb = new StringBuilder();
+ String line;
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
+ while ((line = reader.readLine()) != null) {
+ sb.append(line).append("\n");
+ }
+ return sb.toString();
+ }
+ } finally {
+ is.close();
+ }
+ } catch (Exception e) {
+ throw new DeltaCloudClientException("Error converting Response to String",
e);
+ }
+ return "";
+ }
+
+ public DeltaCloudServerType getServerType() {
+ DeltaCloudServerType serverType = DeltaCloudServerType.UNKNOWN;
+ try {
+ String query = "?format=xml";
+ String apiResponse = sendRequest(DCNS.TYPE + query, HttpMethod.GET);
+ DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = db.parse(new InputSource(new StringReader(apiResponse)));
+
+ NodeList elements = document.getElementsByTagName(DOCUMENT_ELEMENT_API);
+ if (elements.getLength() > 0) {
+ Node n = elements.item(0);
+ Node driver = n.getAttributes().getNamedItem(DOCUMENT_ELEMENT_DRIVER);
+ if (driver != null) {
+ String driverValue = driver.getNodeValue();
+ serverType = DeltaCloudServerType.valueOf(driverValue.toUpperCase());
+ }
+ }
+ } catch (Exception e) {
+ serverType = DeltaCloudServerType.UNKNOWN;
+ }
+ return serverType;
+ }
+
+ @Override
+ public Instance createInstance(String imageId) throws DeltaCloudClientException {
+ String query = "?image_id=" + imageId;
+ return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
+ }
+
+ @Override
+ public Instance createInstance(String imageId, String profileId, String realmId, String
name)
+ throws DeltaCloudClientException {
+ return createInstance(imageId, profileId, realmId, name, null, null, null);
+ }
+
+ public Instance createInstance(String imageId, String profileId, String realmId, String
name, String memory,
+ String storage) throws DeltaCloudClientException {
+ return createInstance(imageId, profileId, realmId, name, null, memory, storage);
+ }
+
+ public Instance createInstance(String imageId, String profileId, String realmId, String
name, String keyname,
+ String memory, String storage) throws DeltaCloudClientException {
+ String query = "?image_id=" + imageId + "&hwp_id=" + profileId
+ "&realm_id=" + realmId + "&name=" + name;
+ if (memory != null)
+ query += "&hwp_memory=" + memory;
+ if (storage != null)
+ query += "&hwp_storage=" + storage;
+ if (keyname != null)
+ query += "&keyname=" + keyname;
+ query += "&commit=create";
+ return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
+ }
+
+ @Override
+ public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException {
+ String request = DCNS.HARDWARE_PROFILES + "/" + profileId;
+ return buildDeltaCloudObject(HardwareProfile.class, sendRequest(request,
HttpMethod.GET));
+ }
+
+ @Override
+ public List<HardwareProfile> listProfiles() throws DeltaCloudClientException {
+ return listDeltaCloudObjects(HardwareProfile.class, DCNS.HARDWARE_PROFILES.toString(),
"hardware_profile");
+ }
+
+ @Override
+ public List<Image> listImages() throws DeltaCloudClientException {
+ return listDeltaCloudObjects(Image.class, DCNS.IMAGES.toString(), "image");
+ }
+
+ @Override
+ public Image listImages(String imageId) throws DeltaCloudClientException {
+ return JAXB.unmarshal(new StringReader(sendRequest(DCNS.IMAGES + "/" +
imageId, HttpMethod.GET)), Image.class);
+ }
+
+ @Override
+ public List<Instance> listInstances() throws DeltaCloudClientException {
+ return listDeltaCloudObjects(Instance.class, DCNS.INSTANCES.toString(),
"instance");
+ }
+
+ @Override
+ public Instance listInstances(String instanceId) throws DeltaCloudClientException {
+ return buildInstance(sendRequest(DCNS.INSTANCES + "/" + instanceId,
HttpMethod.GET));
+ }
+
+ @Override
+ public List<Realm> listRealms() throws DeltaCloudClientException {
+ return listDeltaCloudObjects(Realm.class, DCNS.REALMS.toString(), "realm");
+ }
+
+ @Override
+ public Realm listRealms(String realmId) throws DeltaCloudClientException {
+ return JAXB.unmarshal(new StringReader(sendRequest(DCNS.REALMS + "/" +
realmId, HttpMethod.GET)), Realm.class);
+ }
+
+ /**
+ * Retrieves 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
+ * @param keyStoreLocation
+ * the path to the file to store the key in
+ * @throws DeltaCloudClientException
+ * the delta cloud client exception
+ */
+ public void createKey(String keyname, String keyStoreLocation) throws
DeltaCloudClientException {
+ String xml = sendRequest(DCNS.KEYS + "?name=" + keyname, HttpMethod.POST);
+ 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);
+ w.close();
+ }
+
+ private String trimKey(List<String> keyText) throws IOException {
+ StringBuffer sb = new StringBuffer();
+ String line;
+ BufferedReader reader = new BufferedReader(new StringReader(keyText.get(0)));
+ while ((line = reader.readLine()) != null) {
+ // We must trim off the white-space from the xml
+ // Complete white-space lines are to be ignored.
+ String trimmedLine = line.trim();
+ if (trimmedLine.length() > 0) {
+ sb.append(trimmedLine).append("\n");
+ }
+ }
+ return sb.toString();
+ }
+
+ 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 = getElementText(document, PEM_FILE_SUFFIX); //$NON-NLS-1$
+ return keyText;
+ }
+
+ private File createKeyFile(String keyname, String keyStoreLocation) throws IOException
{
+ File keyFile = Path.fromOSString(keyStoreLocation).append(keyname + "." +
PEM_FILE_SUFFIX).toFile(); //$NON-NLS-1$
+ if (!keyFile.exists()) {
+ keyFile.createNewFile();
+ }
+ keyFile.setReadable(false, false);
+ keyFile.setWritable(true, true);
+ keyFile.setReadable(true, true);
+ return keyFile;
+ }
+
+ public void deleteKey(String keyname) throws DeltaCloudClientException {
+ sendRequest(DCNS.KEYS + "/" + keyname, HttpMethod.DELETE);
+ }
+
+ private Instance updateInstance(String xml, Instance instance) throws
DeltaCloudClientException {
+ try {
+
+ 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(getElementText(document, "state").get(0)); //$NON-NLS-1$
+ getAuthentication(document, instance);
+ instance.setActions(createInstanceActions(instance, document));
+
+ return instance;
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ DeltaCloudClientException newException = new
DeltaCloudClientException(e.getLocalizedMessage());
+ throw newException;
+ }
+ }
+
+ private Instance buildInstance(String xml) throws DeltaCloudClientException {
+ Instance instance = JAXB.unmarshal(new StringReader(xml), Instance.class);
+ updateInstance(xml, instance);
+ return instance;
+ }
+
+ private List<InstanceAction> createInstanceActions(final Instance instance,
Document document)
+ throws DeltaCloudClientException {
+ 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, stripBaseUrl(url), method, instance));
+ }
+ });
+ return actions;
+ }
+
+ private String stripBaseUrl(String url) throws DeltaCloudClientException {
+ String baseUrlString = baseUrl.toString();
+ if (url.indexOf(baseUrlString) != 0) {
+ throw new DeltaCloudClientException(MessageFormat.format(
+ "Resource at {0} is not child resource of root resource at {1}", url,
baseUrl));
+ }
+
+ return url.substring(baseUrlString.length());
+ }
+
+ private String getAttributeTextContent(String attributeName, NamedNodeMap namedNodeMap,
Node node)
+ throws DeltaCloudClientException {
+ Node attributeNode = namedNodeMap.getNamedItem(attributeName);
+ if (attributeNode == null) {
+ throw new DeltaCloudClientException(MessageFormat.format("Could not find
attribute {0} in node {1}",
+ attributeName, node.getNodeName()));
+ }
+
+ return attributeNode.getTextContent();
+ }
+
+ private HardwareProfile buildHardwareProfile(String xml) throws
DeltaCloudClientException {
+ 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)));
+
+ 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());
//$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")) { //$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")) { //$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")) { //$NON-NLS-1$
+ NodeList enumChildren = child.getChildNodes();
+ for (int j = 0; j < enumChildren.getLength(); ++j) {
+ Node enumChild = enumChildren.item(j);
+ if (enumChild.getNodeName().equals("entry")) {
+ enums.add(enumChild.getAttributes().getNamedItem("value").getNodeValue());
//$NON-NLS-1$
+ }
+ }
+ }
+ }
+ p.setEnums(enums);
+ }
+ profile.getProperties().add(p);
+ }
+ return profile;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void forEachNode(Document document, String tagName, INodeVisitor visitor) throws
DeltaCloudClientException {
+ 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());
+ }
+ }
+ }
+
+ private List<String> getAttributeValues(Document document, String elementName,
String attributeName) {
+ NodeList elements = document.getElementsByTagName(elementName);
+ ArrayList<String> values = new ArrayList<String>();
+ for (int i = 0; i < elements.getLength(); i++) {
+ values.add(elements.item(i).getAttributes().getNamedItem(attributeName).getTextContent());
+ }
+ return values;
+ }
+
+ private List<String> getElementText(Document document, String elementName) {
+ NodeList elements = document.getElementsByTagName(elementName);
+ ArrayList<String> values = new ArrayList<String>();
+ for (int i = 0; i < elements.getLength(); i++) {
+ values.add(elements.item(i).getTextContent());
+ }
+ return values;
+ }
+
+ private List<Node> getPropertyNodes(Document document, String elementName) {
+ NodeList elements = document.getElementsByTagName(elementName);
+ ArrayList<Node> values = new ArrayList<Node>();
+ for (int i = 0; i < elements.getLength(); i++) {
+ NodeList children = elements.item(i).getChildNodes();
+ for (int j = 0; j < children.getLength(); ++j) {
+ Node child = children.item(j);
+ if (child.getNodeName().equals("property")) { //$NON-NLS-1$
+ values.add(child);
+ }
+ }
+ }
+ return values;
+ }
+
+ private void getAuthentication(Document document, Instance instance) {
+ NodeList elements = document.getElementsByTagName("authentication");
+ for (int i = 0; i < elements.getLength(); i++) {
+ Node element = elements.item(i);
+ NamedNodeMap attrs = element.getAttributes();
+ Node type = attrs.getNamedItem("type"); //$NON-NLS-1$
+ if (type.getNodeValue().equals("key")) { //$NON-NLS-1$
+ NodeList children = element.getChildNodes();
+ for (int j = 0; j < children.getLength(); ++j) {
+ Node child = children.item(j);
+ if (child.getNodeName().equals("login")) { //$NON-NLS-1$
+ NodeList loginChildren = child.getChildNodes();
+ for (int k = 0; k < loginChildren.getLength(); ++k) {
+ Node loginChild = loginChildren.item(k);
+ if (loginChild.getNodeName().equals("keyname")) { //$NON-NLS-1$
+ instance.setKey(loginChild.getTextContent());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void getProfileProperties(Instance instance, List<Node> propertyNodes) {
+ if (propertyNodes != null) {
+ for (Iterator<Node> i = propertyNodes.iterator(); i.hasNext();) {
+ Node n = i.next();
+ NamedNodeMap attrs = n.getAttributes();
+ String name = attrs.getNamedItem("name").getNodeValue(); //$NON-NLS-1$
+ if (name.equals("memory")) { //$NON-NLS-1$
+ String memory = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
+ if (attrs.getNamedItem("unit") != null) { //$NON-NLS-1$
+ memory += " " + attrs.getNamedItem("unit").getNodeValue();
//$NON-NLS-1$
+ }
+ instance.setMemory(memory);
+ } else if (name.equals("storage")) { //$NON-NLS-1$
+ String storage = attrs.getNamedItem("value").getNodeValue();
//$NON-NLS-1$
+ if (attrs.getNamedItem("unit") != null) { //$NON-NLS-1$
+ storage += " " + attrs.getNamedItem("unit").getNodeValue();
//$NON-NLS-1$
+ }
+ instance.setStorage(storage);
+ } else if (name.equals("cpu")) { //$NON-NLS-1$
+ String cpu = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
+ instance.setCPU(cpu);
+ }
+ }
+ }
+ }
+
+ private String getIdFromHref(String href) {
+ return href.substring(href.lastIndexOf("/") + 1, href.length());
+ }
+
+ private <T extends DeltaCloudObject> List<T>
listDeltaCloudObjects(Class<T> clazz, String path, String elementName)
+ throws DeltaCloudClientException {
+ try {
+ Document document = getDocument(path);
+ ArrayList<T> dco = new ArrayList<T>();
+ NodeList nodeList = document.getElementsByTagName(elementName);
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ dco.add(buildDeltaCloudObject(clazz, nodeToString(nodeList.item(i))));
+ }
+ return dco;
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException("Could not list object of type " +
clazz, e);
+ }
+ }
+
+ private Document getDocument(String path) throws DeltaCloudClientException,
ParserConfigurationException,
+ SAXException, IOException {
+ InputSource is = new InputSource(new StringReader(sendRequest(path, HttpMethod.GET)));
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document document = db.parse(is);
+ return document;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T extends Object> T buildDeltaCloudObject(Class<T> clazz, String
node) throws DeltaCloudClientException {
+ if (clazz.equals(Instance.class)) {
+ return (T) buildInstance(node);
+ } else if (clazz.equals(HardwareProfile.class)) {
+ return (T) buildHardwareProfile(node);
+ } else {
+ return JAXB.unmarshal(new StringReader(node), clazz);
+ }
+ }
+
+ public boolean performInstanceAction(InstanceAction action) throws
DeltaCloudClientException {
+ if (action != null) {
+ String response = sendRequest(action.getUrl(), action.getMethod());
+ if (!InstanceAction.DESTROY.equals(action.getName())) {
+ updateInstance(response, action.getInstance());
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private String nodeToString(Node node) throws DeltaCloudClientException {
+ try {
+ StringWriter writer = new StringWriter();
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ t.transform(new DOMSource(node), new StreamResult(writer));
+ return writer.toString();
+ } catch (TransformerException e) {
+ throw new DeltaCloudClientException("Error transforming node to string",
e);
+ }
+ }
+
+ private interface INodeVisitor {
+ public void visit(Node node) throws Exception;
+ }
+
+}
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java
(from rev 26088,
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/DeltaCloudNotFoundClientException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -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 DeltaCloudNotFoundClientException extends DeltaCloudClientException {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudNotFoundClientException(String message, Throwable clause)
+ {
+ super(message, clause);
+ }
+
+ public DeltaCloudNotFoundClientException(Throwable clause)
+ {
+ super(clause);
+ }
+
+ public DeltaCloudNotFoundClientException(String message)
+ {
+ super(message);
+ }
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
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 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -1,32 +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;
-
-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);
- }
-
-}
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-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -15,73 +15,69 @@
import javax.xml.bind.annotation.XmlElement;
-public class Instance extends DeltaCloudObject
-{
+public class Instance extends DeltaCloudObject {
private static final long serialVersionUID = 1L;
-
- public static enum State { RUNNING, STOPPED, PENDING, TERMINATED, BOGUS };
-
- @XmlElement(name="owner_id")
+
+ public static enum State {
+ RUNNING, STOPPED, PENDING, TERMINATED, BOGUS
+ };
+
+ @XmlElement(name = "owner_id")
private String ownerId;
-
+
@XmlElement
private String name;
-
+
private String imageId;
private String profileId;
private String memory;
-
+
private String storage;
-
+
private String cpu;
-
+
private String realmId;
-
+
private String keyname;
-
+
@XmlElement
private State state;
-
+
private List<InstanceAction> actions;
-
- @XmlElement(name="public_addresses")
+
+ @XmlElement(name = "public_addresses")
private AddressList publicAddresses;
-
- @XmlElement(name="private_addresses")
+
+ @XmlElement(name = "private_addresses")
private AddressList privateAddresses;
-
- private Instance()
- {
+
+ private Instance() {
}
@SuppressWarnings("unused")
- private void setOwnerId(String ownerId)
- {
+ private void setOwnerId(String ownerId) {
this.ownerId = ownerId;
}
-
+
@SuppressWarnings("unused")
- private void setName(String name)
- {
+ private void setName(String name) {
this.name = name;
}
-
- protected void setImageId(String imageId)
- {
+
+ protected void setImageId(String imageId) {
this.imageId = imageId;
}
-
- protected void setProfileId(String profileId)
- {
+
+ protected void setProfileId(String profileId) {
this.profileId = profileId;
}
-
+
protected void setMemory(String memory) {
this.memory = memory;
}
-
+
protected void setStorage(String storage) {
this.storage = storage;
}
@@ -89,70 +85,61 @@
protected void setCPU(String cpu) {
this.cpu = cpu;
}
-
- protected void setRealmId(String realmId)
- {
+
+ protected void setRealmId(String realmId) {
this.realmId = realmId;
}
-
- protected void setActions(List<InstanceAction> actions)
- {
+
+ protected void setActions(List<InstanceAction> actions) {
this.actions = actions;
}
- protected void setState(String state)
- {
+ protected void setState(String state) {
try {
this.state = State.valueOf(state);
} catch (Exception e) {
this.state = State.BOGUS;
}
}
-
+
public void setKey(String keyname) {
this.keyname = keyname;
}
-
+
public String getKey() {
return keyname;
}
-
+
@SuppressWarnings("unused")
- private void setPrivateAddresses(AddressList privateAddresses)
- {
+ private void setPrivateAddresses(AddressList privateAddresses) {
this.privateAddresses = privateAddresses;
}
-
+
@SuppressWarnings("unused")
- private void setPublicAddresses(AddressList publicAddresses)
- {
+ private void setPublicAddresses(AddressList publicAddresses) {
this.publicAddresses = publicAddresses;
}
-
- public String getOwnerId()
- {
+
+ public String getOwnerId() {
return ownerId;
}
- public String getName()
- {
+ public String getName() {
return name;
}
- public String getImageId()
- {
+ public String getImageId() {
return imageId;
}
- public String getProfileId()
- {
+ public String getProfileId() {
return profileId;
}
public String getMemory() {
return memory;
}
-
+
public String getStorage() {
return storage;
}
@@ -161,57 +148,65 @@
return cpu;
}
- public String getRealmId()
- {
+ public String getRealmId() {
return realmId;
}
- public State getState()
- {
+ public State getState() {
return state;
}
-
- public List<InstanceAction> getActions()
- {
+
+ public List<InstanceAction> getActions() {
return actions;
}
-
- public List<String> getActionNames()
- {
- ArrayList<String>names = new ArrayList<String>();
- for (InstanceAction action : actions)
- {
+
+ public List<String> getActionNames() {
+ ArrayList<String> names = new ArrayList<String>();
+ for (InstanceAction action : actions) {
names.add(action.getName());
}
return names;
}
-
+
public InstanceAction getAction(String name) {
if (name == null) {
return null;
}
-
- for(InstanceAction action : actions) {
+
+ for (InstanceAction action : actions) {
if (name.equals(action.getName())) {
return action;
}
}
return null;
}
-
- public List<String> getPublicAddresses()
- {
+
+ public List<String> getPublicAddresses() {
return publicAddresses.getAddress();
}
- public List<String> getPrivateAddresses()
- {
+ public List<String> getPrivateAddresses() {
return privateAddresses.getAddress();
- }
-
+ }
+
+ public boolean start(DeltaCloudClient client) throws DeltaCloudClientException {
+ return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(InstanceAction.START));
+ }
+
+ public boolean stop(DeltaCloudClient client) throws DeltaCloudClientException {
+ return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(InstanceAction.STOP));
+ }
+
+ public boolean destroy(DeltaCloudClient client) throws DeltaCloudClientException {
+ return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(InstanceAction.DESTROY));
+ }
+
+ public boolean reboot(DeltaCloudClient client) throws DeltaCloudClientException {
+ return ((InternalDeltaCloudClient)
client).performInstanceAction(getAction(InstanceAction.REBOOT));
+ }
+
@Override
- public String toString()
- {
+ public String toString() {
String s = "";
s += "Instance:\t" + getId() + "\n";
s += "Owner:\t\t" + getOwnerId() + "\n";
@@ -219,7 +214,7 @@
s += "Realm:\t\t" + getRealmId() + "\n";
s += "Profile:\t\t" + getProfileId() + "\n";
if (getMemory() != null)
- s += "Memory:\t\t" + getMemory() + "\n";
+ s += "Memory:\t\t" + getMemory() + "\n";
if (getStorage() != null) {
s += "Storage:\t\t" + getStorage() + "\n";
}
@@ -227,45 +222,32 @@
s += "CPU:\t\t" + getCPU() + "\n";
}
s += "State:\t\t" + getState() + "\n";
-
-
- for(int i = 0; i < actions.size(); i ++)
- {
- if(i == 0)
- {
- s += "Actions:\t" + actions.get(i) + "\n";
- }
- else
- {
+
+ for (int i = 0; i < actions.size(); i++) {
+ if (i == 0) {
+ s += "Actions:\t" + actions.get(i) + "\n";
+ } else {
s += "\t\t" + actions.get(i) + "\n";
}
}
-
-
- for(int i = 0; i < publicAddresses.getAddress().size(); i ++)
- {
- if(i == 0)
- {
+
+ for (int i = 0; i < publicAddresses.getAddress().size(); i++) {
+ if (i == 0) {
s += "Public Addr:\t" + publicAddresses.getAddress().get(i) +
"\n";
- }
- else
- {
+ } else {
s += "\t\t" + publicAddresses.getAddress().get(i) + "\n";
}
}
-
- for(int i = 0; i < publicAddresses.getAddress().size(); i ++)
- {
- if(i == 0)
- {
+
+ for (int i = 0; i < publicAddresses.getAddress().size(); i++) {
+ if (i == 0) {
s += "Private Addr:\t" + publicAddresses.getAddress().get(i) +
"\n";
- }
- else
- {
+ } else {
s += "\t\t" + privateAddresses.getAddress().get(i) + "\n";
}
}
-
+
return s;
}
+
}
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-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -28,15 +28,17 @@
private String name;
private String url;
private HttpMethod method;
+ private Instance instance;
- public InstanceAction(String name, String url, String method) {
- this(name, url, HttpMethod.valueOf(method.toUpperCase()));
+ protected InstanceAction(String name, String url, String method, Instance instance) {
+ this(name, url, HttpMethod.valueOf(method.toUpperCase()), instance);
}
- public InstanceAction(String name, String url, HttpMethod method) {
+ protected InstanceAction(String name, String url, HttpMethod method, Instance instance)
{
this.name = name;
this.url = url;
this.method = method;
+ this.instance = instance;
}
public String getName() {
@@ -55,4 +57,8 @@
public String toString() {
return "InstanceAction [name=" + name + ", url=" + url + ",
method=" + method + "]";
}
+
+ public Instance getInstance() {
+ return instance;
+ }
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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 InternalDeltaCloudClient extends DeltaCloudClient {
+
+ /**
+ * Performs the given action on the given instance *.
+ *
+ * @param action
+ * the action to perform
+ * @param instance
+ * the instance to perform on
+ * @return true, if the action was performed successfully
+ * @throws DeltaCloudClientException
+ * indicates that an error occured while performing the action
+ * @see InstanceAction
+ * @see Instance
+ */
+ public boolean performInstanceAction(InstanceAction action) throws
DeltaCloudClientException;
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.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-04 13:35:05
UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 13:37:05
UTC (rev 26252)
@@ -1,5 +1,8 @@
2010-11-04 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java:
+ [JBIDE-7484] removed instance related methods from client, unified funtionality in
#performAction and offered additional methods on
+ Instance (#start, #stop, #destroy, #reboot). Furthermore update instance upon action
responses from server.
* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java (getKeyName):
avoid NullPointerExeption when fetching name of key and keyText is not instantiated (is
null)
* src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java:
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -32,24 +32,25 @@
private String action;
private String taskName;
private String expectedState;
-
- public PerformInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance instance,
- String action, String title, String taskName, String expectedState) {
- super(title);
- this.cloud = cloud;
- this.instance = instance;
- this.action = action;
- this.taskName = taskName;
- this.expectedState = expectedState;
- }
-
+
+ public PerformInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance instance,
+ String action, String title, String taskName, String expectedState) {
+ super(title);
+ this.cloud = cloud;
+ this.instance = instance;
+ this.action = action;
+ this.taskName = taskName;
+ this.expectedState = expectedState;
+ }
+
@Override
public IStatus run(IProgressMonitor pm) {
String id = instance.getId();
try {
pm.beginTask(taskName, IProgressMonitor.UNKNOWN);
pm.worked(1);
- // To handle the user starting a new action when we haven't confirmed the last one
yet,
+ // To handle the user starting a new action when we haven't
+ // confirmed the last one yet,
// cancel the previous job and then go on performing this action
Job job = cloud.getActionJob(id);
if (job != null) {
@@ -61,7 +62,8 @@
}
}
cloud.performInstanceAction(id, action);
- while (instance != null && !(instance.getState().equals(expectedState))
+ while (instance != null && expectedState != null
+ && !(instance.getState().equals(expectedState))
&& !(instance.getState().equals(DeltaCloudInstance.TERMINATED))) {
instance = cloud.refreshInstance(id);
try {
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -12,8 +12,8 @@
import java.net.MalformedURLException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
import org.jboss.tools.internal.deltacloud.ui.common.databinding.ObservablePojo;
/**
@@ -36,11 +36,11 @@
private String username;
private String password;
- private DeltaCloudClient.DeltaCloudType cloudType;
+ private DeltaCloudClientImpl.DeltaCloudServerType cloudType;
private String initialName;
public CloudConnectionModel() {
- this("", "", "", "", (DeltaCloudType) null);
+ this("", "", "", "", (DeltaCloudServerType)
null);
}
public CloudConnectionModel(String name, String url, String username, String password,
String cloudType) throws MalformedURLException {
@@ -51,7 +51,7 @@
this(name, url, username, password, getDeltaCloudTypeFromUrl(url));
}
- public CloudConnectionModel(String name, String url, String username, String password,
DeltaCloudType deltaCloudType) {
+ public CloudConnectionModel(String name, String url, String username, String password,
DeltaCloudServerType deltaCloudType) {
this.name = name;
this.initialName = name;
this.url = url;
@@ -60,17 +60,17 @@
this.cloudType = deltaCloudType;
}
- private static DeltaCloudType getDeltaCloudTypeFromUrl(String url) throws
MalformedURLException {
- return new DeltaCloudClient(url, "", "").getServerType();
+ private static DeltaCloudServerType getDeltaCloudTypeFromUrl(String url) throws
MalformedURLException {
+ return new DeltaCloudClientImpl(url, "", "").getServerType();
}
- private static DeltaCloudType getDeltaCloudType(String cloudType, String url) throws
MalformedURLException {
+ private static DeltaCloudServerType getDeltaCloudType(String cloudType, String url)
throws MalformedURLException {
if (cloudType == null) {
return null;
}
try {
- return DeltaCloudType.valueOf(cloudType);
+ return DeltaCloudServerType.valueOf(cloudType);
} catch (IllegalArgumentException e) {
return getDeltaCloudTypeFromUrl(url);
}
@@ -112,11 +112,11 @@
getPropertyChangeSupport().firePropertyChange(PROPERTY_URL, this.url, this.url = url);
}
- public DeltaCloudClient.DeltaCloudType getType() {
+ public DeltaCloudClientImpl.DeltaCloudServerType getType() {
return cloudType;
}
- public void setType(DeltaCloudClient.DeltaCloudType cloudType) {
+ public void setType(DeltaCloudClientImpl.DeltaCloudServerType cloudType) {
getPropertyChangeSupport().firePropertyChange(PROPERTY_TYPE, this.cloudType,
this.cloudType = cloudType);
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -55,7 +55,7 @@
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.common.log.LogHelper;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.CompositeValidator;
@@ -114,30 +114,30 @@
* the label that shall display the delta cloud type
*
* @see IValueChangeListener
- * @see DeltaCloudType
+ * @see DeltaCloudServerType
*/
private class DeltaCloudTypeLabelAdapter implements IValueChangeListener {
private Label typeLabel;
- public DeltaCloudTypeLabelAdapter(DeltaCloudType cloudType, Label typeLabel) {
+ public DeltaCloudTypeLabelAdapter(DeltaCloudServerType cloudType, Label typeLabel) {
this.typeLabel = typeLabel;
init(cloudType);
}
- private void init(DeltaCloudType cloudType) {
+ private void init(DeltaCloudServerType cloudType) {
setLabelText(cloudType);
}
@Override
public void handleValueChange(ValueChangeEvent event) {
Object newValue = event.diff.getNewValue();
- Assert.isTrue(newValue instanceof DeltaCloudType);
- setLabelText((DeltaCloudType) newValue);
+ Assert.isTrue(newValue instanceof DeltaCloudServerType);
+ setLabelText((DeltaCloudServerType) newValue);
}
- private void setLabelText(DeltaCloudType cloudType) {
- if (cloudType != null && cloudType != DeltaCloudType.UNKNOWN) {
+ private void setLabelText(DeltaCloudServerType cloudType) {
+ if (cloudType != null && cloudType != DeltaCloudServerType.UNKNOWN) {
typeLabel.setText(cloudType.toString());
} else {
typeLabel.setText("?"); // $NON-NLS-1$
@@ -503,7 +503,7 @@
*/
IObservableValue cloudTypeObservable =
urlToCloudTypeConverter.getCloudTypeObservable();
DeltaCloudTypeLabelAdapter cloudTypeAdapter =
- new DeltaCloudTypeLabelAdapter((DeltaCloudType) cloudTypeObservable.getValue(),
typeLabel);
+ new DeltaCloudTypeLabelAdapter((DeltaCloudServerType) cloudTypeObservable.getValue(),
typeLabel);
cloudTypeObservable.addValueChangeListener(cloudTypeAdapter);
ControlDecorationSupport.create(urlTypeBinding, SWT.LEFT | SWT.TOP);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudTypeValidator.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudTypeValidator.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudTypeValidator.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -13,14 +13,14 @@
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
public class CloudTypeValidator implements IValidator {
@Override
public IStatus validate(Object value) {
if (value != null
- && !DeltaCloudClient.DeltaCloudType.UNKNOWN.equals(value)) {
+ && !DeltaCloudClientImpl.DeltaCloudServerType.UNKNOWN.equals(value)) {
return ValidationStatus.ok();
} else {
return
ValidationStatus.warning(WizardMessages.getString("IllegalCloudUrl.msg"));
//$NON-NLS-1$
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -15,8 +15,8 @@
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.WritableValue;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
/**
* A class that converts an url (string) to a DeltaCloudType (enum). The state
@@ -40,20 +40,20 @@
@Override
public Object getToType() {
- return DeltaCloudClient.DeltaCloudType.class;
+ return DeltaCloudClientImpl.DeltaCloudServerType.class;
}
@Override
public Object convert(Object fromObject) {
String deltaCloudUrl = (String) fromObject;
- DeltaCloudType cloudType = getCloudType(deltaCloudUrl);
+ DeltaCloudServerType cloudType = getCloudType(deltaCloudUrl);
cloudTypeObservable.setValue(cloudType);
return cloudType;
}
- private DeltaCloudType getCloudType(String deltaCloudUrl) {
+ private DeltaCloudServerType getCloudType(String deltaCloudUrl) {
try {
- return new DeltaCloudClient(deltaCloudUrl, "",
"").getServerType();
+ return new DeltaCloudClientImpl(deltaCloudUrl, "",
"").getServerType();
} catch (MalformedURLException e) {
return null;
}
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/context/MockIntegrationTestContext.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/context/MockIntegrationTestContext.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/context/MockIntegrationTestContext.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -24,8 +24,9 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
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.Instance.State;
@@ -50,7 +51,7 @@
public void setUp() throws IOException, DeltaCloudClientException {
ensureDeltaCloudIsRunning();
- this.client = new DeltaCloudClient(DELTACLOUD_URL, DELTACLOUD_USER,
DELTACLOUD_PASSWORD);
+ this.client = new DeltaCloudClientImpl(DELTACLOUD_URL, DELTACLOUD_USER,
DELTACLOUD_PASSWORD);
Image image = getFirstImage(client);
this.testInstance = createTestInstance(image);
}
@@ -102,7 +103,10 @@
public void quietlyDestroyInstance(Instance instance) {
if (instance != null) {
try {
- client.destroyInstance(instance.getId());
+ if (instance.getState() == Instance.State.RUNNING) {
+ instance.stop(client);
+ }
+ instance.destroy(client);
} catch (Exception e) {
// ignore
}
@@ -120,10 +124,11 @@
* the timeout to wait for
* @return <code>true</code>, if the state was reached while waiting for
* timeout, <code>false</code> otherwise
- * @throws ExecutionException
- * @throws InterruptedException
+ * @throws ExecutionException
+ * @throws InterruptedException
*/
- public boolean waitForInstanceState(final String instanceId, final State state, final
long timeout) throws InterruptedException, ExecutionException {
+ public boolean waitForInstanceState(final String instanceId, final State state, final
long timeout)
+ throws InterruptedException, ExecutionException {
final long startTime = System.currentTimeMillis();
Callable<Boolean> waitingCallable = new Callable<Boolean>() {
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ImageMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ImageMockIntegrationTest.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ImageMockIntegrationTest.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -16,7 +16,7 @@
import java.net.MalformedURLException;
import java.util.List;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.Image;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
@@ -29,8 +29,8 @@
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#listImages()
- * @see DeltaCloudClient#listImages(String)
+ * @see DeltaCloudClientImpl#listImages()
+ * @see DeltaCloudClientImpl#listImages(String)
*
*/
public class ImageMockIntegrationTest {
@@ -50,7 +50,7 @@
@Test(expected = DeltaCloudClientException.class)
public void cannotListIfNotAuthenticated() throws MalformedURLException,
DeltaCloudClientException {
- DeltaCloudClient client = new
DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL, "badUser",
"badPassword");
+ DeltaCloudClientImpl client = new
DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL, "badUser",
"badPassword");
client.listImages();
}
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -17,31 +17,40 @@
import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
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.HttpMethod;
import org.jboss.tools.deltacloud.core.client.Image;
import org.jboss.tools.deltacloud.core.client.Instance;
import org.jboss.tools.deltacloud.core.client.Instance.State;
import org.jboss.tools.deltacloud.core.client.InstanceAction;
+import org.jboss.tools.deltacloud.core.client.InternalDeltaCloudClient;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
- * Integration tests for instance related methods in {@link DeltaCloudClient}.
+ * Integration tests for instance related methods in
+ * {@link DeltaCloudClientImpl}.
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#listInstances()
- * @see DeltaCloudClient#createInstance(String)
- * @see DeltaCloudClient#destroyInstance(String)
- * @see DeltaCloudClient#startInstance(String)
- * @see DeltaCloudClient#shutdownInstance(String)
+ * @see DeltaCloudClientImpl#listInstances()
+ * @see DeltaCloudClientImpl#createInstance(String)
+ * @see DeltaCloudClientImpl#destroyInstance(String)
+ * @see DeltaCloudClientImpl#startInstance(String)
+ * @see DeltaCloudClientImpl#shutdownInstance(String)
*/
public class InstanceMockIntegrationTest {
@@ -92,7 +101,7 @@
, instance);
}
- @Test(expected = DeltaCloudClientException.class)
+ @Test(expected = DeltaCloudNotFoundClientException.class)
public void listDestroyedInstanceThrowsException() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
testSetup.quietlyDestroyInstance(testInstance);
@@ -113,7 +122,8 @@
@Test(expected = DeltaCloudClientException.class)
public void cannotDestroyIfNotAuthenticated() throws MalformedURLException,
DeltaCloudClientException {
- DeltaCloudClient unauthenticatedClient = new
DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL,
+ DeltaCloudClientImpl unauthenticatedClient = new DeltaCloudClientImpl(
+ MockIntegrationTestContext.DELTACLOUD_URL,
"badUser", "badPassword");
Image image = testSetup.getFirstImage(unauthenticatedClient);
unauthenticatedClient.createInstance(image.getId());
@@ -141,21 +151,67 @@
@Test
public void canDestroy() throws DeltaCloudClientException {
Image image = testSetup.getFirstImage(testSetup.getClient());
- Instance instance = testSetup.getClient().createInstance(image.getId());
- testSetup.getClient().destroyInstance(instance.getId());
+ DeltaCloudClient client = testSetup.getClient();
+ Instance instance = client.createInstance(image.getId());
+ instance.stop(client);
+ instance.destroy(client);
assertNull(testSetup.getInstanceById(instance.getId(), testSetup.getClient()));
}
@Test(expected = DeltaCloudClientException.class)
- public void destroyThrowExceptionOnUnknowInstanceId() throws DeltaCloudClientException
{
- testSetup.getClient().destroyInstance("dummy");
+ public void destroyThrowExceptionOnUnknowInstanceId() throws DeltaCloudClientException,
IllegalArgumentException,
+ InstantiationException, IllegalAccessException, InvocationTargetException,
SecurityException, NoSuchMethodException {
+ DeltaCloudClient client = testSetup.getClient();
+ ((InternalDeltaCloudClient) testSetup.getClient()).performInstanceAction(
+ createInstanceAction(
+ InstanceAction.DESTROY,
+ MockIntegrationTestContext.DELTACLOUD_URL,
+ HttpMethod.POST,
+ createInstance()));
}
+ private Instance createInstance() throws IllegalArgumentException,
InstantiationException, IllegalAccessException,
+ InvocationTargetException, SecurityException, NoSuchMethodException {
+ Constructor<Instance> constructor = (Constructor<Instance>) Instance.class
+ .getDeclaredConstructor(null);
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ }
+
+ private InstanceAction createInstanceAction(String name, String url, HttpMethod method,
Instance instance)
+ throws IllegalArgumentException, InstantiationException, IllegalAccessException,
InvocationTargetException, SecurityException, NoSuchMethodException {
+ Constructor<InstanceAction> constructor = (Constructor<InstanceAction>)
InstanceAction.class
+ .getDeclaredConstructor(String.class, String.class, HttpMethod.class,
Instance.class);
+ constructor.setAccessible(true);
+ InstanceAction instanceAction = constructor.newInstance(
+ name,
+ url,
+ method,
+ instance
+ );
+ return instanceAction;
+ }
+
+ private class InstanceActionProxy implements InvocationHandler {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (method.getName().equals("getUrl")) {
+ return MockIntegrationTestContext.DELTACLOUD_URL;
+ } else if (method.getName().equals("getMethod")) {
+ return HttpMethod.POST;
+ } else {
+ return null;
+ }
+ }
+
+ }
+
@Test
public void canShutdownInstance() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
- client.shutdownInstance(testInstance.getId());
+ testInstance.stop(client);
testInstance = client.listInstances(testInstance.getId()); // reload!
assertEquals(State.STOPPED, testInstance.getState());
}
@@ -165,9 +221,9 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
if (testInstance.getState() == State.RUNNING) {
- client.shutdownInstance(testInstance.getId());
+ testInstance.stop(client);
}
- client.startInstance(testInstance.getId());
+ testInstance.start(client);
testInstance = client.listInstances(testInstance.getId()); // reload!
assertEquals(State.RUNNING, testInstance.getState());
}
@@ -177,9 +233,9 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
if (testInstance.getState() == State.RUNNING) {
- client.performInstanceAction(testInstance.getId(), InstanceAction.STOP);
+ testInstance.stop(client);
}
- assertTrue(client.performInstanceAction(testInstance.getId(), InstanceAction.START));
+ assertTrue(testInstance.start(client));
testInstance = client.listInstances(testInstance.getId()); // reload!
assertEquals(State.RUNNING, testInstance.getState());
}
@@ -188,8 +244,8 @@
public void cannotStartRunningInstance() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
- client.startInstance(testInstance.getId());
- assertFalse(client.performInstanceAction(testInstance.getId(), InstanceAction.START));
+ testInstance.start(client);
+ assertFalse(testInstance.start(client));
}
@Test
@@ -197,10 +253,10 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
try {
- client.shutdownInstance(testInstance.getId());
- assertFalse(client.performInstanceAction(testInstance.getId(), InstanceAction.STOP));
+ testInstance.stop(client);
+ assertFalse(testInstance.stop(client));
} finally {
- client.startInstance(testInstance.getId());
+ testInstance.start(client);
}
}
@@ -210,7 +266,7 @@
DeltaCloudClient client = testSetup.getClient();
testInstance = client.listInstances(testInstance.getId()); // reload
assertTrue(testInstance.getState() == State.RUNNING);
- assertFalse(client.performInstanceAction(testInstance.getId(),
InstanceAction.DESTROY));
+ assertFalse(testInstance.destroy(client));
}
@Test
@@ -219,12 +275,12 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
try {
- client.shutdownInstance(testInstance.getId());
+ testInstance.stop(client);
testInstance = client.listInstances(testInstance.getId()); // reload
assertTrue(testInstance.getState() == State.STOPPED);
- assertFalse(client.performInstanceAction(testInstance.getId(),
InstanceAction.REBOOT));
+ assertFalse(testInstance.reboot(client));
} finally {
- client.startInstance(testInstance.getId());
+ testInstance.start(client);
client.listInstances(testInstance.getId()); // reload
}
}
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-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -12,7 +12,7 @@
import java.io.IOException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.junit.After;
@@ -23,8 +23,8 @@
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#createKey(String, String)
- * @see DeltaCloudClient#deleteKey(String)
+ * @see DeltaCloudClientImpl#createKey(String, String)
+ * @see DeltaCloudClientImpl#deleteKey(String)
*/
public class KeyMockIntegrationTest {
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ProfileMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ProfileMockIntegrationTest.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ProfileMockIntegrationTest.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -17,7 +17,7 @@
import java.io.IOException;
import java.util.List;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.HardwareProfile;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
@@ -30,8 +30,8 @@
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#listProfiles()
- * @see DeltaCloudClient#listProfie(String)
+ * @see DeltaCloudClientImpl#listProfiles()
+ * @see DeltaCloudClientImpl#listProfie(String)
*/
public class ProfileMockIntegrationTest {
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/RealmMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/RealmMockIntegrationTest.java 2010-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/RealmMockIntegrationTest.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -17,7 +17,7 @@
import java.io.IOException;
import java.util.List;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.Realm;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
@@ -30,8 +30,8 @@
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#listRealms()
- * @see DeltaCloudClient#listRealm(String)
+ * @see DeltaCloudClientImpl#listRealms()
+ * @see DeltaCloudClientImpl#listRealm(String)
*/
public class RealmMockIntegrationTest {
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-11-04
13:35:05 UTC (rev 26251)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java 2010-11-04
13:37:05 UTC (rev 26252)
@@ -19,9 +19,9 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundException;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
import org.jboss.tools.deltacloud.core.client.HttpMethod;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.jboss.tools.internal.deltacloud.test.fakes.ServerFake;
@@ -30,11 +30,11 @@
import org.junit.Test;
/**
- * Integration tests for {@link DeltaCloudClient#getServerType()}.
+ * Integration tests for {@link DeltaCloudClientImpl#getServerType()}.
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#getServerType()
+ * @see DeltaCloudClientImpl#getServerType()
*/
public class ServerTypeMockIntegrationTest {
@@ -53,7 +53,7 @@
@Test
public void recognizesDeltaCloud() throws IOException {
- assertEquals(DeltaCloudClient.DeltaCloudType.MOCK,testSetup.getClient().getServerType());
+ assertEquals(DeltaCloudClientImpl.DeltaCloudServerType.MOCK,testSetup.getClient().getServerType());
}
/**
@@ -68,7 +68,7 @@
ServerFake serverFake = new ServerFake(new
URL(MockIntegrationTestContext.SERVERFAKE_URL).getPort(),
"<dummy></dummy>");
serverFake.start();
try {
- assertEquals(DeltaCloudClient.DeltaCloudType.UNKNOWN, new
DeltaCloudClient(MockIntegrationTestContext.SERVERFAKE_URL,
MockIntegrationTestContext.DELTACLOUD_USER,
+ assertEquals(DeltaCloudClientImpl.DeltaCloudServerType.UNKNOWN, new
DeltaCloudClientImpl(MockIntegrationTestContext.SERVERFAKE_URL,
MockIntegrationTestContext.DELTACLOUD_USER,
MockIntegrationTestContext.DELTACLOUD_PASSWORD).getServerType());
} finally {
serverFake.stop();
@@ -77,14 +77,14 @@
@Test(expected = DeltaCloudClientException.class)
public void listImages_cannotListIfNotAuthenticated() throws MalformedURLException,
DeltaCloudClientException {
- DeltaCloudClient client = new
DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL, "badUser",
"badPassword");
+ DeltaCloudClientImpl client = new
DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL, "badUser",
"badPassword");
client.listImages();
}
@Test
public void throwsDeltaCloudClientExceptionOnUnknownResource() {
try {
- DeltaCloudClient errorClient = new
DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL) {
+ DeltaCloudClientImpl errorClient = new
DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL) {
@Override
protected HttpUriRequest getRequest(HttpMethod httpMethod, String requestUrl) {
return new HttpGet(MockIntegrationTestContext.DELTACLOUD_URL + "/DUMMY");
@@ -93,7 +93,7 @@
errorClient.listImages();
fail("no exception catched");
} catch (Exception e) {
- assertEquals(DeltaCloudNotFoundException.class, e.getClass());
+ assertEquals(DeltaCloudNotFoundClientException.class, e.getClass());
}
}
}