static Policy fromYamlMap()

in src/main/java/com/google/cloud/run/kafkascaler/scalingconfig/Policy.java [58:79]


  static Policy fromYamlMap(Map<String, Object> input, String resourcePath) {
    Validation.checkKeyExists(input, "type", resourcePath);
    Validation.checkKeyExists(input, "value", resourcePath);
    Validation.checkKeyExists(input, "periodSeconds", resourcePath);

    Policy.Builder builder =
        new AutoValue_Policy.Builder()
            .value((int) input.get("value"))
            .periodSeconds(Duration.ofSeconds((int) input.get("periodSeconds")));
    switch ((String) input.get("type")) {
      case "Percent":
        builder = builder.type(Type.PERCENT);
        break;
      case "Instances":
        builder = builder.type(Type.INSTANCES);
        break;
      default:
        throw new IllegalArgumentException("Unsupported policy type: " + input.get("type"));
    }

    return builder.build();
  }