Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KOGITO-5533: implement evaluation of rules via CloudEvents #1610

Merged
merged 28 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8e3aa81
KOGITO-5533: base pom files
kostola Sep 1, 2021
9cb2c6c
KOGITO-5533: add addons to kogito-bom
kostola Sep 10, 2021
a7ab5d9
KOGITO-5533: add EventDrivenRulesController
kostola Sep 10, 2021
8aa9e6e
KOGITO-5533: add addon discovery
kostola Sep 16, 2021
ebce941
KOGITO-5533: working generator
kostola Sep 16, 2021
0292f61
KOGITO-5533: small cleanup to generator
kostola Sep 16, 2021
b957aa6
KOGITO-5533 fix generator templates
kostola Sep 16, 2021
71296b4
KOGITO-5533: working QuarkusEventDrivenRulesController and addon
kostola Sep 16, 2021
e2b38b0
KOGITO-5533: inject ObjectMapper in executors + implement Spring Boot…
kostola Sep 16, 2021
8bdd2ac
KOGITO-5533: merge branch main
kostola Sep 20, 2021
ca87ca1
KOGITO-5533: fixes
kostola Sep 20, 2021
ddc7c11
KOGITO-5533: add AbstractQueryEntrypointGenerator to reduce duplication
kostola Sep 20, 2021
f64ae6f
KOGITO-5533: change interpolation logic
kostola Sep 20, 2021
0df3dd0
KOGITO-5533: restore Startup in QuarkusEventDrivenRulesController
kostola Sep 20, 2021
1efb2e8
KOGITO-5533: merge branch main
kostola Sep 21, 2021
8fde65c
KOGITO-5533: fix quarkus/addons/events/rules/pom.xml
kostola Sep 21, 2021
6ed8e57
KOGITO-5533: improve EventDrivenRulesController
kostola Sep 21, 2021
b277d21
KOGITO-5533: merge branch main
kostola Sep 21, 2021
6fe846f
KOGITO-5533: minor change to KogitoExtension
kostola Sep 22, 2021
43300fe
KOGITO-5533: merge branch main
kostola Sep 23, 2021
fcce8be
KOGITO-5533: merge branch main
kostola Sep 28, 2021
0e55bcc
KOGITO-5533: add deployment project
kostola Sep 28, 2021
8d7567a
KOGITO-5533: fixes
kostola Sep 28, 2021
545f4ef
KOGITO-5533: fixes
kostola Sep 28, 2021
7952d3d
KOGITO-5533: introduce KogitoRulesExtension
kostola Sep 29, 2021
9ac9fd2
KOGITO-5533: rename setup methods in controllers
kostola Sep 29, 2021
8f28e05
KOGITO-5533: register KogitoRulesExtension
kostola Sep 29, 2021
18f914d
KOGITO-5533: add EventDrivenRulesControllerTest
kostola Sep 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/common/events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<modules>
<module>decisions</module>
<module>rules</module>
</modules>

<profiles>
Expand Down
47 changes: 47 additions & 0 deletions addons/common/events/rules/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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>org.kie.kogito</groupId>
<artifactId>kogito-addons-events-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>kogito-addons-events-rules</artifactId>
<name>Kogito :: Add-Ons :: Events :: Event-Driven Rules</name>
<description>Trigger evaluation of rule models via events</description>

<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-api</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-events-api</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-cloudevents-utils</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.kogito.eventdriven.rules;

import java.util.Optional;

import org.kie.kogito.cloudevents.CloudEventUtils;
import org.kie.kogito.rules.RuleUnit;
import org.kie.kogito.rules.RuleUnitData;
import org.kie.kogito.rules.RuleUnitInstance;
import org.kie.kogito.rules.RuleUnitQuery;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.cloudevents.CloudEvent;

public abstract class AbstractEventDrivenQueryExecutor<D extends RuleUnitData, R> implements EventDrivenQueryExecutor {

private RuleUnit<D> ruleUnit;
private String queryName;
private Class<? extends RuleUnitQuery<R>> queryClass;
private Class<D> dataClass;
private ObjectMapper mapper;

protected AbstractEventDrivenQueryExecutor() {
}

protected AbstractEventDrivenQueryExecutor(RuleUnit<D> ruleUnit, String queryName, Class<? extends RuleUnitQuery<R>> queryClass, Class<D> dataClass, ObjectMapper mapper) {
this.ruleUnit = ruleUnit;
this.queryName = queryName;
this.queryClass = queryClass;
this.dataClass = dataClass;
this.mapper = mapper;
}

protected void setup(RuleUnit<D> ruleUnit, String queryName, Class<? extends RuleUnitQuery<R>> queryClass, Class<D> dataClass, ObjectMapper mapper) {
this.ruleUnit = ruleUnit;
this.queryName = queryName;
this.queryClass = queryClass;
this.dataClass = dataClass;
this.mapper = mapper;
}

@Override
public String getRuleUnitId() {
return ruleUnit.id();
}

@Override
public String getQueryName() {
return queryName;
}

@Override
public Object executeQuery(CloudEvent input) {
return decodeData(input)
.map(this::internalExecuteQuery)
.orElseThrow(IllegalArgumentException::new);
}

private Optional<D> decodeData(CloudEvent input) {
return mapper == null
? CloudEventUtils.decodeData(input, dataClass)
: CloudEventUtils.decodeData(input, dataClass, mapper);
}

private R internalExecuteQuery(D input) {
RuleUnitInstance<D> instance = ruleUnit.createInstance(input);
R response = instance.executeQuery(queryClass);
instance.dispose();
return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.kogito.eventdriven.rules;

import io.cloudevents.CloudEvent;

public interface EventDrivenQueryExecutor {

String getRuleUnitId();

String getQueryName();

Object executeQuery(CloudEvent input);

}
Loading