Java Code Examples for io.fabric8.openshift.api.model.Parameter#getName()

The following examples show how to use io.fabric8.openshift.api.model.Parameter#getName() . 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 6 votes vote down vote up
private 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 (StringUtils.isNotBlank(original.getValue())) {
                    original.setValue(otherParameter.getValue());
                }
            }
        }
    }
}
 
Example 2
Source File: OpenshiftHelper.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
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 3
Source File: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
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 vote down vote up
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;
}