Author: adietish
Date: 2011-09-30 10:08:35 -0400 (Fri, 30 Sep 2011)
New Revision: 35223
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/NotFoundOpenshiftException.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/IUser.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/InvalidCredentialsOpenshiftException.java
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/User.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/InternalUser.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserIntegrationTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/TestUser.java
Log:
[JBIDE-9811] added IOpenshiftService#isValid(User) and IUser#isValid()
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
13:59:16 UTC (rev 35222)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.openshift.core;
+import java.net.MalformedURLException;
import java.util.List;
import org.jboss.ide.eclipse.as.openshift.core.internal.ApplicationInfo;
@@ -29,7 +30,7 @@
/**
* The path (url path addition) to the service
*/
- public static final String SERVICE_PATH = "/com/broker";
+ public static final String SERVICE_PATH = "/broker";
/**
* Returns the url at which the service is reachable.
@@ -46,20 +47,14 @@
public String getPlatformUrl();
/**
- * Returns <code>true</code> if the service is reachable. Returns
+ * Returns <code>true</code> if given user has valid credentials. Returns
* <code>false</code> otherwise.
*
- * @return true if the service is reachable.
- */
- public boolean isReachable();
-
- /**
- * Returns <code>true</code> if the service is reachable and the
credentials
- * are valid. Returns <code>false</code> otherwise.
- *
* @return
+ * @throws OpenshiftException
+ * @throws MalformedURLException
*/
- public boolean areCredentialsValid();
+ public boolean isValid(InternalUser user) throws OpenshiftException;
/**
* List all cartridges that are available on the Openshift Express platform.
@@ -68,6 +63,7 @@
* the user account that shall be used
* @return the list of cartridges available on the platform
* @throws OpenshiftException
+ * @throws MalformedURLException
*
* @see InternalUser
*/
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IUser.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IUser.java 2011-09-30
13:59:16 UTC (rev 35222)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IUser.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -22,6 +22,8 @@
public String getPassword();
+ public boolean isValid() throws OpenshiftException;
+
public String getUUID() throws OpenshiftException;
public IDomain createDomain(String name, ISSHPublicKey key) throws OpenshiftException;
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/InvalidCredentialsOpenshiftException.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/InvalidCredentialsOpenshiftException.java 2011-09-30
13:59:16 UTC (rev 35222)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/InvalidCredentialsOpenshiftException.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -18,7 +18,7 @@
private static final long serialVersionUID = 1L;
- public InvalidCredentialsOpenshiftException(String url, Throwable cause, String
message, Object... arguments) {
- super(url, cause, message);
+ public InvalidCredentialsOpenshiftException(String url, Throwable cause) {
+ super(url, cause, "Your credentials are not authorized to access
\"{0}\"", url);
}
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/NotFoundOpenshiftException.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/NotFoundOpenshiftException.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/NotFoundOpenshiftException.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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 NotFoundOpenshiftException extends OpenshiftEndpointException {
+
+ private static final long serialVersionUID = 1L;
+
+ public NotFoundOpenshiftException(String url, Throwable cause) {
+ super(url, cause, "Could not find any Openshift Express resource at
\"{0}\"", url);
+ }
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/NotFoundOpenshiftException.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/OpenshiftService.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java 2011-09-30
13:59:16 UTC (rev 35222)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -18,6 +18,7 @@
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.NotFoundException;
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;
@@ -51,15 +52,26 @@
this(BASE_URL);
}
- protected OpenshiftService(String baseUrl) {
+ public OpenshiftService(String baseUrl) {
this.baseUrl = baseUrl;
}
+ @Override
public String getServiceUrl() {
return baseUrl + SERVICE_PATH;
}
-
+
@Override
+ public String getPlatformUrl() {
+ return baseUrl;
+ }
+
+ @Override
+ public boolean isValid(InternalUser user) throws OpenshiftException {
+ return getUserInfo(user) != null;
+ }
+
+ @Override
public UserInfo getUserInfo(InternalUser user) throws OpenshiftException {
UserInfoRequest request = new UserInfoRequest(user.getRhlogin(), true);
String url = request.getUrlString(getServiceUrl());
@@ -74,17 +86,21 @@
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);
+ url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url);
+ } catch (UnauthorizedException e) {
+ throw new InvalidCredentialsOpenshiftException(url, e);
+ } catch (NotFoundException e) {
+ throw new NotFoundOpenshiftException(url, e);
} catch (HttpClientException e) {
throw new OpenshiftEndpointException(
- url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url, e);
+ url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url);
}
}
@Override
public List<ICartridge> getCartridges(InternalUser user) throws OpenshiftException
{
ListCartridgesRequest listCartridgesRequest = new
ListCartridgesRequest(user.getRhlogin(), true);
- String url = listCartridgesRequest.getUrlString(BASE_URL);
+ String url = listCartridgesRequest.getUrlString(getServiceUrl());
try {
String listCartridgesRequestString =
new ListCartridgesRequestJsonMarshaller().marshall(listCartridgesRequest);
@@ -95,8 +111,13 @@
OpenshiftResponse<List<ICartridge>> response =
new ListCartridgesResponseUnmarshaller().unmarshall(listCatridgesReponse);
return response.getOpenshiftObject();
+ /**
+ * always allowed to list cartridges, even with invalid credentials
+ */
} catch (MalformedURLException e) {
throw new OpenshiftEndpointException(url, e, "Could not list available cartridges
at \"{0}\"", url);
+ } catch (NotFoundException e) {
+ throw new NotFoundOpenshiftException(url, e);
} catch (HttpClientException e) {
throw new OpenshiftEndpointException(url, e, "Could not list available cartridges
at \"{0}\"", url);
}
@@ -127,33 +148,42 @@
return response.getOpenshiftObject();
} catch (MalformedURLException e) {
throw new OpenshiftEndpointException(url, e, "Could reach openshift platform at
\"{0}\"", url);
+ } catch (UnauthorizedException e) {
+ throw new InvalidCredentialsOpenshiftException(url, e);
+ } catch (NotFoundException e) {
+ throw new NotFoundOpenshiftException(url, e);
} 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,
+ 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,
+ IApplication application = requestApplicationAction(new ApplicationRequest(name,
cartridge,
+ ApplicationAction.DECONFIGURE,
user.getRhlogin(), true), user);
- user.remove(application);
+ user.remove(application);
}
@Override
- public IApplication startApplication(String name, ICartridge cartridge, InternalUser
user) throws OpenshiftException {
+ 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 {
+ public IApplication restartApplication(String name, ICartridge cartridge, InternalUser
user)
+ throws OpenshiftException {
return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.RESTART,
user.getRhlogin(), true), user);
}
@@ -184,11 +214,9 @@
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());
+ throw new InvalidCredentialsOpenshiftException(url, e);
+ } catch (NotFoundException e) {
+ throw new NotFoundOpenshiftException(url, e);
} catch (HttpClientException e) {
throw new OpenshiftEndpointException(
url, e, "Could not {0} application \"{1}\" at
\"{2}\"",
@@ -215,12 +243,9 @@
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());
+ throw new InvalidCredentialsOpenshiftException(url, e);
+ } catch (NotFoundException e) {
+ throw new NotFoundOpenshiftException(url, e);
} catch (HttpClientException e) {
throw new OpenshiftEndpointException(
url, e, "Could not {0} application \"{1}\" at
\"{2}\"",
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/User.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/User.java 2011-09-30
13:59:16 UTC (rev 35222)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/User.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -20,4 +20,8 @@
public User(String rhlogin, String password) {
super(rhlogin, password);
}
+
+ protected User(String rhlogin, String password, String url) {
+ super(rhlogin, password, url);
+ }
}
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
13:59:16 UTC (rev 35222)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/InternalUser.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -21,6 +21,7 @@
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.IUser;
+import org.jboss.ide.eclipse.as.openshift.core.InvalidCredentialsOpenshiftException;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftService;
@@ -43,6 +44,10 @@
this(rhlogin, password, (ISSHPublicKey) null, new OpenshiftService());
}
+ public InternalUser(String rhlogin, String password, String url) {
+ this(rhlogin, password, (ISSHPublicKey) null, new OpenshiftService(url));
+ }
+
public InternalUser(String rhlogin, String password, IOpenshiftService service) {
this(rhlogin, password, (ISSHPublicKey) null, service);
}
@@ -53,6 +58,15 @@
this.sshKey = sshKey;
this.service = service;
}
+
+ @Override
+ public boolean isValid() throws OpenshiftException {
+ try {
+ return service.isValid(this);
+ } catch(InvalidCredentialsOpenshiftException e) {
+ return false;
+ }
+ }
@Override
public IDomain createDomain(String name, ISSHPublicKey key) throws OpenshiftException {
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserIntegrationTest.java 2011-09-30
13:59:16 UTC (rev 35222)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserIntegrationTest.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -12,6 +12,7 @@
import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationAsserts.assertApplication;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -23,6 +24,7 @@
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.ISSHPublicKey;
+import org.jboss.ide.eclipse.as.openshift.core.NotFoundOpenshiftException;
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.OpenshiftService;
@@ -30,6 +32,7 @@
import org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.TestUser;
import org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationUtils;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -38,19 +41,40 @@
public class UserIntegrationTest {
private User user;
+ private TestUser invalidUser;
+ private TestUser badUrlUser;
@Before
public void setUp() throws OpenshiftException, DatatypeConfigurationException {
this.user = new TestUser();
+ this.invalidUser = new TestUser("bogusPassword");
+ this.badUrlUser = new TestUser(TestUser.RHLOGIN, TestUser.PASSWORD,
"http://www.redhat.com");
}
+ @Test
+ public void canCheckIfUserIsValid() throws OpenshiftException {
+ assertTrue(user.isValid());
+ }
+
@Test
+ public void throwsExceptionIfInvalidCredentials() throws OpenshiftException {
+ assertFalse(invalidUser.isValid());
+ }
+
+ @Test(expected=NotFoundOpenshiftException.class)
+ public void throwsExceptionIfBadUrl() throws OpenshiftException {
+ badUrlUser.isValid();
+ }
+
+ @Ignore
+ @Test
public void canGetUserUUID() throws OpenshiftException {
String uuid = user.getUUID();
assertNotNull(uuid);
assertTrue(uuid.length() > 0);
}
+ @Ignore
@Test
public void canGetPublicKey() throws OpenshiftException {
ISSHPublicKey key = user.getSshKey();
@@ -59,6 +83,7 @@
assertTrue(key.getPublicKey().length() > 0);
}
+ @Ignore
@Test
public void canGetDomain() throws OpenshiftException {
IDomain domain = user.getDomain();
@@ -69,6 +94,7 @@
assertTrue(domain.getNamespace().length() > 0);
}
+ @Ignore
@Test(expected=OpenshiftEndpointException.class)
public void cannotCreateDomainIfAlreadyExists() throws OpenshiftException {
IDomain domain = user.getDomain();
@@ -78,6 +104,7 @@
user.createDomain("newDomain", key);
}
+ @Ignore
@Test
public void canGetCartridges() throws OpenshiftException {
Collection<ICartridge> cartridges = user.getCartridges();
@@ -85,12 +112,14 @@
assertTrue(cartridges.size() >= 5);
}
+ @Ignore
@Test
public void canGetApplications() throws OpenshiftException {
Collection<IApplication> applications = user.getApplications();
assertNotNull(applications);
}
+ @Ignore
@Test
public void canCreateApplication() throws OpenshiftException {
String applicationName = ApplicationUtils.createRandomApplicationName();
@@ -106,6 +135,7 @@
}
}
+ @Ignore
@Test
public void canGetApplicationByName() throws OpenshiftException,
DatatypeConfigurationException {
String applicationName = ApplicationUtils.createRandomApplicationName();
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/TestUser.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/TestUser.java 2011-09-30
13:59:16 UTC (rev 35222)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/TestUser.java 2011-09-30
14:08:35 UTC (rev 35223)
@@ -21,8 +21,8 @@
*/
public class TestUser extends User {
- private static final String RHLOGIN = "toolsjboss(a)gmail.com";
- private static final String PASSWORD = "1q2w3e";
+ public static final String RHLOGIN = "toolsjboss(a)gmail.com";
+ public static final String PASSWORD = "1q2w3e";
public TestUser() {
super(RHLOGIN, PASSWORD);
@@ -32,6 +32,10 @@
super(RHLOGIN, password);
}
+ public TestUser(String rhlogin, String password, String url) {
+ super(rhlogin, password, url);
+ }
+
public IApplication createTestApplication() throws OpenshiftException {
return createApplication(ApplicationUtils.createRandomApplicationName(),
Cartridge.JBOSSAS_7);
}