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));
}
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]));
}
}
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));
}
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;
}
}
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")));
}
Aggregations