Search in sources :

Example 16 with OpenShiftException

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");
}
Also used : OpenShiftException(com.openshift.restclient.OpenShiftException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) TemplateApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.TemplateApplicationSource) ITemplate(com.openshift.restclient.model.template.ITemplate) IOException(java.io.IOException) IResource(com.openshift.restclient.model.IResource) ResourceFactoryException(com.openshift.restclient.ResourceFactoryException)

Example 17 with OpenShiftException

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException)

Example 18 with OpenShiftException

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());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with OpenShiftException

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());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 20 with OpenShiftException

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);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) OpenShiftException(com.openshift.restclient.OpenShiftException)

Aggregations

OpenShiftException (com.openshift.restclient.OpenShiftException)20 IStatus (org.eclipse.core.runtime.IStatus)13 IResource (com.openshift.restclient.model.IResource)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Status (org.eclipse.core.runtime.Status)5 Connection (org.jboss.tools.openshift.core.connection.Connection)5 IClient (com.openshift.restclient.IClient)4 IProject (com.openshift.restclient.model.IProject)4 ITemplate (com.openshift.restclient.model.template.ITemplate)4 IOException (java.io.IOException)4 ClientBuilder (com.openshift.restclient.ClientBuilder)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 ISSLCertificateCallback (com.openshift.restclient.ISSLCertificateCallback)2 ResourceKind (com.openshift.restclient.ResourceKind)2 IProjectTemplateProcessing (com.openshift.restclient.capability.resources.IProjectTemplateProcessing)2 IImageStream (com.openshift.restclient.model.IImageStream)2 IService (com.openshift.restclient.model.IService)2 IRoute (com.openshift.restclient.model.route.IRoute)2