I want to parse a docker-compose.yaml to Java classes using SnakeYaml.
Everything went well until I started working with “deployment” tag of Docker specification.
It has a “placement” tag, which has two properties: “constraints” and “preferences”. Each of them can be either a list or a map.
placement:
constraints:
disktype: ssd
disktype2: hdd
preferences:
- datacenter=us-east
I am trying to parse this part of docker-compose to the following class:
@Getter
@Setter
public class DockerDeployPlacement {
private Map<String,String> constraints;
private Map<String,String> preferences;
@Override
public String toString() {
return "DeployPlacementConfig{" +
"constraints='" + constraints + ''' +
", preferences=" + preferences +
'}';
}
}
So, what I want is: if the “constraints” or “preferences” is a List – cast it to Map. The following logic must be applied only to the “placement” Node.
The whole YAML may look like this:
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
update_config:
parallelism: 2
delay: 10s
order: stop-first
rollback_config:
parallelism: 2
delay: 10s
order: stop-first
mode: replicated
replicas: 2
endpoint_mode: vip
labels:
com.example.description: "This label will appear on the web service"
placement:
constraints:
disktype: ssd
disktype2: hdd
preferences:
- datacenter=us-east