Search in sources :

Example 1 with CapabilityVisitor

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

the class ScaleDeploymentHandler method scaleDeployment.

protected void scaleDeployment(ExecutionEvent event, String name, IReplicationController rc, int replicas) {
    if (replicas >= 0) {
        new Job(NLS.bind("Scaling {0} deployment to {1}...", name, replicas)) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    return rc.accept(new CapabilityVisitor<IScalable, IStatus>() {

                        @Override
                        public IStatus visit(IScalable capability) {
                            capability.scaleTo(replicas);
                            return Status.OK_STATUS;
                        }
                    }, new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Scaling is not supported for this resource"));
                } catch (Exception e) {
                    String message = NLS.bind("Unable to scale {0}", name);
                    OpenShiftUIActivator.getDefault().getLogger().logError(message, e);
                    return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, e);
                }
            }
        }.schedule();
    }
}
Also used : ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) Job(org.eclipse.core.runtime.jobs.Job) IScalable(com.openshift.restclient.api.capabilities.IScalable) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with CapabilityVisitor

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

the class CreateResourceJobTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    job = spy(new CreateResourceJobRunner(project, input));
    when(client.get(anyString(), anyString(), anyString())).thenThrow(OpenShiftException.class);
    when(client.getResourceFactory()).thenReturn(resourceFactory);
    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<IClientCapability, IStatus> visitor = (CapabilityVisitor<IClientCapability, IStatus>) args.getArguments()[0];
                return visitor.visit(clientCapability);
            }
            return null;
        }
    });
}
Also used : Answer(org.mockito.stubbing.Answer) IStatus(org.eclipse.core.runtime.IStatus) IClientCapability(com.openshift.restclient.capability.resources.IClientCapability) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) Before(org.junit.Before)

Example 3 with CapabilityVisitor

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

the class ConnectionTest method givenAResourceThatAcceptsAVisitorForIClientCapability.

@SuppressWarnings("unchecked")
private Map<String, Object> givenAResourceThatAcceptsAVisitorForIClientCapability(IClient client) {
    final IClientCapability capability = mock(IClientCapability.class);
    when(capability.getClient()).thenReturn(client);
    IResource resource = mock(IResource.class);
    when(resource.accept(any(CapabilityVisitor.class), any())).thenAnswer(new Answer<IClient>() {

        @Override
        public IClient answer(InvocationOnMock invocation) throws Throwable {
            CapabilityVisitor<IClientCapability, IClient> visitor = (CapabilityVisitor<IClientCapability, IClient>) invocation.getArguments()[0];
            return visitor.visit(capability);
        }
    });
    Map<String, Object> mocks = new HashMap<>();
    mocks.put("capability", capability);
    mocks.put("resource", resource);
    return mocks;
}
Also used : IClientCapability(com.openshift.restclient.capability.resources.IClientCapability) HashMap(java.util.HashMap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IClient(com.openshift.restclient.IClient) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) Matchers.anyString(org.mockito.Matchers.anyString) IResource(com.openshift.restclient.model.IResource)

Example 4 with CapabilityVisitor

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

CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)4 IClientCapability (com.openshift.restclient.capability.resources.IClientCapability)3 IStatus (org.eclipse.core.runtime.IStatus)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Before (org.junit.Before)2 Answer (org.mockito.stubbing.Answer)2 IClient (com.openshift.restclient.IClient)1 IScalable (com.openshift.restclient.api.capabilities.IScalable)1 IProjectTemplateProcessing (com.openshift.restclient.capability.resources.IProjectTemplateProcessing)1 IResource (com.openshift.restclient.model.IResource)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 ValidationStatus (org.eclipse.core.databinding.validation.ValidationStatus)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 Label (org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label)1 Matchers.anyString (org.mockito.Matchers.anyString)1