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