summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-25 21:29:12 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-25 21:29:12 +0100
commit912bc8b903dfa6d438c2469ecdad35c181c71830 (patch)
tree1e6ee9fdcb2b9d488914b80623d68189867533bb
parent92b957036218c03a20ba35c19a70bdf5e2333fd3 (diff)
downloadrules-sandbox-912bc8b903dfa6d438c2469ecdad35c181c71830.tar.gz
rules-sandbox-912bc8b903dfa6d438c2469ecdad35c181c71830.tar.bz2
rules-sandbox-912bc8b903dfa6d438c2469ecdad35c181c71830.tar.xz
rules-sandbox-912bc8b903dfa6d438c2469ecdad35c181c71830.zip
Improving usability, massive refactoring.
* Moving all Drools code into their own modules. This fixes ri-engine to acme dependency. * Now they all inherit from their own parent, should be used by third party code too. * Separating acme planning code into its own module. * Splitting rules code from ri-engine into ri-base. ri-engine is now a pure launcher for modules. * Dumping kogito for the most part, but it seems like the planner still requires that.
-rw-r--r--.run/CloudPlaningMain.run.xml15
-rw-r--r--.settings.sh2
-rw-r--r--module/acme-planner/classpath.txt133
-rw-r--r--module/acme-planner/pom.xml38
-rw-r--r--module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudBalance.java (renamed from module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudBalance.java)0
-rw-r--r--module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudBalancingEasyScoreCalculator.java (renamed from module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudBalancingEasyScoreCalculator.java)0
-rw-r--r--module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudComputer.java (renamed from module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudComputer.java)0
-rw-r--r--module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudPlaningMain.java (renamed from module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudPlaningMain.java)0
-rw-r--r--module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudPlanner.java (renamed from module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudPlanner.java)0
-rw-r--r--module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudProcess.java (renamed from module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudProcess.java)0
-rw-r--r--module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudProcessDifficultyComparator.java (renamed from module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudProcessDifficultyComparator.java)0
-rw-r--r--module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/ScalewayInstance.java (renamed from module/acme/src/main/java/io/trygvis/acme/planning/machine/ScalewayInstance.java)0
-rw-r--r--module/acme-planner/src/main/resources/io/trygvis/acme/planning/machine/solver-config.xml (renamed from module/acme/src/main/resources/io/trygvis/acme/planning/machine/solver-config.xml)0
-rw-r--r--module/acme/classpath.txt62
-rw-r--r--module/acme/pom.xml23
-rw-r--r--module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java24
-rw-r--r--module/acme/src/main/java/io/trygvis/acme/VpnMain.java41
-rw-r--r--module/ri-base/classpath.txt26
-rw-r--r--module/ri-base/pom.xml66
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/core/Problem.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/core/Problem.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/dba/Cluster.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/dba/Cluster.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/dba/Container.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/dba/Container.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/dns/DnsEntry.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsEntry.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/dns/DnsZone.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsZone.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/engine/KeyValue.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/engine/KeyValue.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/engine/TemplateEngine.java10
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/machine/Machine.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/machine/Machine.java)1
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/machine/MachineSpecification.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/machine/MachineSpecification.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/network/IpCalc.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/network/IpCalc.java)0
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/network/Ipv4Address.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/network/Ipv4Address.java)3
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java (renamed from module/ri-engine/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java)2
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java96
-rw-r--r--module/ri-base/src/main/resources/META-INF/kmodule.xml (renamed from module/ri-engine/src/main/resources/META-INF/kmodule.xml)0
-rw-r--r--module/ri-base/src/main/resources/io/trygvis/rules/dba/dba.drl (renamed from module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl)4
-rw-r--r--module/ri-base/src/main/resources/io/trygvis/rules/engine/init.drl (renamed from module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl)0
-rw-r--r--module/ri-base/src/main/resources/io/trygvis/rules/machine/machine.drl1
-rw-r--r--module/ri-base/src/main/resources/io/trygvis/rules/terraform/terraform.drl (renamed from module/ri-engine/src/main/resources/io/trygvis/rules/terraform/terraform.drl)12
-rw-r--r--module/ri-base/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.txt (renamed from module/ri-engine/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.java)3
-rw-r--r--module/ri-engine/classpath.txt71
-rw-r--r--module/ri-engine/pom.xml80
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java45
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java64
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/JinjavaTemplateEngine.java40
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/Main.java20
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java34
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/DatabaseCommand.java20
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java55
-rw-r--r--module/ri-module-parent/classpath.txt23
-rw-r--r--module/ri-module-parent/pom.xml83
-rw-r--r--module/ri-wireguard/classpath.txt28
-rw-r--r--module/ri-wireguard/pom.xml14
-rw-r--r--module/ri-wireguard/src/main/resources/logback.xml13
-rw-r--r--out/acme/wireguard.yaml17
-rw-r--r--pom.xml20
55 files changed, 984 insertions, 205 deletions
diff --git a/.run/CloudPlaningMain.run.xml b/.run/CloudPlaningMain.run.xml
new file mode 100644
index 0000000..dfee516
--- /dev/null
+++ b/.run/CloudPlaningMain.run.xml
@@ -0,0 +1,15 @@
+<component name="ProjectRunConfigurationManager">
+ <configuration default="false" name="CloudPlaningMain" type="Application" factoryName="Application" nameIsGenerated="true">
+ <option name="MAIN_CLASS_NAME" value="io.trygvis.acme.planning.machine.CloudPlaningMain" />
+ <module name="acme" />
+ <extension name="coverage">
+ <pattern>
+ <option name="PATTERN" value="io.trygvis.acme.planning.machine.*" />
+ <option name="ENABLED" value="true" />
+ </pattern>
+ </extension>
+ <method v="2">
+ <option name="Make" enabled="true" />
+ </method>
+ </configuration>
+</component> \ No newline at end of file
diff --git a/.settings.sh b/.settings.sh
new file mode 100644
index 0000000..6cdf786
--- /dev/null
+++ b/.settings.sh
@@ -0,0 +1,2 @@
+alias mvn="$(pwd)/mvnw"
+alias engine="java --enable-preview -jar $(echo $(pwd)/module/ri-engine/target/*.jar)"
diff --git a/module/acme-planner/classpath.txt b/module/acme-planner/classpath.txt
new file mode 100644
index 0000000..3aadd88
--- /dev/null
+++ b/module/acme-planner/classpath.txt
@@ -0,0 +1,133 @@
+io.trygvis.rules-sandbox:acme-planner:1.0-SNAPSHOT:jar
+aopalliance:aopalliance:1.0:jar
+ch.obermuhlner:big-math:2.0.0:jar
+ch.qos.logback:logback-classic:1.2.3:jar
+ch.qos.logback:logback-core:1.2.3:jar
+com.fasterxml.jackson.core:jackson-annotations:2.12.0:jar
+com.fasterxml.jackson.core:jackson-core:2.12.0:jar
+com.fasterxml.jackson.core:jackson-databind:2.12.0:jar
+com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.0:jar
+com.github.javaparser:javaparser-core:3.13.10:jar
+com.github.virtuald:curvesapi:1.06:jar
+com.google.code.findbugs:annotations:3.0.1:jar
+com.google.errorprone:error_prone_annotations:2.1.3:jar
+com.google.guava:guava:25.0-jre:jar
+com.google.inject:guice:4.0:jar
+com.google.j2objc:j2objc-annotations:1.1:jar
+com.google.protobuf:protobuf-java:3.6.1:jar
+com.google.re2j:re2j:1.2:jar
+com.googlecode.java-ipv6:java-ipv6:0.17:jar
+com.hubspot.jinjava:jinjava:2.5.6:jar
+com.sun.activation:jakarta.activation:1.2.2:jar
+com.sun.istack:istack-commons-runtime:3.0.8:jar
+com.thoughtworks.xstream:xstream:1.4.14:jar
+com.zaxxer:SparseBitSet:1.2:jar
+commons-codec:commons-codec:1.14:jar
+commons-io:commons-io:2.8.0:jar
+commons-net:commons-net:3.3:jar
+info.picocli:picocli:4.6.1:jar
+io.trygvis.rules-sandbox:ri-engine:1.0-SNAPSHOT:jar
+jakarta.activation:jakarta.activation-api:1.2.2:jar
+jakarta.xml.bind:jakarta.xml.bind-api:2.3.3:jar
+javax.annotation:jsr250-api:1.0:jar
+javax.enterprise:cdi-api:1.0:jar
+javax.inject:javax.inject:1:jar
+org.antlr:antlr-runtime:3.5.2:jar
+org.apache.ant:ant:1.9.15:jar
+org.apache.ant:ant-launcher:1.9.15:jar
+org.apache.commons:commons-collections4:4.4:jar
+org.apache.commons:commons-compress:1.19:jar
+org.apache.commons:commons-lang3:3.10:jar
+org.apache.commons:commons-math3:3.4.1:jar
+org.apache.httpcomponents:httpclient:4.5.12:jar
+org.apache.httpcomponents:httpcore:4.4.13:jar
+org.apache.maven:maven-aether-provider:3.3.9:jar
+org.apache.maven:maven-artifact:3.3.9:jar
+org.apache.maven:maven-builder-support:3.3.9:jar
+org.apache.maven:maven-compat:3.3.9:jar
+org.apache.maven:maven-core:3.3.9:jar
+org.apache.maven:maven-model:3.3.9:jar
+org.apache.maven:maven-model-builder:3.3.9:jar
+org.apache.maven:maven-plugin-api:3.3.9:jar
+org.apache.maven:maven-repository-metadata:3.3.9:jar
+org.apache.maven:maven-settings:3.3.9:jar
+org.apache.maven:maven-settings-builder:3.3.9:jar
+org.apache.maven.wagon:wagon-http:3.0.0:jar
+org.apache.maven.wagon:wagon-http-shared:3.0.0:jar
+org.apache.maven.wagon:wagon-provider-api:3.0.0:jar
+org.apache.poi:poi:4.1.2:jar
+org.apache.poi:poi-ooxml:4.1.2:jar
+org.apache.poi:poi-ooxml-schemas:4.1.2:jar
+org.apache.xmlbeans:xmlbeans:3.1.0:jar
+org.checkerframework:checker-compat-qual:2.0.0:jar
+org.codehaus.mojo:animal-sniffer-annotations:1.14:jar
+org.codehaus.plexus:plexus-classworlds:2.5.2:jar
+org.codehaus.plexus:plexus-component-annotations:1.6:jar
+org.codehaus.plexus:plexus-interpolation:1.21:jar
+org.codehaus.plexus:plexus-utils:3.0.22:jar
+org.drools:drools-canonical-model:7.48.0.Final:jar
+org.drools:drools-compiler:7.48.0.Final:jar
+org.drools:drools-core:7.48.0.Final:jar
+org.drools:drools-core-dynamic:7.48.0.Final:jar
+org.drools:drools-core-reflective:7.48.0.Final:jar
+org.drools:drools-decisiontables:7.48.0.Final:jar
+org.drools:drools-ecj:7.48.0.Final:jar
+org.drools:drools-model-compiler:7.48.0.Final:jar
+org.drools:drools-mvel:7.48.0.Final:jar
+org.drools:drools-mvel-compiler:7.48.0.Final:jar
+org.drools:drools-mvel-parser:7.48.0.Final:jar
+org.drools:drools-serialization-protobuf:7.48.0.Final:jar
+org.drools:drools-templates:7.48.0.Final:jar
+org.eclipse.aether:aether-api:1.1.0:jar
+org.eclipse.aether:aether-connector-basic:1.1.0:jar
+org.eclipse.aether:aether-impl:1.1.0:jar
+org.eclipse.aether:aether-spi:1.1.0:jar
+org.eclipse.aether:aether-transport-file:1.1.0:jar
+org.eclipse.aether:aether-transport-http:1.1.0:jar
+org.eclipse.aether:aether-transport-wagon:1.1.0:jar
+org.eclipse.aether:aether-util:1.1.0:jar
+org.eclipse.sisu:org.eclipse.sisu.inject:0.3.2:jar
+org.eclipse.sisu:org.eclipse.sisu.plexus:0.3.2:jar
+org.glassfish.jaxb:jaxb-runtime:2.3.3:jar
+org.glassfish.jaxb:txw2:2.3.3:jar
+org.javassist:javassist:3.24.1-GA:jar
+org.jsoup:jsoup:1.10.3:jar
+org.kie:kie-api:7.48.0.Final:jar
+org.kie:kie-ci:7.48.0.Final:jar
+org.kie:kie-internal:7.48.0.Final:jar
+org.kie:kie-memory-compiler:7.48.0.Final:jar
+org.kie.kogito:drools-compiler:1.1.0.Final:jar
+org.kie.kogito:drools-core:1.1.0.Final:jar
+org.kie.kogito:drools-core-dynamic:1.1.0.Final:jar
+org.kie.kogito:drools-core-static:1.1.0.Final:jar
+org.kie.kogito:kogito-api:1.1.0.Final:jar
+org.kie.kogito:kogito-drools-model:1.1.0.Final:jar
+org.kie.kogito:kogito-internal:1.1.0.Final:jar
+org.kie.kogito:kogito-services:1.1.0.Final:jar
+org.kie.soup:kie-soup-commons:7.48.0.Final:jar
+org.kie.soup:kie-soup-maven-integration:7.48.0.Final:jar
+org.kie.soup:kie-soup-maven-support:7.48.0.Final:jar
+org.kie.soup:kie-soup-project-datamodel-api:7.48.0.Final:jar
+org.kie.soup:kie-soup-project-datamodel-commons:7.48.0.Final:jar
+org.kie.soup:kie-soup-xstream:7.48.0.Final:jar
+org.mvel:mvel2:2.4.11.Final:jar
+org.optaplanner:optaplanner-core:8.1.0.Final:jar
+org.optaplanner:optaplanner-persistence-common:8.1.0.Final:jar
+org.optaplanner:optaplanner-persistence-jackson:8.1.0.Final:jar
+org.optaplanner:optaplanner-spring-boot-autoconfigure:8.1.0.Final:jar
+org.optaplanner:optaplanner-spring-boot-starter:8.1.0.Final:jar
+org.slf4j:jcl-over-slf4j:1.7.30:jar
+org.slf4j:slf4j-api:1.7.30:jar
+org.sonatype.plexus:plexus-cipher:1.7:jar
+org.sonatype.plexus:plexus-sec-dispatcher:1.3:jar
+org.springframework:spring-aop:5.2.7.RELEASE:jar
+org.springframework:spring-beans:5.2.7.RELEASE:jar
+org.springframework:spring-context:5.2.7.RELEASE:jar
+org.springframework:spring-core:5.2.7.RELEASE:jar
+org.springframework:spring-expression:5.2.7.RELEASE:jar
+org.springframework:spring-jcl:5.2.7.RELEASE:jar
+org.springframework.boot:spring-boot:2.3.1.RELEASE:jar
+org.springframework.boot:spring-boot-autoconfigure:2.3.1.RELEASE:jar
+org.yaml:snakeyaml:1.26:jar
+xmlpull:xmlpull:1.1.3.1:jar
+xpp3:xpp3_min:1.1.4c:jar
diff --git a/module/acme-planner/pom.xml b/module/acme-planner/pom.xml
new file mode 100644
index 0000000..ed8699d
--- /dev/null
+++ b/module/acme-planner/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>io.trygvis.rules-sandbox</groupId>
+ <artifactId>rules-sandbox</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>acme-planner</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.optaplanner</groupId>
+ <artifactId>optaplanner-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ri-engine</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.optaplanner</groupId>
+ <artifactId>optaplanner-spring-boot-starter</artifactId>
+ <version>8.1.0.Final</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+</project>
diff --git a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudBalance.java b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudBalance.java
index 7311918..7311918 100644
--- a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudBalance.java
+++ b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudBalance.java
diff --git a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudBalancingEasyScoreCalculator.java b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudBalancingEasyScoreCalculator.java
index 6a14372..6a14372 100644
--- a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudBalancingEasyScoreCalculator.java
+++ b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudBalancingEasyScoreCalculator.java
diff --git a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudComputer.java b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudComputer.java
index aa2087d..aa2087d 100644
--- a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudComputer.java
+++ b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudComputer.java
diff --git a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudPlaningMain.java b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudPlaningMain.java
index 60b3fd3..60b3fd3 100644
--- a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudPlaningMain.java
+++ b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudPlaningMain.java
diff --git a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudPlanner.java b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudPlanner.java
index c629656..c629656 100644
--- a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudPlanner.java
+++ b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudPlanner.java
diff --git a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudProcess.java b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudProcess.java
index 2002903..2002903 100644
--- a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudProcess.java
+++ b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudProcess.java
diff --git a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudProcessDifficultyComparator.java b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudProcessDifficultyComparator.java
index 658e826..658e826 100644
--- a/module/acme/src/main/java/io/trygvis/acme/planning/machine/CloudProcessDifficultyComparator.java
+++ b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/CloudProcessDifficultyComparator.java
diff --git a/module/acme/src/main/java/io/trygvis/acme/planning/machine/ScalewayInstance.java b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/ScalewayInstance.java
index dfdc0e0..dfdc0e0 100644
--- a/module/acme/src/main/java/io/trygvis/acme/planning/machine/ScalewayInstance.java
+++ b/module/acme-planner/src/main/java/io/trygvis/acme/planning/machine/ScalewayInstance.java
diff --git a/module/acme/src/main/resources/io/trygvis/acme/planning/machine/solver-config.xml b/module/acme-planner/src/main/resources/io/trygvis/acme/planning/machine/solver-config.xml
index 81ae8ed..81ae8ed 100644
--- a/module/acme/src/main/resources/io/trygvis/acme/planning/machine/solver-config.xml
+++ b/module/acme-planner/src/main/resources/io/trygvis/acme/planning/machine/solver-config.xml
diff --git a/module/acme/classpath.txt b/module/acme/classpath.txt
index ea09fc3..96576c4 100644
--- a/module/acme/classpath.txt
+++ b/module/acme/classpath.txt
@@ -1,78 +1,28 @@
-io.trygvis.rules-sandbox:acme:1.0-SNAPSHOT:jar
-ch.obermuhlner:big-math:2.0.0:jar
-ch.qos.logback:logback-classic:1.2.3:jar
-ch.qos.logback:logback-core:1.2.3:jar
+io.trygvis.rules-sandbox.module:acme:1.0-SNAPSHOT:jar
com.fasterxml.jackson.core:jackson-annotations:2.12.0:jar
com.fasterxml.jackson.core:jackson-core:2.12.0:jar
com.fasterxml.jackson.core:jackson-databind:2.12.0:jar
-com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.0:jar
com.github.javaparser:javaparser-core:3.13.10:jar
-com.google.code.findbugs:annotations:3.0.1:jar
-com.google.errorprone:error_prone_annotations:2.1.3:jar
-com.google.guava:guava:25.0-jre:jar
-com.google.j2objc:j2objc-annotations:1.1:jar
-com.google.re2j:re2j:1.2:jar
-com.googlecode.java-ipv6:java-ipv6:0.17:jar
-com.hubspot.jinjava:jinjava:2.5.6:jar
-com.sun.activation:jakarta.activation:1.2.2:jar
-com.sun.istack:istack-commons-runtime:3.0.8:jar
com.thoughtworks.xstream:xstream:1.4.14:jar
commons-codec:commons-codec:1.14:jar
commons-io:commons-io:2.8.0:jar
-commons-net:commons-net:3.3:jar
-info.picocli:picocli:4.6.1:jar
-io.trygvis.rules-sandbox:ri-engine:1.0-SNAPSHOT:jar
-io.trygvis.rules-sandbox:ri-wireguard:1.0-SNAPSHOT:jar
-jakarta.activation:jakarta.activation-api:1.2.2:jar
-jakarta.xml.bind:jakarta.xml.bind-api:2.3.3:jar
+io.trygvis.rules-sandbox.module:ri-base:1.0-SNAPSHOT:jar
+io.trygvis.rules-sandbox.module:ri-wireguard:1.0-SNAPSHOT:jar
org.antlr:antlr-runtime:3.5.2:jar
-org.apache.commons:commons-lang3:3.10:jar
-org.apache.commons:commons-math3:3.4.1:jar
-org.checkerframework:checker-compat-qual:2.0.0:jar
-org.codehaus.mojo:animal-sniffer-annotations:1.14:jar
org.drools:drools-canonical-model:7.48.0.Final:jar
org.drools:drools-compiler:7.48.0.Final:jar
org.drools:drools-core:7.48.0.Final:jar
+org.drools:drools-core-dynamic:7.48.0.Final:jar
org.drools:drools-core-reflective:7.48.0.Final:jar
org.drools:drools-ecj:7.48.0.Final:jar
org.drools:drools-model-compiler:7.48.0.Final:jar
-org.drools:drools-mvel:7.48.0.Final:jar
org.drools:drools-mvel-compiler:7.48.0.Final:jar
org.drools:drools-mvel-parser:7.48.0.Final:jar
-org.glassfish.jaxb:jaxb-runtime:2.3.3:jar
-org.glassfish.jaxb:txw2:2.3.3:jar
-org.javassist:javassist:3.24.1-GA:jar
-org.jsoup:jsoup:1.10.3:jar
+org.kie:kie-api:7.48.0.Final:jar
+org.kie:kie-internal:7.48.0.Final:jar
org.kie:kie-memory-compiler:7.48.0.Final:jar
-org.kie.kogito:drools-compiler:1.1.0.Final:jar
-org.kie.kogito:drools-core:1.1.0.Final:jar
-org.kie.kogito:drools-core-dynamic:1.1.0.Final:jar
-org.kie.kogito:drools-core-static:1.1.0.Final:jar
-org.kie.kogito:kogito-api:1.1.0.Final:jar
-org.kie.kogito:kogito-drools-model:1.1.0.Final:jar
-org.kie.kogito:kogito-internal:1.1.0.Final:jar
-org.kie.kogito:kogito-services:1.1.0.Final:jar
-org.kie.kogito:kogito-timer:1.1.0.Final:jar
-org.kie.soup:kie-soup-commons:7.48.0.Final:jar
org.kie.soup:kie-soup-maven-support:7.48.0.Final:jar
-org.kie.soup:kie-soup-project-datamodel-api:7.48.0.Final:jar
-org.kie.soup:kie-soup-project-datamodel-commons:7.48.0.Final:jar
org.kie.soup:kie-soup-xstream:7.48.0.Final:jar
-org.mvel:mvel2:2.4.11.Final:jar
-org.optaplanner:optaplanner-core:8.1.0.Final:jar
-org.optaplanner:optaplanner-persistence-common:8.1.0.Final:jar
-org.optaplanner:optaplanner-persistence-jackson:8.1.0.Final:jar
-org.optaplanner:optaplanner-spring-boot-autoconfigure:8.1.0.Final:jar
-org.optaplanner:optaplanner-spring-boot-starter:8.1.0.Final:jar
org.slf4j:slf4j-api:1.7.30:jar
-org.springframework:spring-aop:5.2.7.RELEASE:jar
-org.springframework:spring-beans:5.2.7.RELEASE:jar
-org.springframework:spring-context:5.2.7.RELEASE:jar
-org.springframework:spring-core:5.2.7.RELEASE:jar
-org.springframework:spring-expression:5.2.7.RELEASE:jar
-org.springframework:spring-jcl:5.2.7.RELEASE:jar
-org.springframework.boot:spring-boot:2.3.1.RELEASE:jar
-org.springframework.boot:spring-boot-autoconfigure:2.3.1.RELEASE:jar
-org.yaml:snakeyaml:1.26:jar
xmlpull:xmlpull:1.1.3.1:jar
xpp3:xpp3_min:1.1.4c:jar
diff --git a/module/acme/pom.xml b/module/acme/pom.xml
index 396b1d2..3081602 100644
--- a/module/acme/pom.xml
+++ b/module/acme/pom.xml
@@ -5,34 +5,25 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.trygvis.rules-sandbox</groupId>
- <artifactId>rules-sandbox</artifactId>
+ <groupId>io.trygvis.rules-sandbox.module</groupId>
+ <artifactId>ri-module-parent</artifactId>
<version>1.0-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
+ <relativePath>../ri-module-parent/pom.xml</relativePath>
</parent>
<artifactId>acme</artifactId>
<dependencies>
<dependency>
- <groupId>org.optaplanner</groupId>
- <artifactId>optaplanner-spring-boot-starter</artifactId>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ri-base</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>ri-engine</artifactId>
+ <artifactId>ri-wireguard</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.optaplanner</groupId>
- <artifactId>optaplanner-spring-boot-starter</artifactId>
- <version>8.1.0.Final</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
</project>
diff --git a/module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java b/module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java
index caab325..c65a3b2 100644
--- a/module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java
+++ b/module/acme/src/main/java/io/trygvis/acme/AcmeAppsMain.java
@@ -1,18 +1,14 @@
package io.trygvis.acme;
-import io.trygvis.rules.engine.Engine;
-
-import java.io.File;
-import java.io.IOException;
-
public class AcmeAppsMain {
- public static void main(String[] args) throws IOException {
- try (var engine = new Engine(
- "acme-apps",
- "acme.yaml",
- new File("acme-apps"),
- new String[]{"init", "generate"})) {
- engine.io.dump("acme/apps", engine.session.getFactHandles());
- }
- }
+// public static void main(String[] args) throws IOException {
+// try (var engine = new Engine(
+// "acme-apps",
+// new File("acme.yaml"),
+// new File("acme-apps"),
+// new String[]{"init", "generate"},
+// new File[0])) {
+// engine.io.dump(new File("out", "acme/apps.yaml"), 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 1859e2a..cbf962c 100644
--- a/module/acme/src/main/java/io/trygvis/acme/VpnMain.java
+++ b/module/acme/src/main/java/io/trygvis/acme/VpnMain.java
@@ -1,28 +1,21 @@
package io.trygvis.acme;
-import io.trygvis.rules.dns.DnsEntry;
-import io.trygvis.rules.engine.Engine;
-import io.trygvis.rules.machine.Machine;
-import io.trygvis.rules.network.Ipv4Address;
-import io.trygvis.rules.network.Ipv4Cidr;
-
-import java.io.File;
-import java.io.IOException;
-
public class VpnMain {
- public static void main(String[] args) throws IOException {
- try (var engine = new Engine(
- "acme-wireguard",
- "acme.yaml",
- new File("acme-wireguard"),
- new String[]{"init", "generate"})) {
- engine.io.dump("acme/wireguard", engine.session.getFactHandles(), (Object o) ->
- o.getClass().getName().contains("Wg")
- || o instanceof Machine
- || o instanceof DnsEntry
- || o instanceof Ipv4Cidr
- || o instanceof Ipv4Address
- );
- }
- }
+// public static void main(String[] args) throws IOException {
+// try (var engine = new Engine(
+// "acme-wireguard",
+// new File("acme.yaml"),
+// new File("acme-wireguard"),
+// new String[]{"init", "generate"},
+// new File[0])) {
+// var outputFile = new File("out", "acme/wireguard.yaml");
+// engine.io.dump(outputFile, engine.session.getFactHandles(), (Object o) ->
+// o.getClass().getName().contains("Wg")
+// || o instanceof Machine
+// || o instanceof DnsEntry
+// || o instanceof Ipv4Cidr
+// || o instanceof Ipv4Address
+// );
+// }
+// }
}
diff --git a/module/ri-base/classpath.txt b/module/ri-base/classpath.txt
new file mode 100644
index 0000000..1461d46
--- /dev/null
+++ b/module/ri-base/classpath.txt
@@ -0,0 +1,26 @@
+io.trygvis.rules-sandbox.module:ri-base:1.0-SNAPSHOT:kjar
+com.fasterxml.jackson.core:jackson-annotations:2.12.0:jar
+com.fasterxml.jackson.core:jackson-core:2.12.0:jar
+com.fasterxml.jackson.core:jackson-databind:2.12.0:jar
+com.github.javaparser:javaparser-core:3.13.10:jar
+com.thoughtworks.xstream:xstream:1.4.14:jar
+commons-codec:commons-codec:1.14:jar
+commons-io:commons-io:2.8.0:jar
+org.antlr:antlr-runtime:3.5.2:jar
+org.drools:drools-canonical-model:7.48.0.Final:jar
+org.drools:drools-compiler:7.48.0.Final:jar
+org.drools:drools-core:7.48.0.Final:jar
+org.drools:drools-core-dynamic:7.48.0.Final:jar
+org.drools:drools-core-reflective:7.48.0.Final:jar
+org.drools:drools-ecj:7.48.0.Final:jar
+org.drools:drools-model-compiler:7.48.0.Final:jar
+org.drools:drools-mvel-compiler:7.48.0.Final:jar
+org.drools:drools-mvel-parser:7.48.0.Final:jar
+org.kie:kie-api:7.48.0.Final:jar
+org.kie:kie-internal:7.48.0.Final:jar
+org.kie:kie-memory-compiler:7.48.0.Final:jar
+org.kie.soup:kie-soup-maven-support:7.48.0.Final:jar
+org.kie.soup:kie-soup-xstream:7.48.0.Final:jar
+org.slf4j:slf4j-api:1.7.30:jar
+xmlpull:xmlpull:1.1.3.1:jar
+xpp3:xpp3_min:1.1.4c:jar
diff --git a/module/ri-base/pom.xml b/module/ri-base/pom.xml
new file mode 100644
index 0000000..43703f7
--- /dev/null
+++ b/module/ri-base/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>io.trygvis.rules-sandbox.module</groupId>
+ <artifactId>ri-module-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../ri-module-parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ri-base</artifactId>
+ <packaging>kjar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>5.7.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <version>5.7.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-commons</artifactId>
+ <version>1.7.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-maven-plugin</artifactId>
+ <version>${version.drools}</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.0.0-M5</version>
+ <configuration>
+ <failIfNoTests>false</failIfNoTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/core/Problem.java b/module/ri-base/src/main/java/io/trygvis/rules/core/Problem.java
index 04d1af3..04d1af3 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/core/Problem.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/core/Problem.java
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/dba/Cluster.java b/module/ri-base/src/main/java/io/trygvis/rules/dba/Cluster.java
index 0b65aaa..0b65aaa 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/dba/Cluster.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/dba/Cluster.java
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/dba/Container.java b/module/ri-base/src/main/java/io/trygvis/rules/dba/Container.java
index 3888661..3888661 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/dba/Container.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/dba/Container.java
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsEntry.java b/module/ri-base/src/main/java/io/trygvis/rules/dns/DnsEntry.java
index 105ef79..105ef79 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsEntry.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/dns/DnsEntry.java
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java b/module/ri-base/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java
index 79bf934..79bf934 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/dns/DnsEntryTerraformExpression.java
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsZone.java b/module/ri-base/src/main/java/io/trygvis/rules/dns/DnsZone.java
index 1af5c8f..1af5c8f 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/dns/DnsZone.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/dns/DnsZone.java
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/KeyValue.java b/module/ri-base/src/main/java/io/trygvis/rules/engine/KeyValue.java
index 5046169..5046169 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/KeyValue.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/engine/KeyValue.java
diff --git a/module/ri-base/src/main/java/io/trygvis/rules/engine/TemplateEngine.java b/module/ri-base/src/main/java/io/trygvis/rules/engine/TemplateEngine.java
new file mode 100644
index 0000000..eafa6e4
--- /dev/null
+++ b/module/ri-base/src/main/java/io/trygvis/rules/engine/TemplateEngine.java
@@ -0,0 +1,10 @@
+package io.trygvis.rules.engine;
+
+import java.io.IOException;
+import java.util.Map;
+
+public interface TemplateEngine {
+ void clean();
+
+ void template(String name, String output, Map<String, Object> params) throws IOException;
+}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/machine/Machine.java b/module/ri-base/src/main/java/io/trygvis/rules/machine/Machine.java
index 34c17ca..8f162c6 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/machine/Machine.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/machine/Machine.java
@@ -3,7 +3,6 @@ package io.trygvis.rules.machine;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-@SuppressWarnings("unused")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name")
public class Machine {
public String name;
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/machine/MachineSpecification.java b/module/ri-base/src/main/java/io/trygvis/rules/machine/MachineSpecification.java
index 2e17ae5..2e17ae5 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/machine/MachineSpecification.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/machine/MachineSpecification.java
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/network/IpCalc.java b/module/ri-base/src/main/java/io/trygvis/rules/network/IpCalc.java
index 7ec344c..7ec344c 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/network/IpCalc.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/network/IpCalc.java
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/network/Ipv4Address.java b/module/ri-base/src/main/java/io/trygvis/rules/network/Ipv4Address.java
index 7ca9ca5..9021198 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/network/Ipv4Address.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/network/Ipv4Address.java
@@ -20,7 +20,8 @@ public class Ipv4Address implements Comparable<Ipv4Address> {
public boolean equals(Object o) {
if (this == o) return true;
- if (o instanceof Ipv4Address other) {
+ if (o instanceof Ipv4Address) {
+ Ipv4Address other = (Ipv4Address) o;
return address == other.address;
}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java b/module/ri-base/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java
index 6362107..851af95 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java
@@ -4,9 +4,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.checkerframework.checker.nullness.compatqual.NonNullType;
-import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
diff --git a/module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java b/module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java
new file mode 100644
index 0000000..41bd6ae
--- /dev/null
+++ b/module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java
@@ -0,0 +1,96 @@
+package io.trygvis.rules.terraform;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TerraformResource {
+ private static final String EOL = System.getProperty("line.separator");
+ private final String output;
+ private final String kind;
+ private final String instance;
+ private final Map<String, TerraformValue> values = new HashMap<>();
+
+ public TerraformResource(String output, String kind, String instance) {
+ this.output = output;
+ this.kind = kind;
+ this.instance = instance;
+ }
+
+ public String getOutput() {
+ return output;
+ }
+
+ public void putString(String key, String value) {
+ values.put(key, new StringTerraformValue(value));
+ }
+
+ public String asString() {
+ var buf = new StringBuilder();
+
+ buf.append(quote(kind));
+ buf.append(" ");
+ buf.append(quote(instance));
+ buf.append(" {");
+ buf.append(EOL);
+
+ for (var entry : values.entrySet()) {
+ buf.append(" ");
+ buf.append(entry.getKey());
+ buf.append(" = ");
+ buf.append(entry.getValue().asString());
+ buf.append(EOL);
+ }
+
+ buf.append("}");
+ buf.append(EOL);
+
+ return buf.toString();
+ }
+
+ public interface TerraformValue {
+ String asString();
+ }
+
+ public static class StringTerraformValue implements TerraformValue {
+ private final String value;
+
+ public StringTerraformValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String asString() {
+ return quote(value);
+ }
+ }
+
+ public static class BooleanTerraformValue implements TerraformValue {
+ private final boolean value;
+
+ public BooleanTerraformValue(boolean value) {
+ this.value = value;
+ }
+
+ @Override
+ public String asString() {
+ return String.valueOf(value);
+ }
+ }
+
+ public static class ExpressionTerraformValue implements TerraformValue {
+ private final String value;
+
+ public ExpressionTerraformValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String asString() {
+ return value;
+ }
+ }
+
+ private static String quote(String value) {
+ return "\"%s\"".formatted(value);
+ }
+}
diff --git a/module/ri-engine/src/main/resources/META-INF/kmodule.xml b/module/ri-base/src/main/resources/META-INF/kmodule.xml
index 79c5e79..79c5e79 100644
--- a/module/ri-engine/src/main/resources/META-INF/kmodule.xml
+++ b/module/ri-base/src/main/resources/META-INF/kmodule.xml
diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl b/module/ri-base/src/main/resources/io/trygvis/rules/dba/dba.drl
index 0bee004..c31bc57 100644
--- a/module/ri-engine/src/main/resources/io/trygvis/rules/dba/dba.drl
+++ b/module/ri-base/src/main/resources/io/trygvis/rules/dba/dba.drl
@@ -50,7 +50,7 @@ then
for (Object o : $containers) {
Container c = (Container) o;
- var list = (List) containersByMachine.get(c.getMachine());
+ List list = (List) containersByMachine.get(c.getMachine());
if (list == null) {
list = new ArrayList();
containersByMachine.put(c.getMachine(), list);
@@ -60,7 +60,7 @@ then
System.out.println("containersByMachine = " + containersByMachine);
- var path = "ansible/dba/" + $cluster.name + ".yml";
+ String path = "ansible/dba/" + $cluster.name + ".yml";
te.template("dba/cluster", path, Map.of(
"cluster", $cluster,
"containers", $containers,
diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl b/module/ri-base/src/main/resources/io/trygvis/rules/engine/init.drl
index 267cc4a..267cc4a 100644
--- a/module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl
+++ b/module/ri-base/src/main/resources/io/trygvis/rules/engine/init.drl
diff --git a/module/ri-base/src/main/resources/io/trygvis/rules/machine/machine.drl b/module/ri-base/src/main/resources/io/trygvis/rules/machine/machine.drl
new file mode 100644
index 0000000..0250cc6
--- /dev/null
+++ b/module/ri-base/src/main/resources/io/trygvis/rules/machine/machine.drl
@@ -0,0 +1 @@
+package io.trygvis.rules.machine;
diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/terraform/terraform.drl b/module/ri-base/src/main/resources/io/trygvis/rules/terraform/terraform.drl
index 07a96e2..5ebd082 100644
--- a/module/ri-engine/src/main/resources/io/trygvis/rules/terraform/terraform.drl
+++ b/module/ri-base/src/main/resources/io/trygvis/rules/terraform/terraform.drl
@@ -25,7 +25,7 @@ rule "Terraform for Machine"
when
$machine: Machine()
then
- var scw = new ScalewayMachine();
+ ScalewayMachine scw = new ScalewayMachine();
scw.setKey($machine.name);
scw.setMachine($machine);
@@ -37,10 +37,10 @@ when
$machine : Machine(fqdn != null)
not(DnsEntry(fqdn == $machine.fqdn))
then
- var a = DnsEntry.a($machine.fqdn);
+ DnsEntry a = DnsEntry.a($machine.fqdn);
insert(a);
- var ipv4 = "scaleway_instance_ip.%s.address".formatted($machine.name);
+ String ipv4 = "scaleway_instance_ip.%s.address".formatted($machine.name);
insert(new DnsEntryTerraformExpression(a, $machine.name, ipv4));
end
@@ -49,7 +49,7 @@ rule "main-scaleway-machine.tf"
when
$managedZones : ArrayList() from collect(GoogleManagedZoneTerraformExpression())
then
- var path = "terraform/main-scaleway-machine.tf";
+ String path = "terraform/main-scaleway-machine.tf";
te.template("terraform-main-scaleway-machine", path, Map.of(
"managedZones", $managedZones
));
@@ -61,7 +61,7 @@ when
$m: Machine()
$scw: ScalewayMachine(machine == $m)
then
- var path = "terraform/scaleway-machine-%s.tf".formatted($scw.getKey());
+ String path = "terraform/scaleway-machine-%s.tf".formatted($scw.getKey());
te.template("terraform-machine", path, Map.of("m", $m, "scw", $scw));
end
@@ -72,7 +72,7 @@ when
$tf : DnsEntryTerraformExpression(entry == $entry)
$managedZone : GoogleManagedZoneTerraformExpression()
then
- var path = "terraform/dns-%s.tf".formatted($tf.key);
+ String path = "terraform/dns-%s.tf".formatted($tf.key);
te.template("terraform-record-set", path, Map.of(
"entry", $entry,
"managedZone", $managedZone,
diff --git a/module/ri-engine/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.java b/module/ri-base/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.txt
index 0d9f33e..826f586 100644
--- a/module/ri-engine/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.java
+++ b/module/ri-base/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.txt
@@ -1,5 +1,6 @@
package io.trygvis.rules.network;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@@ -11,7 +12,7 @@ class Ipv4CidrTest {
@Test
public void basic() {
- assertThrows(IllegalArgumentException.class, () -> parseCidr("192.168.1.1/24").addresses());
+ Assertions.assertThrows(IllegalArgumentException.class, () -> parseCidr("192.168.1.1/24").addresses());
assertEquals(256, parseCidr("192.168.1.0/24").addresses().size());
assertEquals(128, parseCidr("192.168.1.128/25").addresses().size());
}
diff --git a/module/ri-engine/classpath.txt b/module/ri-engine/classpath.txt
index 7d0804a..580eec1 100644
--- a/module/ri-engine/classpath.txt
+++ b/module/ri-engine/classpath.txt
@@ -1,4 +1,5 @@
io.trygvis.rules-sandbox:ri-engine:1.0-SNAPSHOT:jar
+aopalliance:aopalliance:1.0:jar
ch.obermuhlner:big-math:2.0.0:jar
ch.qos.logback:logback-classic:1.2.3:jar
ch.qos.logback:logback-core:1.2.3:jar
@@ -6,50 +7,94 @@ com.fasterxml.jackson.core:jackson-annotations:2.12.0:jar
com.fasterxml.jackson.core:jackson-core:2.12.0:jar
com.fasterxml.jackson.core:jackson-databind:2.12.0:jar
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.0:jar
+com.github.virtuald:curvesapi:1.06:jar
com.google.code.findbugs:annotations:3.0.1:jar
com.google.errorprone:error_prone_annotations:2.1.3:jar
com.google.guava:guava:25.0-jre:jar
+com.google.inject:guice:4.0:jar
com.google.j2objc:j2objc-annotations:1.1:jar
+com.google.protobuf:protobuf-java:3.6.1:jar
com.google.re2j:re2j:1.2:jar
com.googlecode.java-ipv6:java-ipv6:0.17:jar
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.14:jar
commons-io:commons-io:2.8.0:jar
commons-net:commons-net:3.3:jar
info.picocli:picocli:4.6.1:jar
-io.trygvis.rules-sandbox:ri-wireguard:1.0-SNAPSHOT:jar
+javax.annotation:jsr250-api:1.0:jar
+javax.enterprise:cdi-api:1.0:jar
+javax.inject:javax.inject:1:jar
org.antlr:antlr-runtime:3.5.2:jar
+org.apache.ant:ant:1.9.15:jar
+org.apache.ant:ant-launcher:1.9.15:jar
+org.apache.commons:commons-collections4:4.4:jar
+org.apache.commons:commons-compress:1.19:jar
org.apache.commons:commons-lang3:3.10:jar
+org.apache.commons:commons-math3:3.6.1:jar
+org.apache.httpcomponents:httpclient:4.5.12:jar
+org.apache.httpcomponents:httpcore:4.4.13:jar
+org.apache.maven:maven-aether-provider:3.3.9:jar
+org.apache.maven:maven-artifact:3.3.9:jar
+org.apache.maven:maven-builder-support:3.3.9:jar
+org.apache.maven:maven-compat:3.3.9:jar
+org.apache.maven:maven-core:3.3.9:jar
+org.apache.maven:maven-model:3.3.9:jar
+org.apache.maven:maven-model-builder:3.3.9:jar
+org.apache.maven:maven-plugin-api:3.3.9:jar
+org.apache.maven:maven-repository-metadata:3.3.9:jar
+org.apache.maven:maven-settings:3.3.9:jar
+org.apache.maven:maven-settings-builder:3.3.9:jar
+org.apache.maven.wagon:wagon-http:3.0.0:jar
+org.apache.maven.wagon:wagon-http-shared:3.0.0:jar
+org.apache.maven.wagon:wagon-provider-api:3.0.0:jar
+org.apache.poi:poi:4.1.2:jar
+org.apache.poi:poi-ooxml:4.1.2:jar
+org.apache.poi:poi-ooxml-schemas:4.1.2:jar
+org.apache.xmlbeans:xmlbeans:3.1.0:jar
org.checkerframework:checker-compat-qual:2.0.0:jar
org.codehaus.mojo:animal-sniffer-annotations:1.14:jar
+org.codehaus.plexus:plexus-classworlds:2.5.2:jar
+org.codehaus.plexus:plexus-component-annotations:1.6:jar
+org.codehaus.plexus:plexus-interpolation:1.21:jar
+org.codehaus.plexus:plexus-utils:3.0.22:jar
org.drools:drools-compiler:7.48.0.Final:jar
org.drools:drools-core:7.48.0.Final:jar
+org.drools:drools-core-dynamic:7.48.0.Final:jar
org.drools:drools-core-reflective:7.48.0.Final:jar
+org.drools:drools-decisiontables:7.48.0.Final:jar
org.drools:drools-ecj:7.48.0.Final:jar
org.drools:drools-mvel:7.48.0.Final:jar
+org.drools:drools-serialization-protobuf:7.48.0.Final:jar
+org.drools:drools-templates:7.48.0.Final:jar
+org.eclipse.aether:aether-api:1.1.0:jar
+org.eclipse.aether:aether-connector-basic:1.1.0:jar
+org.eclipse.aether:aether-impl:1.1.0:jar
+org.eclipse.aether:aether-spi:1.1.0:jar
+org.eclipse.aether:aether-transport-file:1.1.0:jar
+org.eclipse.aether:aether-transport-http:1.1.0:jar
+org.eclipse.aether:aether-transport-wagon:1.1.0:jar
+org.eclipse.aether:aether-util:1.1.0:jar
+org.eclipse.sisu:org.eclipse.sisu.inject:0.3.2:jar
+org.eclipse.sisu:org.eclipse.sisu.plexus:0.3.2:jar
org.javassist:javassist:3.24.1-GA:jar
org.jsoup:jsoup:1.10.3:jar
-org.kie:kie-dmn-api:7.48.0.Final:jar
-org.kie:kie-dmn-model:7.48.0.Final:jar
+org.kie:kie-api:7.48.0.Final:jar
+org.kie:kie-ci:7.48.0.Final:jar
+org.kie:kie-internal:7.48.0.Final:jar
org.kie:kie-memory-compiler:7.48.0.Final:jar
-org.kie:kie-pmml-api:7.48.0.Final:jar
-org.kie:kie-pmml-commons:7.48.0.Final:jar
-org.kie:kie-pmml-evaluator-api:7.48.0.Final:jar
-org.kie.kogito:drools-core:1.1.0.Final:jar
-org.kie.kogito:drools-core-static:1.1.0.Final:jar
-org.kie.kogito:kogito-api:1.1.0.Final:jar
-org.kie.kogito:kogito-internal:1.1.0.Final:jar
-org.kie.kogito:kogito-pmml-api-dependencies:1.1.0.Final:pom
-org.kie.kogito:kogito-services:1.1.0.Final:jar
-org.kie.kogito:kogito-timer:1.1.0.Final:jar
org.kie.soup:kie-soup-commons:7.48.0.Final:jar
+org.kie.soup:kie-soup-maven-integration:7.48.0.Final:jar
org.kie.soup:kie-soup-maven-support:7.48.0.Final:jar
org.kie.soup:kie-soup-project-datamodel-api:7.48.0.Final:jar
org.kie.soup:kie-soup-project-datamodel-commons:7.48.0.Final:jar
org.kie.soup:kie-soup-xstream:7.48.0.Final:jar
org.mvel:mvel2:2.4.11.Final:jar
+org.slf4j:jcl-over-slf4j:1.7.30:jar
org.slf4j:slf4j-api:1.7.30:jar
+org.sonatype.plexus:plexus-cipher:1.7:jar
+org.sonatype.plexus:plexus-sec-dispatcher:1.3:jar
org.yaml:snakeyaml:1.26:jar
xmlpull:xmlpull:1.1.3.1:jar
xpp3:xpp3_min:1.1.4c:jar
diff --git a/module/ri-engine/pom.xml b/module/ri-engine/pom.xml
index 3a7243e..97fee1c 100644
--- a/module/ri-engine/pom.xml
+++ b/module/ri-engine/pom.xml
@@ -15,17 +15,28 @@
<dependencies>
<dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>ri-wireguard</artifactId>
- <version>${project.version}</version>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-core</artifactId>
</dependency>
-
<dependency>
- <groupId>org.kie.kogito</groupId>
- <artifactId>drools-core</artifactId>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-compiler</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-decisiontables</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
+ <artifactId>drools-templates</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-ci</artifactId>
+ </dependency>
+ <!--
+ <dependency>
+ <groupId>org.drools</groupId>
<artifactId>drools-mvel</artifactId>
<exclusions>
<exclusion>
@@ -38,6 +49,7 @@
</exclusion>
</exclusions>
</dependency>
+ -->
<dependency>
<groupId>ch.qos.logback</groupId>
@@ -63,6 +75,11 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
+ <dependency>
+ <groupId>info.picocli</groupId>
+ <artifactId>picocli</artifactId>
+ <version>${version.picocli}</version>
+ </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
@@ -77,4 +94,55 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>info.picocli</groupId>
+ <artifactId>picocli-codegen</artifactId>
+ <version>${version.picocli}</version>
+ </path>
+ </annotationProcessorPaths>
+ <compilerArgs combine.children="append">
+ <arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
+ </compilerArgs>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.2.0</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>lib/</classpathPrefix>
+ <mainClass>io.trygvis.rules.engine.Main</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
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 b8ee03a..d3d309a 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
@@ -14,6 +14,8 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import org.drools.core.common.DefaultFactHandle;
import org.drools.core.factmodel.GeneratedFact;
import org.kie.api.KieBase;
+import org.kie.api.definition.type.FactType;
+import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.rule.FactHandle;
import java.io.File;
@@ -29,14 +31,14 @@ public class DbIo {
private static final List<String> prioritizedKeys = List.of("key", "name", "fqdn");
- public DbIo(KieBase kieBase) {
+ public DbIo(KieContainer container, KieBase kieBase) {
var factory = new YAMLFactory();
factory.enable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
factory.enable(YAMLGenerator.Feature.USE_NATIVE_OBJECT_ID);
mapper = new ObjectMapper(factory);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
var typeFactory = TypeFactory.defaultInstance()
- .withClassLoader(new AcmeClassLoader(kieBase));
+ .withClassLoader(new DbClassLoader(container, kieBase));
mapper.setTypeFactory(typeFactory);
mapper.findAndRegisterModules();
@@ -50,7 +52,7 @@ public class DbIo {
for (String name : prioritizedKeys) {
try {
final String getter = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
- var f = klass.getMethod(getter);
+ klass.getMethod(getter);
return new ObjectIdInfo(PropertyName.construct(name), null, ObjectIdGenerators.PropertyGenerator.class, null);
} catch (NoSuchMethodException ignore) {
}
@@ -64,8 +66,8 @@ public class DbIo {
});
}
- public List<Object> load(String file) throws IOException {
- var parser = mapper.getFactory().createParser(new File(file));
+ public List<Object> load(File file) throws IOException {
+ var parser = mapper.getFactory().createParser(file);
var objects = mapper.readValues(parser, DbObject.class).readAll(new ArrayList<>());
@@ -79,6 +81,8 @@ public class DbIo {
}
items.add(x);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
+ System.out.println("e.getClass() = " + e.getClass().getName());
+ System.out.println("e.getMessage() = " + e.getMessage());
// ignore
}
}
@@ -86,8 +90,8 @@ public class DbIo {
return items;
}
- public void dump(String s, Collection<FactHandle> factHandles) throws IOException {
- dump(s, factHandles, (o) -> true);
+ public void dump(File file, Collection<FactHandle> factHandles) throws IOException {
+ dump(file, factHandles, (o) -> true);
}
// This should just sort by all getters instead.
@@ -221,10 +225,8 @@ public class DbIo {
static record DbObject2(String type, Object data) {
}
- public void dump(String s, Collection<FactHandle> factHandles, Function<Object, Boolean> filter) throws IOException {
- var yamlFile = new File("out", s + ".yaml");
-
- FileUtil.createMissingParentDirectories(yamlFile);
+ public void dump(File file, Collection<FactHandle> factHandles, Function<Object, Boolean> filter) throws IOException {
+ FileUtil.createMissingParentDirectories(file);
var facts = new TreeMap<Class<?>, FactCollection<Object>>(Comparator.comparing(Class::getName));
for (var handle : factHandles) {
@@ -260,16 +262,18 @@ public class DbIo {
objects.sort(new DbObjectComparator());
var factory = mapper.getFactory();
- try (var writer = new FileWriter(yamlFile);
+ try (var writer = new FileWriter(file);
var g = factory.createGenerator(writer)) {
g.writeObject(objects);
}
}
- private static class AcmeClassLoader extends ClassLoader {
+ private static class DbClassLoader extends ClassLoader {
private final KieBase kieBase;
+ private final KieContainer container;
- public AcmeClassLoader(KieBase kieBase) {
+ public DbClassLoader(KieContainer container, KieBase kieBase) {
+ this.container = container;
this.kieBase = kieBase;
}
@@ -287,7 +291,18 @@ public class DbIo {
pkg = name.substring(0, i);
klass = name.substring(i + 1);
}
- var clazz = kieBase.getFactType(pkg, klass);
+
+ try {
+ return container.getClassLoader().loadClass(name);
+ } catch (ClassNotFoundException ignore) {
+ }
+
+ FactType clazz = null;
+ try {
+ clazz = kieBase.getFactType(pkg, klass);
+ } catch (UnsupportedOperationException ignore) {
+ System.out.println("AcmeClassLoader.loadClass: " + name);
+ }
if (clazz == null) {
throw e;
}
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 b73e2e8..3db1625 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
@@ -2,41 +2,83 @@ package io.trygvis.rules.engine;
import org.drools.core.audit.WorkingMemoryConsoleLogger;
import org.kie.api.KieServices;
+import org.kie.api.builder.Message;
+import org.kie.api.builder.Message.Level;
+import org.kie.api.builder.ReleaseId;
import org.kie.api.event.rule.AgendaEventListener;
import org.kie.api.event.rule.RuleRuntimeEventListener;
import org.kie.api.runtime.KieSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
public class Engine implements Closeable {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
public final DbIo io;
public final KieSession session;
- public Engine(String name, String database, File output, String[] agendaGroups) throws IOException {
+ public Engine(String name, File database, File output, String[] agendaGroups, File[] modules) throws IOException {
+ logger.info("Getting KieServices");
+
var services = KieServices.Factory.get();
- var container = services.getKieClasspathContainer();
- var kieBase = container.getKieBase(name);
- io = new DbIo(kieBase);
- var objects = io.load(database);
+ ReleaseId releaseId = null;
+ for (File path : (modules == null ? new File[0] : modules)) {
+ logger.info("New KieBuilder: {}", path);
+
+
+// var kieBuilder = services.newKieBuilder(fileSystem);
+ var kieBuilder = services.newKieBuilder(path);
+ logger.info("Building module");
+ kieBuilder.buildAll();
+
+ logger.info("Module built!");
+
+ var results = kieBuilder.getResults();
+
+ for (Message message : results.getMessages(Level.INFO, Level.WARNING, Level.ERROR)) {
+// logger.info("{} {}", message.getLevel(), message.getText());
+ logger.info(message.toString());
+ }
+
+ var module = kieBuilder.getKieModule();
+ releaseId = module.getReleaseId();
+ logger.info("module.getReleaseId() = {}", releaseId);
+ logger.info("module.getClass() = {}", module.getClass());
+ }
+
+ logger.info("Creating classpath container");
+// var container = services.getKieClasspathContainer();
+ var container = services.newKieContainer(releaseId);
+
+ logger.info("Creating KieBase");
+ logger.info("Available kie base names: {}", container.getKieBaseNames());
+ var kieBase = container.getKieBase(name);
session = container.newKieSession(name);
- var logger = new WorkingMemoryConsoleLogger(session);
- session.addEventListener((AgendaEventListener) logger);
- session.addEventListener((RuleRuntimeEventListener) logger);
+ var l = new WorkingMemoryConsoleLogger(session);
+ session.addEventListener((AgendaEventListener) l);
+ session.addEventListener((RuleRuntimeEventListener) l);
- session.setGlobal("te", new TemplateEngine(output));
+ session.setGlobal("te", new JinjavaTemplateEngine(output));
+
+ logger.info("Loading data");
+ io = new DbIo(container, kieBase);
+ var objects = io.load(database);
+ logger.info("Loaded {} objects", objects.size());
for (var object : objects) {
- System.out.println("object = " + object);
+ logger.info("object = " + object);
session.insert(object);
}
for (var agendaGroup : agendaGroups) {
- System.out.println("Setting agenda: " + agendaGroup);
+ logger.info("Setting agenda: " + agendaGroup);
session.getAgenda().getAgendaGroup(agendaGroup).setFocus();
session.fireAllRules();
}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/JinjavaTemplateEngine.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/JinjavaTemplateEngine.java
new file mode 100644
index 0000000..42b2127
--- /dev/null
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/JinjavaTemplateEngine.java
@@ -0,0 +1,40 @@
+package io.trygvis.rules.engine;
+
+import ch.qos.logback.core.util.FileUtil;
+import com.hubspot.jinjava.Jinjava;
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+public class JinjavaTemplateEngine implements TemplateEngine {
+ private final Jinjava jinjava = new Jinjava();
+
+ private final File basedir;
+
+ public JinjavaTemplateEngine(File basedir) {
+ this.basedir = basedir;
+ }
+
+ @Override
+ public void clean() {
+ try {
+ System.out.println("Cleaning gen!");
+ FileUtils.deleteDirectory(basedir);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ 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);
+ var f = new File(basedir, output);
+ FileUtil.createMissingParentDirectories(f);
+ Files.writeString(f.toPath(), renderedTemplate);
+ }
+}
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/Main.java
new file mode 100644
index 0000000..4f06091
--- /dev/null
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Main.java
@@ -0,0 +1,20 @@
+package io.trygvis.rules.engine;
+
+import io.trygvis.rules.engine.cli.DatabaseCommand;
+import io.trygvis.rules.engine.cli.RunCommand;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+
+@Command(
+ name = "engine",
+ subcommands = {RunCommand.class, DatabaseCommand.class},
+ mixinStandardHelpOptions = true,
+ version = "UNSPECIFIED")
+class Main {
+
+ public static void main(String... args) {
+ //noinspection InstantiationOfUtilityClass
+ int exitCode = new CommandLine(new Main()).execute(args);
+ System.exit(exitCode);
+ }
+}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java
index cc085c0..eafa6e4 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java
@@ -1,38 +1,10 @@
package io.trygvis.rules.engine;
-import ch.qos.logback.core.util.FileUtil;
-import com.hubspot.jinjava.Jinjava;
-import org.apache.commons.io.FileUtils;
-
-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();
-
- private final File basedir;
-
- public TemplateEngine(File basedir) {
- this.basedir = basedir;
- }
-
- public void clean() {
- try {
- System.out.println("Cleaning gen!");
- FileUtils.deleteDirectory(basedir);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+public interface TemplateEngine {
+ void clean();
- 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);
- var f = new File(basedir, output);
- FileUtil.createMissingParentDirectories(f);
- Files.writeString(f.toPath(), renderedTemplate);
- }
+ void template(String name, String output, Map<String, Object> params) throws IOException;
}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/DatabaseCommand.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/DatabaseCommand.java
new file mode 100644
index 0000000..03650b5
--- /dev/null
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/DatabaseCommand.java
@@ -0,0 +1,20 @@
+package io.trygvis.rules.engine.cli;
+
+import picocli.CommandLine.Command;
+
+import java.util.concurrent.Callable;
+
+import static picocli.CommandLine.Option;
+
+@Command(name = "database")
+public class DatabaseCommand implements Callable<Integer> {
+
+ @Option(names = {"-v", "--verbose"})
+ private boolean verbose;
+
+ @Override
+ public Integer call() {
+ System.out.println("DatabaseCommand.call");
+ return 0;
+ }
+}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
new file mode 100644
index 0000000..345d8b8
--- /dev/null
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
@@ -0,0 +1,55 @@
+package io.trygvis.rules.engine.cli;
+
+import io.trygvis.rules.engine.Engine;
+
+import java.io.File;
+import java.util.concurrent.Callable;
+
+import static picocli.CommandLine.Command;
+import static picocli.CommandLine.Option;
+
+@Command(name = "run")
+public class RunCommand implements Callable<Integer> {
+
+ @Option(names = {"-n", "--name"})
+ public String name;
+
+ @Option(names = {"-i", "--input"})
+ public File input;
+
+ @Option(names = {"--output-state"})
+ public File outputState;
+
+ @Option(names = {"--generated-output"})
+ public File generatedOutput;
+
+ @Option(names = {"--agenda-groups"})
+ public String[] agendaGroups;
+
+ @Option(names = {"--modules"}, split = ",")
+ public File[] modules;
+
+ @Override
+ public Integer call() throws Exception {
+ System.out.println("RunCommand.call");
+
+ if (agendaGroups == null || agendaGroups.length == 0) {
+ agendaGroups = new String[]{"init", "generate"};
+ }
+
+ try (var engine = new Engine(name, input, generatedOutput, agendaGroups, modules)) {
+ engine.io.dump(outputState, engine.session.getFactHandles(), (Object o) ->
+ o.getClass().getName().contains("Wg") ||
+ o.getClass().getSimpleName().contains("Machine") ||
+ o.getClass().getSimpleName().contains("DnsEntry") ||
+ o.getClass().getSimpleName().contains("Ipv4Cidr") ||
+ o.getClass().getSimpleName().contains("Ipv4Address")
+ );
+ System.out.println("RunCommand.call");
+ }
+
+ System.out.println("RunCommand.call");
+
+ return 0;
+ }
+}
diff --git a/module/ri-module-parent/classpath.txt b/module/ri-module-parent/classpath.txt
new file mode 100644
index 0000000..8624088
--- /dev/null
+++ b/module/ri-module-parent/classpath.txt
@@ -0,0 +1,23 @@
+io.trygvis.rules-sandbox.module:ri-module-parent:1.0-SNAPSHOT:pom
+com.github.javaparser:javaparser-core:3.13.10:jar
+com.thoughtworks.xstream:xstream:1.4.14:jar
+commons-codec:commons-codec:1.14:jar
+commons-io:commons-io:2.8.0:jar
+org.antlr:antlr-runtime:3.5.2:jar
+org.drools:drools-canonical-model:7.48.0.Final:jar
+org.drools:drools-compiler:7.48.0.Final:jar
+org.drools:drools-core:7.48.0.Final:jar
+org.drools:drools-core-dynamic:7.48.0.Final:jar
+org.drools:drools-core-reflective:7.48.0.Final:jar
+org.drools:drools-ecj:7.48.0.Final:jar
+org.drools:drools-model-compiler:7.48.0.Final:jar
+org.drools:drools-mvel-compiler:7.48.0.Final:jar
+org.drools:drools-mvel-parser:7.48.0.Final:jar
+org.kie:kie-api:7.48.0.Final:jar
+org.kie:kie-internal:7.48.0.Final:jar
+org.kie:kie-memory-compiler:7.48.0.Final:jar
+org.kie.soup:kie-soup-maven-support:7.48.0.Final:jar
+org.kie.soup:kie-soup-xstream:7.48.0.Final:jar
+org.slf4j:slf4j-api:1.7.30:jar
+xmlpull:xmlpull:1.1.3.1:jar
+xpp3:xpp3_min:1.1.4c:jar
diff --git a/module/ri-module-parent/pom.xml b/module/ri-module-parent/pom.xml
new file mode 100644
index 0000000..1c54527
--- /dev/null
+++ b/module/ri-module-parent/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>ri-module-parent</artifactId>
+ <groupId>io.trygvis.rules-sandbox.module</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <version.drools>7.48.0.Final</version.drools>
+ <java.version>13</java.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-model-compiler</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ </dependencies>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>io.trygvis.rules-sandbox</groupId>
+ <artifactId>ri-engine</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-maven-plugin</artifactId>
+ <version>${version.drools}</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <release>${java.version}</release>
+ <source>${java.version}</source>
+ <target>${java.version}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.2.0</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>eu.nets.oss.maven</groupId>
+ <artifactId>classpath-maven-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <id>default</id>
+ <goals>
+ <goal>export-classpath</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/module/ri-wireguard/classpath.txt b/module/ri-wireguard/classpath.txt
index 52ccd4d..567c91f 100644
--- a/module/ri-wireguard/classpath.txt
+++ b/module/ri-wireguard/classpath.txt
@@ -1 +1,27 @@
-io.trygvis.rules-sandbox:ri-wireguard:1.0-SNAPSHOT:jar
+io.trygvis.rules-sandbox.module:ri-wireguard:1.0-SNAPSHOT:jar
+com.fasterxml.jackson.core:jackson-annotations:2.12.0:jar
+com.fasterxml.jackson.core:jackson-core:2.12.0:jar
+com.fasterxml.jackson.core:jackson-databind:2.12.0:jar
+com.github.javaparser:javaparser-core:3.13.10:jar
+com.thoughtworks.xstream:xstream:1.4.14:jar
+commons-codec:commons-codec:1.14:jar
+commons-io:commons-io:2.8.0:jar
+io.trygvis.rules-sandbox.module:ri-base:1.0-SNAPSHOT:jar
+org.antlr:antlr-runtime:3.5.2:jar
+org.drools:drools-canonical-model:7.48.0.Final:jar
+org.drools:drools-compiler:7.48.0.Final:jar
+org.drools:drools-core:7.48.0.Final:jar
+org.drools:drools-core-dynamic:7.48.0.Final:jar
+org.drools:drools-core-reflective:7.48.0.Final:jar
+org.drools:drools-ecj:7.48.0.Final:jar
+org.drools:drools-model-compiler:7.48.0.Final:jar
+org.drools:drools-mvel-compiler:7.48.0.Final:jar
+org.drools:drools-mvel-parser:7.48.0.Final:jar
+org.kie:kie-api:7.48.0.Final:jar
+org.kie:kie-internal:7.48.0.Final:jar
+org.kie:kie-memory-compiler:7.48.0.Final:jar
+org.kie.soup:kie-soup-maven-support:7.48.0.Final:jar
+org.kie.soup:kie-soup-xstream:7.48.0.Final:jar
+org.slf4j:slf4j-api:1.7.30:jar
+xmlpull:xmlpull:1.1.3.1:jar
+xpp3:xpp3_min:1.1.4c:jar
diff --git a/module/ri-wireguard/pom.xml b/module/ri-wireguard/pom.xml
index a6ca2b8..86c6faa 100644
--- a/module/ri-wireguard/pom.xml
+++ b/module/ri-wireguard/pom.xml
@@ -5,12 +5,20 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.trygvis.rules-sandbox</groupId>
- <artifactId>rules-sandbox</artifactId>
+ <groupId>io.trygvis.rules-sandbox.module</groupId>
+ <artifactId>ri-module-parent</artifactId>
<version>1.0-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
+ <relativePath>../ri-module-parent/pom.xml</relativePath>
</parent>
<artifactId>ri-wireguard</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ri-base</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
</project>
diff --git a/module/ri-wireguard/src/main/resources/logback.xml b/module/ri-wireguard/src/main/resources/logback.xml
new file mode 100644
index 0000000..354003d
--- /dev/null
+++ b/module/ri-wireguard/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.apache.http" level="WARN"/>
+ <root level="debug">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration>
diff --git a/out/acme/wireguard.yaml b/out/acme/wireguard.yaml
index 58572d9..6eff70e 100644
--- a/out/acme/wireguard.yaml
+++ b/out/acme/wireguard.yaml
@@ -39,6 +39,23 @@
data:
fqdn: "ws-2.vpn.acme.com"
type: "A"
+- type: "io.trygvis.rules.dba.DbaMachineRole"
+ data:
+ &1 machine: "acme-1"
+ roles:
+ - "ci-app"
+- type: "io.trygvis.rules.dba.DbaMachineRole"
+ data:
+ &2 machine: "acme-2"
+ roles:
+ - "ops"
+ - "ci-db"
+- type: "io.trygvis.rules.dba.DbaMachineRole"
+ data:
+ &3 machine: "acme-3"
+ roles:
+ - "production-app"
+ - "production-db"
- type: "io.trygvis.rules.wireguard.WgNet"
data:
&vpn0 name: "vpn0"
diff --git a/pom.xml b/pom.xml
index 03b371e..f84b3f6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,10 +12,11 @@
<properties>
<java.module.name>io.trygvis.rules.sandbox</java.module.name>
<version.jackson>2.12.0</version.jackson>
- <version.kogito>1.1.0.Final</version.kogito>
+ <!--<version.kogito>1.1.0.Final</version.kogito>-->
<!-- This should match the version in kogito -->
<version.drools>7.48.0.Final</version.drools>
<version.springboot>2.3.1.RELEASE</version.springboot>
+ <version.picocli>4.6.1</version.picocli>
<java.version>15</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@@ -36,6 +37,7 @@
<type>pom</type>
<scope>import</scope>
</dependency>
+ <!--
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-bom</artifactId>
@@ -43,6 +45,7 @@
<type>pom</type>
<scope>import</scope>
</dependency>
+ -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-bom</artifactId>
@@ -68,7 +71,10 @@
<modules>
<module>module/acme</module>
+ <module>module/acme-planner</module>
+ <module>module/ri-base</module>
<module>module/ri-engine</module>
+ <module>module/ri-module-parent</module>
<module>module/ri-wireguard</module>
</modules>
@@ -80,7 +86,9 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
- <compilerArgs>--enable-preview</compilerArgs>
+ <compilerArgs>
+ <arg>--enable-preview</arg>
+ </compilerArgs>
<encoding>UTF-8</encoding>
<release>${java.version}</release>
<source>${java.version}</source>
@@ -96,6 +104,14 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.2.0</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>eu.nets.oss.maven</groupId>
<artifactId>classpath-maven-plugin</artifactId>
<version>1.0</version>