Search in sources :

Example 36 with IConnection

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

the class ConnectionWizardPageModel method connect.

public IStatus connect() {
    if (isConnected() && listener.secureStoreException == null) {
        return Status.OK_STATUS;
    }
    IStatus status = Status.OK_STATUS;
    listener.secureStoreException = null;
    try {
        IConnection connection = createConnection();
        if (connection != null) {
            addConnectionListener(connection);
            if (connection.connect()) {
                connection.enablePromptCredentials(true);
                this.connection = connection;
                wizardModel.setConnection(connection);
                ConnectionsRegistrySingleton.getInstance().setRecent(connection);
                connection.notifyUsage();
            } else {
                String message = NLS.bind("Unable to connect to {0}", connection.getHost());
                OpenShiftCommonUIActivator.log(message, null);
                status = StatusFactory.errorStatus(OpenShiftCommonUIActivator.PLUGIN_ID, message);
            }
        }
    } catch (Exception e) {
        status = StatusFactory.errorStatus(OpenShiftCommonUIActivator.PLUGIN_ID, e.getMessage());
        OpenShiftCommonUIActivator.log(e);
    } finally {
        removeConnectionListener(connection);
    }
    update(selectedConnection, connectionFactory, host, useDefaultHost, Status.OK_STATUS, status);
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) SecureStoreException(org.jboss.tools.openshift.internal.common.core.security.SecureStoreException)

Example 37 with IConnection

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

the class OpenShiftCoreActivator method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    registerDebugOptionsListener(PLUGIN_ID, new Trace(this), context);
    Collection<Connection> connections = new ConnectionPersistency().load();
    ConnectionsRegistrySingleton.getInstance().addAll(connections);
    ConnectionsRegistrySingleton.getInstance().addListener(new ConnectionsRegistryAdapter() {

        // @TODO I think we need to handle the cleanup case where a connection
        // username changes since username is what makes up part of the
        // the key that is saved which seems to apply to secure values
        // and preference values
        @Override
        public void connectionRemoved(IConnection connection) {
            if (!(connection instanceof Connection)) {
                return;
            }
            ((Connection) connection).removeSecureStoreData();
            ConnectionURL url = ConnectionURL.safeForConnection(connection);
            if (url != null) {
                OpenShiftCorePreferences.INSTANCE.removeAuthScheme(url.toString());
            }
            saveAllConnections();
        }

        @Override
        public void connectionAdded(IConnection connection) {
            if (connection instanceof Connection) {
                saveAllConnections();
            }
        }

        @Override
        public void connectionChanged(IConnection connection, String property, Object oldValue, Object newValue) {
            if (connection instanceof Connection && (oldValue instanceof Connection || newValue instanceof Connection)) {
                saveAllConnections();
            }
        }
    });
    ServerCore.addServerLifecycleListener(getServerListener());
    // A clone of the auto-publish thread implementation
    resourceChangeListener = new ResourceChangePublisher();
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE);
}
Also used : 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) ConnectionPersistency(org.jboss.tools.openshift.core.connection.ConnectionPersistency) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ConnectionsRegistryAdapter(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistryAdapter) ResourceChangePublisher(org.jboss.tools.openshift.internal.core.server.resources.ResourceChangePublisher)

Example 38 with IConnection

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

the class SelectedRoutePreference method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShell(event);
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    final IRoute route = UIUtils.getFirstElement(currentSelection, IRoute.class);
    // Open route
    if (route != null) {
        return openBrowser(shell, route);
    }
    IServiceWrapper service = UIUtils.getFirstElement(currentSelection, IServiceWrapper.class);
    if (service != null) {
        new RouteOpenerJob(service.getWrapped().getNamespaceName(), shell) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                this.routes = service.getResourcesOfKind(ResourceKind.ROUTE).stream().map(r -> (IRoute) r.getWrapped()).collect(Collectors.toList());
                return Status.OK_STATUS;
            }
        }.schedule();
        return Status.OK_STATUS;
    }
    // Open Project
    final IProject project = UIUtils.getFirstElement(currentSelection, IProject.class);
    if (project != null) {
        new RouteOpenerJob(project.getName(), shell) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                this.routes = project.getResources(ResourceKind.ROUTE);
                return Status.OK_STATUS;
            }
        }.schedule();
        return Status.OK_STATUS;
    }
    // Open Connection
    final IConnection connection = UIUtils.getFirstElement(currentSelection, IConnection.class);
    if (connection != null) {
        return openBrowser(shell, connection.getHost());
    }
    return nothingToOpenDialog(shell);
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) StringUtils(org.apache.commons.lang.StringUtils) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IStatus(org.eclipse.core.runtime.IStatus) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) Map(java.util.Map) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) Shell(org.eclipse.swt.widgets.Shell) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) SelectRouteDialog(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Dialog(org.eclipse.jface.dialogs.Dialog) IRoute(com.openshift.restclient.model.route.IRoute) UIUpdatingJob(org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob) ISelection(org.eclipse.jface.viewers.ISelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IRoute(com.openshift.restclient.model.route.IRoute) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IProject(com.openshift.restclient.model.IProject)

Example 39 with IConnection

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

the class PortForwardingHandler method getConnection.

@Override
protected IConnection getConnection(ExecutionEvent event) {
    ISelection selection = UIUtils.getCurrentSelection(event);
    final IPod pod = UIUtils.getFirstElement(selection, IPod.class);
    Connection connection = null;
    if (pod != null) {
        connection = ConnectionsRegistryUtil.safeGetConnectionFor(pod);
    }
    return connection;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IPod(com.openshift.restclient.model.IPod)

Example 40 with IConnection

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

the class ConnectionsFactoryTest method createShouldReturnFactoryForGivenHost.

@Test
public void createShouldReturnFactoryForGivenHost() throws IOException {
    // pre-condition
    // operation
    IConnection connection = connectionsFactory.create(A_CONNECTION_SERVER);
    // verification
    assertThat(connection).isNotNull();
    assertThat(connection.getClass()).isEqualTo(AConnection.class);
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

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