use of io.fabric8.openshift.api.model.Parameter in project fabric8 by jboss-fuse.
the class Templates method combineParameters.
protected static void combineParameters(List<Parameter> parameters, List<Parameter> otherParameters) {
if (otherParameters != null && otherParameters.size() > 0) {
Map<String, Parameter> map = new HashMap<>();
for (Parameter parameter : parameters) {
map.put(parameter.getName(), parameter);
}
for (Parameter otherParameter : otherParameters) {
String name = otherParameter.getName();
Parameter original = map.get(name);
if (original == null) {
parameters.add(otherParameter);
} else {
if (Strings.isNotBlank(original.getValue())) {
original.setValue(otherParameter.getValue());
}
}
}
}
}
use of io.fabric8.openshift.api.model.Parameter in project fabric8 by jboss-fuse.
the class Templates method processTemplatesLocally.
/**
* Lets locally process the templates so that we can process templates on any kubernetes environment
*/
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\": \"" + KubernetesHelper.defaultApiVersion + "\",\n" + " \"items\": " + KubernetesHelper.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 regex = "${" + name + "}";
String value = parameter.getValue();
// TODO generate random strings for passwords etc!
if (Strings.isNullOrBlank(value)) {
if (failOnMissingParameterValue) {
throw new IllegalArgumentException("No value available for parameter name: " + name);
} else {
value = "";
}
}
json = Strings.replaceAllWithoutRegex(json, regex, value);
}
}
return OBJECT_MAPPER.readerFor(KubernetesList.class).readValue(json);
} else {
KubernetesList answer = new KubernetesList();
answer.setItems(objects);
return answer;
}
}
Aggregations