Search in sources :

Example 1 with ClientBuilder

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

the class ConnectionTest method should_not_equals_if_different_user.

@Test
public void should_not_equals_if_different_user() throws Exception {
    // given
    Connection two = new Connection(new ClientBuilder("https://localhost:8443").build(), null);
    two.setUsername("bar");
    // when
    // then
    assertThat(connection).isNotEqualTo(two);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) ClientBuilder(com.openshift.restclient.ClientBuilder) Test(org.junit.Test)

Example 2 with ClientBuilder

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

use of com.openshift.restclient.ClientBuilder in project wildfly-swarm by wildfly-swarm.

the class ClientService method openshiftClient.

private IClient openshiftClient() throws IOException {
    String kubeHost = serviceHost("kubernetes");
    int kubePort = servicePort("kubernetes");
    Path tokenFile = Paths.get("/var/run/secrets/kubernetes.io/serviceaccount/token");
    String scheme = "http";
    String token = null;
    if (Files.exists(tokenFile)) {
        token = new String(Files.readAllBytes(tokenFile));
        scheme = "https";
    }
    return new ClientBuilder(scheme + "://" + kubeHost + ":" + kubePort).usingToken(token).build();
}
Also used : Path(java.nio.file.Path) ClientBuilder(com.openshift.restclient.ClientBuilder)

Example 4 with ClientBuilder

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

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

the class OpenShiftServiceRequirement method fulfill.

@Override
public void fulfill() {
    this.connection = ConnectionUtils.getConnectionOrDefault(serviceSpec.connectionURL());
    assertNotNull(NLS.bind("No connection for {0} exists", serviceSpec.connectionURL()), connection);
    final String projectName = TestUtils.getValueOrDefault(serviceSpec.project(), DatastoreOS3.TEST_PROJECT);
    assertTrue(NLS.bind("No project {0} exists on server {1}", projectName, connection.getHost()), OpenShift3NativeResourceUtils.hasProject(projectName, connection));
    final String serviceName = serviceSpec.service();
    final String templateName = serviceSpec.template();
    IResourceFactory factory = new ClientBuilder(connection.getHost()).build().getResourceFactory();
    try {
        // try if template comes from a URL
        URL url = new URL(templateName);
        template = factory.create(url.openStream());
    } catch (MalformedURLException ex) {
        // template is not a URL, try a path to local file instead
        if (new File(templateName).exists()) {
            try {
                template = factory.create(new FileInputStream(templateName));
            } catch (FileNotFoundException e) {
                throw new RedDeerException("Unable to read local template", e);
            }
        } else {
            // it is not an external template
            template = connection.getResource(ResourceKind.TEMPLATE, OpenShiftResources.OPENSHIFT_PROJECT, templateName);
        }
    } catch (IOException ex) {
        throw new RedDeerException("Unable to read template from URL", ex);
    }
    assertNotNull(template);
    this.service = getOrCreateService(projectName, serviceName, template);
    if (serviceSpec.waitForBuild()) {
        waitForResources(serviceName, projectName, service);
        waitForUI(serviceName, projectName);
    }
}
Also used : RedDeerException(org.eclipse.reddeer.common.exception.RedDeerException) MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) IResourceFactory(com.openshift.restclient.IResourceFactory) File(java.io.File) URL(java.net.URL) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) FileInputStream(java.io.FileInputStream) ClientBuilder(com.openshift.restclient.ClientBuilder)

Aggregations

ClientBuilder (com.openshift.restclient.ClientBuilder)7 IClient (com.openshift.restclient.IClient)3 OpenShiftException (com.openshift.restclient.OpenShiftException)3 IOException (java.io.IOException)3 LazySSLCertificateCallback (org.jboss.tools.openshift.core.LazySSLCertificateCallback)3 ISSLCertificateCallback (com.openshift.restclient.ISSLCertificateCallback)2 TimeoutException (java.util.concurrent.TimeoutException)2 CommandTimeoutException (org.jboss.tools.openshift.cdk.server.core.internal.adapter.controllers.CommandTimeoutException)2 Connection (org.jboss.tools.openshift.core.connection.Connection)2 Test (org.junit.Test)2 IResourceFactory (com.openshift.restclient.IResourceFactory)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 CoreException (org.eclipse.core.runtime.CoreException)1 RedDeerException (org.eclipse.reddeer.common.exception.RedDeerException)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1