Author: adietish
Date: 2010-12-16 13:32:41 -0500 (Thu, 16 Dec 2010)
New Revision: 27565
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
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/DeltaCloudClientImpl.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java
Log:
[JBIDE-7371] implementing listing keys with deltacloud client
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-12-16
18:30:07 UTC (rev 27564)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-12-16
18:32:41 UTC (rev 27565)
@@ -124,7 +124,29 @@
public Instance createInstance(String imageId, String profileId, String realmId, String
name, String keyname,
String memory, String storage) throws DeltaCloudClientException;
+ /**
+ * Creates a key for a given name on the deltacloud server and stores it
+ * in the file at the given path. The file gets created if the file path
+ * does not exist yet.
+ *
+ * @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;
+ public String createKey(String keyname) throws DeltaCloudClientException;
+
+ /**
+ * Deletes the key with the given name on the deltacloud server
+ *
+ * @param keyname
+ * @throws DeltaCloudClientException
+ */
public void deleteKey(String keyname) throws DeltaCloudClientException;
+
+ public List<Key> listKeys() throws DeltaCloudClientException;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2010-12-16
18:30:07 UTC (rev 27564)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2010-12-16
18:32:41 UTC (rev 27565)
@@ -51,6 +51,7 @@
import org.eclipse.core.runtime.Path;
import org.jboss.tools.deltacloud.core.client.request.AbstractListObjectsRequest;
import org.jboss.tools.deltacloud.core.client.request.CreateInstanceRequest;
+import org.jboss.tools.deltacloud.core.client.request.CreateKeyRequest;
import org.jboss.tools.deltacloud.core.client.request.DeleteKeyRequest;
import org.jboss.tools.deltacloud.core.client.request.DeltaCloudRequest;
import org.jboss.tools.deltacloud.core.client.request.DeltaCloudRequest.HttpMethod;
@@ -60,7 +61,7 @@
import org.jboss.tools.deltacloud.core.client.request.ListImagesRequest;
import org.jboss.tools.deltacloud.core.client.request.ListInstanceRequest;
import org.jboss.tools.deltacloud.core.client.request.ListInstancesRequest;
-import org.jboss.tools.deltacloud.core.client.request.ListKeyRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListKeysRequest;
import org.jboss.tools.deltacloud.core.client.request.ListRealmRequest;
import org.jboss.tools.deltacloud.core.client.request.ListRealmsRequest;
import org.jboss.tools.deltacloud.core.client.request.PerformInstanceActionRequest;
@@ -82,7 +83,7 @@
private static final String DOCUMENT_ELEMENT_API = "api";
private static final Pattern ELEMENT_TEXTVALUE_REGEX = Pattern.compile("[^\n\t
]+[^\n]+");
-
+
public static Logger logger = Logger.getLogger(DeltaCloudClientImpl.class);
public static enum DeltaCloudServerType {
@@ -152,7 +153,7 @@
return null;
}
String xml = readInputStreamToString(entity.getContent());
- logger.debug("Response\n" + xml);
+ logger.debug("Response:\n" + xml);
return xml;
}
@@ -164,7 +165,7 @@
* @param requestUrl
* the requested url
* @return the request instance
- * @throws MalformedURLException
+ * @throws MalformedURLException
*/
protected HttpUriRequest createRequest(DeltaCloudRequest deltaCloudRequest) throws
MalformedURLException {
HttpUriRequest request = null;
@@ -191,9 +192,10 @@
* @param httpClient
* the http client
* @return the default http client
- * @throws UnknownHostException
+ * @throws UnknownHostException
*/
- private DefaultHttpClient addCredentials(URL url, DefaultHttpClient httpClient, String
username, String password) throws UnknownHostException {
+ private DefaultHttpClient addCredentials(URL url, DefaultHttpClient httpClient, String
username, String password)
+ throws UnknownHostException {
if (username != null && password != null) {
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(url.getHost(), url.getPort()),
@@ -262,19 +264,22 @@
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 {
- return buildInstance(sendRequest(new CreateInstanceRequest(baseUrl, imageId, profileId,
realmId, name, keyname, memory, storage)));
+ public Instance createInstance(String imageId, String profileId, String realmId, String
name, String keyname,
+ String memory, String storage) throws DeltaCloudClientException {
+ return buildInstance(sendRequest(new CreateInstanceRequest(baseUrl, imageId, profileId,
realmId, name, keyname,
+ memory, storage)));
}
@Override
public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException {
- return buildDeltaCloudObject(HardwareProfile.class, sendRequest(new
ListHardwareProfileRequest(baseUrl, profileId)));
+ return buildDeltaCloudObject(HardwareProfile.class, sendRequest(new
ListHardwareProfileRequest(baseUrl,
+ profileId)));
}
@Override
public List<HardwareProfile> listProfiles() throws DeltaCloudClientException {
- return listDeltaCloudObjects(HardwareProfile.class,
- new ListHardwareProfilesRequest(baseUrl),"hardware_profile");
+ return listDeltaCloudObjects(HardwareProfile.class,
+ new ListHardwareProfilesRequest(baseUrl), "hardware_profile");
}
@Override
@@ -294,7 +299,8 @@
@Override
public Instance listInstances(String instanceId) throws DeltaCloudClientException {
-// return JAXB.unmarshal(new StringReader(sendRequest(new ListInstanceRequest(baseUrl,
instanceId))), Instance.class);
+ // return JAXB.unmarshal(new StringReader(sendRequest(new
+ // ListInstanceRequest(baseUrl, instanceId))), Instance.class);
return buildInstance(sendRequest(new ListInstanceRequest(baseUrl, instanceId)));
}
@@ -308,20 +314,12 @@
return JAXB.unmarshal(new StringReader(sendRequest(new ListRealmRequest(baseUrl,
realmId))), 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 String createKey(String keyname) throws DeltaCloudClientException {
+ return sendRequest(new CreateKeyRequest(baseUrl, keyname));
+ }
+
public void createKey(String keyname, String keyStoreLocation) throws
DeltaCloudClientException {
- String xml = sendRequest(new ListKeyRequest(baseUrl, keyname));
+ String xml = createKey(keyname);
try {
String key = trimKey(getKey(xml));
File keyFile = createKeyFile(keyname, keyStoreLocation);
@@ -361,7 +359,10 @@
}
private File createKeyFile(String keyname, String keyStoreLocation) throws IOException
{
- File keyFile = Path.fromOSString(keyStoreLocation).append(keyname + "." +
PEM_FILE_SUFFIX).toFile(); //$NON-NLS-1$
+ File keyFile =
+ Path.fromOSString(keyStoreLocation)
+ .append(keyname).append(".").append(PEM_FILE_SUFFIX)
+ .toFile(); //$NON-NLS-1$
if (!keyFile.exists()) {
keyFile.createNewFile();
}
@@ -374,6 +375,12 @@
public void deleteKey(String keyname) throws DeltaCloudClientException {
sendRequest(new DeleteKeyRequest(baseUrl, keyname));
}
+
+ public List<Key> listKeys() throws DeltaCloudClientException {
+ String xml = sendRequest(new ListKeysRequest(baseUrl));
+ Key instance = JAXB.unmarshal(new StringReader(xml), Key.class);
+ throw new UnsupportedOperationException();
+ }
private Instance updateInstance(String xml, Instance instance) throws
DeltaCloudClientException {
try {
@@ -631,12 +638,14 @@
try {
String response = sendRequest(
new PerformInstanceActionRequest(new URL(action.getUrl()),
- action.getMethod()));
+ action.getMethod()));
if (!InstanceAction.DESTROY.equals(action.getName())) {
updateInstance(response, action.getInstance());
}
} catch (MalformedURLException e) {
- throw new DeltaCloudClientException(MessageFormat.format("Could not perform
action {0} on instance {1}", action.getName(), action.getInstance().getName()), e);
+ throw new DeltaCloudClientException(MessageFormat.format(
+ "Could not perform action {0} on instance {1}", action.getName(),
action.getInstance()
+ .getName()), e);
}
return true;
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java 2010-12-16
18:32:41 UTC (rev 27565)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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 javax.xml.bind.annotation.XmlElement;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class Key extends DeltaCloudObject {
+
+ private static final long serialVersionUID = 1L;
+
+ public static enum InstanceState {
+ RUNNING, STOPPED, PENDING, TERMINATED, BOGUS
+ };
+
+ @XmlElement
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ @SuppressWarnings("unused")
+ private void setName(String name) {
+ this.name = name;
+ }
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Key.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
(from rev 27554,
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java)
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java 2010-12-16
18:32:41 UTC (rev 27565)
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import java.net.URL;
+
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+
+/**
+ * Creates a key on the deltacloud server
+ *
+ * @author André Dietisheim
+ */
+public class CreateKeyRequest extends AbstractDeltaCloudRequest {
+
+ private String keyName;
+
+ public CreateKeyRequest(URL baseUrl, String keyName) {
+ super(baseUrl, HttpMethod.POST);
+ this.keyName = keyName;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("keys").parameter("name",
keyName).toString();
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java 2010-12-16
18:30:07 UTC (rev 27564)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java 2010-12-16
18:32:41 UTC (rev 27565)
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.deltacloud.core.client.request;
-
-import java.net.URL;
-
-import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
-
-
-/**
- * Lists a key on the deltacloud server
- *
- * @author André Dietisheim
- */
-public class ListKeyRequest extends AbstractDeltaCloudRequest {
-
- private String keyName;
-
- public ListKeyRequest(URL baseUrl, String keyName) {
- super(baseUrl, HttpMethod.POST);
- this.keyName = keyName;
- }
-
- @Override
- protected String doCreateUrl(UrlBuilder urlBuilder) {
- return urlBuilder.path("keys").parameter("name",
keyName).toString();
- }
-}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java 2010-12-16
18:32:41 UTC (rev 27565)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import java.net.URL;
+
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+
+/**
+ * Lists keys available on the deltacloud server
+ *
+ * @author André Dietisheim
+ */
+public class ListKeysRequest extends AbstractDeltaCloudRequest {
+
+ public ListKeysRequest(URL baseUrl) {
+ super(baseUrl, HttpMethod.GET);
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("keys").toString();
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java 2010-12-16
18:30:07 UTC (rev 27564)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java 2010-12-16
18:32:41 UTC (rev 27565)
@@ -10,13 +10,16 @@
******************************************************************************/
package org.jboss.tools.internal.deltacloud.test.core.client;
+import static org.junit.Assert.assertNotNull;
+
import java.io.IOException;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.junit.After;
import org.junit.Before;
+import org.junit.Test;
/**
* Integration tests for key related operations in delta cloud client.
@@ -40,4 +43,16 @@
public void tearDown() {
testSetup.tearDown();
}
+
+ @Test
+ public void canCreateKey() throws DeltaCloudClientException {
+ String key = testSetup.getClient().createKey("test");
+ assertNotNull(key);
+
+ }
+
+ @Test
+ public void canListKeys() {
+
+ }
}