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

[incubator-kie-issues#1473] Introduce Transactional annotation, conditionally deleted #3671

Merged
merged 27 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
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…
Sep 17, 2024
5b54d4e
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Sep 18, 2024
5875d51
[incubator-kie-issues#1473] Simplified following suggestions.
Sep 18, 2024
da675e1
[incubator-kie-issues#1473] Implemented KogitoContextTestUtils#restCo…
Sep 18, 2024
8102962
[incubator-kie-issues#1473] Set log level to debug inside manageTrans…
Sep 18, 2024
cfa7584
[incubator-kie-issues#1473] Add spring-tx dependency to jbpm-spring-b…
Sep 18, 2024
6f7a76e
[incubator-kie-issues#1473] Add quarkus-narayana-jta dependency to ko…
Sep 19, 2024
dae9508
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Sep 23, 2024
078e758
[incubator-kie-issues#1473] Add quarkus-narayana-jta-deployment depen…
Sep 23, 2024
1b679f4
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Sep 25, 2024
d4414a5
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Sep 25, 2024
41a42ba
[incubator-kie-issues#1473] Introduce nasty workaround (delay) to avo…
Sep 25, 2024
2534cfa
[incubator-kie-issues#1473] Disabling transaction for sonataflow-quar…
Sep 25, 2024
9fad45d
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Sep 26, 2024
ca99f4f
[incubator-kie-issues#1473] Conditionally add the thread sleep. Fix k…
Sep 26, 2024
5a0d748
[incubator-kie-issues#1473] Importing new wait strategy.
Sep 26, 2024
d128790
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Sep 27, 2024
7805381
[incubator-kie-issues#1473] WIP - Experimenting Thread.join inside tr…
Sep 27, 2024
d8761b6
[incubator-kie-issues#1473] WIP - fix formatting
Sep 27, 2024
aa96611
[incubator-kie-issues#1473] WIP - commented out conditionally exclude…
Sep 30, 2024
9c4d4e7
[incubator-kie-issues#1473] WIP - commented out conditionally exclude…
Sep 30, 2024
9359c55
[incubator-kie-issues#1473] Disabling transaction for serverless
Sep 30, 2024
ac5adfb
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Oct 1, 2024
3ffa165
[incubator-kie-issues#1473] Fix formatting
Oct 1, 2024
2bed966
[incubator-kie-issues#1473] Fix test
Oct 1, 2024
990cbd9
[incubator-kie-issues#1473] Fixed as per PR suggestion. Using context…
Oct 2, 2024
351145f
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Oct 2, 2024
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
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 All @@ -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());
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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()))));
}
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Copy link
Contributor

@fjtirado fjtirado Sep 30, 2024

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?

WorkflowFormat.fromFileName(resource.getSourcePath()), context);
if (resource.hasURL()) {
parser.withBaseURI(resource.getURL());
} else {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);

Expand All @@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The 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(
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading