Search in sources :

Example 56 with Connection

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

the class ResourceUtilsTest method shouldReturnDeploymentConfigForServiceByNameGivenServiceHasDCNameSelector.

@Test
public void shouldReturnDeploymentConfigForServiceByNameGivenServiceHasDCNameSelector() throws CoreException {
    // given
    Connection connection = ResourceMocks.create3ProjectsConnection();
    IService service = ResourceMocks.PROJECT2_SERVICES[1];
    // when
    IDeploymentConfig dc = ResourceUtils.getDeploymentConfigFor(service, connection);
    // then
    assertThat(dc).isEqualTo(ResourceMocks.PROJECT2_DEPLOYMENTCONFIGS[2]);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 57 with Connection

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

the class ConnectionPropertySourceTest method setup.

@Before
public void setup() throws Exception {
    connection = new Connection("http://localhost:8080", null, null);
    connection.setUsername("foo");
    source = new ConnectionPropertySource(connection);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) ConnectionPropertySource(org.jboss.tools.openshift.internal.ui.property.ConnectionPropertySource) Before(org.junit.Before)

Example 58 with Connection

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

Example 59 with Connection

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

the class OpenShiftPropertySourceAdapterFactory method getAdapter.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType == IPropertySource.class) {
        Connection connection = Adapters.adapt(adaptableObject, Connection.class);
        if (connection != null) {
            if (currentConnectionPropertySource != null) {
                currentConnectionPropertySource.dispose();
            }
            return currentConnectionPropertySource = new ConnectionPropertySource(connection);
        }
        IResource resource = Adapters.adapt(adaptableObject, IResource.class);
        if (resource != null) {
            switch(resource.getKind()) {
                case ResourceKind.BUILD:
                    return new BuildPropertySource((IBuild) resource);
                case ResourceKind.BUILD_CONFIG:
                    return new BuildConfigPropertySource((IBuildConfig) resource);
                case ResourceKind.EVENT:
                    return new EventPropertySource((IEvent) resource);
                case ResourceKind.IMAGE_STREAM:
                    return new ImageStreamPropertySource((IImageStream) resource);
                case ResourceKind.POD:
                    return new PodPropertySource((IPod) resource);
                case ResourceKind.REPLICATION_CONTROLLER:
                    return new ReplicationControllerPropertySource((IReplicationController) resource);
                case ResourceKind.ROUTE:
                    return new RoutePropertySource((IRoute) resource);
                case ResourceKind.SERVICE:
                    return new ServicePropertySource((IService) resource);
                case ResourceKind.PVC:
                    return new StoragePropertySource((IPersistentVolumeClaim) resource);
                default:
                    return new ResourcePropertySource<>(resource);
            }
        }
    }
    return null;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource)

Example 60 with Connection

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

the class ImportApplicationWizard method init.

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    if (model.getConnection() != null && model.getSelectedItem() != null) {
        return;
    }
    Connection connection = UIUtils.getFirstElement(selection, Connection.class);
    if (connection != null) {
        model.setConnection(connection);
    } else {
        IResource resource = UIUtils.getFirstElement(selection, IResource.class);
        if (resource != null) {
            setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(resource));
            model.setSelectedItem(resource);
        } else {
            IProject project = UIUtils.getFirstElement(selection, IProject.class);
            if (project != null) {
                setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(project));
                model.setSelectedItem(project);
            }
        }
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject)

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