use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.
the class ConnectionWrapper method startLoadJob.
void startLoadJob(ProjectWrapper projectWrapper, IExceptionHandler handler) {
new Job(NLS.bind("Loading OpenShift project {0}...", projectWrapper.getWrapped().getName())) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
IProject project = projectWrapper.getWrapped();
IOpenShiftConnection connection = projectWrapper.getParent().getWrapped();
WatchManager.getInstance().startWatch(project, connection);
Collection<IResource> resources = new HashSet<>();
for (String kind : RESOURCE_KINDS) {
resources.addAll(getWrapped().getResources(kind, project.getNamespaceName()));
}
resources.forEach(r -> resourceCache.add(r));
projectWrapper.initWithResources(resources);
projectWrapper.fireChanged();
} catch (OperationCanceledException e) {
projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
} catch (Throwable e) {
projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
handler.handleException(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.
the class OpenshiftUIModel method refresh.
@Override
public void refresh() {
Map<IOpenShiftConnection, ConnectionWrapper> updated = new HashMap<>();
boolean changed = false;
synchronized (connections) {
HashMap<IOpenShiftConnection, ConnectionWrapper> oldWrappers = new HashMap<>(connections);
connections.clear();
for (IOpenShiftConnection connection : ConnectionsRegistrySingleton.getInstance().getAll(IOpenShiftConnection.class)) {
ConnectionWrapper existingWrapper = oldWrappers.remove(connection);
if (existingWrapper == null) {
ConnectionWrapper newWrapper = new ConnectionWrapper(this, connection);
connections.put(connection, newWrapper);
changed = true;
} else {
connections.put(connection, existingWrapper);
updated.put(connection, existingWrapper);
}
}
if (!oldWrappers.isEmpty()) {
changed = true;
}
}
if (changed) {
fireChanged(this);
}
updated.keySet().forEach(r -> {
ConnectionWrapper wrapper = updated.get(r);
wrapper.updateWith(r);
});
for (ConnectionWrapper connection : getConnections()) {
connection.refresh();
}
}
use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.
the class ConnectionWrapperTest method prepareData.
@Before
public void prepareData() throws Exception {
this.project = mock(IProject.class);
when(project.getName()).thenReturn(NAMESPACE);
when(project.getNamespaceName()).thenReturn(NAMESPACE);
IOpenShiftConnection connection = mock(IOpenShiftConnection.class);
when(connection.isDefaultHost()).thenReturn(true);
when(connection.getUsername()).thenReturn("bdshadow");
when(connection.getResources(eq(ResourceKind.PROJECT))).thenReturn(Arrays.asList(new IResource[] { project }));
// by doing this we call a protected OpenshiftUIModel constructor, which adds listener to the
OpenshiftUIModel.getInstance();
// ConnectionsRegistrySingleton
ConnectionsRegistrySingleton.getInstance().add(connection);
ConnectionWrapper connectionWrapper = OpenshiftUIModel.getInstance().getConnectionWrapperForConnection(connection);
connectionWrapper.refresh();
this.projectWrapper = (ProjectWrapper) connectionWrapper.getResources().iterator().next();
this.resource = mock(IBuildConfig.class);
when(this.resource.getKind()).thenReturn(ResourceKind.BUILD_CONFIG);
when(this.resource.getNamespaceName()).thenReturn(NAMESPACE);
when(this.resource.getProject()).thenReturn(project);
this.watchListener = new WatchListenerTestable(WatchManager.getInstance(), project, connection, ResourceKind.BUILD_CONFIG, 0, 0);
watchListener.setState("CONNECTED");
}
use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.
the class OpenShiftProjectCacheTest method testGetProjectForOnlyMakesInitialCallToServer.
@Test
public void testGetProjectForOnlyMakesInitialCallToServer() throws InterruptedException, TimeoutException {
IOpenShiftConnection connection = connectionWrapper.getWrapped();
connectionWrapper.load(IExceptionHandler.NULL_HANDLER);
connectionWrapper.load(IExceptionHandler.NULL_HANDLER);
UITestUtils.waitForState(connectionWrapper, LoadingState.LOADED);
verify(connection, times(1)).getResources(ResourceKind.PROJECT);
}
use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.
the class ConnectionPropertySource method getPropertyValue.
@Override
public Object getPropertyValue(Object id) {
if (id == null) {
return null;
}
if (HOST.equals(id)) {
return this.connection.toString();
}
if (USERNAME.equals(id)) {
return this.connection.getUsername();
}
if (connection instanceof IOpenShiftConnection) {
IOpenShiftConnection openshiftConnection = (IOpenShiftConnection) this.connection;
if (OPENSHIFT_MASTER_VERSION.equals(id)) {
return openshiftConnection.getOpenShiftMasterVersion();
}
if (KUBERNETES_MASTER_VERSION.equals(id)) {
return openshiftConnection.getKubernetesMasterVersion();
}
Object result = openshiftConnection.getExtendedProperties().get(id);
return result == null ? "" : result.toString();
}
return null;
}
Aggregations