Search in sources :

Example 6 with OpenShiftException

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

the class OpenShiftResourceDocumentProvider method doSaveDocument.

@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException {
    OpenShiftResourceInput input = getInput(element);
    if (input == null) {
        return;
    }
    IResource resource = input.getResource();
    IClient client = ResourceUtils.getClient(resource);
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    Connection connection = input.getConnection();
    String resourceName = input.getName();
    IResource newResource = connection.getResourceFactory().create(document.get());
    final Exception[] exceptions = new Exception[1];
    Job updateResourceJob = new Job("Update " + resourceName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                client.update(newResource);
            } catch (Exception e) {
                exceptions[0] = e;
                Display.getDefault().asyncExec(() -> setDirty(element));
                String problem = e.getMessage();
                if (e instanceof OpenShiftException) {
                    OpenShiftException oe = (OpenShiftException) e;
                    if (oe.getStatus() != null) {
                        problem = oe.getStatus().getMessage();
                    }
                }
                IStatus error = OpenShiftUIActivator.statusFactory().errorStatus(NLS.bind("Could not update \"{0}\" for project \"{1}\" : {2}", new String[] { resourceName, resource.getNamespaceName(), problem }), e);
                return error;
            }
            return Status.OK_STATUS;
        }
    };
    updateResourceJob.schedule();
    Shell shell = Display.getCurrent().getActiveShell();
    service.showInDialog(shell, updateResourceJob);
    // we need to ensure the dirty flag stays set to true
    if (exceptions[0] != null) {
        throw new CoreException(OpenShiftUIActivator.statusFactory().errorStatus(exceptions[0]));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IClient(com.openshift.restclient.IClient) CoreException(org.eclipse.core.runtime.CoreException) OpenShiftException(com.openshift.restclient.OpenShiftException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IProgressService(org.eclipse.ui.progress.IProgressService) Job(org.eclipse.core.runtime.jobs.Job) IResource(com.openshift.restclient.model.IResource)

Example 7 with OpenShiftException

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

the class MinishiftPoller 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 {
        String v = client.getServerReadyStatus();
        if ("ok".equals(v))
            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) 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 8 with OpenShiftException

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

the class PortForwardingWizardPage method onStartPortForwarding.

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!wizardModel.checkPortForwardingAllowed()) {
                // This is rather a testing case, it is not very probable at normal usage.
                viewer.refresh(true);
                MessageDialog.openWarning(getShell(), "Warning", "Some ports are in use now.");
                return;
            }
            try {
                WizardUtils.runInWizard(new Job("Starting port forwarding...") {

                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        wizardModel.startPortForwarding();
                        refreshViewerInput(viewer);
                        return Status.OK_STATUS;
                    }
                }, getContainer(), getDataBindingContext());
            } catch (OpenShiftException | InvocationTargetException | InterruptedException e1) {
                LOG.logError(e1);
                MessageDialog.openError(getShell(), "Error starting 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) Job(org.eclipse.core.runtime.jobs.Job) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with OpenShiftException

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

the class OpenShiftServerExtendedProperties method getWelcomePageUrl.

@Override
public String getWelcomePageUrl() throws GetWelcomePageURLException {
    String welcomePageUrl = null;
    try {
        // Get connection explicitly to report failure. Try and connect right now to know if it fails.
        // Do not catch OpenShiftException, let it be reported. We are more concerned of NPE.
        Connection connection = OpenShiftServerUtils.getConnection(server);
        if (connection == null || !connection.connect()) {
            throw new GetWelcomePageURLException("Connection is not established.");
        }
        IResource resource = OpenShiftServerUtils.getResource(server, connection, new NullProgressMonitor());
        if (resource == null) {
            throw new GetWelcomePageURLException("Resource is missing.");
        }
        IProject project = resource.getProject();
        if ((project != null) && (resource instanceof IService)) {
            List<IRoute> routes = ResourceUtils.getRoutesFor((IService) resource, project.getResources(ResourceKind.ROUTE));
            IRoute route = getRoute(OpenShiftServerUtils.getRouteURL(server), routes);
            if (route == null) {
                route = getRoute(routes);
            }
            // Reporting route == null is implemented in getRoute.
            if (route != null) {
                welcomePageUrl = route.getURL();
            }
        }
    } catch (OpenShiftException e) {
        throw new GetWelcomePageURLException(e.getMessage(), e);
    }
    return welcomePageUrl;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService)

Example 10 with OpenShiftException

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

the class ConnectionFactory method create.

@Override
public Connection create(String url) {
    if (StringUtils.isEmpty(url)) {
        return null;
    }
    try {
        LazySSLCertificateCallback sslCertCallback = new LazySSLCertificateCallback();
        IClient client = new ClientBuilder(url).sslCertificateCallback(sslCertCallback).withMaxRequests(ConnectionProperties.MAX_REQUESTS).withMaxRequestsPerHost(ConnectionProperties.MAX_REQUESTS).build();
        return new Connection(client, new LazyCredentialsPrompter());
    } catch (OpenShiftException e) {
        OpenShiftCoreActivator.pluginLog().logInfo(NLS.bind("Could not create OpenShift connection: Malformed url {0}", url), e);
        return null;
    }
}
Also used : LazySSLCertificateCallback(org.jboss.tools.openshift.core.LazySSLCertificateCallback) OpenShiftException(com.openshift.restclient.OpenShiftException) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IClient(com.openshift.restclient.IClient) LazyCredentialsPrompter(org.jboss.tools.openshift.core.LazyCredentialsPrompter) ClientBuilder(com.openshift.restclient.ClientBuilder)

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