Java Code Examples for io.fabric8.openshift.api.model.Parameter#getValue()
The following examples show how to use
io.fabric8.openshift.api.model.Parameter#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenshiftHelper.java From jkube with Eclipse Public License 2.0 | 5 votes |
public static KubernetesList processTemplatesLocally(Template entity, boolean failOnMissingParameterValue) throws IOException { List<HasMetadata> objects = null; if (entity != null) { objects = entity.getObjects(); if (objects == null || objects.isEmpty()) { return null; } } List<Parameter> parameters = entity != null ? entity.getParameters() : null; if (parameters != null && !parameters.isEmpty()) { String json = "{\"kind\": \"List\", \"apiVersion\": \"" + DEFAULT_API_VERSION + "\",\n" + " \"items\": " + ResourceUtil.toJson(objects) + " }"; // lets make a few passes in case there's expressions in values for (int i = 0; i < 5; i++) { for (Parameter parameter : parameters) { String name = parameter.getName(); String from = "${" + name + "}"; String value = parameter.getValue(); // TODO generate random strings for passwords etc! if (StringUtils.isBlank(value)) { if (failOnMissingParameterValue) { throw new IllegalArgumentException("No value available for parameter name: " + name); } else { value = ""; } } json = json.replace(from, value); } } return OBJECT_MAPPER.readerFor(KubernetesList.class).readValue(json); } else { KubernetesList answer = new KubernetesList(); answer.setItems(objects); return answer; } }
Example 2
Source File: Fabric8OpenShiftServiceImpl.java From launchpad-missioncontrol with Apache License 2.0 | 5 votes |
private void applyParameterValueProperties(final OpenShiftProject project, final Template template) { RouteList routes = null; for (Parameter parameter : template.getParameters()) { // Find any parameters with special "fabric8-value" properties if (parameter.getAdditionalProperties().containsKey("fabric8-value") && parameter.getValue() == null) { String value = parameter.getAdditionalProperties().get("fabric8-value").toString(); Matcher m = PARAM_VAR_PATTERN.matcher(value); StringBuffer newval = new StringBuffer(); while (m.find()) { String type = m.group(1); String routeName = m.group(2); String propertyPath = m.group(3); String propertyValue = ""; // We only support "route/XXX[.spec.host]" for now, // but we're prepared for future expansion if ("route".equals(type) && ".spec.host".equals(propertyPath)) { // Try to find a Route with that name and use its host name if (routes == null) { routes = client.routes().inNamespace(project.getName()).list(); } propertyValue = routes.getItems().stream() .filter(r -> routeName.equals(r.getMetadata().getName())) .map(r -> r.getSpec().getHost()) .filter(Objects::nonNull) .findAny() .orElse(propertyValue); } m.appendReplacement(newval, Matcher.quoteReplacement(propertyValue)); } m.appendTail(newval); parameter.setValue(newval.toString()); } } }
Example 3
Source File: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
private static List<HasMetadata> processTemplate(Template template, Boolean failOnMissing) { List<Parameter> parameters = template != null ? template.getParameters() : null; KubernetesList list = new KubernetesListBuilder() .withItems(template.getObjects()) .build(); try { String json = OBJECT_MAPPER.writeValueAsString(list); if (parameters != null && !parameters.isEmpty()) { // lets make a few passes in case there's expressions in values for (int i = 0; i < 5; i++) { for (Parameter parameter : parameters) { String name = parameter.getName(); String regex = "${" + name + "}"; String value; if (Utils.isNotNullOrEmpty(parameter.getValue())) { value = parameter.getValue(); } else if (EXPRESSION.equals(parameter.getGenerate())) { Generex generex = new Generex(parameter.getFrom()); value = generex.random(); } else if (failOnMissing) { throw new IllegalArgumentException("No value available for parameter name: " + name); } else { value = ""; } json = json.replace(regex, value); } } } list = OBJECT_MAPPER.readValue(json, KubernetesList.class); } catch (IOException e) { throw KubernetesClientException.launderThrowable(e); } return list.getItems(); }
Example 4
Source File: TemplateOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
public KubernetesList processLocally(Map<String, String> valuesMap) { String namespace = getItem() != null ? getItem().getMetadata().getNamespace() : getNamespace(); if (namespace == null) { namespace = getConfig().getNamespace(); } String name = getItem() != null ? getItem().getMetadata().getName() : getName(); Template t = withParameters(valuesMap) .inNamespace(namespace) .withName(name) .get(); List<Parameter> parameters = t != null ? t.getParameters() : null; KubernetesList list = new KubernetesListBuilder() .withItems(t != null && t.getObjects() != null ? t.getObjects() : Collections.<HasMetadata>emptyList()) .build(); try { String json = JSON_MAPPER.writeValueAsString(list); if (parameters != null && !parameters.isEmpty()) { // lets make a few passes in case there's expressions in values for (int i = 0; i < 5; i++) { for (Parameter parameter : parameters) { String parameterName = parameter.getName(); String parameterValue; if (valuesMap.containsKey(parameterName)) { parameterValue = valuesMap.get(parameterName); } else if (Utils.isNotNullOrEmpty(parameter.getValue())) { parameterValue = parameter.getValue(); } else if (EXPRESSION.equals(parameter.getGenerate())) { Generex generex = new Generex(parameter.getFrom()); parameterValue = generex.random(); } else if (parameter.getRequired() == null || !parameter.getRequired()) { parameterValue = ""; } else { throw new IllegalArgumentException("No value available for parameter name: " + parameterName); } if (parameterValue == null) { logger.debug("Parameter {} has a null value", parameterName); parameterValue = ""; } json = Utils.interpolateString(json, Collections.singletonMap(parameterName, parameterValue)); } } } list = JSON_MAPPER.readValue(json, KubernetesList.class); } catch (IOException e) { throw KubernetesClientException.launderThrowable(e); } return list; }