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();
}
}
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;
}
});
}
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;
}
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;
}
});
}
Aggregations