-
Notifications
You must be signed in to change notification settings - Fork 214
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
[incubator-kie-issues#1473] Introduce Transactional annotation, conditionally deleted #3671
Merged
Merged
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
40313da
[incubator-kie-issues#1473] WIP - Implemented transactional imports a…
5b54d4e
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
5875d51
[incubator-kie-issues#1473] Simplified following suggestions.
da675e1
[incubator-kie-issues#1473] Implemented KogitoContextTestUtils#restCo…
8102962
[incubator-kie-issues#1473] Set log level to debug inside manageTrans…
cfa7584
[incubator-kie-issues#1473] Add spring-tx dependency to jbpm-spring-b…
6f7a76e
[incubator-kie-issues#1473] Add quarkus-narayana-jta dependency to ko…
dae9508
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
078e758
[incubator-kie-issues#1473] Add quarkus-narayana-jta-deployment depen…
1b679f4
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
d4414a5
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
41a42ba
[incubator-kie-issues#1473] Introduce nasty workaround (delay) to avo…
2534cfa
[incubator-kie-issues#1473] Disabling transaction for sonataflow-quar…
9fad45d
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
ca99f4f
[incubator-kie-issues#1473] Conditionally add the thread sleep. Fix k…
5a0d748
[incubator-kie-issues#1473] Importing new wait strategy.
d128790
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
7805381
[incubator-kie-issues#1473] WIP - Experimenting Thread.join inside tr…
d8761b6
[incubator-kie-issues#1473] WIP - fix formatting
aa96611
[incubator-kie-issues#1473] WIP - commented out conditionally exclude…
9c4d4e7
[incubator-kie-issues#1473] WIP - commented out conditionally exclude…
9359c55
[incubator-kie-issues#1473] Disabling transaction for serverless
ac5adfb
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
3ffa165
[incubator-kie-issues#1473] Fix formatting
2bed966
[incubator-kie-issues#1473] Fix test
990cbd9
[incubator-kie-issues#1473] Fixed as per PR suggestion. Using context…
351145f
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -89,16 +90,23 @@ public class ProcessCodegen extends AbstractGenerator { | |
public static final String GENERATOR_NAME = "processes"; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessCodegen.class); | ||
|
||
private static final GeneratedFileType PROCESS_TYPE = GeneratedFileType.of("PROCESS", GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType PROCESS_INSTANCE_TYPE = GeneratedFileType.of("PROCESS_INSTANCE", GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType MESSAGE_PRODUCER_TYPE = GeneratedFileType.of("MESSAGE_PRODUCER", GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType MESSAGE_CONSUMER_TYPE = GeneratedFileType.of("MESSAGE_CONSUMER", GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType PRODUCER_TYPE = GeneratedFileType.of("PRODUCER", GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType PROCESS_TYPE = GeneratedFileType.of("PROCESS", | ||
GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType PROCESS_INSTANCE_TYPE = GeneratedFileType.of("PROCESS_INSTANCE", | ||
GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType MESSAGE_PRODUCER_TYPE = GeneratedFileType.of("MESSAGE_PRODUCER", | ||
GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType MESSAGE_CONSUMER_TYPE = GeneratedFileType.of("MESSAGE_CONSUMER", | ||
GeneratedFileType.Category.SOURCE); | ||
private static final GeneratedFileType PRODUCER_TYPE = GeneratedFileType.of("PRODUCER", | ||
GeneratedFileType.Category.SOURCE); | ||
private static final SemanticModules BPMN_SEMANTIC_MODULES = new SemanticModules(); | ||
public static final String SVG_EXPORT_NAME_EXPRESION = "%s-svg.svg"; | ||
|
||
private static final String GLOBAL_OPERATIONAL_DASHBOARD_TEMPLATE = "/grafana-dashboard-template/processes/global-operational-dashboard-template.json"; | ||
private static final String PROCESS_OPERATIONAL_DASHBOARD_TEMPLATE = "/grafana-dashboard-template/processes/process-operational-dashboard-template.json"; | ||
private static final String GLOBAL_OPERATIONAL_DASHBOARD_TEMPLATE = "/grafana-dashboard-template/processes/global" + | ||
"-operational-dashboard-template.json"; | ||
private static final String PROCESS_OPERATIONAL_DASHBOARD_TEMPLATE = "/grafana-dashboard-template/processes" + | ||
"/process-operational-dashboard-template.json"; | ||
|
||
static { | ||
ProcessValidatorRegistry.getInstance().registerAdditonalValidator(JavaRuleFlowProcessValidator.getInstance()); | ||
|
@@ -109,7 +117,8 @@ public class ProcessCodegen extends AbstractGenerator { | |
|
||
private final List<ProcessGenerator> processGenerators = new ArrayList<>(); | ||
|
||
public static ProcessCodegen ofCollectedResources(KogitoBuildContext context, Collection<CollectedResource> resources) { | ||
public static ProcessCodegen ofCollectedResources(KogitoBuildContext context, | ||
Collection<CollectedResource> resources) { | ||
Map<String, byte[]> processSVGMap = new HashMap<>(); | ||
Map<String, Throwable> processesErrors = new HashMap<>(); | ||
boolean useSvgAddon = context.getAddonsConfig().useProcessSVG(); | ||
|
@@ -126,7 +135,8 @@ public static ProcessCodegen ofCollectedResources(KogitoBuildContext context, Co | |
return p.stream().map(KogitoWorkflowProcess.class::cast).map(GeneratedInfo::new).map(info -> addResource(info, resource)); | ||
} else if (SupportedExtensions.getSWFExtensions().stream().anyMatch(resource.getSourcePath()::endsWith)) { | ||
GeneratedInfo<KogitoWorkflowProcess> generatedInfo = parseWorkflowFile(resource, context); | ||
notifySourceFileCodegenBindListeners(context, resource, Collections.singletonList(generatedInfo.info())); | ||
notifySourceFileCodegenBindListeners(context, resource, | ||
Collections.singletonList(generatedInfo.info())); | ||
return Stream.of(addResource(generatedInfo, resource)); | ||
} | ||
} catch (ValidationException e) { | ||
|
@@ -149,12 +159,14 @@ public static ProcessCodegen ofCollectedResources(KogitoBuildContext context, Co | |
return ofProcesses(context, processes); | ||
} | ||
|
||
private static GeneratedInfo<KogitoWorkflowProcess> addResource(GeneratedInfo<KogitoWorkflowProcess> info, Resource r) { | ||
private static GeneratedInfo<KogitoWorkflowProcess> addResource(GeneratedInfo<KogitoWorkflowProcess> info, | ||
Resource r) { | ||
((ProcessImpl) info.info()).setResource(r); | ||
return info; | ||
} | ||
|
||
private static void notifySourceFileCodegenBindListeners(KogitoBuildContext context, Resource resource, Collection<Process> processes) { | ||
private static void notifySourceFileCodegenBindListeners(KogitoBuildContext context, Resource resource, | ||
Collection<Process> processes) { | ||
context.getSourceFileCodegenBindNotifier() | ||
.ifPresent(notifier -> processes.forEach(p -> notifier.notify(new SourceFileCodegenBindEvent(p.getId(), resource.getSourcePath())))); | ||
} | ||
|
@@ -170,7 +182,8 @@ private static void handleValidation(KogitoBuildContext context, Map<String, Thr | |
} | ||
} | ||
|
||
private static GeneratedInfo<KogitoWorkflowProcess> validate(GeneratedInfo<KogitoWorkflowProcess> processInfo, Map<String, Throwable> processesErrors) { | ||
private static GeneratedInfo<KogitoWorkflowProcess> validate(GeneratedInfo<KogitoWorkflowProcess> processInfo, | ||
Map<String, Throwable> processesErrors) { | ||
Process process = processInfo.info(); | ||
try { | ||
ProcessValidatorRegistry.getInstance().getValidator(process, process.getResource()).validate(process); | ||
|
@@ -213,14 +226,16 @@ public static boolean isFilenameValid(String file) { | |
} | ||
} | ||
|
||
private static ProcessCodegen ofProcesses(KogitoBuildContext context, List<GeneratedInfo<KogitoWorkflowProcess>> processes) { | ||
private static ProcessCodegen ofProcesses(KogitoBuildContext context, | ||
List<GeneratedInfo<KogitoWorkflowProcess>> processes) { | ||
return new ProcessCodegen(context, processes); | ||
} | ||
|
||
protected static GeneratedInfo<KogitoWorkflowProcess> parseWorkflowFile(Resource r, KogitoBuildContext context) { | ||
InternalResource resource = (InternalResource) r; | ||
try (Reader reader = resource.getReader()) { | ||
ServerlessWorkflowParser parser = ServerlessWorkflowParser.of(reader, WorkflowFormat.fromFileName(resource.getSourcePath()), context); | ||
ServerlessWorkflowParser parser = ServerlessWorkflowParser.of(reader, | ||
WorkflowFormat.fromFileName(resource.getSourcePath()), context); | ||
if (resource.hasURL()) { | ||
parser.withBaseURI(resource.getURL()); | ||
} else { | ||
|
@@ -335,7 +350,8 @@ protected Collection<GeneratedFile> internalGenerate() { | |
String classPrefix = sanitizeClassName(execModelGen.extractedProcessId()); | ||
KogitoWorkflowProcess workFlowProcess = execModelGen.process(); | ||
ModelClassGenerator modelClassGenerator = | ||
processIdToModelGenerator.getOrDefault(execModelGen.getProcessId(), new ModelClassGenerator(context(), workFlowProcess)); | ||
processIdToModelGenerator.getOrDefault(execModelGen.getProcessId(), | ||
new ModelClassGenerator(context(), workFlowProcess)); | ||
|
||
ProcessGenerator p = new ProcessGenerator( | ||
context(), | ||
|
@@ -363,7 +379,8 @@ protected Collection<GeneratedFile> internalGenerate() { | |
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); | ||
|
||
|
@@ -374,13 +391,14 @@ protected Collection<GeneratedFile> internalGenerate() { | |
// generate message consumers for processes with message start events | ||
if (trigger.getType().equals(TriggerMetaData.TriggerType.ConsumeMessage)) { | ||
MessageConsumerGenerator messageConsumerGenerator = | ||
megs.computeIfAbsent(new ProcessCloudEventMeta(workFlowProcess.getId(), trigger), k -> new MessageConsumerGenerator( | ||
context(), | ||
workFlowProcess, | ||
modelClassGenerator.className(), | ||
execModelGen.className(), | ||
applicationCanonicalName(), | ||
trigger)); | ||
megs.computeIfAbsent(new ProcessCloudEventMeta(workFlowProcess.getId(), trigger), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, the format changes are making difficult to review the PR |
||
k -> new MessageConsumerGenerator( | ||
context(), | ||
workFlowProcess, | ||
modelClassGenerator.className(), | ||
execModelGen.className(), | ||
applicationCanonicalName(), | ||
trigger)); | ||
metaData.addConsumer(trigger.getName(), messageConsumerGenerator.compilationUnit()); | ||
} else if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) { | ||
MessageProducerGenerator messageProducerGenerator = new MessageProducerGenerator( | ||
|
@@ -420,11 +438,14 @@ protected Collection<GeneratedFile> internalGenerate() { | |
for (List<UserTaskModelMetaData> utmd : processIdToUserTaskModel.values()) { | ||
|
||
for (UserTaskModelMetaData ut : utmd) { | ||
storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getInputModelClassName()), ut.generateInput()); | ||
storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getInputModelClassName()), | ||
ut.generateInput()); | ||
|
||
storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getOutputModelClassName()), ut.generateOutput()); | ||
storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getOutputModelClassName()), | ||
ut.generateOutput()); | ||
|
||
storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getTaskModelClassName()), ut.generateModel()); | ||
storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getTaskModelClassName()), | ||
ut.generateModel()); | ||
} | ||
} | ||
|
||
|
@@ -438,7 +459,8 @@ protected Collection<GeneratedFile> internalGenerate() { | |
for (ProcessResourceGenerator resourceGenerator : rgs) { | ||
storeFile(REST_TYPE, resourceGenerator.generatedFilePath(), | ||
resourceGenerator.generate()); | ||
storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(resourceGenerator.getTaskModelFactoryClassName()), resourceGenerator.getTaskModelFactory()); | ||
storeFile(MODEL_TYPE, | ||
UserTasksModelClassGenerator.generatedFilePath(resourceGenerator.getTaskModelFactoryClassName()), resourceGenerator.getTaskModelFactory()); | ||
} | ||
} | ||
|
||
|
@@ -457,15 +479,18 @@ protected Collection<GeneratedFile> internalGenerate() { | |
|
||
p.getAdditionalClasses().forEach(cp -> { | ||
String packageName = cp.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse(""); | ||
String clazzName = cp.findFirst(ClassOrInterfaceDeclaration.class).map(cls -> cls.getName().toString()).get(); | ||
String clazzName = | ||
cp.findFirst(ClassOrInterfaceDeclaration.class).map(cls -> cls.getName().toString()).get(); | ||
String path = (packageName + "." + clazzName).replace('.', '/') + ".java"; | ||
storeFile(GeneratedFileType.SOURCE, path, cp.toString()); | ||
}); | ||
} | ||
|
||
if ((context().getAddonsConfig().useProcessSVG())) { | ||
Map<String, byte[]> svgs = context().getContextAttribute(ContextAttributesConstants.PROCESS_AUTO_SVG_MAPPING, Map.class); | ||
svgs.keySet().stream().forEach(key -> storeFile(GeneratedFileType.INTERNAL_RESOURCE, "META-INF/processSVG/" + key + ".svg", svgs.get(key))); | ||
Map<String, byte[]> svgs = | ||
context().getContextAttribute(ContextAttributesConstants.PROCESS_AUTO_SVG_MAPPING, Map.class); | ||
svgs.keySet().stream().forEach(key -> storeFile(GeneratedFileType.INTERNAL_RESOURCE, "META-INF/processSVG" + | ||
"/" + key + ".svg", svgs.get(key))); | ||
} | ||
|
||
if (context().hasRESTForGenerator(this)) { | ||
|
@@ -504,6 +529,11 @@ protected Collection<GeneratedFile> internalGenerate() { | |
return generatedFiles; | ||
} | ||
|
||
protected boolean isTransactionEnabled() { | ||
String processTransactionProperty = String.format("%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); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, the formatter is changing this, curious ;), someone knows why?