Search in sources :

Example 16 with Parameter

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());
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Parameter(io.fabric8.openshift.api.model.Parameter)

Example 17 with Parameter

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;
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Parameter(io.fabric8.openshift.api.model.Parameter) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList)

Aggregations

Parameter (io.fabric8.openshift.api.model.Parameter)11 HashMap (java.util.HashMap)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 File (java.io.File)3 HashSet (java.util.HashSet)3 TreeSet (java.util.TreeSet)3 Configuration (io.fabric8.annotations.Configuration)2 Endpoint (io.fabric8.annotations.Endpoint)2 External (io.fabric8.annotations.External)2 Path (io.fabric8.annotations.Path)2 PortName (io.fabric8.annotations.PortName)2 Protocol (io.fabric8.annotations.Protocol)2 ServiceName (io.fabric8.annotations.ServiceName)2 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 KubernetesHelper.createIntOrString (io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString)1