Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Browse files Browse the repository at this point in the history
…1473
  • Loading branch information
Gabriele-Cardosi committed Oct 2, 2024
2 parents 990cbd9 + 38f8c14 commit 351145f
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.drools.core.common.InternalKnowledgeRuntime;
import org.jbpm.process.core.Context;
import org.jbpm.process.core.ContextContainer;
import org.jbpm.process.core.context.exception.CompensationScope;
import org.jbpm.process.core.impl.XmlProcessDumper;
import org.jbpm.process.core.impl.XmlProcessDumperFactory;
import org.jbpm.process.instance.ContextInstance;
import org.jbpm.process.instance.InternalProcessRuntime;
import org.jbpm.process.instance.ProcessInstance;
import org.jbpm.ruleflow.core.Metadata;
import org.jbpm.workflow.core.WorkflowProcess;
import org.kie.api.definition.process.Process;
import org.kie.api.runtime.rule.Agenda;
Expand Down Expand Up @@ -152,9 +154,16 @@ public void setState(final int state, String outcome) {
}

public void internalSetState(final int state) {
if (state == KogitoProcessInstance.STATE_ABORTED && automaticCompensation()) {
signalEvent(Metadata.COMPENSATION, CompensationScope.IMPLICIT_COMPENSATION_PREFIX + process.getId());
}
this.state = state;
}

private boolean automaticCompensation() {
return process.getMetaData().containsKey(Metadata.COMPENSATE_WHEN_ABORTED);
}

