diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-12 20:57:56 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-12 21:35:09 +0100 |
commit | 250cb0fb4fa9787c78b73b44425676cfec3a7944 (patch) | |
tree | 5a5c15990b15203d8e6386a9ebeb49de2bf0fea5 /module/ri-engine/src/main/resources | |
parent | 5f294077a362d0127146882e6c90b863c4f54703 (diff) | |
download | rules-sandbox-250cb0fb4fa9787c78b73b44425676cfec3a7944.tar.gz rules-sandbox-250cb0fb4fa9787c78b73b44425676cfec3a7944.tar.bz2 rules-sandbox-250cb0fb4fa9787c78b73b44425676cfec3a7944.tar.xz rules-sandbox-250cb0fb4fa9787c78b73b44425676cfec3a7944.zip |
Starting on generating ansible files for docker-compose setups.
Diffstat (limited to 'module/ri-engine/src/main/resources')
-rw-r--r-- | module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl b/module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl new file mode 100644 index 0000000..9bdc0a5 --- /dev/null +++ b/module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl @@ -0,0 +1,69 @@ +package io.trygvis.rules.dba + +import io.trygvis.rules.core.Problem +import io.trygvis.rules.machine.Machine +import java.util.ArrayList +import java.util.Map +import java.util.HashMap +import java.util.List +import java.util.stream.Collectors +import java.util.Collections + +global io.trygvis.rules.engine.TemplateEngine te; + +dialect "mvel" + +declare DbaMachineRole + machine : String + roles : String[] +end + +rule "Assign containers to hosts" +when + $machine : Machine() + $machineRole : DbaMachineRole(machine == $machine.name) + $container : Container(machine == null, $machineRole.roles contains machineRole) +then + System.out.println("Assigning container to machine: " + $machine.name); + modify($container) { + machine = $machine + } +end + +rule "Containers without hosts" + agenda-group "generate" +when + $container : Container(machine == null) +then + insert(new Problem("No machine for container", $container)) +end + +rule "Generate docker-compose.yaml" + agenda-group "generate" +when + $cluster : Cluster() + $containers : ArrayList(size > 0) from collect(Container(cluster == $cluster)) +then + System.out.println("Docker compose for cluster: " + $cluster.name + " with " + $containers.size() + " containers"); + + Map containersByMachine = new HashMap(); + for (Object o : $containers) { + Container c = (Container) o; + + var list = (List) containersByMachine.get(c.getMachine()); + if (list == null) { + list = new ArrayList(); + containersByMachine.put(c.getMachine(), list); + } + list.add(c); + } + + System.out.println("containersByMachine = " + containersByMachine); + + var path = "ansible/dba/" + $cluster.name + ".yml"; + te.template("dba/cluster", path, Map.of( + "cluster", $cluster, + "containers", $containers, + "containersByMachine", containersByMachine + )); +end |