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