summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-06 15:20:40 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-06 15:21:16 +0100
commite84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00 (patch)
treeafb7c00c654c122a313acaba8630708a87ae4ffd
parent9504c7efb9b57aeacf5e2717a43c3cf178a65aee (diff)
downloadrules-sandbox-e84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00.tar.gz
rules-sandbox-e84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00.tar.bz2
rules-sandbox-e84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00.tar.xz
rules-sandbox-e84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00.zip
Splitting Main into two runs, Vpn and AcmeApps.
-rw-r--r--module/acme/classpath.txt2
-rw-r--r--module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java13
-rw-r--r--module/acme/src/main/java/io/trygvis/acme/VpnMain.java6
-rw-r--r--module/acme/src/main/resources/META-INF/kmodule.xml10
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java13
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java6
-rw-r--r--out/acme/apps.yaml (renamed from out/phase-1.yaml)216
-rw-r--r--out/acme/wireguard.yaml (renamed from out/vpn0.yaml)0
8 files changed, 30 insertions, 236 deletions
diff --git a/module/acme/classpath.txt b/module/acme/classpath.txt
index 5d086d8..ed8e5f6 100644
--- a/module/acme/classpath.txt
+++ b/module/acme/classpath.txt
@@ -17,7 +17,7 @@ com.hubspot.jinjava:jinjava:2.5.6:jar
com.thoughtworks.xstream:xstream:1.4.14:jar
com.zaxxer:SparseBitSet:1.2:jar
commons-codec:commons-codec:1.11:jar
-commons-io:commons-io:2.6:jar
+commons-io:commons-io:2.8.0:jar
commons-net:commons-net:2.2:jar
io.trygvis.rules-sandbox:ri-engine:1.0-SNAPSHOT:jar
io.trygvis.rules-sandbox:ri-wireguard:1.0-SNAPSHOT:jar
diff --git a/module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java b/module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java
new file mode 100644
index 0000000..f21ebc3
--- /dev/null
+++ b/module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java
@@ -0,0 +1,13 @@
+package io.trygvis.acme;
+
+import io.trygvis.rules.engine.Engine;
+
+import java.io.IOException;
+
+public class AcmeAppsMain {
+ public static void main(String[] args) throws IOException {
+ try (var engine = new Engine("acme-apps", "acme.yaml")) {
+ engine.io.dump("acme/apps", engine.session.getFactHandles());
+ }
+ }
+}
diff --git a/module/acme/src/main/java/io/trygvis/acme/VpnMain.java b/module/acme/src/main/java/io/trygvis/acme/VpnMain.java
index d5f986d..d6c8061 100644
--- a/module/acme/src/main/java/io/trygvis/acme/VpnMain.java
+++ b/module/acme/src/main/java/io/trygvis/acme/VpnMain.java
@@ -10,10 +10,8 @@ import java.io.IOException;
public class VpnMain {
public static void main(String[] args) throws IOException {
- try (var engine = new Engine("acme.yaml")) {
- engine.io.dump("phase-1", engine.session.getFactHandles());
-
- engine.io.dump("vpn0", engine.session.getFactHandles(), (Object o) ->
+ try (var engine = new Engine("acme-wireguard", "acme.yaml")) {
+ engine.io.dump("acme/wireguard", engine.session.getFactHandles(), (Object o) ->
o.getClass().getName().contains("Wg")
|| o instanceof Machine
|| o instanceof DnsEntry
diff --git a/module/acme/src/main/resources/META-INF/kmodule.xml b/module/acme/src/main/resources/META-INF/kmodule.xml
index 351a25e..da34a59 100644
--- a/module/acme/src/main/resources/META-INF/kmodule.xml
+++ b/module/acme/src/main/resources/META-INF/kmodule.xml
@@ -3,9 +3,11 @@
xmlns="http://www.drools.org/xsd/kmodule"
xsi:schemaLocation="http://www.drools.org/xsd/kmodule https://www.drools.org/xsd/kmodule_7_1.xsd">
- <kbase packages="io.trygvis.acme" default="true"
- includes="engine,wireguard">
- <ksession name="Default" default="true">
- </ksession>
+ <kbase packages="io.trygvis.acme" includes="engine" name="acme-apps">
+ <ksession name="acme-apps" default="true"/>
+ </kbase>
+
+ <kbase packages="io.trygvis.acme" includes="engine,wireguard" name="acme-wireguard">
+ <ksession name="acme-wireguard" default="true"/>
</kbase>
</kmodule>
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
index b835da5..7f946d9 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
@@ -1,5 +1,6 @@
package io.trygvis.rules.engine;
+import ch.qos.logback.core.util.FileUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
@@ -41,7 +42,7 @@ public class DbIo {
var x = mapper.treeToValue(object.data, type);
items.add(x);
} catch (ClassNotFoundException e) {
- throw new IOException(e);
+ // ignore
}
}
@@ -183,13 +184,9 @@ public class DbIo {
}
public void dump(String s, Collection<FactHandle> factHandles, Function<Object, Boolean> filter) throws IOException {
- var out = new File("out");
+ var yamlFile = new File("out", s + ".yaml");
- if (!out.isDirectory()) {
- if (!out.mkdirs()) {
- throw new IOException("Could not create directory: " + out);
- }
- }
+ FileUtil.createMissingParentDirectories(yamlFile);
var facts = new TreeMap<Class<?>, FactCollection<Object>>(Comparator.comparing(Class::getName));
for (var handle : factHandles) {
@@ -212,7 +209,7 @@ public class DbIo {
}
var factory = mapper.getFactory();
- try (var writer = new FileWriter(new File(out, s + ".yaml"));
+ try (var writer = new FileWriter(yamlFile);
var g = factory.createGenerator(writer)) {
for (var e : facts.entrySet()) {
var name = e.getKey().getName();
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
index 2565112..f624603 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
@@ -13,15 +13,15 @@ public class Engine implements Closeable {
public final DbIo io;
public final KieSession session;
- public Engine(String database) throws IOException {
+ public Engine(String k, String database) throws IOException {
var services = KieServices.Factory.get();
var container = services.getKieClasspathContainer();
- var kieBase = container.getKieBase();
+ var kieBase = container.getKieBase(k);
io = new DbIo(kieBase);
var objects = io.load(database);
- session = container.newKieSession();
+ session = container.newKieSession(k);
session.setGlobal("te", new TemplateEngine());
diff --git a/out/phase-1.yaml b/out/acme/apps.yaml
index 91b0524..82050eb 100644
--- a/out/phase-1.yaml
+++ b/out/acme/apps.yaml
@@ -153,39 +153,14 @@ data:
---
type: "io.trygvis.rules.dns.DnsEntry"
data:
- fqdn: "acme-1.vpn.acme.com"
- type: "A"
----
-type: "io.trygvis.rules.dns.DnsEntry"
-data:
fqdn: "acme-2.machine.acme.com"
type: "A"
---
type: "io.trygvis.rules.dns.DnsEntry"
data:
- fqdn: "acme-2.vpn.acme.com"
- type: "A"
----
-type: "io.trygvis.rules.dns.DnsEntry"
-data:
fqdn: "acme-3.machine.acme.com"
type: "A"
---
-type: "io.trygvis.rules.dns.DnsEntry"
-data:
- fqdn: "acme-3.vpn.acme.com"
- type: "A"
----
-type: "io.trygvis.rules.dns.DnsEntry"
-data:
- fqdn: "ws-1.vpn.acme.com"
- type: "A"
----
-type: "io.trygvis.rules.dns.DnsEntry"
-data:
- fqdn: "ws-2.vpn.acme.com"
- type: "A"
----
type: "io.trygvis.rules.dns.DnsEntryTerraformExpression"
data:
entry:
@@ -295,194 +270,3 @@ data:
name: "ws-2"
fqdn: null
key: "ws-2"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "acme-1"
- to: "acme-2"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "acme-1"
- to: "acme-3"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "acme-2"
- to: "acme-1"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "acme-2"
- to: "acme-3"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "acme-3"
- to: "acme-1"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "acme-3"
- to: "acme-2"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "ws-1"
- to: "acme-1"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "ws-1"
- to: "acme-2"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "ws-1"
- to: "acme-3"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "ws-2"
- to: "acme-1"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "ws-2"
- to: "acme-2"
----
-type: "io.trygvis.rules.wireguard.WgConnection"
-data:
- host: "ws-2"
- to: "acme-3"
----
-type: "io.trygvis.rules.wireguard.WgHost"
-data:
- name: "acme-1"
- net: "vpn0"
- publicName: "acme-1.machine.acme.com"
- netToNetIp: null
- networkIp: null
----
-type: "io.trygvis.rules.wireguard.WgHost"
-data:
- name: "acme-2"
- net: "vpn0"
- publicName: "acme-2.machine.acme.com"
- netToNetIp: null
- networkIp: null
----
-type: "io.trygvis.rules.wireguard.WgHost"
-data:
- name: "acme-3"
- net: "vpn0"
- publicName: "acme-3.machine.acme.com"
- netToNetIp: null
- networkIp: null
----
-type: "io.trygvis.rules.wireguard.WgHost"
-data:
- name: "ws-1"
- net: "vpn0"
- publicName: null
- netToNetIp: null
- networkIp: null
----
-type: "io.trygvis.rules.wireguard.WgHost"
-data:
- name: "ws-2"
- net: "vpn0"
- publicName: null
- netToNetIp: null
- networkIp: null
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "acme-1"
- role: "link"
- ip:
- value: "192.168.10.4"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "acme-1"
- role: "network"
- ip:
- value: "10.55.55.4"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "acme-2"
- role: "link"
- ip:
- value: "192.168.10.3"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "acme-2"
- role: "network"
- ip:
- value: "10.55.55.3"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "acme-3"
- role: "link"
- ip:
- value: "192.168.10.2"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "acme-3"
- role: "network"
- ip:
- value: "10.55.55.2"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "ws-1"
- role: "link"
- ip:
- value: "192.168.10.1"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "ws-1"
- role: "network"
- ip:
- value: "10.55.55.1"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "ws-2"
- role: "link"
- ip:
- value: "192.168.10.0"
----
-type: "io.trygvis.rules.wireguard.WgIpAllocation"
-data:
- host: "ws-2"
- role: "network"
- ip:
- value: "10.55.55.0"
----
-type: "io.trygvis.rules.wireguard.WgIpPool"
-data:
- net: "vpn0"
- role: "link"
- cidr:
- value: "192.168.10.0/29"
----
-type: "io.trygvis.rules.wireguard.WgIpPool"
-data:
- net: "vpn0"
- role: "network"
- cidr:
- value: "10.55.55.0/24"
----
-type: "io.trygvis.rules.wireguard.WgNet"
-data:
- name: "vpn0"
- domain: "vpn.acme.com"
- linkCidr: "192.168.10.0/29"
- networkCidr: "10.55.55.0/24"
diff --git a/out/vpn0.yaml b/out/acme/wireguard.yaml
index 4601931..4601931 100644
--- a/out/vpn0.yaml
+++ b/out/acme/wireguard.yaml