use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class RefreshResourceHandler method createRefreshJob.
private Job createRefreshJob(IOpenshiftUIElement<?, ?> element) {
return new AbstractDelegatingMonitorJob(LOADING_OPEN_SHIFT_INFORMATIONS) {
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
monitor.beginTask(LOADING_OPEN_SHIFT_INFORMATIONS, IProgressMonitor.UNKNOWN);
element.refresh();
} catch (OpenShiftException e) {
OpenShiftCommonUIActivator.getDefault().getLogger().logError(FAILED_TO_REFRESH_ELEMENT, e);
return new Status(Status.ERROR, OpenShiftCommonUIActivator.PLUGIN_ID, FAILED_TO_REFRESH_ELEMENT, e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
}
use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class OpenShiftServiceRequirement method cleanUp.
@Override
public void cleanUp() {
if (serviceSpec.cleanup()) {
String projectName = TestUtils.getValueOrDefault(serviceSpec.project(), DatastoreOS3.TEST_PROJECT);
final IProject project = OpenShift3NativeResourceUtils.getProject(projectName, connection);
IProjectTemplateProcessing capability = project.getCapability(IProjectTemplateProcessing.class);
ITemplate processed = capability.process(template);
for (IResource resource : processed.getObjects()) {
IResource res = connection.getResource(resource.getKind(), projectName, resource.getName());
try {
connection.deleteResource(res);
} catch (OpenShiftException ex) {
LOGGER.error("Unable to remove " + res.getKind() + " named " + res.getName());
LOGGER.error(StackTraceUtils.stackTraceToString(ex));
}
}
cleanResources(connection, ResourceKind.BUILD, project, template);
cleanResources(connection, ResourceKind.REPLICATION_CONTROLLER, project, template);
cleanResources(connection, ResourceKind.POD, project, template);
new WaitWhile(new AbstractWaitCondition() {
@Override
public boolean test() {
for (IResource resource : project.getResources(ResourceKind.POD)) {
if (resource.getName().startsWith(template.getName())) {
return true;
}
}
return false;
}
@Override
public String description() {
return "at least one application pod is running";
}
}, TimePeriod.LONG);
new OpenShiftExplorerView().getOpenShift3Connection(connection).refresh();
}
}
use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class DeployImageJob method updateTriggerIfUpdate.
protected boolean updateTriggerIfUpdate(Connection connection, String project, String name) {
try {
IDeploymentConfig dc = connection.getResource(ResourceKind.DEPLOYMENT_CONFIG, project, name);
IDeploymentImageChangeTrigger trigger = (IDeploymentImageChangeTrigger) dc.getTriggers().stream().filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType())).findFirst().orElse(null);
if (trigger == null || !ResourceKind.IMAGE_STREAM_TAG.equals(trigger.getKind()) || StringUtils.isBlank(trigger.getNamespace()) || connection.getResource(ResourceKind.IMAGE_STREAM, trigger.getNamespace(), trigger.getFrom().getName()) == null) {
return false;
}
DockerImageURI sourceImage = getSourceImage();
if (sourceImage.getName().equals(trigger.getFrom().getName()) && !sourceImage.getTag().equals(trigger.getFrom().getTag())) {
trigger.setFrom(new DockerImageURI(null, null, sourceImage.getName(), sourceImage.getTag()));
connection.updateResource(dc);
}
return true;
} catch (NotFoundException e) {
return false;
} catch (OpenShiftException e) {
if (e.getStatus() != null && e.getStatus().getCode() == IHttpConstants.STATUS_NOT_FOUND) {
return false;
}
throw e;
}
}
use of com.openshift.restclient.OpenShiftException 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.OpenShiftException in project jbosstools-openshift by jbosstools.
the class PortForwardingWizardPage method onStopPortForwarding.
private SelectionListener onStopPortForwarding(final TableViewer viewer) {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
WizardUtils.runInWizard(new Job("Stopping port forwarding...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
wizardModel.stopPortForwarding();
} catch (IOException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", "Failed to close console inputstream while stopping port-forwarding: " + e.getMessage()));
OpenShiftUIActivator.getDefault().getLogger().logError("Failed to close console inputstream while stopping port-forwarding", e);
}
refreshViewerInput(viewer);
if (!wizardModel.isPortForwardingAllowed()) {
// Ports remain in use after a reasonable wait.
// Lets give UI a break and then repeat waiting.
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
waitForPortsToGetFree(viewer);
}
});
}
return Status.OK_STATUS;
}
}, getContainer(), getDataBindingContext());
} catch (OpenShiftException | InvocationTargetException | InterruptedException e1) {
LOG.logError(e1);
MessageDialog.openError(getShell(), "Error stopping port forwarding", e1.getMessage());
}
}
};
}
Aggregations