Author: adietish
Date: 2010-11-03 14:19:46 -0400 (Wed, 03 Nov 2010)
New Revision: 26235
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/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.ui/src/org/jboss/tools/deltacloud/ui/commands/InstanceStoppedPropertyTester.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/MandatoryStringValidator.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.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/ServerTypeMockIntegrationTest.java
Log:
[JBIDE-7484] reimplemented instance action to store the action-uri where it is reachable
(and now comply to the Deltacloud API)
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-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -11,7 +11,6 @@
package org.jboss.tools.deltacloud.core;
import java.net.MalformedURLException;
-import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -70,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(new URL(url), username, passwd); //$NON-NLS-1$
+ this.client = new DeltaCloudClient(url, username, passwd); //$NON-NLS-1$
this.url = url;
this.name = name;
this.username = username;
@@ -94,7 +93,7 @@
public void editCloud(String name, String url, String username, String passwd, String
type)
throws MalformedURLException {
- this.client = new DeltaCloudClient(new URL(url + "/api"), username, passwd);
//$NON-NLS-1$
+ this.client = new DeltaCloudClient(url, username, passwd); //$NON-NLS-1$
this.url = url;
this.name = name;
this.username = username;
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-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -13,20 +13,21 @@
import java.util.List;
import org.jboss.tools.deltacloud.core.client.Instance;
+import org.jboss.tools.deltacloud.core.client.InstanceAction;
public class DeltaCloudInstance {
- public final static String PENDING = Instance.InstanceState.PENDING.toString();
- public final static String RUNNING = Instance.InstanceState.RUNNING.toString();
- public final static String STOPPED = Instance.InstanceState.STOPPED.toString();
- public final static String TERMINATED = Instance.InstanceState.TERMINATED.toString();
- public final static String BOGUS = Instance.InstanceState.BOGUS.toString();
+ public final static String PENDING = Instance.State.PENDING.toString();
+ public final static String RUNNING = Instance.State.RUNNING.toString();
+ public final static String STOPPED = Instance.State.STOPPED.toString();
+ public final static String TERMINATED = Instance.State.TERMINATED.toString();
+ public final static String BOGUS = Instance.State.BOGUS.toString();
- public final static String START = Instance.Action.START.toString();
- public final static String STOP = Instance.Action.STOP.toString();
- public final static String REBOOT = Instance.Action.REBOOT.toString();
- public final static String DESTROY = Instance.Action.DESTROY.toString();
+ public final static String START = InstanceAction.START;
+ public final static String STOP = InstanceAction.STOP;
+ public final static String REBOOT = InstanceAction.REBOOT;
+ public final static String DESTROY = InstanceAction.DESTROY;
private Instance instance;
private String givenName;
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-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -46,7 +46,6 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.Path;
-import org.jboss.tools.deltacloud.core.client.Instance.Action;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -56,9 +55,10 @@
public class DeltaCloudClient implements API {
+ private static final String BASEURL_API = "/api";
private static final String PEM_FILE_SUFFIX = "pem";
- private static final String DOCUMENT_ELEMENT_DRIVER = "driver"; //$NON-NLS-1$
- private static final String DOCUMENT_ELEMENT_API = "api"; //$NON-NLS-1$
+ private static final String DOCUMENT_ELEMENT_DRIVER = "driver";
+ private static final String DOCUMENT_ELEMENT_API = "api";
public static Logger logger = Logger.getLogger(DeltaCloudClient.class);
@@ -93,38 +93,30 @@
}
}
- protected static enum RequestType {
- POST, GET, DELETE
- };
-
private URL baseUrl;
private String username;
private String password;
public DeltaCloudClient(String url) throws MalformedURLException {
- this(new URL(url), null, null);
+ this(url, null, null);
}
public DeltaCloudClient(String url, String username, String password) throws
MalformedURLException {
- this(new URL(url), username, password);
- }
- public DeltaCloudClient(URL url, String username, String password) {
-
logger.debug("Creating new Delta Cloud Client for Server: " + url);
- this.baseUrl = url;
+ this.baseUrl = new URL(url + BASEURL_API);
this.username = username;
this.password = password;
}
- private String sendRequest(String path, RequestType requestType) throws
DeltaCloudClientException {
+ private String sendRequest(String path, HttpMethod httpMethod) throws
DeltaCloudClientException {
DefaultHttpClient httpClient = addCredentials(new DefaultHttpClient());
- String requestUrl = baseUrl.toString() + "/api" + path;
+ String requestUrl = baseUrl.toString() + path;
logger.debug("Sending Request to: " + requestUrl);
try {
- HttpUriRequest request = getRequest(requestType, requestUrl);
+ HttpUriRequest request = getRequest(httpMethod, requestUrl);
HttpResponse httpResponse = httpClient.execute(request);
throwOnHttpErrors(requestUrl, httpResponse);
return getResponse(httpResponse.getEntity());
@@ -144,15 +136,14 @@
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (HttpStatusCode.OK.isStatus(statusCode)) {
return;
- }
- else if (HttpStatusCode.FORBIDDEN.isStatus(statusCode)) {
+ } 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)
+ } 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}\"",
@@ -173,21 +164,22 @@
/**
* Returns a request instance for the given request type and url.
*
- * @param requestType
+ * @param httpMethod
* the request type to use
* @param requestUrl
* the requested url
* @return the request instance
*/
- protected HttpUriRequest getRequest(RequestType requestType, String requestUrl) {
+ protected HttpUriRequest getRequest(HttpMethod httpMethod, String requestUrl) {
HttpUriRequest request = null;
- switch (requestType) {
+ switch (httpMethod) {
case POST:
request = new HttpPost(requestUrl);
break;
case DELETE:
request = new HttpDelete(requestUrl);
break;
+ case GET:
default:
request = new HttpGet(requestUrl);
}
@@ -237,7 +229,7 @@
DeltaCloudType serverType = DeltaCloudType.UNKNOWN;
try {
String query = "?format=xml";
- String apiResponse = sendRequest(DCNS.TYPE + query, RequestType.GET);
+ String apiResponse = sendRequest(DCNS.TYPE + query, HttpMethod.GET);
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = db.parse(new InputSource(new StringReader(apiResponse)));
@@ -259,7 +251,7 @@
@Override
public Instance createInstance(String imageId) throws DeltaCloudClientException {
String query = "?image_id=" + imageId;
- return buildInstance(sendRequest(DCNS.INSTANCES + query, RequestType.POST));
+ return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
}
@Override
@@ -283,13 +275,13 @@
if (keyname != null)
query += "&keyname=" + keyname;
query += "&commit=create";
- return buildInstance(sendRequest(DCNS.INSTANCES + query, RequestType.POST));
+ 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,
RequestType.GET));
+ return buildDeltaCloudObject(HardwareProfile.class, sendRequest(request,
HttpMethod.GET));
}
@Override
@@ -304,18 +296,17 @@
@Override
public Image listImages(String imageId) throws DeltaCloudClientException {
- return JAXB.unmarshal(new StringReader(sendRequest(DCNS.IMAGES + "/" +
imageId, RequestType.GET)), Image.class);
+ 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,
RequestType.GET));
+ return buildInstance(sendRequest(DCNS.INSTANCES + "/" + instanceId,
HttpMethod.GET));
}
@Override
@@ -325,12 +316,13 @@
@Override
public Realm listRealms(String realmId) throws DeltaCloudClientException {
- return JAXB.unmarshal(new StringReader(sendRequest(DCNS.REALMS + "/" +
realmId, RequestType.GET)), Realm.class);
+ 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.
+ * 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
@@ -340,7 +332,7 @@
* the delta cloud client exception
*/
public void createKey(String keyname, String keyStoreLocation) throws
DeltaCloudClientException {
- String xml = sendRequest(DCNS.KEYS + "?name=" + keyname, RequestType.POST);
+ String xml = sendRequest(DCNS.KEYS + "?name=" + keyname, HttpMethod.POST);
try {
String key = trimKey(getKey(xml));
File keyFile = createKeyFile(keyname, keyStoreLocation);
@@ -391,7 +383,7 @@
}
public void deleteKey(String keyname) throws DeltaCloudClientException {
- sendRequest(DCNS.KEYS + "/" + keyname, RequestType.DELETE);
+ sendRequest(DCNS.KEYS + "/" + keyname, HttpMethod.DELETE);
}
@Override
@@ -399,7 +391,7 @@
/**
* shouldn't that be PUT? changing resource states == PUT!
*/
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.REBOOT,
RequestType.GET);
+ sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.REBOOT,
HttpMethod.GET);
}
@Override
@@ -407,7 +399,7 @@
/**
* shouldn't that be PUT? changing resource states == PUT!
*/
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.STOP,
RequestType.POST);
+ sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.STOP, HttpMethod.POST);
}
@Override
@@ -415,12 +407,12 @@
/**
* shouldn't that be PUT? changing resource states == PUT!
*/
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.START,
RequestType.POST);
+ sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.START,
HttpMethod.POST);
}
@Override
public void destroyInstance(String instanceId) throws DeltaCloudClientException {
- sendRequest(DCNS.INSTANCES + "/" + instanceId, RequestType.DELETE);
+ sendRequest(DCNS.INSTANCES + "/" + instanceId, HttpMethod.DELETE);
}
private Instance buildInstance(String xml) throws DeltaCloudClientException {
@@ -437,27 +429,55 @@
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));
- instance.setActions(createActions(instance, document));
-
return instance;
- // } catch (DeltaCloudClientException e) {
- // throw e;
+ } catch (DeltaCloudClientException e) {
+ throw e;
} catch (Exception e) {
DeltaCloudClientException newException = new
DeltaCloudClientException(e.getLocalizedMessage());
throw newException;
}
}
- private List<Action> createActions(Instance instance, Document document) {
- ArrayList<Instance.Action> actions = new ArrayList<Instance.Action>();
- for (String s : getAttributeValues(document, "link", "rel"))
//$NON-NLS-1$ //$NON-NLS-2$
- {
- actions.add(Instance.Action.valueOf(s.toUpperCase()));
- }
+ 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);
@@ -466,8 +486,6 @@
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new InputSource(new StringReader(xml)));
- // checkForErrors(document);
-
List<Node> nodes = getPropertyNodes(document, "hardware_profile");
//$NON-NLS-1$
for (Node n : nodes) {
@@ -512,6 +530,17 @@
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>();
@@ -609,7 +638,7 @@
dco.add(buildDeltaCloudObject(clazz, nodeToString(nodeList.item(i))));
}
return dco;
- } catch(DeltaCloudClientException e) {
+ } catch (DeltaCloudClientException e) {
throw e;
} catch (Exception e) {
throw new DeltaCloudClientException("Could not list object of type " +
clazz, e);
@@ -618,7 +647,7 @@
private Document getDocument(String path) throws DeltaCloudClientException,
ParserConfigurationException,
SAXException, IOException {
- InputSource is = new InputSource(new StringReader(sendRequest(path,
RequestType.GET)));
+ InputSource is = new InputSource(new StringReader(sendRequest(path, HttpMethod.GET)));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(is);
@@ -636,11 +665,33 @@
}
}
- public boolean performInstanceAction(String instanceId, String action) throws
DeltaCloudClientException {
+ /**
+ * 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.
+ *
+ * @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
+ * @throws DeltaCloudClientException
+ * indicates that an error occured while performing the action
+ *
+ * @see #startInstance(String)
+ * @see #shutdownInstance(String)
+ * @see #destroyInstance(String)
+ * @see #rebootInstance(String)
+ */
+ public boolean performInstanceAction(String instanceId, String actionName) throws
DeltaCloudClientException {
Instance instance = listInstances(instanceId);
- if (instance.getActionNames().contains(action)) {
- String request = DCNS.INSTANCES + "/" + instanceId + "/" +
action.toLowerCase();
- sendRequest(request, RequestType.POST);
+ InstanceAction action = instance.getAction(actionName);
+ if (action != null) {
+ sendRequest(action.getUrl(), action.getMethod());
return true;
}
return false;
@@ -656,4 +707,9 @@
throw new DeltaCloudClientException("Error transforming node to string",
e);
}
}
+
+ private interface INodeVisitor {
+ public void visit(Node node) throws Exception;
+ }
+
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * 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 enum HttpMethod {
+ GET, POST, PUT, DELETE, HEAD;
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-11-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -19,10 +19,8 @@
{
private static final long serialVersionUID = 1L;
- public static enum InstanceState { RUNNING, STOPPED, PENDING, TERMINATED, BOGUS };
+ public static enum State { RUNNING, STOPPED, PENDING, TERMINATED, BOGUS };
- public static enum Action { START, STOP, REBOOT, DESTROY };
-
@XmlElement(name="owner_id")
private String ownerId;
@@ -44,9 +42,9 @@
private String keyname;
@XmlElement
- private InstanceState state;
+ private State state;
- private List<Action> actions;
+ private List<InstanceAction> actions;
@XmlElement(name="public_addresses")
private AddressList publicAddresses;
@@ -97,17 +95,17 @@
this.realmId = realmId;
}
- protected void setActions(List<Action> actions)
+ protected void setActions(List<InstanceAction> actions)
{
this.actions = actions;
}
-
+
protected void setState(String state)
{
try {
- this.state = InstanceState.valueOf(state);
+ this.state = State.valueOf(state);
} catch (Exception e) {
- this.state = InstanceState.BOGUS;
+ this.state = State.BOGUS;
}
}
@@ -168,12 +166,12 @@
return realmId;
}
- public InstanceState getState()
+ public State getState()
{
return state;
}
- public List<Action> getActions()
+ public List<InstanceAction> getActions()
{
return actions;
}
@@ -181,13 +179,26 @@
public List<String> getActionNames()
{
ArrayList<String>names = new ArrayList<String>();
- for (Action action : actions)
+ for (InstanceAction action : actions)
{
- names.add(action.name());
+ names.add(action.getName());
}
return names;
}
+ public InstanceAction getAction(String name) {
+ if (name == null) {
+ return null;
+ }
+
+ for(InstanceAction action : actions) {
+ if (name.equals(action.getName())) {
+ return action;
+ }
+ }
+ return null;
+ }
+
public List<String> getPublicAddresses()
{
return publicAddresses.getAddress();
Added:
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
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * An action that is executable on an instance
+ *
+ * @author André Dietisheim
+ * @see Instance
+ * @see DeltaCloudClient#performInstanceAction(String, String);
+ *
+ */
+public class InstanceAction {
+
+ public static final String START = "start";
+ public static final String STOP = "stop";
+ public static final String DESTROY = "destroy";
+ public static final String REBOOT = "reboot";
+
+ private String name;
+ private String url;
+ private HttpMethod method;
+
+ public InstanceAction(String name, String url, String method) {
+ this(name, url, HttpMethod.valueOf(method.toUpperCase()));
+ }
+
+ public InstanceAction(String name, String url, HttpMethod method) {
+ this.name = name;
+ this.url = url;
+ this.method = method;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public HttpMethod getMethod() {
+ return method;
+ }
+
+ @Override
+ public String toString() {
+ return "InstanceAction [name=" + name + ", url=" + url + ",
method=" + method + "]";
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/InstanceStoppedPropertyTester.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/InstanceStoppedPropertyTester.java 2010-11-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/InstanceStoppedPropertyTester.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -13,7 +13,7 @@
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.Assert;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
-import org.jboss.tools.deltacloud.core.client.Instance.InstanceState;
+import org.jboss.tools.deltacloud.core.client.Instance.State;
import org.jboss.tools.deltacloud.ui.views.CVInstanceElement;
/**
@@ -30,7 +30,7 @@
DeltaCloudInstance instance = (DeltaCloudInstance) cvInstance.getElement();
Assert.isTrue(expectedValue instanceof Boolean);
Boolean isExpectedValue = (Boolean) expectedValue;
- boolean isStopped = InstanceState.STOPPED.toString().equals(instance.getState());
+ boolean isStopped = State.STOPPED.toString().equals(instance.getState());
return isExpectedValue.equals(isStopped);
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java 2010-11-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/StartInstanceHandler.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -47,19 +47,21 @@
}
private void startInstance(CVInstanceElement cvInstance) {
- DeltaCloudInstance instance = (DeltaCloudInstance) cvInstance.getElement();
- CloudViewElement element = cvInstance;
- while (!(element instanceof CVCloudElement)) {
- element = (CloudViewElement) element.getParent();
+ if (cvInstance != null) {
+ DeltaCloudInstance instance = (DeltaCloudInstance) cvInstance.getElement();
+ CloudViewElement element = cvInstance;
+ while (!(element instanceof CVCloudElement)) {
+ element = (CloudViewElement) element.getParent();
+ }
+ CVCloudElement cvcloud = (CVCloudElement) element;
+ DeltaCloud cloud = (DeltaCloud) cvcloud.getElement();
+ PerformInstanceActionThread t = new PerformInstanceActionThread(cloud, instance,
+ DeltaCloudInstance.START,
+ CVMessages.getString(STARTING_INSTANCE_TITLE),
+ CVMessages.getFormattedString(STARTING_INSTANCE_MSG, new String[] {
instance.getName() }),
+ DeltaCloudInstance.RUNNING);
+ t.setUser(true);
+ t.schedule();
}
- CVCloudElement cvcloud = (CVCloudElement) element;
- DeltaCloud cloud = (DeltaCloud) cvcloud.getElement();
- PerformInstanceActionThread t = new PerformInstanceActionThread(cloud, instance,
- DeltaCloudInstance.START,
- CVMessages.getString(STARTING_INSTANCE_TITLE),
- CVMessages.getFormattedString(STARTING_INSTANCE_MSG, new String[] {
instance.getName() }),
- DeltaCloudInstance.RUNNING);
- t.setUser(true);
- t.schedule();
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/MandatoryStringValidator.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/MandatoryStringValidator.java 2010-11-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/MandatoryStringValidator.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -33,7 +33,7 @@
*/
public IStatus validate(Object value) {
if (!((value instanceof String) && ((String) value).length() > 0)) {
- return ValidationStatus.warning(errorMessage);
+ return ValidationStatus.error(errorMessage);
}
return ValidationStatus.ok();
}
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-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -68,7 +68,7 @@
*/
public class CloudConnectionPage extends WizardPage {
- private static final int CLOUDTYPE_CHECK_DELAY = 500;
+ private static final int CLOUDTYPE_CHECK_DELAY = 1000;
private static final String DESCRIPTION = "CloudConnection.desc";
//$NON-NLS-1$
private static final String TITLE = "CloudConnection.title"; //$NON-NLS-1$
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-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -25,12 +25,11 @@
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.Action;
import org.jboss.tools.deltacloud.core.client.Instance.State;
+import org.jboss.tools.deltacloud.core.client.InstanceAction;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -65,7 +64,7 @@
* @throws DeltaCloudClientException
* the delta cloud client exception
*/
- @Ignore
+
@Test
public void listContainsTestInstance() throws DeltaCloudClientException {
DeltaCloudClient client = testSetup.getClient();
@@ -75,7 +74,6 @@
assertNotNull(testSetup.getInstanceById(testInstance.getId(), client));
}
- @Ignore
@Test
public void listTestInstance() throws DeltaCloudClientException {
Instance instance =
testSetup.getClient().listInstances(testSetup.getTestInstance().getId());
@@ -94,7 +92,6 @@
, instance);
}
- @Ignore
@Test(expected = DeltaCloudClientException.class)
public void listDestroyedInstanceThrowsException() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
@@ -114,7 +111,6 @@
assertTrue(publicAddresses.equals(instance.getPublicAddresses()));
}
- @Ignore
@Test(expected = DeltaCloudClientException.class)
public void cannotDestroyIfNotAuthenticated() throws MalformedURLException,
DeltaCloudClientException {
DeltaCloudClient unauthenticatedClient = new
DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL,
@@ -123,7 +119,6 @@
unauthenticatedClient.createInstance(image.getId());
}
- @Ignore
@Test
public void canCreateInstance() throws DeltaCloudClientException {
Instance instance = null;
@@ -143,7 +138,6 @@
testSetup.getClient().createInstance("dummy");
}
- @Ignore
@Test
public void canDestroy() throws DeltaCloudClientException {
Image image = testSetup.getFirstImage(testSetup.getClient());
@@ -152,13 +146,11 @@
assertNull(testSetup.getInstanceById(instance.getId(), testSetup.getClient()));
}
- @Ignore
@Test(expected = DeltaCloudClientException.class)
public void destroyThrowExceptionOnUnknowInstanceId() throws DeltaCloudClientException
{
testSetup.getClient().destroyInstance("dummy");
}
- @Ignore
@Test
public void canShutdownInstance() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
@@ -168,7 +160,6 @@
assertEquals(State.STOPPED, testInstance.getState());
}
- @Ignore
@Test
public void canStartInstance() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
@@ -186,9 +177,9 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
if (testInstance.getState() == State.RUNNING) {
- client.performInstanceAction(testInstance.getId(), Action.STOP.toString());
+ client.performInstanceAction(testInstance.getId(), InstanceAction.STOP);
}
- assertTrue(client.performInstanceAction(testInstance.getId(),
Action.START.toString()));
+ assertTrue(client.performInstanceAction(testInstance.getId(), InstanceAction.START));
testInstance = client.listInstances(testInstance.getId()); // reload!
assertEquals(State.RUNNING, testInstance.getState());
}
@@ -198,7 +189,7 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
client.startInstance(testInstance.getId());
- assertFalse(client.performInstanceAction(testInstance.getId(),
Action.START.toString()));
+ assertFalse(client.performInstanceAction(testInstance.getId(), InstanceAction.START));
}
@Test
@@ -207,7 +198,7 @@
DeltaCloudClient client = testSetup.getClient();
try {
client.shutdownInstance(testInstance.getId());
- assertFalse(client.performInstanceAction(testInstance.getId(),
Action.STOP.toString()));
+ assertFalse(client.performInstanceAction(testInstance.getId(), InstanceAction.STOP));
} finally {
client.startInstance(testInstance.getId());
}
@@ -219,18 +210,19 @@
DeltaCloudClient client = testSetup.getClient();
testInstance = client.listInstances(testInstance.getId()); // reload
assertTrue(testInstance.getState() == State.RUNNING);
- assertFalse(client.performInstanceAction(testInstance.getId(),
Action.DESTROY.toString()));
+ assertFalse(client.performInstanceAction(testInstance.getId(),
InstanceAction.DESTROY));
}
@Test
- public void cannotRebootStoppedInstance() throws DeltaCloudClientException,
InterruptedException, ExecutionException {
+ public void cannotRebootStoppedInstance() throws DeltaCloudClientException,
InterruptedException,
+ ExecutionException {
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
try {
client.shutdownInstance(testInstance.getId());
testInstance = client.listInstances(testInstance.getId()); // reload
assertTrue(testInstance.getState() == State.STOPPED);
- assertFalse(client.performInstanceAction(testInstance.getId(),
Action.REBOOT.toString()));
+ assertFalse(client.performInstanceAction(testInstance.getId(),
InstanceAction.REBOOT));
} finally {
client.startInstance(testInstance.getId());
client.listInstances(testInstance.getId()); // reload
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-03
17:39:44 UTC (rev 26234)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java 2010-11-03
18:19:46 UTC (rev 26235)
@@ -22,6 +22,7 @@
import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundException;
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.jboss.tools.internal.deltacloud.test.fakes.ServerFake;
import org.junit.After;
@@ -85,7 +86,7 @@
try {
DeltaCloudClient errorClient = new
DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL) {
@Override
- protected HttpUriRequest getRequest(RequestType requestType, String requestUrl) {
+ protected HttpUriRequest getRequest(HttpMethod httpMethod, String requestUrl) {
return new HttpGet(MockIntegrationTestContext.DELTACLOUD_URL + "/DUMMY");
}
};