use of org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder in project jbosstools-openshift by jbosstools.
the class JobChainBuilderTest method should_schedule_3_jobs_given_successfull_condition_not_fullfilled.
@Test
public void should_schedule_3_jobs_given_successfull_condition_not_fullfilled() {
// given
JobCounter counter = new JobCounter(3);
JobChainBuilder builder = new JobChainBuilder(createJob("Job 1", counter));
counter.setBuilder(builder);
createJobs(3, new ISchedulingCondition[] { null, null, new JobChainBuilder.SuccessfullyDoneCondition() }, builder, counter);
// when
builder.schedule();
// then
assertThat(counter.getDone()).isEqualTo(3);
}
use of org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder in project jbosstools-openshift by jbosstools.
the class EditResourceLimitsHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IResource resource = UIUtils.getFirstElement(UIUtils.getCurrentSelection(event), IResource.class);
RetrieveDCOrRCJob job = new RetrieveDCOrRCJob(resource);
new JobChainBuilder(job).runWhenSuccessfullyDone(new UIJob("Launching Edit Resource Limits Wizard...") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IReplicationController dcOrRc = job.getDeplConfigOrReplController();
if (dcOrRc == null) {
return Status.CANCEL_STATUS;
}
editResources(HandlerUtil.getActiveShell(event), dcOrRc, dcOrRc.getName());
return Status.OK_STATUS;
}
}).schedule();
return null;
}
use of org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder in project jbosstools-openshift by jbosstools.
the class AbstractProjectPage method getLoadResourcesJobBuilder.
/**
* Create and configure the list of jobs that need to be performed during
* resource loading. The base behavior is to load the projects and force project
* creation if no project exists.
*
* @param closeAfter
* return parameter if wizard needs to be closed (may be updated)
* @param closeOnCancel
* true if the wizard need to be closed
* @return the job builder
*/
protected JobChainBuilder getLoadResourcesJobBuilder(final boolean[] closeAfter, final boolean closeOnCancel) {
JobChainBuilder builder = new JobChainBuilder(new AbstractDelegatingMonitorJob("Loading projects...") {
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
model.loadResources();
} catch (OpenShiftException e) {
closeAfter[0] = closeOnCancel;
String problem = e.getStatus() == null ? e.getMessage() : e.getStatus().getMessage();
return OpenShiftUIActivator.statusFactory().errorStatus(problem, e);
}
return Status.OK_STATUS;
}
});
builder.runWhenSuccessfullyDone(new UIJob("Verifying required project...") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (!model.hasProjects()) {
List<IProject> projects = new ObservableTreeItem2ModelConverter().convert(model.getProjectItems());
Connection connection = model.getConnection();
NewProjectWizard newProjectWizard = new NewProjectWizard(connection, projects);
if (Dialog.CANCEL == WizardUtils.openWizardDialog(newProjectWizard, getShell())) {
closeAfter[0] = closeOnCancel;
return Status.CANCEL_STATUS;
} else {
model.loadResources();
model.setProject(newProjectWizard.getProject());
}
}
return Status.OK_STATUS;
}
});
return builder;
}
use of org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder 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;
}
use of org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder in project jbosstools-openshift by jbosstools.
the class ApplicationSourceListPage method getLoadResourcesJobBuilder.
@Override
protected JobChainBuilder getLoadResourcesJobBuilder(boolean[] closeAfter, boolean closeOnCancel) {
JobChainBuilder builder = super.getLoadResourcesJobBuilder(closeAfter, closeOnCancel);
builder.runWhenSuccessfullyDone(new UIJob("Expanding resource tree...") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
templatesViewer.expandAll();
return Status.OK_STATUS;
}
});
return builder;
}
Aggregations