Search in sources :

Example 1 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class OpenShiftConnectionRequirement method fulfill.

@Override
public void fulfill() {
    String server = TestUtils.getValueOrDefault(connectionSpec.server(), DatastoreOS3.SERVER);
    String username = TestUtils.getValueOrDefault(connectionSpec.username(), DatastoreOS3.USERNAME);
    String password = TestUtils.getValueOrDefault(connectionSpec.password(), DatastoreOS3.PASSWORD);
    String token = TestUtils.getValueOrDefault(connectionSpec.token(), DatastoreOS3.TOKEN);
    try {
        ConnectionURL url;
        if (StringUtils.isNotEmpty(password) && StringUtils.isNotEmpty(username)) {
            url = getConnectionURL(username, server);
        } else {
            url = getConnectionURL(server);
        }
        Connection connection = ConnectionsRegistrySingleton.getInstance().getByUrl(url, Connection.class);
        if (connection == null) {
            LOGGER.debug(NLS.bind("No connection for {0} found. Creating a new one.", url));
            connection = createConnection(server, username, password, token);
            ConnectionsRegistrySingleton.getInstance().add(connection);
        }
        LOGGER.debug(NLS.bind("Connecting to OpenShift 3 server at {0}", url));
        connection.connect();
        this.connection = connection;
    } catch (UnsupportedEncodingException | MalformedURLException e) {
        throw new OpenShiftToolsException(NLS.bind("Could not create connection for {0} : {1}", server, e));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RequiredBasicConnection(org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)

Example 2 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class ConnectionURLTest method shouldExtractUrlPortions.

@Test
public void shouldExtractUrlPortions() throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions
    String scheme = UrlUtils.SCHEME_HTTP;
    String username = "adietish@redhat.com";
    String password = "12345";
    String server = "openshift.redhat.com";
    // operations
    ConnectionURL connectionUrl = ConnectionURL.forURL(scheme + URLEncoder.encode(username, "UTF-8") + ":" + password + "@" + server);
    // verifications
    assertEquals(scheme, connectionUrl.getScheme());
    assertEquals(username, connectionUrl.getUsername());
    assertEquals(server, connectionUrl.getHost());
    assertEquals(scheme + server, connectionUrl.getHostWithScheme());
}
Also used : ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) Test(org.junit.Test)

Example 3 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class ConnectionURLTest method shouldAllowPortInUrl.

@Test
public void shouldAllowPortInUrl() throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions
    // operations
    ConnectionURL connectionUrl = ConnectionURL.forURL("http://adietish%40redhat.com@localhost:8081");
    // verifications
    assertEquals("http://localhost:8081", connectionUrl.getHostWithScheme());
}
Also used : ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) Test(org.junit.Test)

Example 4 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class ConnectionRegistryTest method shouldGetConnectionByUrl.

@Test
public void shouldGetConnectionByUrl() throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions
    registry.add(connection);
    // operations
    ConnectionURL connectionUrl = ConnectionURL.forConnection(connection);
    IConnection queriedConnection = registry.getByUrl(connectionUrl);
    // verifications
    assertEquals(connection, queriedConnection);
}
Also used : ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

Example 5 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class OpenShiftServerUtils method getConnection.

/**
 * Returns the connection for the given server. Returns {@code null} if none was
 * found.
 *
 * @param server
 * @return
 */
public static Connection getConnection(IServerAttributes server) {
    if (server == null) {
        return null;
    }
    Connection connection = null;
    try {
        String url = getConnectionURL(server);
        if (StringUtils.isEmpty(url)) {
            return null;
        }
        ConnectionURL connectionUrl = ConnectionURL.forURL(url);
        if (connectionUrl != null) {
            connection = ConnectionsRegistrySingleton.getInstance().getByUrl(connectionUrl, Connection.class);
        }
        if (connection == null) {
            OpenShiftCoreActivator.pluginLog().logError(NLS.bind("Could not find an existing OpenShift connection to host {0} with user {1} for server {2}", new String[] { connectionUrl.getHost(), connectionUrl.getUsername(), server.getName() }));
        }
    } catch (UnsupportedEncodingException | MalformedURLException e) {
        OpenShiftCoreActivator.pluginLog().logError(NLS.bind("Connection url stored in server {0} is malformed.", server.getName()), e);
    }
    return connection;
}
Also used : MalformedURLException(java.net.MalformedURLException) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ConnectionURL (org.jboss.tools.openshift.common.core.connection.ConnectionURL)11 Test (org.junit.Test)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 MalformedURLException (java.net.MalformedURLException)3 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)3 Connection (org.jboss.tools.openshift.core.connection.Connection)3 OpenShiftToolsException (org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)2 ConnectionsRegistryAdapter (org.jboss.tools.openshift.common.core.connection.ConnectionsRegistryAdapter)1 ConnectionPersistency (org.jboss.tools.openshift.core.connection.ConnectionPersistency)1 ResourceChangePublisher (org.jboss.tools.openshift.internal.core.server.resources.ResourceChangePublisher)1 RequiredBasicConnection (org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection)1