summaryrefslogtreecommitdiff
path: root/module/ri-engine/src/main/java/io/trygvis
diff options
context:
space:
mode:
Diffstat (limited to 'module/ri-engine/src/main/java/io/trygvis')
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeMyApp.java6
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeOps.java4
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeIo.java)13
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/DbObject.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeObject.java)8
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/engine/Main.java)33
5 files changed, 23 insertions, 41 deletions
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeMyApp.java b/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeMyApp.java
deleted file mode 100644
index a1340e7..0000000
--- a/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeMyApp.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package io.trygvis.rules.acme;
-
-public class AcmeMyApp {
- public String environment;
- public String dockerTag;
-}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeOps.java b/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeOps.java
deleted file mode 100644
index 147fcfa..0000000
--- a/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeOps.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.trygvis.rules.acme;
-
-public class AcmeOps {
-}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeIo.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
index 456195d..b835da5 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeIo.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
@@ -1,10 +1,9 @@
-package io.trygvis.rules.acme;
+package io.trygvis.rules.engine;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
-import org.apache.commons.collections4.OrderedMap;
import org.drools.core.common.DefaultFactHandle;
import org.kie.api.KieBase;
import org.kie.api.runtime.rule.FactHandle;
@@ -16,10 +15,10 @@ import java.util.*;
import java.util.function.Function;
@SuppressWarnings("unchecked")
-public class AcmeIo {
+public class DbIo {
private final ObjectMapper mapper;
- public AcmeIo(KieBase kieBase) {
+ public DbIo(KieBase kieBase) {
var factory = new YAMLFactory();
factory.enable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
factory.enable(YAMLGenerator.Feature.USE_NATIVE_OBJECT_ID);
@@ -33,10 +32,10 @@ public class AcmeIo {
public List<Object> load(String file) throws IOException {
var parser = mapper.getFactory().createParser(new File(file));
- var objects = mapper.readValues(parser, AcmeObject.class).readAll(new ArrayList<>());
+ var objects = mapper.readValues(parser, DbObject.class).readAll(new ArrayList<>());
List<Object> items = new ArrayList<>(objects.size());
- for (AcmeObject object : objects) {
+ for (DbObject object : objects) {
try {
var type = mapper.getTypeFactory().findClass(object.type);
var x = mapper.treeToValue(object.data, type);
@@ -221,7 +220,7 @@ public class AcmeIo {
var collection = e.getValue();
collection.sort();
for (var fact : collection.values) {
- g.writeObject(new AcmeObject(name, mapper.valueToTree(fact)));
+ g.writeObject(new DbObject(name, mapper.valueToTree(fact)));
}
}
}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeObject.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbObject.java
index a75c4ba..6b9817e 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/acme/AcmeObject.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbObject.java
@@ -1,15 +1,15 @@
-package io.trygvis.rules.acme;
+package io.trygvis.rules.engine;
import com.fasterxml.jackson.databind.node.ObjectNode;
-public final class AcmeObject {
+public final class DbObject {
public String type;
public ObjectNode data;
- public AcmeObject() {
+ public DbObject() {
}
- public AcmeObject(String type, ObjectNode data) {
+ public DbObject(String type, ObjectNode data) {
this.type = type;
this.data = data;
}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/Main.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
index 7c96be6..2565112 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/Main.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
@@ -1,27 +1,27 @@
package io.trygvis.rules.engine;
-import io.trygvis.rules.acme.AcmeIo;
-import io.trygvis.rules.dns.DnsEntry;
-import io.trygvis.rules.machine.Machine;
-import io.trygvis.rules.network.Ipv4Address;
-import io.trygvis.rules.network.Ipv4Cidr;
import org.drools.core.audit.WorkingMemoryConsoleLogger;
import org.kie.api.KieServices;
import org.kie.api.event.rule.AgendaEventListener;
import org.kie.api.event.rule.RuleRuntimeEventListener;
+import org.kie.api.runtime.KieSession;
+import java.io.Closeable;
import java.io.IOException;
-public class Main {
- public static void main(String[] args) throws IOException {
+public class Engine implements Closeable {
+ public final DbIo io;
+ public final KieSession session;
+
+ public Engine(String database) throws IOException {
var services = KieServices.Factory.get();
var container = services.getKieClasspathContainer();
var kieBase = container.getKieBase();
- var io = new AcmeIo(kieBase);
- var objects = io.load("acme.yaml");
+ io = new DbIo(kieBase);
+ var objects = io.load(database);
- var session = container.newKieSession();
+ session = container.newKieSession();
session.setGlobal("te", new TemplateEngine());
@@ -37,17 +37,10 @@ public class Main {
session.getAgenda().getAgendaGroup("init").setFocus();
session.fireAllRules();
+ }
- io.dump("phase-1", session.getFactHandles());
-
- io.dump("vpn0", session.getFactHandles(), (Object o) ->
- o.getClass().getName().contains("Wg")
- || o instanceof Machine
- || o instanceof DnsEntry
- || o instanceof Ipv4Cidr
- || o instanceof Ipv4Address
- );
-
+ @Override
+ public void close() {
session.dispose();
}
}