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;
}
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);
}
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);
}
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;
}
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);
}
Aggregations