Search in sources :

Example 31 with IConnection

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

the class CDKOpenshiftUtilityTest method testOpenshiftRegistryDefault.

@Test
public void testOpenshiftRegistryDefault() throws Exception {
    CDKOpenshiftUtility util = new CDKOpenshiftUtility();
    IServer s = mockServer("openshift36");
    createCDKFile("Basic", null, null);
    ServiceManagerEnvironment adb = createLoader(s, "10.1.2.2", "2376", null);
    ConnectionsRegistry registry = (ConnectionsRegistry) mock(ConnectionsRegistry.class);
    IConnection con = util.createOpenshiftConnection(adb, registry);
    assertNotNull(con);
    Object o = ((Connection) con).getExtendedProperties().get(ICommonAttributes.IMAGE_REGISTRY_URL_KEY);
    assertEquals("https://hub.openshift.rhel-cdk.10.1.2.2.xip.io", o);
}
Also used : IServer(org.eclipse.wst.server.core.IServer) ConnectionsRegistry(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry) CDKOpenshiftUtility(org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility) ServiceManagerEnvironment(org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

Example 32 with IConnection

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

the class CDKOpenshiftUtilityTest method testOpenshiftConnectionCredentials.

@Test
public void testOpenshiftConnectionCredentials() throws Exception {
    CDKOpenshiftUtility util = new CDKOpenshiftUtility();
    IServer s = mockServer("openshift33");
    createCDKFile("Basic", null, null);
    ServiceManagerEnvironment adb = createLoader(s);
    IConnection con = util.createOpenshiftConnection(adb, null);
    assertNotNull(con);
    assertEquals(con.getUsername(), "openshift-dev");
    assertEquals(con.getPassword(), "devel");
    createCDKFile("Basic", "test", null);
    adb = createLoader(s);
    con = util.createOpenshiftConnection(adb, null);
    assertNotNull(con);
    assertEquals(con.getUsername(), "test");
    assertEquals(con.getPassword(), null);
    createCDKFile("Basic", "test", "pass");
    adb = createLoader(s);
    con = util.createOpenshiftConnection(adb, null);
    assertNotNull(con);
    assertEquals(con.getUsername(), "test");
    assertEquals(con.getPassword(), "pass");
}
Also used : IServer(org.eclipse.wst.server.core.IServer) CDKOpenshiftUtility(org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility) ServiceManagerEnvironment(org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

Example 33 with IConnection

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

the class CDKOpenshiftUtilityTest method testOpenshiftRegistry.

@Test
public void testOpenshiftRegistry() throws Exception {
    CDKOpenshiftUtility util = new CDKOpenshiftUtility();
    IServer s = mockServer("openshift35");
    createCDKFile("Basic", null, null);
    ServiceManagerEnvironment adb = createLoader(s, "10.1.2.2", "2376", "https://custom.url");
    ConnectionsRegistry registry = (ConnectionsRegistry) mock(ConnectionsRegistry.class);
    IConnection con = util.createOpenshiftConnection(adb, registry);
    assertNotNull(con);
    Object o = ((Connection) con).getExtendedProperties().get(ICommonAttributes.IMAGE_REGISTRY_URL_KEY);
    assertEquals(o, "https://custom.url");
}
Also used : IServer(org.eclipse.wst.server.core.IServer) ConnectionsRegistry(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry) CDKOpenshiftUtility(org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility) ServiceManagerEnvironment(org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

Example 34 with IConnection

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

the class CDKOpenshiftUtility method createOpenshiftConnection.

public IConnection createOpenshiftConnection(ServiceManagerEnvironment env, ConnectionsRegistry registry) {
    // Create the connection
    String soughtHost = env.openshiftHost + ":" + env.openshiftPort;
    ConnectionsFactoryTracker connectionsFactory = new ConnectionsFactoryTracker();
    connectionsFactory.open();
    IConnectionFactory factory = connectionsFactory.getById(IConnectionsFactory.CONNECTIONFACTORY_OPENSHIFT_ID);
    IConnection con = factory.create(soughtHost);
    // Set some defaults
    String authScheme = env.getAuthorizationScheme();
    String username = env.getUsername();
    String password = env.getPassword();
    if (authScheme != null && !authScheme.isEmpty()) {
        authScheme = new String("" + authScheme.charAt(0)).toUpperCase() + authScheme.substring(1);
    }
    ((Connection) con).setAuthScheme(authScheme);
    ((Connection) con).setUsername(username);
    if (password != null) {
        ((Connection) con).setPassword(password);
    }
    ((Connection) con).setRememberPassword(true);
    String ocLoc = env.get(ServiceManagerEnvironmentLoader.OC_LOCATION_KEY);
    if (ocLoc != null) {
        ((Connection) con).setExtendedProperty(ICommonAttributes.OC_LOCATION_KEY, ocLoc);
        ((Connection) con).setExtendedProperty(ICommonAttributes.OC_OVERRIDE_KEY, true);
    }
    updateOpenshiftConnection(env, con, false);
    if (registry != null)
        registry.add(con);
    return con;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IConnectionFactory(org.jboss.tools.openshift.common.core.connection.IConnectionFactory) ConnectionsFactoryTracker(org.jboss.tools.openshift.common.core.connection.ConnectionsFactoryTracker)

Example 35 with IConnection

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

the class ConfigureDependentFrameworksListener method configureOpenshift.

private void configureOpenshift(IServer server, ServiceManagerEnvironment adb) {
    CDKOpenshiftUtility util = new CDKOpenshiftUtility();
    IConnection con = util.findExistingOpenshiftConnection(server, adb);
    if (con == null) {
        con = util.createOpenshiftConnection(adb);
    } else {
        util.updateOpenshiftConnection(adb, con);
    }
    if (con != null) {
        con.connect();
    }
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection)

Aggregations

IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)40 Test (org.junit.Test)13 Connection (org.jboss.tools.openshift.core.connection.Connection)9 IStatus (org.eclipse.core.runtime.IStatus)5 IServer (org.eclipse.wst.server.core.IServer)5 CDKOpenshiftUtility (org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility)5 ServiceManagerEnvironment (org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment)5 ArrayList (java.util.ArrayList)3 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)3 Label (org.eclipse.swt.widgets.Label)3 IRoute (com.openshift.restclient.model.route.IRoute)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 ISelection (org.eclipse.jface.viewers.ISelection)2 ConnectionsRegistry (org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry)2 NewConnectionMarker (org.jboss.tools.openshift.common.core.connection.NewConnectionMarker)2 IClient (com.openshift.restclient.IClient)1 ResourceKind (com.openshift.restclient.ResourceKind)1 IAuthorizationContext (com.openshift.restclient.authorization.IAuthorizationContext)1