@Override
public int getState() {
return this.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class Metadata {
public static final String LINK_NAME = "LinkName";
public static final String CONDITION = "Condition";
public static final String IS_FOR_COMPENSATION = "isForCompensation";
public static final String COMPENSATE_WHEN_ABORTED = "compensateIfAborted";
public static final String CORRELATION_KEY = "CorrelationKey";
public static final String CUSTOM_ASYNC = "customAsync";
public static final String CUSTOM_AUTO_START = "customAutoStart";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public interface Generator {
GeneratedFileType REST_TYPE = GeneratedFileType.of("REST", GeneratedFileType.Category.SOURCE, true, true);
GeneratedFileType MODEL_TYPE = GeneratedFileType.of("MODEL", GeneratedFileType.Category.SOURCE, true, true);

/**
* kogito.codegen.(engine_name) -> (boolean) enable/disable engine code generation (default true)
*/
String CONFIG_PREFIX = "kogito.codegen.";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
public class GeneratorConfig {

/**
* the type of generated rest (currently used only by processes); possible values: reactive; (default is empty)
*/
public static final String KOGITO_REST_RESOURCE_TYPE_PROP = "kogito.rest.resource.type";

private GeneratorConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,38 @@ public class DecisionCodegen extends AbstractGenerator {
public static final Logger LOGGER = LoggerFactory.getLogger(DecisionCodegen.class);
public static final String GENERATOR_NAME = "decisions";

/**
* (boolean) generate java classes to support strongly typed input (default false)
*/
public static String STRONGLY_TYPED_CONFIGURATION_KEY = "kogito.decisions.stronglytyped";
/**
* model validation strategy; possible values: ENABLED, DISABLED, IGNORE; (default ENABLED)
*/
public static String VALIDATION_CONFIGURATION_KEY = "kogito.decisions.validation";

/**
* (string) kafka bootstrap server address
*/
public static final String KOGITO_ADDON_TRACING_DECISION_KAFKA_BOOTSTRAPADDRESS = "kogito.addon.tracing.decision.kafka.bootstrapAddress";
/**
* (string) name of the decision topic; default to kogito-tracing-decision
*/
public static final String KOGITO_ADDON_TRACING_DECISION_KAFKA_TOPIC_NAME = "kogito.addon.tracing.decision.kafka.topic.name";
/**
* (integer) number of decision topic partitions; default to 1
*/
public static final String KOGITO_ADDON_TRACING_DECISION_KAFKA_TOPIC_PARTITIONS = "kogito.addon.tracing.decision.kafka.topic.partitions";

/**
* (integer) number of decision topic replication factor; default to 1
*/
public static final String KOGITO_ADDON_TRACING_DECISION_KAFKA_TOPIC_REPLICATION_FACTOR = "kogito.addon.tracing.decision.kafka.topic.replicationFactor";

/**
* (boolean) enable/disable asynchronous collection of decision events; default to true
*/
public static final String KOGITO_ADDON_TRACING_DECISION_ASYNC_ENABLED = "kogito.addon.tracing.decision.asyncEnabled";

public static DecisionCodegen ofCollectedResources(KogitoBuildContext context, Collection<CollectedResource> resources) {
OASFactoryResolver.instance(); // manually invoke SPI, o/w Kogito CodeGen Kogito Quarkus extension failure at NewFileHotReloadTest due to java.util.ServiceConfigurationError: org.eclipse.microprofile.openapi.spi.OASFactoryResolver: io.smallrye.openapi.spi.OASFactoryResolverImpl not a subtype
List<CollectedResource> dmnResources = resources.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,19 @@ public class PersistenceGenerator extends AbstractGenerator {
* Kogito persistence properties
*/
// Generic
/**
* (boolean) enable/disable proto generation for DATA-INDEX; default to true
*/
public static final String KOGITO_PERSISTENCE_DATA_INDEX_PROTO_GENERATION = "kogito.persistence.data-index.proto.generation";
public static final String KOGITO_PERSISTENCE_DATA_INDEX_PROTO_GENERATION_DEFAULT = "true";
/**
* (boolean) enable/disable proto marshaller generation; default to true
*/
public static final String KOGITO_PERSISTENCE_PROTO_MARSHALLER = "kogito.persistence.proto.marshaller";
public static final String KOGITO_PERSISTENCE_PROTO_MARSHALLER_DEFAULT = "true";
/**
* (string) kind of persistence used; possible values: filesystem, infinispan, mongodb, postgresql, kafka, jdbc; default to infinispan
*/
public static final String KOGITO_PERSISTENCE_TYPE = "kogito.persistence.type";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@
public final class NamedRuleUnitConfig {

private static String CONFIG_PREFIX = "kogito.rules.";
/**
* (string) kind of event processing type for a given rule-unit; possible values: CLOUD, STREAM; default is null
*/
private static String CONFIG_EVENT_PROCESSING_TYPE = CONFIG_PREFIX + "\"%s\".event-processing-type";
/**
* (string) kind of event clock type for a given rule-unit; possible values: PSEUDO, REALTIME; default is null
*/
private static String CONFIG_CLOCK_TYPE = CONFIG_PREFIX + "\"%s\".clock-type";
/**
* (integer) size of session poolfor a given rule-unit; possible values; default is null
*/
private static String CONFIG_SESSIONS_POOL = CONFIG_PREFIX + "\"%s\".sessions-pool";

public static List<NamedRuleUnitConfig> fromContext(KogitoBuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@

public class WorkflowOperationIdFactoryProvider {

/**
* (string) strategy for generating the configuration key of open API specifications; possible values are:
* file_name: uses the last element of the spec uri
* full_uri: uses the full path of the uri
* spec_title: uses the spec title
* function_name: uses the function name
*
*/
public static final String PROPERTY_NAME = "kogito.sw.operationIdStrategy";

private static final Map<String, WorkflowOperationIdFactory> operationIds = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private GeneratedInfo<KogitoWorkflowProcess> parseProcess() {
handlers.forEach(StateHandler::handleConnections);
if (parserContext.isCompensation()) {
factory.metaData(Metadata.COMPENSATION, true);
factory.metaData(Metadata.COMPENSATE_WHEN_ABORTED, true);
factory.addCompensationContext(workflow.getId());
}
TimeoutsDefinition timeouts = workflow.getTimeouts();
Expand Down
14 changes: 14 additions & 0 deletions quarkus/addons/dynamic/integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<!-- hack for CI to work -->
<dependency>
<groupId>org.apache.kie.sonataflow</groupId>
<artifactId>sonataflow-quarkus-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "compensation",
"version": "1.0",
"name": "Workflow Error example",
"description": "An example of how compensation works",
"name": "Workflow compensation",
"description": "Test compensation works",
"start": "printStatus",
"errors": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"id": "automatic_compensation",
"version": "1.0",
"name": "Workflow abortion compensation",
"description": "Testing automatic compensation on abort",
"start": "double",
"functions": [
{
"name": "double",
"type": "expression",
"operation": ".value*=2"
},
{
"name": "half",
"type": "expression",
"operation": ".value/=2"
}],
"events": [
{
"name": "never",
"source": "",
"type": "never"
}
],
"states": [
{
"name": "double",
"type": "operation",
"compensatedBy" : "half",
"actions" : [{
"functionRef" : "double"
}],
"transition": "waitEvent"
},
{
"name": "waitEvent",
"type": "event",
"onEvents": [
{
"eventRefs": [
"never"
],
"actions": [
]
}
],
"end" : true
},
{
"name": "half",
"usedForCompensation" : true,
"type": "operation",
"actions" : [{
"functionRef" : "half"
}],
"end": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void testErrorRest2() {
.statusCode(201)
.body("workflowdata.compensated", is(true))
.body("workflowdata.isEven", is(false));

}

@Test
Expand All @@ -66,4 +65,23 @@ public void testErrorRest3() {
.statusCode(201)
.body("workflowdata.compensated", is(false));
}

@Test
public void testCompensationOnAbort() {
String pid = given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body("{\"value\" : 2}").when()
.post("/automatic_compensation")
.then()
.statusCode(201).extract().path("id");
given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.when()
.delete("/automatic_compensation/" + pid)
.then()
.statusCode(200)
.body("workflowdata.value", is(2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
@ApplicationScoped
public class KogitoBeanProducer {

/**
* (string) strategy to resolve a Process version to use; possible values: project, workflow; if "project", requires project GAV; default is workflow
*/
public static final String KOGITO_WORKFLOW_VERSION_STRATEGY = "kogito.workflow.version-strategy";

@DefaultBean
@Produces
CorrelationService correlationService() {
Expand Down

0 comments on commit 351145f

Please sign in to comment.