use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class StartBuildJob method doRun.
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
monitor.beginTask("Starting build job", IProgressMonitor.UNKNOWN);
IBuild build = buildsource.accept(new CapabilityVisitor<IBuildTriggerable, IBuild>() {
@Override
public IBuild visit(IBuildTriggerable triggerable) {
return triggerable.trigger();
}
}, null);
if (build == null) {
return new Status(Status.INFO, OpenShiftUIActivator.PLUGIN_ID, "Manually triggering builds is unsupported");
}
return Status.OK_STATUS;
} catch (OpenShiftException e) {
return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, NLS.bind("Error starting build {0}.", buildsource.getName()), e);
} finally {
monitor.done();
}
}
use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class CreateApplicationFromTemplateJob method doRun.
@Override
protected IStatus doRun(IProgressMonitor monitor) {
template.updateParameterValues(parameters);
for (Label label : labels) {
template.addObjectLabel(label.getName(), label.getValue());
}
IStatus status = project.accept(new CapabilityVisitor<IProjectTemplateProcessing, IStatus>() {
@Override
public IStatus visit(IProjectTemplateProcessing capability) {
try {
ITemplate processed = capability.process(template);
Collection<IResource> existing = findExistingResources(project, processed);
if (!existing.isEmpty()) {
return createErrorStatusForExistingResources(existing);
}
parameters = processed.getParameters().values();
resources = capability.apply(processed);
return handleResponse(resources);
} catch (OpenShiftException e) {
String message = e.getMessage();
if (e.getStatus() != null) {
message = e.getStatus().getMessage();
}
return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, -1, message, e);
}
}
}, new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Template processing is unsupported for this client and server combination.", null));
return status;
}
use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class ResourceCreationJobUtils method findExistingResources.
/*
* MAYBE this should be part of Connection in an exists method?
*/
public static Collection<IResource> findExistingResources(Connection connection, Collection<IResource> resources) {
List<IResource> existing = new ArrayList<>(resources.size());
for (IResource resource : resources) {
try {
IResource found = connection.refresh(resource);
existing.add(found);
} catch (OpenShiftException e) {
// this is expected if the resource is not found
// @TODO change to NotFoundException of some kind
}
}
return existing;
}
use of com.openshift.restclient.OpenShiftException 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 com.openshift.restclient.OpenShiftException 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;
}
Aggregations