Search in sources :

Example 51 with Connection

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

the class OpenShiftCoreActivator method saveAllConnections.

protected void saveAllConnections() {
    Collection<Connection> connections = ConnectionsRegistrySingleton.getInstance().getAll(Connection.class);
    new ConnectionPersistency().save(connections);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ConnectionPersistency(org.jboss.tools.openshift.core.connection.ConnectionPersistency)

Example 52 with Connection

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

the class OpenshiftEapProfileDetector method getBuildConfig.

private IBuildConfig getBuildConfig(IConnection connection, IResource resource) {
    if (resource == null || resource.getProject() == null || !(connection instanceof Connection)) {
        return null;
    }
    Connection connectionInstance = (Connection) connection;
    List<IBuildConfig> buildConfigs = connectionInstance.getResources(ResourceKind.BUILD_CONFIG, resource.getProject().getName());
    if (buildConfigs == null) {
        return null;
    }
    return ResourceUtils.getBuildConfigFor(resource, buildConfigs);
}
Also used : IBuildConfig(com.openshift.restclient.model.IBuildConfig) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection)

Example 53 with Connection

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

the class OpenShiftResourceDocumentProvider method doSaveDocument.

@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException {
    OpenShiftResourceInput input = getInput(element);
    if (input == null) {
        return;
    }
    IResource resource = input.getResource();
    IClient client = ResourceUtils.getClient(resource);
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    Connection connection = input.getConnection();
    String resourceName = input.getName();
    IResource newResource = connection.getResourceFactory().create(document.get());
    final Exception[] exceptions = new Exception[1];
    Job updateResourceJob = new Job("Update " + resourceName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                client.update(newResource);
            } catch (Exception e) {
                exceptions[0] = e;
                Display.getDefault().asyncExec(() -> setDirty(element));
                String problem = e.getMessage();
                if (e instanceof OpenShiftException) {
                    OpenShiftException oe = (OpenShiftException) e;
                    if (oe.getStatus() != null) {
                        problem = oe.getStatus().getMessage();
                    }
                }
                IStatus error = OpenShiftUIActivator.statusFactory().errorStatus(NLS.bind("Could not update \"{0}\" for project \"{1}\" : {2}", new String[] { resourceName, resource.getNamespaceName(), problem }), e);
                return error;
            }
            return Status.OK_STATUS;
        }
    };
    updateResourceJob.schedule();
    Shell shell = Display.getCurrent().getActiveShell();
    service.showInDialog(shell, updateResourceJob);
    // we need to ensure the dirty flag stays set to true
    if (exceptions[0] != null) {
        throw new CoreException(OpenShiftUIActivator.statusFactory().errorStatus(exceptions[0]));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IClient(com.openshift.restclient.IClient) CoreException(org.eclipse.core.runtime.CoreException) OpenShiftException(com.openshift.restclient.OpenShiftException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IProgressService(org.eclipse.ui.progress.IProgressService) Job(org.eclipse.core.runtime.jobs.Job) IResource(com.openshift.restclient.model.IResource)

Example 54 with Connection

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

the class OpenShiftCommonUIActivatorTest method testShowExplorerOnNewConnections.

@Test
public void testShowExplorerOnNewConnections() throws Exception {
    // Ensure OpenShift Explorer is hidden
    assertThat(isOpenShiftExplorerVisible()).isFalse();
    // Come up with a dummy connection
    Connection connection = mock(Connection.class);
    when(connection.getHost()).thenReturn("foo");
    when(connection.getUsername()).thenReturn("bar");
    // adding a new connection should open the OpenShift explorer
    ConnectionsRegistrySingleton.getInstance().add(connection);
    UITestUtils.waitForDeferredEvents();
    // check OpenShift explorer is visible now
    assertThat(isOpenShiftExplorerVisible()).isTrue();
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) Test(org.junit.Test)

Example 55 with Connection

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

the class ResourceUtilsTest method shouldReturnNullGivenNoDCNameSelectorNorRCisFoundForService.

@Test
public void shouldReturnNullGivenNoDCNameSelectorNorRCisFoundForService() throws CoreException {
    // given
    Connection connection = ResourceMocks.create3ProjectsConnection();
    IService service = ResourceMocks.PROJECT2_SERVICES[0];
    // when
    IDeploymentConfig dc = ResourceUtils.getDeploymentConfigFor(service, connection);
    // then
    assertThat(dc).isNull();
}
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)

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