Search in sources :

Example 1 with ITemplate

use of com.openshift.restclient.model.template.ITemplate 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();
    }
}
Also used : IProjectTemplateProcessing(com.openshift.restclient.capability.resources.IProjectTemplateProcessing) WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) OpenShiftException(com.openshift.restclient.OpenShiftException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ITemplate(com.openshift.restclient.model.template.ITemplate) AbstractWaitCondition(org.eclipse.reddeer.common.condition.AbstractWaitCondition) OpenShiftExplorerView(org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 2 with ITemplate

use of com.openshift.restclient.model.template.ITemplate in project jbosstools-openshift by jbosstools.

the class CreateApplicationFromTemplateJob method doRun.

@Override
protected IStatus doRun(IProgressMonitor monitor) {
    template.updateParameterValues(parameters);
    for (Label label : labels) {
        template.addObjectLabel(label.getName(), label.getValue());
    }
    IStatus status = project.accept(new CapabilityVisitor<IProjectTemplateProcessing, IStatus>() {

        @Override
        public IStatus visit(IProjectTemplateProcessing capability) {
            try {
                ITemplate processed = capability.process(template);
                Collection<IResource> existing = findExistingResources(project, processed);
                if (!existing.isEmpty()) {
                    return createErrorStatusForExistingResources(existing);
                }
                parameters = processed.getParameters().values();
                resources = capability.apply(processed);
                return handleResponse(resources);
            } catch (OpenShiftException e) {
                String message = e.getMessage();
                if (e.getStatus() != null) {
                    message = e.getStatus().getMessage();
                }
                return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, -1, message, e);
            }
        }
    }, new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Template processing is unsupported for this client and server combination.", null));
    return status;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) IProjectTemplateProcessing(com.openshift.restclient.capability.resources.IProjectTemplateProcessing) OpenShiftException(com.openshift.restclient.OpenShiftException) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) Collection(java.util.Collection) ITemplate(com.openshift.restclient.model.template.ITemplate)

Example 3 with ITemplate

use of com.openshift.restclient.model.template.ITemplate in project jbosstools-openshift by jbosstools.

the class NewApplicationWizardModel method updateLabels.

private void updateLabels(IApplicationSource source) {
    if (source != null) {
        if (ResourceKind.TEMPLATE.equals(source.getKind())) {
            ITemplate template = (ITemplate) source.getSource();
            setLabels(template.getObjectLabels());
        } else {
            setLabels(Arrays.asList(new Label(APP_LABEL_NAME, source.getSource().getName())));
        }
    }
}
Also used : ITemplate(com.openshift.restclient.model.template.ITemplate)

Example 4 with ITemplate

use of com.openshift.restclient.model.template.ITemplate in project jbosstools-openshift by jbosstools.

the class ApplicationSourceListPage method onDefinedResourcesClicked.

private SelectionAdapter onDefinedResourcesClicked() {
    return new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ITemplate template = (ITemplate) model.getSelectedAppSource().getSource();
            new ResourceSummaryDialog(getShell(), template.getObjects(), "Template Details", NLS.bind("The following resources will be created by using template\n\"{0}\":", template.getName()), new ResourceDetailsLabelProvider(template.getParameters()), new ResourceDetailsContentProvider()).open();
        }
    };
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ResourceSummaryDialog(org.jboss.tools.openshift.internal.ui.dialog.ResourceSummaryDialog) ITemplate(com.openshift.restclient.model.template.ITemplate)

Example 5 with ITemplate

use of com.openshift.restclient.model.template.ITemplate 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)

Aggregations

ITemplate (com.openshift.restclient.model.template.ITemplate)6 OpenShiftException (com.openshift.restclient.OpenShiftException)3 IProjectTemplateProcessing (com.openshift.restclient.capability.resources.IProjectTemplateProcessing)2 IResource (com.openshift.restclient.model.IResource)2 ResourceFactoryException (com.openshift.restclient.ResourceFactoryException)1 IProject (com.openshift.restclient.model.IProject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 AbstractWaitCondition (org.eclipse.reddeer.common.condition.AbstractWaitCondition)1 WaitWhile (org.eclipse.reddeer.common.wait.WaitWhile)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ResourceSummaryDialog (org.jboss.tools.openshift.internal.ui.dialog.ResourceSummaryDialog)1