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