Skip to content

Commit

Permalink
[incubator-kie-issues#1473] Introduce Transactional annotation, condi…
Browse files Browse the repository at this point in the history
…tionally deleted (apache#3671)

* [incubator-kie-issues#1473] WIP - Implemented transactional imports and annotations with optional removal. Add unit tests. Small refactoring to allow unit testing/ TDD

* [incubator-kie-issues#1473] Simplified following suggestions.
Now the annotation is conditionally add during code generation.

* [incubator-kie-issues#1473] Implemented KogitoContextTestUtils#restContextBuilders for rest-specific tests.
Enforced exclusion of "Java" context from processes' rest generation.

* [incubator-kie-issues#1473] Set log level to debug inside manageTransactional

* [incubator-kie-issues#1473] Add spring-tx dependency to jbpm-spring-boot-starter to be always available for springboot projects

* [incubator-kie-issues#1473] Add quarkus-narayana-jta dependency to kogito-quarkus-workflow-common to be always available for quarkus projects

* [incubator-kie-issues#1473] Add quarkus-narayana-jta-deployment dependency

* [incubator-kie-issues#1473] Introduce nasty workaround (delay) to avoid ARJUNA issues with nested threads

* [incubator-kie-issues#1473] Disabling transaction for sonataflow-quarkus-integration-test

* [incubator-kie-issues#1473] Conditionally add the thread sleep. Fix kogito.processes.transactionEnabled variable

* [incubator-kie-issues#1473] Importing new wait strategy.

* [incubator-kie-issues#1473] WIP - Experimenting Thread.join inside transaction (instead of Thread.sleep)

* [incubator-kie-issues#1473] WIP - fix formatting

* [incubator-kie-issues#1473] WIP - commented out conditionally excluded serverless transaction. Disable transaction workaround.

* [incubator-kie-issues#1473] WIP - commented out conditionally excluded serverless transaction. Disable transaction workaround.

* [incubator-kie-issues#1473] Disabling transaction for serverless

* [incubator-kie-issues#1473] Fix formatting

* [incubator-kie-issues#1473] Fix test

* [incubator-kie-issues#1473] Fixed as per PR suggestion. Using context.hasRest() instead of name.equals("Java") to check for rest endpoint creation. Implemented MockQuarkusKogitoBuildContext and MockSpringBootKogitoBuildContext to override the hasRest method during tests.

---------

Co-authored-by: Gabriele-Cardosi <[email protected]>
  • Loading branch information
2 people authored and rgdoliveira committed Oct 3, 2024
1 parent f2ca753 commit 3e8a0cc
Show file tree
Hide file tree
Showing 13 changed files with 397 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.codegen.api.context.impl;

/**
* Mocked <code>QuarkusKogitoBuildContext</code> to provide <code>hasRest() = true</code>
* during test
*/
public class MockQuarkusKogitoBuildContext extends QuarkusKogitoBuildContext {

protected MockQuarkusKogitoBuildContext(MockQuarkusKogitoBuildContextBuilder builder) {
super(builder);
}

public static Builder builder() {
return new MockQuarkusKogitoBuildContextBuilder();
}

@Override
public boolean hasRest() {
return true;
}

protected static class MockQuarkusKogitoBuildContextBuilder extends QuarkusKogitoBuildContextBuilder {

protected MockQuarkusKogitoBuildContextBuilder() {
}

@Override
public MockQuarkusKogitoBuildContext build() {
return new MockQuarkusKogitoBuildContext(this);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.codegen.api.context.impl;

/**
* Mocked <code>SpringBootKogitoBuildContext</code> to provide <code>hasRest() = true</code>
* during test
*/
public class MockSpringBootKogitoBuildContext extends SpringBootKogitoBuildContext {

protected MockSpringBootKogitoBuildContext(MockSpringBootKogitoBuildContextBuilder builder) {
super(builder);
}

public static Builder builder() {
return new MockSpringBootKogitoBuildContextBuilder();
}

@Override
public boolean hasRest() {
return true;
}

protected static class MockSpringBootKogitoBuildContextBuilder extends SpringBootKogitoBuildContextBuilder {

protected MockSpringBootKogitoBuildContextBuilder() {
}

@Override
public MockSpringBootKogitoBuildContext build() {
return new MockSpringBootKogitoBuildContext(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.junit.jupiter.params.provider.Arguments;
import org.kie.kogito.codegen.api.context.KogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.MockQuarkusKogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.MockSpringBootKogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext;

Expand All @@ -44,6 +46,16 @@ public static Stream<Arguments> contextBuilders() {
Arguments.of(SpringBootKogitoBuildContext.builder()));
}

/**
*
* @return <b>Mocked</b> <code>QuarkusKogitoBuildContext</code> and <code>SpringBootKogitoBuildContext</code> providing <code>hasRest() = true</code>
*/
public static Stream<Arguments> restContextBuilders() {
return Stream.of(
Arguments.of(MockQuarkusKogitoBuildContext.builder()),
Arguments.of(MockSpringBootKogitoBuildContext.builder()));
}

public static Predicate<String> mockClassAvailabilityResolver(Collection<String> includedClasses, Collection<String> excludedClasses) {
return mockClassAvailabilityResolver(includedClasses, excludedClasses, KogitoContextTestUtils.class.getClassLoader());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static org.kie.kogito.codegen.process.ProcessResourceGenerator.TRANSACTION_ENABLED;
import static org.kie.kogito.grafana.GrafanaConfigurationWriter.buildDashboardName;
import static org.kie.kogito.grafana.GrafanaConfigurationWriter.generateOperationalDashboard;
import static org.kie.kogito.internal.utils.ConversionUtils.sanitizeClassName;
Expand Down Expand Up @@ -352,20 +353,23 @@ protected Collection<GeneratedFile> internalGenerate() {

ProcessMetaData metaData = processIdToMetadata.get(workFlowProcess.getId());

//Creating and adding the ResourceGenerator
ProcessResourceGenerator processResourceGenerator = new ProcessResourceGenerator(
//Creating and adding the ResourceGenerator for REST generation
if (context().hasRest()) {
ProcessResourceGenerator processResourceGenerator = new ProcessResourceGenerator(
context(),
workFlowProcess,
modelClassGenerator.className(),
execModelGen.className(),
applicationCanonicalName());

processResourceGenerator
processResourceGenerator
.withUserTasks(processIdToUserTaskModel.get(workFlowProcess.getId()))
.withSignals(metaData.getSignals())
.withTriggers(metaData.isStartable(), metaData.isDynamic(), metaData.getTriggers());
.withTriggers(metaData.isStartable(), metaData.isDynamic(), metaData.getTriggers())
.withTransaction(isTransactionEnabled());

rgs.add(processResourceGenerator);
rgs.add(processResourceGenerator);
}

if (metaData.getTriggers() != null) {

Expand Down Expand Up @@ -468,7 +472,7 @@ protected Collection<GeneratedFile> internalGenerate() {
svgs.keySet().stream().forEach(key -> storeFile(GeneratedFileType.INTERNAL_RESOURCE, "META-INF/processSVG/" + key + ".svg", svgs.get(key)));
}

if (context().hasRESTForGenerator(this)) {
if (context().hasRest() && context().hasRESTForGenerator(this)) {
final ProcessCloudEventMetaFactoryGenerator topicsGenerator =
new ProcessCloudEventMetaFactoryGenerator(context(), processExecutableModelGenerators);
storeFile(REST_TYPE, topicsGenerator.generatedFilePath(), topicsGenerator.generate());
Expand Down Expand Up @@ -504,6 +508,11 @@ protected Collection<GeneratedFile> internalGenerate() {
return generatedFiles;
}

protected boolean isTransactionEnabled() {
String processTransactionProperty = String.format("kogito.%s.%s", GENERATOR_NAME, TRANSACTION_ENABLED);
return "true".equalsIgnoreCase(context().getApplicationProperty(processTransactionProperty).orElse("true"));
}

private void storeFile(GeneratedFileType type, String path, String source) {
if (generatedFiles.stream().anyMatch(f -> path.equals(f.relativePath()))) {
LOGGER.warn("There's already a generated file named {} to be compiled. Ignoring.", path);
Expand Down
Loading

0 comments on commit 3e8a0cc

Please sign in to comment.