Search in sources :

Example 6 with IClient

use of com.openshift.restclient.IClient 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 7 with IClient

use of com.openshift.restclient.IClient 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 8 with IClient

use of com.openshift.restclient.IClient 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 9 with IClient

use of com.openshift.restclient.IClient 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)

Example 10 with IClient

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

the class ConnectionTest method ownsResource_should_return_false_when_clients_are_different.

@Test
public void ownsResource_should_return_false_when_clients_are_different() {
    IClient diffClient = mock(IClient.class);
    Map<String, Object> mocks = givenAResourceThatAcceptsAVisitorForIClientCapability(diffClient);
    assertFalse(connection.ownsResource((IResource) mocks.get("resource")));
}
Also used : IClient(com.openshift.restclient.IClient) Matchers.anyString(org.mockito.Matchers.anyString) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Aggregations

IClient (com.openshift.restclient.IClient)12 OpenShiftException (com.openshift.restclient.OpenShiftException)4 ClientBuilder (com.openshift.restclient.ClientBuilder)3 IResource (com.openshift.restclient.model.IResource)3 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)3 LazySSLCertificateCallback (org.jboss.tools.openshift.core.LazySSLCertificateCallback)3 Connection (org.jboss.tools.openshift.core.connection.Connection)3 ISSLCertificateCallback (com.openshift.restclient.ISSLCertificateCallback)2 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CoreException (org.eclipse.core.runtime.CoreException)2 CommandTimeoutException (org.jboss.tools.openshift.cdk.server.core.internal.adapter.controllers.CommandTimeoutException)2 RequiredBasicConnection (org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IAuthorizationContext (com.openshift.restclient.authorization.IAuthorizationContext)1 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)1 IClientCapability (com.openshift.restclient.capability.resources.IClientCapability)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1