use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithDeploymentConfigTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
// given
List<ObservableTreeItem> resourceItems = new ArrayList<>(model.getResourceItems());
Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
IDeploymentConfig deploymentConfig = ResourceMocks.createResource(IDeploymentConfig.class, ResourceKind.DEPLOYMENT_CONFIG);
when(project.getResources(ResourceKind.DEPLOYMENT_CONFIG)).thenReturn(Collections.singletonList(deploymentConfig));
// when
model.loadResources(connection);
// then
List<ObservableTreeItem> newResourceItems = model.getResourceItems();
assertThat(newResourceItems).isNotEqualTo(resourceItems);
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithReplicationControllerTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
// given
List<ObservableTreeItem> resourceItems = new ArrayList<>(model.getResourceItems());
Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
IReplicationController replicationController = ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER);
when(project.getResources(ResourceKind.REPLICATION_CONTROLLER)).thenReturn(Collections.singletonList(replicationController));
// when
model.loadResources(connection);
// then
List<ObservableTreeItem> newResourceItems = model.getResourceItems();
assertThat(newResourceItems).isNotEqualTo(resourceItems);
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ConnectionWrapper method refresh.
void refresh(ProjectWrapper projectWrapper) {
resourceCache.flush(projectWrapper.getWrapped().getNamespaceName());
IProject project = projectWrapper.getWrapped();
IOpenShiftConnection connection = projectWrapper.getParent().getWrapped();
WatchManager.getInstance().stopWatch(project, connection);
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.updateWithResources(resources);
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ConnectionWrapper method updateWithResources.
private void updateWithResources(List<IProject> newValue) {
Map<IProject, ProjectWrapper> updated = new HashMap<>();
boolean changed = false;
synchronized (projects) {
HashMap<String, ProjectWrapper> oldWrappers = new HashMap<>(projects);
projects.clear();
for (IProject r : newValue) {
ProjectWrapper existingWrapper = oldWrappers.remove(r.getName());
if (existingWrapper == null) {
ProjectWrapper newWrapper = new ProjectWrapper(this, r);
resourceCache.add(r);
projects.put(r.getName(), newWrapper);
changed = true;
} else {
projects.put(r.getName(), existingWrapper);
updated.put(r, existingWrapper);
}
}
if (!oldWrappers.isEmpty()) {
changed = true;
}
}
updated.keySet().forEach(r -> {
ProjectWrapper wrapper = updated.get(r);
wrapper.updateWith(r);
});
if (changed) {
fireChanged();
}
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class NewApplicationWizard method performFinish.
@Override
public boolean performFinish() {
final IResourcesModelJob createJob = isTemplateFlow() ? fromTemplateModel.createFinishJob() : fromImageModel.createFinishJob();
createJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
IStatus status = event.getResult();
if (JobUtils.isOk(status) || JobUtils.isWarning(status)) {
Display.getDefault().syncExec(createJob.getSummaryRunnable(getShell()));
OpenShiftUIUtils.showOpenShiftExplorer();
if (model.getEclipseProject() != null) {
// No need to import the project from git, it's already here
return;
}
Collection<IResource> resources = createJob.getResources();
final Map<IProject, Collection<IBuildConfig>> projectsAndBuildConfigs = getBuildConfigs(resources);
if (projectsAndBuildConfigs.isEmpty()) {
return;
}
Connection connection = model.getConnection();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
ImportApplicationWizard wizard = new ImportApplicationWizard(projectsAndBuildConfigs);
wizard.addImportJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
IService service = getService(resources);
List<org.eclipse.core.resources.IProject> importedProjects = wizard.getImportJob().getImportedProjects();
if (service != null && importedProjects.size() == 1) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (MessageDialog.openQuestion(getShell(), "Create server adapter", NLS.bind("Would you like to create a server adapter for the imported {0} project?", importedProjects.get(0).getName()))) {
createServerAdapter(importedProjects.get(0), connection, service, getRoute(resources));
}
}
});
}
}
});
new WizardDialog(getShell(), wizard).open();
}
});
}
}
protected Map<IProject, Collection<IBuildConfig>> getBuildConfigs(Collection<IResource> resources) {
Map<IProject, Collection<IBuildConfig>> projects = new LinkedHashMap<>();
for (IResource resource : resources) {
if (resource instanceof IBuildConfig) {
IBuildConfig buildConfig = (IBuildConfig) resource;
if (StringUtils.isNotBlank(buildConfig.getSourceURI())) {
IProject p = buildConfig.getProject();
Collection<IBuildConfig> buildConfigs = projects.get(p);
if (buildConfigs == null) {
buildConfigs = new LinkedHashSet<>();
projects.put(p, buildConfigs);
}
buildConfigs.add(buildConfig);
}
}
}
return projects;
}
protected IService getService(Collection<IResource> resources) {
IResource service = getResourceOfType(resources, IService.class);
return service == null ? null : (IService) service;
}
protected IRoute getRoute(Collection<IResource> resources) {
IResource route = getResourceOfType(resources, IRoute.class);
return route == null ? null : (IRoute) route;
}
private IResource getResourceOfType(Collection<IResource> resources, Class<? extends IResource> type) {
for (IResource resource : resources) {
if (type.isInstance(resource)) {
return resource;
}
}
return null;
}
protected void createServerAdapter(org.eclipse.core.resources.IProject project, Connection connection, IService service, IRoute route) {
try {
IServerWorkingCopy server = OpenShiftServerUtils.create(OpenShiftResourceUniqueId.get(service));
ServerSettingsWizardPageModel serverModel = new ServerSettingsWizardPageModel(service, route, project, connection, server, OCBinary.getInstance().getStatus(connection, new NullProgressMonitor()), RSyncValidator.get().getStatus());
serverModel.loadResources();
serverModel.updateServer();
server.setAttribute(OpenShiftServerUtils.SERVER_START_ON_CREATION, false);
serverModel.saveServer(null);
} catch (CoreException ce) {
OpenShiftUIActivator.getDefault().getLogger().logError("Error occured while creating a server adapter", ce);
return;
}
}
});
boolean success = false;
try {
Job job = new JobChainBuilder(createJob.getJob()).runWhenSuccessfullyDone(new RefreshResourcesJob(createJob, true)).build();
IStatus status = runInWizard(job, createJob.getDelegatingProgressMonitor(), getContainer());
success = isFailed(status);
} catch (InvocationTargetException | InterruptedException e) {
OpenShiftUIActivator.getDefault().getLogger().logError(e);
success = false;
} finally {
UsageStats.getInstance().newV3Application(model.getConnection().getHost(), success);
}
return success;
}
Aggregations