Search in sources :

Example 11 with Connection

use of org.jboss.tools.openshift.core.connection.Connection 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 12 with Connection

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

the class OpenShiftConnectionRequirement method createConnectionWithCredentials.

private Connection createConnectionWithCredentials(String server, String username, String password) {
    IClient client = createClient(server);
    Connection connection = new Connection(client, null);
    connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_BASIC);
    connection.setUsername(username);
    connection.setPassword(password);
    return connection;
}
Also used : RequiredBasicConnection(org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IClient(com.openshift.restclient.IClient)

Example 13 with Connection

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

the class OpenShiftConnectionRequirement method createConnectionWithToken.

private Connection createConnectionWithToken(String server, String token) {
    IClient client = createClient(server);
    Connection connection = new Connection(client, null);
    connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_OAUTH);
    connection.setUsername(connection.getUsername());
    connection.setToken(token);
    connection.refresh();
    return connection;
}
Also used : RequiredBasicConnection(org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IClient(com.openshift.restclient.IClient)

Example 14 with Connection

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

the class OpenShiftProjectRequirement method fulfill.

@Override
public void fulfill() {
    String projectName = TestUtils.getValueOrDefault(projectSpec.name(), DatastoreOS3.TEST_PROJECT);
    Connection connection = ConnectionUtils.getConnectionOrDefault(projectSpec.connectionURL());
    assertNotNull(NLS.bind("No connection {0} exists", projectSpec.connectionURL()), connection);
    this.project = OpenShift3NativeProjectUtils.getOrCreateProject(projectName, projectSpec.displayName(), projectSpec.description(), connection);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection)

Example 15 with Connection

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

the class OpenShiftProjectRequirement method cleanUp.

@Override
public void cleanUp() {
    if (projectSpec.cleanup()) {
        Connection connection = ConnectionUtils.getConnectionOrDefault(projectSpec.connectionURL());
        connection.deleteResource(project);
        new WaitWhile(new OpenShiftProjectExists(project.getName(), connection));
    }
}
Also used : OpenShiftProjectExists(org.jboss.tools.openshift.reddeer.condition.OpenShiftProjectExists) WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) Connection(org.jboss.tools.openshift.core.connection.Connection)

Aggregations

Connection (org.jboss.tools.openshift.core.connection.Connection)110 Test (org.junit.Test)48 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)30 IResource (com.openshift.restclient.model.IResource)27 IProject (com.openshift.restclient.model.IProject)18 IService (com.openshift.restclient.model.IService)11 IStatus (org.eclipse.core.runtime.IStatus)11 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)9 Collection (java.util.Collection)8 List (java.util.List)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IPod (com.openshift.restclient.model.IPod)7 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IRoute (com.openshift.restclient.model.route.IRoute)6 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Status (org.eclipse.core.runtime.Status)6