Search in sources :

Example 11 with OpenShiftException

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();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IBuildTriggerable(com.openshift.restclient.capability.resources.IBuildTriggerable) OpenShiftException(com.openshift.restclient.OpenShiftException) IBuild(com.openshift.restclient.model.IBuild)

Example 12 with OpenShiftException

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;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) IProjectTemplateProcessing(com.openshift.restclient.capability.resources.IProjectTemplateProcessing) OpenShiftException(com.openshift.restclient.OpenShiftException) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) Collection(java.util.Collection) ITemplate(com.openshift.restclient.model.template.ITemplate)

Example 13 with OpenShiftException

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;
}
Also used : OpenShiftException(com.openshift.restclient.OpenShiftException) ArrayList(java.util.ArrayList) IResource(com.openshift.restclient.model.IResource)

Example 14 with OpenShiftException

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;
}
Also used : AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) UIJob(org.eclipse.ui.progress.UIJob) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) List(java.util.List) NewProjectWizard(org.jboss.tools.openshift.internal.ui.wizard.project.NewProjectWizard) JobChainBuilder(org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder)

Example 15 with OpenShiftException

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;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) IImageStream(com.openshift.restclient.model.IImageStream) OpenShiftException(com.openshift.restclient.OpenShiftException) TemplateApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.TemplateApplicationSource) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) IModelFactory(org.jboss.tools.openshift.internal.ui.treeitem.IModelFactory) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) ResourceKind(com.openshift.restclient.ResourceKind) ITagReference(com.openshift.restclient.model.image.ITagReference) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Connection(org.jboss.tools.openshift.core.connection.Connection) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) IProjectTemplateList(com.openshift.restclient.capability.resources.IProjectTemplateList) ITemplate(com.openshift.restclient.model.template.ITemplate) ImageStreamApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromimage.ImageStreamApplicationSource) Collections(java.util.Collections) ArrayUtils(org.apache.commons.lang.ArrayUtils) ITagReference(com.openshift.restclient.model.image.ITagReference) OpenShiftException(com.openshift.restclient.OpenShiftException) ArrayList(java.util.ArrayList) IImageStream(com.openshift.restclient.model.IImageStream) ImageStreamApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromimage.ImageStreamApplicationSource)

Aggregations

OpenShiftException (com.openshift.restclient.OpenShiftException)20 IStatus (org.eclipse.core.runtime.IStatus)13 IResource (com.openshift.restclient.model.IResource)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Status (org.eclipse.core.runtime.Status)5 Connection (org.jboss.tools.openshift.core.connection.Connection)5 IClient (com.openshift.restclient.IClient)4 IProject (com.openshift.restclient.model.IProject)4 ITemplate (com.openshift.restclient.model.template.ITemplate)4 IOException (java.io.IOException)4 ClientBuilder (com.openshift.restclient.ClientBuilder)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 ISSLCertificateCallback (com.openshift.restclient.ISSLCertificateCallback)2 ResourceKind (com.openshift.restclient.ResourceKind)2 IProjectTemplateProcessing (com.openshift.restclient.capability.resources.IProjectTemplateProcessing)2 IImageStream (com.openshift.restclient.model.IImageStream)2 IService (com.openshift.restclient.model.IService)2 IRoute (com.openshift.restclient.model.route.IRoute)2