Search in sources :

Example 1 with OpenShiftException

use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.

the class RefreshResourceHandler method createRefreshJob.

private Job createRefreshJob(IOpenshiftUIElement<?, ?> element) {
    return new AbstractDelegatingMonitorJob(LOADING_OPEN_SHIFT_INFORMATIONS) {

        @Override
        protected IStatus doRun(IProgressMonitor monitor) {
            try {
                monitor.beginTask(LOADING_OPEN_SHIFT_INFORMATIONS, IProgressMonitor.UNKNOWN);
                element.refresh();
            } catch (OpenShiftException e) {
                OpenShiftCommonUIActivator.getDefault().getLogger().logError(FAILED_TO_REFRESH_ELEMENT, e);
                return new Status(Status.ERROR, OpenShiftCommonUIActivator.PLUGIN_ID, FAILED_TO_REFRESH_ELEMENT, e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OpenShiftException(com.openshift.restclient.OpenShiftException)

Example 2 with OpenShiftException

use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.

the class OpenShiftServiceRequirement method cleanUp.

@Override
public void cleanUp() {
    if (serviceSpec.cleanup()) {
        String projectName = TestUtils.getValueOrDefault(serviceSpec.project(), DatastoreOS3.TEST_PROJECT);
        final IProject project = OpenShift3NativeResourceUtils.getProject(projectName, connection);
        IProjectTemplateProcessing capability = project.getCapability(IProjectTemplateProcessing.class);
        ITemplate processed = capability.process(template);
        for (IResource resource : processed.getObjects()) {
            IResource res = connection.getResource(resource.getKind(), projectName, resource.getName());
            try {
                connection.deleteResource(res);
            } catch (OpenShiftException ex) {
                LOGGER.error("Unable to remove " + res.getKind() + " named " + res.getName());
                LOGGER.error(StackTraceUtils.stackTraceToString(ex));
            }
        }
        cleanResources(connection, ResourceKind.BUILD, project, template);
        cleanResources(connection, ResourceKind.REPLICATION_CONTROLLER, project, template);
        cleanResources(connection, ResourceKind.POD, project, template);
        new WaitWhile(new AbstractWaitCondition() {

            @Override
            public boolean test() {
                for (IResource resource : project.getResources(ResourceKind.POD)) {
                    if (resource.getName().startsWith(template.getName())) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            public String description() {
                return "at least one application pod is running";
            }
        }, TimePeriod.LONG);
        new OpenShiftExplorerView().getOpenShift3Connection(connection).refresh();
    }
}
Also used : IProjectTemplateProcessing(com.openshift.restclient.capability.resources.IProjectTemplateProcessing) WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) OpenShiftException(com.openshift.restclient.OpenShiftException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ITemplate(com.openshift.restclient.model.template.ITemplate) AbstractWaitCondition(org.eclipse.reddeer.common.condition.AbstractWaitCondition) OpenShiftExplorerView(org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 3 with OpenShiftException

use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.

the class DeployImageJob method updateTriggerIfUpdate.

protected boolean updateTriggerIfUpdate(Connection connection, String project, String name) {
    try {
        IDeploymentConfig dc = connection.getResource(ResourceKind.DEPLOYMENT_CONFIG, project, name);
        IDeploymentImageChangeTrigger trigger = (IDeploymentImageChangeTrigger) dc.getTriggers().stream().filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType())).findFirst().orElse(null);
        if (trigger == null || !ResourceKind.IMAGE_STREAM_TAG.equals(trigger.getKind()) || StringUtils.isBlank(trigger.getNamespace()) || connection.getResource(ResourceKind.IMAGE_STREAM, trigger.getNamespace(), trigger.getFrom().getName()) == null) {
            return false;
        }
        DockerImageURI sourceImage = getSourceImage();
        if (sourceImage.getName().equals(trigger.getFrom().getName()) && !sourceImage.getTag().equals(trigger.getFrom().getTag())) {
            trigger.setFrom(new DockerImageURI(null, null, sourceImage.getName(), sourceImage.getTag()));
            connection.updateResource(dc);
        }
        return true;
    } catch (NotFoundException e) {
        return false;
    } catch (OpenShiftException e) {
        if (e.getStatus() != null && e.getStatus().getCode() == IHttpConstants.STATUS_NOT_FOUND) {
            return false;
        }
        throw e;
    }
}
Also used : ResourceCreationJobUtils.findExistingResources(org.jboss.tools.openshift.internal.ui.job.ResourceCreationJobUtils.findExistingResources) StringUtils(org.apache.commons.lang.StringUtils) IImageStream(com.openshift.restclient.model.IImageStream) HashMap(java.util.HashMap) AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) DockerImageUtils(org.jboss.tools.openshift.internal.core.docker.DockerImageUtils) OpenShiftException(com.openshift.restclient.OpenShiftException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ITargetPort(com.openshift.restclient.model.route.ITargetPort) IStatus(org.eclipse.core.runtime.IStatus) Map(java.util.Map) NotFoundException(com.openshift.restclient.NotFoundException) IResourceFactory(com.openshift.restclient.IResourceFactory) Trace(org.jboss.tools.openshift.internal.core.Trace) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IService(com.openshift.restclient.model.IService) ResourceCreationJobUtils.createErrorStatusForExistingResources(org.jboss.tools.openshift.internal.ui.job.ResourceCreationJobUtils.createErrorStatusForExistingResources) IHttpConstants(com.openshift.restclient.http.IHttpConstants) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) Connection(org.jboss.tools.openshift.core.connection.Connection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeployImageParameters(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeployImageParameters) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IServicePort(com.openshift.restclient.model.IServicePort) IRoute(com.openshift.restclient.model.route.IRoute) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) DockerImageURI(com.openshift.restclient.images.DockerImageURI) OpenShiftException(com.openshift.restclient.OpenShiftException) NotFoundException(com.openshift.restclient.NotFoundException) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Example 4 with OpenShiftException

use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.

the class VagrantPoller method checkOpenShiftHealth.

protected boolean checkOpenShiftHealth(String url, int timeout) throws OpenShiftNotReadyPollingException {
    ISSLCertificateCallback sslCallback = new LazySSLCertificateCallback();
    IClient client = new ClientBuilder(url).sslCertificateCallback(sslCallback).withConnectTimeout(timeout, TimeUnit.MILLISECONDS).build();
    Exception e = null;
    try {
        if ("ok".equals(client.getServerReadyStatus()))
            return true;
    } catch (OpenShiftException ex) {
        e = ex;
    }
    String msg = NLS.bind("The CDK VM is up and running, but OpenShift is unreachable at url {0}. " + "The VM may not have been registered successfully. Please check your console output for more information", url);
    throw new OpenShiftNotReadyPollingException(CDKCoreActivator.statusFactory().errorStatus(CDKCoreActivator.PLUGIN_ID, msg, e, OpenShiftNotReadyPollingException.OPENSHIFT_UNREACHABLE_CODE));
}
Also used : ISSLCertificateCallback(com.openshift.restclient.ISSLCertificateCallback) LazySSLCertificateCallback(org.jboss.tools.openshift.core.LazySSLCertificateCallback) OpenShiftException(com.openshift.restclient.OpenShiftException) IClient(com.openshift.restclient.IClient) TimeoutException(java.util.concurrent.TimeoutException) CoreException(org.eclipse.core.runtime.CoreException) OpenShiftException(com.openshift.restclient.OpenShiftException) IOException(java.io.IOException) CommandTimeoutException(org.jboss.tools.openshift.cdk.server.core.internal.adapter.controllers.CommandTimeoutException) ClientBuilder(com.openshift.restclient.ClientBuilder)

Example 5 with OpenShiftException

use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.

the class PortForwardingWizardPage method onStopPortForwarding.

private SelectionListener onStopPortForwarding(final TableViewer viewer) {
    return new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                WizardUtils.runInWizard(new Job("Stopping port forwarding...") {

                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        try {
                            wizardModel.stopPortForwarding();
                        } catch (IOException e) {
                            Display.getDefault().syncExec(() -> MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", "Failed to close console inputstream while stopping port-forwarding: " + e.getMessage()));
                            OpenShiftUIActivator.getDefault().getLogger().logError("Failed to close console inputstream while stopping port-forwarding", e);
                        }
                        refreshViewerInput(viewer);
                        if (!wizardModel.isPortForwardingAllowed()) {
                            // Ports remain in use after a reasonable wait.
                            // Lets give UI a break and then repeat waiting.
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    waitForPortsToGetFree(viewer);
                                }
                            });
                        }
                        return Status.OK_STATUS;
                    }
                }, getContainer(), getDataBindingContext());
            } catch (OpenShiftException | InvocationTargetException | InterruptedException e1) {
                LOG.logError(e1);
                MessageDialog.openError(getShell(), "Error stopping port forwarding", e1.getMessage());
            }
        }
    };
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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