use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ApplicationSourceTreeItems method loadImageStreams.
private Collection<IApplicationSource> loadImageStreams(IProject project, Connection conn) {
final Collection<IImageStream> streams = conn.getResources(ResourceKind.IMAGE_STREAM, project.getNamespaceName());
try {
if (StringUtils.isNotBlank(conn.getClusterNamespace())) {
Collection<IImageStream> commonStreams = conn.getResources(ResourceKind.IMAGE_STREAM, (String) conn.getClusterNamespace());
commonStreams.stream().filter(s -> !streams.contains(s)).forEach(s -> streams.add(s));
}
} catch (OpenShiftException e) {
OpenShiftUIActivator.log(IStatus.ERROR, e.getLocalizedMessage(), e);
}
Collection<IApplicationSource> sources = new ArrayList<>();
for (IImageStream is : streams) {
List<ITagReference> tags = is.getTags().stream().filter(t -> t.isAnnotatedWith(OpenShiftAPIAnnotations.TAGS) && ArrayUtils.contains(t.getAnnotation(OpenShiftAPIAnnotations.TAGS).split(","), BUILDER_TAG)).collect(Collectors.toList());
if (!tags.isEmpty()) {
tags.forEach(t -> sources.add(new ImageStreamApplicationSource(is, t)));
}
}
return sources;
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class RefreshTest method stubProject.
private IProject stubProject(String name, int version) {
StubInvocationHandler handler = new StubInvocationHandler();
IProject instance = (IProject) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { IProject.class }, handler);
handler.stub((proxy, method, args) -> instance).when(instance.getProject());
handler.stub((proxy, method, args) -> name).when(instance.getNamespaceName());
stubResource(handler, instance, ResourceKind.PROJECT, name, version);
return instance;
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class RefreshTest method testRefreshConnection.
@Test
public void testRefreshConnection() throws InterruptedException, TimeoutException {
IProject project1 = stubProject("test1", 1);
IProject project2 = stubProject("test2", 1);
IProject project2prime = stubProject("test2", 2);
when(getConnectionMock().getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project1));
IConnectionWrapper connection = getConnection();
getConnection().load(IExceptionHandler.NULL_HANDLER);
UITestUtils.waitForState(connection, LoadingState.LOADED);
assertEquals(1, connection.getResources().size());
assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project1, project2));
verify(listener).elementChanged(connection);
assertEquals(2, connection.getResources().size());
assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project2.equals(projectWrapper.getWrapped())));
registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2));
verify(listener, times(2)).elementChanged(connection);
assertEquals(1, connection.getResources().size());
Optional<IResourceWrapper<?, ?>> project2Wrapper = connection.getResources().stream().filter(projectWrapper -> project2.equals(projectWrapper.getWrapped())).findFirst();
assertTrue(project2Wrapper.isPresent());
registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2prime));
verify(listener, times(2)).elementChanged(connection);
verify(listener).elementChanged(project2Wrapper.get());
assertEquals(1, connection.getResources().size());
assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> {
IResource resource = projectWrapper.getWrapped();
String version = resource.getResourceVersion();
return project2.equals(resource) && version.equals("2");
}));
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class DeleteProjectJob method doRun.
@Override
protected IStatus doRun(IProgressMonitor monitor) {
final IProject project = (IProject) resource;
Connection connection = ConnectionsRegistryUtil.getConnectionFor(project);
WatchManager.getInstance().stopWatch(project, connection);
List<IProject> oldProjects = connection.getResources(ResourceKind.PROJECT);
IStatus status = super.doRun(monitor);
if (status.isOK() && waitForServerToReconcileProjectDelete(connection, project)) {
List<IProject> newProjects = new ArrayList<>(oldProjects);
newProjects.remove(project);
ConnectionsRegistrySingleton.getInstance().fireConnectionChanged(connection, ConnectionProperties.PROPERTY_PROJECTS, oldProjects, newProjects);
}
return status;
}
use of com.openshift.restclient.model.IProject 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);
}
Aggregations