diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-01 23:13:14 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-01 23:13:14 +0100 |
commit | 1911481101e15463c8aecbdc03a6ce5b63b0d68f (patch) | |
tree | 254e8fe5e8cffb0cee35f77e1b9bfaa071d16489 /src/main/java | |
parent | e4821f82249bddb443a1f6a6e403087cab659c6d (diff) | |
download | rules-sandbox-1911481101e15463c8aecbdc03a6ce5b63b0d68f.tar.gz rules-sandbox-1911481101e15463c8aecbdc03a6ce5b63b0d68f.tar.bz2 rules-sandbox-1911481101e15463c8aecbdc03a6ce5b63b0d68f.tar.xz rules-sandbox-1911481101e15463c8aecbdc03a6ce5b63b0d68f.zip |
Generating DNS too.
Diffstat (limited to 'src/main/java')
7 files changed, 81 insertions, 5 deletions
diff --git a/src/main/java/io/trygvis/rules/dns/DnsEntry.java b/src/main/java/io/trygvis/rules/dns/DnsEntry.java index e7d9f4c..105ef79 100644 --- a/src/main/java/io/trygvis/rules/dns/DnsEntry.java +++ b/src/main/java/io/trygvis/rules/dns/DnsEntry.java @@ -16,4 +16,12 @@ public class DnsEntry { public static DnsEntry aaaa(String fqdn) { return new DnsEntry(fqdn, "AAAA"); } + + public String getFqdn() { + return fqdn; + } + + public String getType() { + return type; + } } diff --git a/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java b/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java new file mode 100644 index 0000000..79bf934 --- /dev/null +++ b/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java @@ -0,0 +1,21 @@ +package io.trygvis.rules.dns; + +public class DnsEntryTerraformExpression { + public DnsEntry entry; + public String key; + public String expression; + + public DnsEntryTerraformExpression(DnsEntry entry, String key, String expression) { + this.entry = entry; + this.key = key; + this.expression = expression; + } + + public String getKey() { + return key; + } + + public String getExpression() { + return expression; + } +} diff --git a/src/main/java/io/trygvis/rules/engine/KeyValue.java b/src/main/java/io/trygvis/rules/engine/KeyValue.java new file mode 100644 index 0000000..5046169 --- /dev/null +++ b/src/main/java/io/trygvis/rules/engine/KeyValue.java @@ -0,0 +1,14 @@ +package io.trygvis.rules.engine; + +public class KeyValue { + public String key; + public String value; + + public KeyValue() { + } + + public KeyValue(String key, String value) { + this.key = key; + this.value = value; + } +} diff --git a/src/main/java/io/trygvis/rules/engine/Main.java b/src/main/java/io/trygvis/rules/engine/Main.java index 3730c28..d469f3a 100644 --- a/src/main/java/io/trygvis/rules/engine/Main.java +++ b/src/main/java/io/trygvis/rules/engine/Main.java @@ -2,7 +2,6 @@ package io.trygvis.rules.engine; import io.trygvis.rules.acme.AcmeIo; import org.drools.core.audit.WorkingMemoryConsoleLogger; -import org.drools.core.common.DefaultFactHandle; import org.kie.api.KieServices; import org.kie.api.event.rule.AgendaEventListener; import org.kie.api.event.rule.RuleRuntimeEventListener; @@ -19,6 +18,8 @@ public class Main { var container = services.getKieClasspathContainer(); var session = container.newKieSession(); + session.setGlobal("te", new TemplateEngine()); + for (var object : objects) { System.out.println("object = " + object); session.insert(object); @@ -27,6 +28,9 @@ public class Main { var logger = new WorkingMemoryConsoleLogger(session); session.addEventListener((AgendaEventListener) logger); session.addEventListener((RuleRuntimeEventListener) logger); + + session.getAgenda().getAgendaGroup("init").setFocus(); + session.fireAllRules(); io.dump("phase-1", session.getFactHandles()); diff --git a/src/main/java/io/trygvis/rules/engine/TemplateEngine.java b/src/main/java/io/trygvis/rules/engine/TemplateEngine.java new file mode 100644 index 0000000..ace7aaf --- /dev/null +++ b/src/main/java/io/trygvis/rules/engine/TemplateEngine.java @@ -0,0 +1,30 @@ +package io.trygvis.rules.engine; + +import ch.qos.logback.core.util.FileUtil; +import com.hubspot.jinjava.Jinjava; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; + +public class TemplateEngine { + private final Jinjava jinjava = new Jinjava(); + + public void template(String name, String output, Map<String, Object> params) throws IOException { + var template = Files.readString(Path.of("j2", name + ".j2")); + String renderedTemplate = jinjava.render(template, params); +// System.out.println("-----------------------------------"); +// for (var item : params.entrySet()) { +// System.out.printf(" %s : %s%n", item.getKey(), item.getValue()); +// } + System.out.println("-----------------------------------"); + System.out.println(renderedTemplate); + System.out.println("-----------------------------------"); + + var f = new File("gen", output); + FileUtil.createMissingParentDirectories(f); + Files.writeString(f.toPath(), renderedTemplate); + } +} diff --git a/src/main/java/io/trygvis/rules/machine/Machine.java b/src/main/java/io/trygvis/rules/machine/Machine.java index b58aeb2..c2a7460 100644 --- a/src/main/java/io/trygvis/rules/machine/Machine.java +++ b/src/main/java/io/trygvis/rules/machine/Machine.java @@ -3,6 +3,9 @@ package io.trygvis.rules.machine; public class Machine { public String name; + public Machine() { + } + public Machine(String name) { this.name = name; } diff --git a/src/main/java/io/trygvis/rules/terraform/Machine.java b/src/main/java/io/trygvis/rules/terraform/Machine.java deleted file mode 100644 index 01bea77..0000000 --- a/src/main/java/io/trygvis/rules/terraform/Machine.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.trygvis.rules.terraform; - -public class Machine { -} |