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