use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class NewApplicationWizardModel method getLocalAppSource.
private IApplicationSource getLocalAppSource(IProgressMonitor monitor, String filename) {
if (StringUtils.isBlank(filename)) {
return null;
}
IResource resource = null;
filename = VariablesHelper.replaceVariables(filename);
try {
if (!OpenshiftUIConstants.URL_VALIDATOR.isValid(filename) && !Files.isRegularFile(Paths.get(filename))) {
return null;
}
try (InputStream input = createInputStream(filename, monitor)) {
resource = resourceFactory.create(input);
if (resource != null && !(resource instanceof ITemplate)) {
throw new NotATemplateException(resource.getKind());
}
}
} catch (FileNotFoundException e) {
throw new OpenShiftException(e, NLS.bind("Could not find the file \"{0}\" to upload", filename));
} catch (IOException e) {
throw new OpenShiftException(e, NLS.bind("Error reading the file or URL \"{0}\" to upload", filename));
} catch (ResourceFactoryException | ClassCastException e) {
throw e;
}
switch(resource.getKind()) {
case ResourceKind.TEMPLATE:
return new TemplateApplicationSource((ITemplate) resource);
}
throw new OpenShiftException("Creating applications from local files is only allowed using a template");
}
use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class NewApplicationWizardModel method loadAppSource.
@Override
public void loadAppSource(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
try {
if (useLocalAppSource) {
IApplicationSource source = getLocalAppSource(monitor, localAppSourceFilename);
updateSelectedAppSource(useLocalAppSource, serverAppSource, source, localAppSourceFilename);
}
} catch (OpenShiftException e) {
status = StatusFactory.errorStatus(OpenShiftUIActivator.PLUGIN_ID, NLS.bind("Could not load template from {0}: {1}", localAppSourceFilename, e.getLocalizedMessage()), e);
} catch (NotATemplateException e) {
status = StatusFactory.errorStatus(OpenShiftUIActivator.PLUGIN_ID, NLS.bind("{0} is not a template: {1}", localAppSourceFilename, e.getLocalizedMessage()));
}
updateAppSourceStatus(status);
}
use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class CreateResourceJobTest method shouldReturnErrorWhenThereIsAnException.
/*
* Display failed resources and end wizard
*/
@Test
public void shouldReturnErrorWhenThereIsAnException() {
final String message = "Test with exception";
when(resourceFactory.create(input)).thenThrow(new OpenShiftException(message));
IStatus result = job.runMe();
assertEquals(IStatus.ERROR, result.getSeverity());
assertEquals(message, result.getMessage());
}
use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class CreateApplicationFromTemplateJobTest method shouldReturnErrorWhenThereIsAnException.
/*
* Display failed resources and end wizard
*/
@Test
public void shouldReturnErrorWhenThereIsAnException() {
final String message = "Test with exception";
when(capability.process(template)).thenThrow(new OpenShiftException(message));
IStatus result = job.runMe();
assertEquals(IStatus.ERROR, result.getSeverity());
assertEquals(message, result.getMessage());
}
use of com.openshift.restclient.OpenShiftException in project jbosstools-openshift by jbosstools.
the class AbstractDeleteResourceJob method delete.
protected IStatus delete(final IResource resource, final Connection connection, final IProgressMonitor monitor) {
if (resource == null || monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
try {
monitor.subTask(NLS.bind("Delete Resource {0}...", resource.getName()));
if (connection != null) {
connection.deleteResource(resource);
ConnectionsRegistrySingleton.getInstance().fireConnectionChanged(connection, ConnectionProperties.PROPERTY_RESOURCE, resource, null);
}
return Status.OK_STATUS;
} catch (OpenShiftException e) {
return new Status(Status.ERROR, OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Error deleting {0} named {1}.", resource.getKind(), resource.getName()), e);
}
}
Aggregations