@Override public KubernetesList process(Map<String, String> valuesMap) { Template t = get(); try { List<Parameter> parameters = t.getParameters(); if (parameters != null) { for (Parameter p : parameters) { String v = valuesMap.get(p.getName()); if (v != null) { p.setGenerate(null); p.setValue(v); } } } RequestBody body = RequestBody.create(JSON, JSON_MAPPER.writeValueAsString(t)); Request.Builder requestBuilder = new Request.Builder().post(body).url(getProcessUrl()); t = handleResponse(requestBuilder); KubernetesList l = new KubernetesList(); l.setItems(t.getObjects()); return l; } catch (Exception e) { throw KubernetesClientException.launderThrowable(forOperationType("process"), e); } }
private static List<HasMetadata> processTemplate(Template template, Boolean failOnMissing) { List<Parameter> parameters = template != null ? template.getParameters() : null; KubernetesList list = new KubernetesListBuilder() .withItems(template.getObjects())
public static void main(String[] args) throws IOException { try (OpenShiftClient client = new DefaultOpenShiftClient()) { try { client.namespaces().createNew().withNewMetadata().withName("thisisatest").endMetadata().done(); Template t = client.templates().load(TemplateExample.class.getResourceAsStream("/test-template.yml")).get(); for (Parameter p : t.getParameters()) { System.out.println(p.getName()); } t = client.templates().load(TemplateExample.class.getResourceAsStream("/test-template.yml")).get(); t = client.templates().inNamespace("thisisatest").load(TemplateExample.class.getResourceAsStream("/test-template.yml")).create(); t = client.templates().inNamespace("thisisatest").withName("eap6-basic-sti").get(); System.out.println(t.getMetadata().getName()); KubernetesList l = client.templates().inNamespace("thisisatest").withName("eap6-basic-sti").process(); System.out.println(l.getItems().size()); l = client.lists().load(TemplateExample.class.getResourceAsStream("/test-list.yml")).get(); System.out.println(l.getItems().size()); l = client.lists().inNamespace("thisisatest").load(TemplateExample.class.getResourceAsStream("/test-list.yml")).create(); } finally { // And finally clean up the namespace client.namespaces().withName("thisisatest").delete(); logger.info("Deleted namespace"); } } } }
.get(); List<Parameter> parameters = t != null ? t.getParameters() : null; KubernetesList list = new KubernetesListBuilder() .withItems(t != null && t.getObjects() != null ? t.getObjects() : Collections.<HasMetadata>emptyList())
public SortedMap<String, Parameter> getParameterMap() { SortedMap<String, Parameter> map = new TreeMap<String, Parameter>(); if (template != null) { List<io.fabric8.openshift.api.model.Parameter> list = template.getParameters(); for (io.fabric8.openshift.api.model.Parameter param : list) { map.put(param.getName(), new Parameter(param)); } } return map; }
public void addMissingParameters(Template template) { List<Parameter> parameters = template.getParameters(); if (parameters == null) { parameters = new ArrayList<>(); } Map<String, Parameter> map = new HashMap<>(); for (Parameter parameter : parameters) { map.put(parameter.getName(), parameter); } mergeParametersIntoMap(map, templateParameters.values()); for (Parameter parameter : map.values()) { if (!parameters.contains(parameter)) { parameters.add(parameter); } } template.setParameters(parameters); }
private void createTemplateParameters(File outputDir, Template template, File templatesDir) throws MojoExecutionException { JsonNodeFactory nodeFactory = JsonNodeFactory.instance; ObjectNode values = nodeFactory.objectNode(); List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters(); if (parameters == null || parameters.isEmpty()) { return;
public static Template combineTemplates(Template firstTemplate, Template template) { List<HasMetadata> objects = template.getObjects(); if (objects != null) { for (HasMetadata object : objects) { addTemplateObject(firstTemplate, object); } } List<Parameter> parameters = firstTemplate.getParameters(); if (parameters == null) { parameters = new ArrayList<>(); firstTemplate.setParameters(parameters); } combineParameters(parameters, template.getParameters()); String name = KubernetesHelper.getName(template); if (StringUtils.isNotBlank(name)) { // lets merge all the fabric8 annotations using the template id qualifier as a postfix Map<String, String> annotations = KubernetesHelper.getOrCreateAnnotations(firstTemplate); Map<String, String> otherAnnotations = KubernetesHelper.getOrCreateAnnotations(template); Set<Map.Entry<String, String>> entries = otherAnnotations.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); String value = entry.getValue(); if (!annotations.containsKey(key)) { annotations.put(key, value); } } } return firstTemplate; }
private static Template createTemplateWithObjects(KubernetesList kubernetesResources, Template template) { List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters(); List<HasMetadata> items = kubernetesResources.getItems(); Template tempTemplate = null; if (parameters != null && parameters.size() > 0 && items != null && items.size() > 0) { tempTemplate = new Template(); tempTemplate.setMetadata(template.getMetadata()); tempTemplate.setParameters(parameters); tempTemplate.setObjects(items); } return tempTemplate; }
List<Parameter> parameters = entity != null ? entity.getParameters() : null; if (parameters != null && !parameters.isEmpty()) { String json = "{\"kind\": \"List\", \"apiVersion\": \"" + DEFAULT_API_VERSION + "\",\n" +
@Override public KubernetesList process(Map<String, String> valuesMap) { Template t = get(); try { List<Parameter> parameters = t.getParameters(); if (parameters != null) { for (Parameter p : parameters) { String v = valuesMap.get(p.getName()); if (v != null) { p.setGenerate(null); p.setValue(v); } } } RequestBody body = RequestBody.create(JSON, JSON_MAPPER.writeValueAsString(t)); Request.Builder requestBuilder = new Request.Builder().post(body).url(getProcessUrl()); t = handleResponse(requestBuilder); KubernetesList l = new KubernetesList(); l.setItems(t.getObjects()); return l; } catch (Exception e) { throw KubernetesClientException.launderThrowable(forOperationType("process"), e); } }
private static List<HasMetadata> processTemplate(Template template, Boolean failOnMissing) { List<Parameter> parameters = template != null ? template.getParameters() : null; KubernetesList list = new KubernetesListBuilder() .withItems(template.getObjects())
public void addOpenShiftResources(List<HasMetadata> items) { for (HasMetadata item : items) { if (item instanceof Template) { Template template = (Template) item; if (!KubernetesResourceUtil.isAppCatalogResource(template)) { List<HasMetadata> objects = notNullList(template.getObjects()); String sourceUrl = getSourceUrlAnnotation(template); if (StringUtils.isNotBlank(sourceUrl)) { for (HasMetadata object : objects) { setSourceUrlAnnotationIfNotSet(object, sourceUrl); } } addOpenShiftResources(objects); mergeParametersIntoMap(templateParameters, notNullList(template.getParameters())); continue; } } KindAndName key = new KindAndName(item); HasMetadata old = openshiftDependencyResources.get(key); if (old != null) { log.warn("Duplicate OpenShift resources for %s at %s and %s", key, getSourceUrlAnnotation(old), getSourceUrlAnnotation(item)); } openshiftDependencyResources.put(key, item); } }
public TemplateBuilder(Template instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withLabels(instance.getLabels()); this.withMetadata(instance.getMetadata()); this.withObjects(instance.getObjects()); this.withParameters(instance.getParameters()); this.validationEnabled = validationEnabled; }
public TemplateFluentImpl(Template instance){ this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withLabels(instance.getLabels()); this.withMetadata(instance.getMetadata()); this.withObjects(instance.getObjects()); this.withParameters(instance.getParameters()); }
public TemplateBuilder(TemplateFluent<?> fluent,Template instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withLabels(instance.getLabels()); fluent.withMetadata(instance.getMetadata()); fluent.withObjects(instance.getObjects()); fluent.withParameters(instance.getParameters()); this.validationEnabled = validationEnabled; } public TemplateBuilder(Template instance){
.get(); List<Parameter> parameters = t != null ? t.getParameters() : null; KubernetesList list = new KubernetesListBuilder() .withItems(t != null && t.getObjects() != null ? t.getObjects() : Collections.<HasMetadata>emptyList())