Author: adietish
Date: 2011-09-30 06:14:12 -0400 (Fri, 30 Sep 2011)
New Revision: 35204
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/SSHPublicKey.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/InternalUser.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/UserInfo.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/unmarshalling/ApplicationResponseUnmarshaller.java
Log:
[JBIDE-9793] added #getServiceUrl. moved OpenshiftService abd SSHKeyPair to visible
package
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java 2011-09-30
09:43:53 UTC (rev 35203)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java 2011-09-30
10:14:12 UTC (rev 35204)
@@ -27,11 +27,18 @@
public static final String BASE_URL = "https://openshift.redhat.com";
/**
- * The service base url
+ * the path (url path addition)
*/
- public static final String SERVICE_BASE_URL = BASE_URL + "/com/broker";
+ public static final String SERVICE_PATH = "/com/broker";
/**
+ * returns the url at which the service is reachable.
+ *
+ * @return
+ */
+ public String getServiceUrl();
+
+ /**
* List all cartridges that are available on the Openshift Express platform.
*
* @param user the user account that shall be used
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java
(from rev 35203,
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java 2011-09-30
10:14:12 UTC (rev 35204)
@@ -0,0 +1,234 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.ide.eclipse.as.openshift.core;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+import org.jboss.ide.eclipse.as.openshift.core.internal.Application;
+import org.jboss.ide.eclipse.as.openshift.core.internal.InternalUser;
+import org.jboss.ide.eclipse.as.openshift.core.internal.UserInfo;
+import org.jboss.ide.eclipse.as.openshift.core.internal.httpclient.HttpClientException;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.httpclient.UnauthorizedException;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.httpclient.UrlConnectionHttpClient;
+import org.jboss.ide.eclipse.as.openshift.core.internal.request.AbstractDomainRequest;
+import org.jboss.ide.eclipse.as.openshift.core.internal.request.ApplicationAction;
+import org.jboss.ide.eclipse.as.openshift.core.internal.request.ApplicationRequest;
+import org.jboss.ide.eclipse.as.openshift.core.internal.request.ChangeDomainRequest;
+import org.jboss.ide.eclipse.as.openshift.core.internal.request.CreateDomainRequest;
+import org.jboss.ide.eclipse.as.openshift.core.internal.request.ListCartridgesRequest;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.request.OpenshiftEnvelopeFactory;
+import org.jboss.ide.eclipse.as.openshift.core.internal.request.UserInfoRequest;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.request.marshalling.ApplicationRequestJsonMarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.request.marshalling.DomainRequestJsonMarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.request.marshalling.ListCartridgesRequestJsonMarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.request.marshalling.UserInfoRequestJsonMarshaller;
+import org.jboss.ide.eclipse.as.openshift.core.internal.response.OpenshiftResponse;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.ApplicationResponseUnmarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.ApplicationStatusResponseUnmarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.DomainResponseUnmarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.JsonSanitizer;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.ListCartridgesResponseUnmarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.UserInfoResponseUnmarshaller;
+
+/**
+ * @author André Dietisheim
+ */
+public class OpenshiftService implements IOpenshiftService {
+
+ private String baseUrl;
+
+ public OpenshiftService() {
+ this(BASE_URL);
+ }
+
+ protected OpenshiftService(String baseUrl) {
+ this.baseUrl = baseUrl;
+ }
+
+ public String getServiceUrl() {
+ return baseUrl + SERVICE_PATH;
+ }
+
+ @Override
+ public UserInfo getUserInfo(InternalUser user) throws OpenshiftException {
+ UserInfoRequest request = new UserInfoRequest(user.getRhlogin(), true);
+ String url = request.getUrlString(getServiceUrl());
+ try {
+ String requestString = new UserInfoRequestJsonMarshaller().marshall(request);
+ String openShiftRequestString = new OpenshiftEnvelopeFactory(user.getPassword(),
requestString)
+ .createString();
+ String responseString = createHttpClient(url).post(openShiftRequestString);
+ responseString = JsonSanitizer.sanitize(responseString);
+ OpenshiftResponse<UserInfo> response =
+ new UserInfoResponseUnmarshaller().unmarshall(responseString);
+ return response.getOpenshiftObject();
+ } catch (MalformedURLException e) {
+ throw new OpenshiftEndpointException(
+ url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url, e);
+ } catch (HttpClientException e) {
+ throw new OpenshiftEndpointException(
+ url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url, e);
+ }
+ }
+
+ @Override
+ public List<ICartridge> getCartridges(InternalUser user) throws OpenshiftException
{
+ ListCartridgesRequest listCartridgesRequest = new
ListCartridgesRequest(user.getRhlogin(), true);
+ String url = listCartridgesRequest.getUrlString(BASE_URL);
+ try {
+ String listCartridgesRequestString =
+ new ListCartridgesRequestJsonMarshaller().marshall(listCartridgesRequest);
+ String request = new OpenshiftEnvelopeFactory(user.getPassword(),
listCartridgesRequestString)
+ .createString();
+ String listCatridgesReponse = createHttpClient(url).post(request);
+ listCatridgesReponse = JsonSanitizer.sanitize(listCatridgesReponse);
+ OpenshiftResponse<List<ICartridge>> response =
+ new ListCartridgesResponseUnmarshaller().unmarshall(listCatridgesReponse);
+ return response.getOpenshiftObject();
+ } catch (MalformedURLException e) {
+ throw new OpenshiftEndpointException(url, e, "Could not list available cartridges
at \"{0}\"", url);
+ } catch (HttpClientException e) {
+ throw new OpenshiftEndpointException(url, e, "Could not list available cartridges
at \"{0}\"", url);
+ }
+ }
+
+ @Override
+ public IDomain createDomain(String name, ISSHPublicKey sshKey, InternalUser user) throws
OpenshiftException {
+ return requestDomainAction(new CreateDomainRequest(name, sshKey, user.getRhlogin(),
true), user);
+ }
+
+ @Override
+ public IDomain changeDomain(String newName, ISSHPublicKey sshKey, InternalUser user)
throws OpenshiftException {
+ return requestDomainAction(new ChangeDomainRequest(newName, sshKey, user.getRhlogin(),
true), user);
+ }
+
+ protected IDomain requestDomainAction(AbstractDomainRequest request, InternalUser user)
throws OpenshiftException {
+ String url = request.getUrlString(getServiceUrl());
+ try {
+ String requestString =
+ new OpenshiftEnvelopeFactory(
+ user.getPassword(),
+ new DomainRequestJsonMarshaller().marshall(request))
+ .createString();
+ String responseString = createHttpClient(url).post(requestString);
+ responseString = JsonSanitizer.sanitize(responseString);
+ OpenshiftResponse<IDomain> response =
+ new DomainResponseUnmarshaller(request.getName(), user).unmarshall(responseString);
+ return response.getOpenshiftObject();
+ } catch (MalformedURLException e) {
+ throw new OpenshiftEndpointException(url, e, "Could reach openshift platform at
\"{0}\"", url);
+ } catch (HttpClientException e) {
+ throw new OpenshiftEndpointException(url, e, "Could not {0}",
request.toHumanReadable());
+ }
+ }
+
+ @Override
+ public Application createApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
+ Application application = requestApplicationAction(new ApplicationRequest(name,
cartridge, ApplicationAction.CONFIGURE,
+ user.getRhlogin(), true), user);
+ return application;
+ }
+
+ @Override
+ public void destroyApplication(String name, ICartridge cartridge, InternalUser user)
throws OpenshiftException {
+ IApplication application = requestApplicationAction(new ApplicationRequest(name,
cartridge, ApplicationAction.DECONFIGURE,
+ user.getRhlogin(), true), user);
+ user.remove(application);
+ }
+
+ @Override
+ public IApplication startApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
+ return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.START,
+ user.getRhlogin(), true), user);
+ }
+
+ @Override
+ public IApplication restartApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
+ return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.RESTART,
+ user.getRhlogin(), true), user);
+ }
+
+ @Override
+ public IApplication stopApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
+ return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.STOP,
+ user.getRhlogin(), true), user);
+ }
+
+ @Override
+ public String getStatus(String applicationName, ICartridge cartridge, InternalUser user)
throws OpenshiftException {
+ ApplicationRequest applicationRequest =
+ new ApplicationRequest(applicationName, cartridge, ApplicationAction.STATUS,
user.getRhlogin(), true);
+ String url = applicationRequest.getUrlString(getServiceUrl());
+ try {
+ String applicationRequestString =
+ new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
+ String request = new OpenshiftEnvelopeFactory(user.getPassword(),
applicationRequestString).createString();
+ String response = createHttpClient(url).post(request);
+
+ response = JsonSanitizer.sanitize(response);
+ OpenshiftResponse<String> openshiftResponse =
+ new ApplicationStatusResponseUnmarshaller().unmarshall(response);
+ return openshiftResponse.getOpenshiftObject();
+ } catch (MalformedURLException e) {
+ throw new OpenshiftException(
+ e, "Could not {0} application \"{1}\" at \"{2}\": Invalid
url \"{2}\"",
+ applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url);
+ } catch (UnauthorizedException e) {
+ throw new InvalidCredentialsOpenshiftException(
+ url, e,
+ "Could not {0} application \"{1}\" at \"{2}\": Invalid
credentials user \"{3}\", password \"{4}\"",
+ applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url,
+ user.getRhlogin(), user.getPassword());
+ } catch (HttpClientException e) {
+ throw new OpenshiftEndpointException(
+ url, e, "Could not {0} application \"{1}\" at
\"{2}\"",
+ applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url);
+ }
+ }
+
+ protected Application requestApplicationAction(ApplicationRequest applicationRequest,
InternalUser user)
+ throws OpenshiftException {
+ String url = applicationRequest.getUrlString(getServiceUrl());
+ try {
+ String applicationRequestString =
+ new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
+ String request = new OpenshiftEnvelopeFactory(user.getPassword(),
applicationRequestString).createString();
+ String response = createHttpClient(url).post(request);
+
+ response = JsonSanitizer.sanitize(response);
+ OpenshiftResponse<Application> openshiftResponse =
+ new ApplicationResponseUnmarshaller(applicationRequest.getName(),
+ applicationRequest.getCartridge(), user, this).unmarshall(response);
+ return openshiftResponse.getOpenshiftObject();
+ } catch (MalformedURLException e) {
+ throw new OpenshiftException(
+ e, "Could not {0} application \"{1}\" at \"{2}\": Invalid
url \"{2}\"",
+ applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url);
+ } catch (UnauthorizedException e) {
+ throw new InvalidCredentialsOpenshiftException(
+ url, e,
+ "Could not {0} application \"{1}\" at \"{2}\": Invalid
credentials user \"{3}\", password \"{4}\"",
+ applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url,
+ user.getRhlogin(),
+ user.getPassword());
+ } catch (HttpClientException e) {
+ throw new OpenshiftEndpointException(
+ url, e, "Could not {0} application \"{1}\" at
\"{2}\"",
+ applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url);
+ }
+ }
+
+ private IHttpClient createHttpClient(String url) throws MalformedURLException {
+ return new UrlConnectionHttpClient(new URL(url));
+ }
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java
(from rev 35151,
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/SSHPublicKey.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java 2011-09-30
10:14:12 UTC (rev 35204)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.ide.eclipse.as.openshift.core;
+
+
+/**
+ * @author André Dietisheim
+ */
+public class SSHPublicKey implements ISSHPublicKey {
+
+ private String publicKey;
+
+ public SSHPublicKey(String publicKey) {
+ this.publicKey = publicKey;
+ }
+
+ public String getPublicKey() {
+ return publicKey;
+ }
+
+ void update(String publicKey) {
+ }
+
+ public void update(ISSHPublicKey sshPublicKey) throws OpenshiftException {
+ this.publicKey = sshPublicKey.getPublicKey();
+ }
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/InternalUser.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/InternalUser.java 2011-09-30
09:43:53 UTC (rev 35203)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/InternalUser.java 2011-09-30
10:14:12 UTC (rev 35204)
@@ -22,6 +22,7 @@
import org.jboss.ide.eclipse.as.openshift.core.ISSHPublicKey;
import org.jboss.ide.eclipse.as.openshift.core.IUser;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftService;
/**
* @author André Dietisheim
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java 2011-09-30
09:43:53 UTC (rev 35203)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java 2011-09-30
10:14:12 UTC (rev 35204)
@@ -1,236 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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.ide.eclipse.as.openshift.core.internal;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-
-import org.jboss.ide.eclipse.as.openshift.core.IApplication;
-import org.jboss.ide.eclipse.as.openshift.core.ICartridge;
-import org.jboss.ide.eclipse.as.openshift.core.IDomain;
-import org.jboss.ide.eclipse.as.openshift.core.IHttpClient;
-import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftService;
-import org.jboss.ide.eclipse.as.openshift.core.ISSHPublicKey;
-import org.jboss.ide.eclipse.as.openshift.core.InvalidCredentialsOpenshiftException;
-import org.jboss.ide.eclipse.as.openshift.core.OpenshiftEndpointException;
-import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
-import org.jboss.ide.eclipse.as.openshift.core.internal.httpclient.HttpClientException;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.httpclient.UnauthorizedException;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.httpclient.UrlConnectionHttpClient;
-import org.jboss.ide.eclipse.as.openshift.core.internal.request.AbstractDomainRequest;
-import org.jboss.ide.eclipse.as.openshift.core.internal.request.ApplicationAction;
-import org.jboss.ide.eclipse.as.openshift.core.internal.request.ApplicationRequest;
-import org.jboss.ide.eclipse.as.openshift.core.internal.request.ChangeDomainRequest;
-import org.jboss.ide.eclipse.as.openshift.core.internal.request.CreateDomainRequest;
-import org.jboss.ide.eclipse.as.openshift.core.internal.request.ListCartridgesRequest;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.request.OpenshiftEnvelopeFactory;
-import org.jboss.ide.eclipse.as.openshift.core.internal.request.UserInfoRequest;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.request.marshalling.ApplicationRequestJsonMarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.request.marshalling.DomainRequestJsonMarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.request.marshalling.ListCartridgesRequestJsonMarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.request.marshalling.UserInfoRequestJsonMarshaller;
-import org.jboss.ide.eclipse.as.openshift.core.internal.response.OpenshiftResponse;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.ApplicationResponseUnmarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.ApplicationStatusResponseUnmarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.DomainResponseUnmarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.JsonSanitizer;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.ListCartridgesResponseUnmarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.response.unmarshalling.UserInfoResponseUnmarshaller;
-
-/**
- * @author André Dietisheim
- */
-public class OpenshiftService implements IOpenshiftService {
-
- private String baseUrl;
-
- public OpenshiftService() {
- this(BASE_URL);
- }
-
- protected OpenshiftService(String baseUrl) {
- this.baseUrl = baseUrl;
- }
-
- @Override
- public UserInfo getUserInfo(InternalUser user) throws OpenshiftException {
- UserInfoRequest request = new UserInfoRequest(user.getRhlogin(), true);
- String url = request.getUrlString(baseUrl);
- try {
- String requestString = new UserInfoRequestJsonMarshaller().marshall(request);
- String openShiftRequestString = new OpenshiftEnvelopeFactory(user.getPassword(),
requestString)
- .createString();
- String responseString = createHttpClient(url).post(openShiftRequestString);
- responseString = JsonSanitizer.sanitize(responseString);
- OpenshiftResponse<UserInfo> response =
- new UserInfoResponseUnmarshaller().unmarshall(responseString);
- return response.getOpenshiftObject();
- } catch (MalformedURLException e) {
- throw new OpenshiftEndpointException(
- url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url, e);
- } catch (HttpClientException e) {
- throw new OpenshiftEndpointException(
- url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url, e);
- }
- }
-
- @Override
- public List<ICartridge> getCartridges(InternalUser user) throws OpenshiftException
{
- ListCartridgesRequest listCartridgesRequest = new
ListCartridgesRequest(user.getRhlogin(), true);
- String url = listCartridgesRequest.getUrlString(BASE_URL);
- try {
- String listCartridgesRequestString =
- new ListCartridgesRequestJsonMarshaller().marshall(listCartridgesRequest);
- String request = new OpenshiftEnvelopeFactory(user.getPassword(),
listCartridgesRequestString)
- .createString();
- String listCatridgesReponse = createHttpClient(url).post(request);
- listCatridgesReponse = JsonSanitizer.sanitize(listCatridgesReponse);
- OpenshiftResponse<List<ICartridge>> response =
- new ListCartridgesResponseUnmarshaller().unmarshall(listCatridgesReponse);
- return response.getOpenshiftObject();
- } catch (MalformedURLException e) {
- throw new OpenshiftEndpointException(url, e, "Could not list available cartridges
at \"{0}\"", url);
- } catch (HttpClientException e) {
- throw new OpenshiftEndpointException(url, e, "Could not list available cartridges
at \"{0}\"", url);
- }
- }
-
- @Override
- public IDomain createDomain(String name, ISSHPublicKey sshKey, InternalUser user) throws
OpenshiftException {
- return requestDomainAction(new CreateDomainRequest(name, sshKey, user.getRhlogin(),
true), user);
- }
-
- @Override
- public IDomain changeDomain(String newName, ISSHPublicKey sshKey, InternalUser user)
throws OpenshiftException {
- return requestDomainAction(new ChangeDomainRequest(newName, sshKey, user.getRhlogin(),
true), user);
- }
-
- protected IDomain requestDomainAction(AbstractDomainRequest request, InternalUser user)
throws OpenshiftException {
- String url = request.getUrlString(baseUrl);
- try {
- String requestString =
- new OpenshiftEnvelopeFactory(
- user.getPassword(),
- new DomainRequestJsonMarshaller().marshall(request))
- .createString();
- String responseString = createHttpClient(url).post(requestString);
- responseString = JsonSanitizer.sanitize(responseString);
- OpenshiftResponse<IDomain> response =
- new DomainResponseUnmarshaller(request.getName(), user).unmarshall(responseString);
- return response.getOpenshiftObject();
- } catch (MalformedURLException e) {
- throw new OpenshiftEndpointException(url, e, "Could reach openshift platform at
\"{0}\"", url);
- } catch (HttpClientException e) {
- throw new OpenshiftEndpointException(url, e, "Could not {0}",
request.toHumanReadable());
- }
- }
-
- @Override
- public Application createApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
- Application application = requestApplicationAction(new ApplicationRequest(name,
cartridge, ApplicationAction.CONFIGURE,
- user.getRhlogin(), true), user);
- return application;
- }
-
- @Override
- public void destroyApplication(String name, ICartridge cartridge, InternalUser user)
throws OpenshiftException {
- IApplication application = requestApplicationAction(new ApplicationRequest(name,
cartridge, ApplicationAction.DECONFIGURE,
- user.getRhlogin(), true), user);
- user.remove(application);
- }
-
- @Override
- public IApplication startApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
- return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.START,
- user.getRhlogin(), true), user);
- }
-
- @Override
- public IApplication restartApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
- return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.RESTART,
- user.getRhlogin(), true), user);
- }
-
- @Override
- public IApplication stopApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
- return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.STOP,
- user.getRhlogin(), true), user);
- }
-
- @Override
- public String getStatus(String applicationName, ICartridge cartridge, InternalUser user)
throws OpenshiftException {
- ApplicationRequest applicationRequest =
- new ApplicationRequest(applicationName, cartridge, ApplicationAction.STATUS,
user.getRhlogin(), true);
- String url = applicationRequest.getUrlString(baseUrl);
- try {
- String applicationRequestString =
- new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
- String request = new OpenshiftEnvelopeFactory(user.getPassword(),
applicationRequestString).createString();
- String response = createHttpClient(url).post(request);
-
- response = JsonSanitizer.sanitize(response);
- OpenshiftResponse<String> openshiftResponse =
- new ApplicationStatusResponseUnmarshaller().unmarshall(response);
- return openshiftResponse.getOpenshiftObject();
- } catch (MalformedURLException e) {
- throw new OpenshiftException(
- e, "Could not {0} application \"{1}\" at \"{2}\": Invalid
url \"{2}\"",
- applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url);
- } catch (UnauthorizedException e) {
- throw new InvalidCredentialsOpenshiftException(
- url, e,
- "Could not {0} application \"{1}\" at \"{2}\": Invalid
credentials user \"{3}\", password \"{4}\"",
- applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url,
- user.getRhlogin(), user.getPassword());
- } catch (HttpClientException e) {
- throw new OpenshiftEndpointException(
- url, e, "Could not {0} application \"{1}\" at
\"{2}\"",
- applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url);
- }
- }
-
- protected Application requestApplicationAction(ApplicationRequest applicationRequest,
InternalUser user)
- throws OpenshiftException {
- String url = applicationRequest.getUrlString(baseUrl);
- try {
- String applicationRequestString =
- new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
- String request = new OpenshiftEnvelopeFactory(user.getPassword(),
applicationRequestString).createString();
- String response = createHttpClient(url).post(request);
-
- response = JsonSanitizer.sanitize(response);
- OpenshiftResponse<Application> openshiftResponse =
- new ApplicationResponseUnmarshaller(applicationRequest.getName(),
- applicationRequest.getCartridge(), user, this).unmarshall(response);
- return openshiftResponse.getOpenshiftObject();
- } catch (MalformedURLException e) {
- throw new OpenshiftException(
- e, "Could not {0} application \"{1}\" at \"{2}\": Invalid
url \"{2}\"",
- applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url);
- } catch (UnauthorizedException e) {
- throw new InvalidCredentialsOpenshiftException(
- url, e,
- "Could not {0} application \"{1}\" at \"{2}\": Invalid
credentials user \"{3}\", password \"{4}\"",
- applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url,
- user.getRhlogin(),
- user.getPassword());
- } catch (HttpClientException e) {
- throw new OpenshiftEndpointException(
- url, e, "Could not {0} application \"{1}\" at
\"{2}\"",
- applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url);
- }
- }
-
- private IHttpClient createHttpClient(String url) throws MalformedURLException {
- return new UrlConnectionHttpClient(new URL(url));
- }
-}
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/SSHPublicKey.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/SSHPublicKey.java 2011-09-30
09:43:53 UTC (rev 35203)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/SSHPublicKey.java 2011-09-30
10:14:12 UTC (rev 35204)
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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.ide.eclipse.as.openshift.core.internal;
-
-import org.jboss.ide.eclipse.as.openshift.core.ISSHPublicKey;
-import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
-
-/**
- * @author André Dietisheim
- */
-public class SSHPublicKey implements ISSHPublicKey {
-
- private String publicKey;
-
- public SSHPublicKey(String publicKey) {
- this.publicKey = publicKey;
- }
-
- public String getPublicKey() {
- return publicKey;
- }
-
- void update(String publicKey) {
- }
-
- public void update(ISSHPublicKey sshPublicKey) throws OpenshiftException {
- this.publicKey = sshPublicKey.getPublicKey();
- }
-}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/UserInfo.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/UserInfo.java 2011-09-30
09:43:53 UTC (rev 35203)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/UserInfo.java 2011-09-30
10:14:12 UTC (rev 35204)
@@ -12,7 +12,9 @@
import java.util.List;
+import org.jboss.ide.eclipse.as.openshift.core.SSHPublicKey;
+
/**
* @author André Dietisheim
*/
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/unmarshalling/ApplicationResponseUnmarshaller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/unmarshalling/ApplicationResponseUnmarshaller.java 2011-09-30
09:43:53 UTC (rev 35203)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/unmarshalling/ApplicationResponseUnmarshaller.java 2011-09-30
10:14:12 UTC (rev 35204)
@@ -12,8 +12,8 @@
import org.jboss.dmr.ModelNode;
import org.jboss.ide.eclipse.as.openshift.core.ICartridge;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftService;
import org.jboss.ide.eclipse.as.openshift.core.internal.Application;
-import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
import org.jboss.ide.eclipse.as.openshift.core.internal.InternalUser;
/**