Search in sources :

Example 1 with IProjectTemplateProcessing

use of com.openshift.restclient.capability.resources.IProjectTemplateProcessing 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 IProjectTemplateProcessing

use of com.openshift.restclient.capability.resources.IProjectTemplateProcessing 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 IProjectTemplateProcessing

use of com.openshift.restclient.capability.resources.IProjectTemplateProcessing in project jbosstools-openshift by jbosstools.

the class CreateApplicationFromTemplateJobTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    labels.add(new Label("foo", "bar"));
    job = spy(new CreateApplicationFromTemplateJobRunner(project, template, parameters, labels));
    when(client.get(anyString(), anyString(), anyString())).thenThrow(OpenShiftException.class);
    when(clientCapability.getClient()).thenReturn(client);
    when(project.accept(isA(CapabilityVisitor.class), any())).thenAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock args) throws Throwable {
            if (args.getArguments()[1] instanceof IStatus) {
                CapabilityVisitor<IProjectTemplateProcessing, IStatus> visitor = (CapabilityVisitor<IProjectTemplateProcessing, IStatus>) args.getArguments()[0];
                return visitor.visit(capability);
            } else if (args.getArguments()[1] instanceof Collection) {
                CapabilityVisitor<IClientCapability, Collection> visitor = (CapabilityVisitor<IClientCapability, Collection>) args.getArguments()[0];
                return visitor.visit(clientCapability);
            }
            return null;
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IClientCapability(com.openshift.restclient.capability.resources.IClientCapability) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) Answer(org.mockito.stubbing.Answer) IProjectTemplateProcessing(com.openshift.restclient.capability.resources.IProjectTemplateProcessing) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Collection(java.util.Collection) Before(org.junit.Before)

Aggregations

IProjectTemplateProcessing (com.openshift.restclient.capability.resources.IProjectTemplateProcessing)3 OpenShiftException (com.openshift.restclient.OpenShiftException)2 ITemplate (com.openshift.restclient.model.template.ITemplate)2 Collection (java.util.Collection)2 IStatus (org.eclipse.core.runtime.IStatus)2 Label (org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label)2 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)1 IClientCapability (com.openshift.restclient.capability.resources.IClientCapability)1 IProject (com.openshift.restclient.model.IProject)1 IResource (com.openshift.restclient.model.IResource)1 Status (org.eclipse.core.runtime.Status)1 AbstractWaitCondition (org.eclipse.reddeer.common.condition.AbstractWaitCondition)1 WaitWhile (org.eclipse.reddeer.common.wait.WaitWhile)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 OpenShiftExplorerView (org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1