From 47e57329910867a37d949cbe6b5b58e2daba6f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pere=20Fern=C3=A1ndez?= Date: Fri, 31 May 2024 10:58:00 +0200 Subject: [PATCH] incubator-kie-issues#1283: Fix Kogito Addons Quarkus Data Index `DevMode` (#3540) --- .../KogitoDevServicesProcessor.java | 32 +++++++++++++------ ...erverlessWorkflowDevServicesProcessor.java | 32 +++++++++++++------ .../AbstractDevServicesProcessor.java | 2 +- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/quarkus/extensions/kogito-quarkus-processes-extension/kogito-quarkus-processes-deployment/src/main/java/org/kie/kogito/quarkus/processes/deployment/KogitoDevServicesProcessor.java b/quarkus/extensions/kogito-quarkus-processes-extension/kogito-quarkus-processes-deployment/src/main/java/org/kie/kogito/quarkus/processes/deployment/KogitoDevServicesProcessor.java index 05fb6777d5d..51e9b5b090c 100644 --- a/quarkus/extensions/kogito-quarkus-processes-extension/kogito-quarkus-processes-deployment/src/main/java/org/kie/kogito/quarkus/processes/deployment/KogitoDevServicesProcessor.java +++ b/quarkus/extensions/kogito-quarkus-processes-extension/kogito-quarkus-processes-deployment/src/main/java/org/kie/kogito/quarkus/processes/deployment/KogitoDevServicesProcessor.java @@ -27,6 +27,7 @@ import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.processor.DotNames; +import io.quarkus.deployment.Capabilities; import io.quarkus.deployment.IsDevelopment; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -36,6 +37,8 @@ import io.quarkus.devui.spi.page.CardPageBuildItem; import io.quarkus.devui.spi.page.Page; +import static org.kie.kogito.quarkus.workflow.devservices.DataIndexEventPublisher.KOGITO_DATA_INDEX; + /** * Starts a Data Index as dev service if needed. */ @@ -49,16 +52,25 @@ public void logger(BuildProducer additionalBean, Launch } @BuildStep(onlyIf = { GlobalDevServicesConfig.Enabled.class, IsDevelopment.class }) - CardPageBuildItem createDevUILink(List systemPropertyBuildItems) { - Optional dataindex_url_prop = getProperty(systemPropertyBuildItems, "kogito.data-index.url"); - if (dataindex_url_prop.isPresent()) { - CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); - cardPageBuildItem.addPage(Page.externalPageBuilder("Data Index GraphQL UI") - .url(dataindex_url_prop.get() + "/q/graphql-ui/") - .isHtmlContent() - .icon("font-awesome-solid:signs-post")); - return cardPageBuildItem; + CardPageBuildItem createDataIndexDevUILink(Capabilities capabilities, + KogitoWorkflowBuildTimeConfig kogitoBuildTimeConfig, + List systemPropertyBuildItems) { + + Optional dataIndexUrlProp = getProperty(systemPropertyBuildItems, KOGITO_DATA_INDEX); + + if (capabilities.isPresent(DATA_INDEX_CAPABILITY) || !areDevServicesEnabled(kogitoBuildTimeConfig) || dataIndexUrlProp.isEmpty()) { + return null; } - return null; + + CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); + cardPageBuildItem.addPage(Page.externalPageBuilder("Data Index GraphQL UI") + .url(dataIndexUrlProp.get() + "/q/graphql-ui/") + .isHtmlContent() + .icon("font-awesome-solid:signs-post")); + return cardPageBuildItem; + } + + private boolean areDevServicesEnabled(KogitoWorkflowBuildTimeConfig kogitoBuildTimeConfig) { + return kogitoBuildTimeConfig.devservices.enabled.orElse(true); } } diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/deployment/ServerlessWorkflowDevServicesProcessor.java b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/deployment/ServerlessWorkflowDevServicesProcessor.java index 02cba0f8d7d..31d86e51a58 100644 --- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/deployment/ServerlessWorkflowDevServicesProcessor.java +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/deployment/ServerlessWorkflowDevServicesProcessor.java @@ -27,6 +27,7 @@ import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.processor.DotNames; +import io.quarkus.deployment.Capabilities; import io.quarkus.deployment.IsDevelopment; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -36,6 +37,8 @@ import io.quarkus.devui.spi.page.CardPageBuildItem; import io.quarkus.devui.spi.page.Page; +import static org.kie.kogito.quarkus.workflow.devservices.DataIndexEventPublisher.KOGITO_DATA_INDEX; + public class ServerlessWorkflowDevServicesProcessor extends AbstractDevServicesProcessor { @BuildStep public void logger(BuildProducer additionalBean, LaunchModeBuildItem launchMode, KogitoWorkflowBuildTimeConfig config) { @@ -45,16 +48,25 @@ public void logger(BuildProducer additionalBean, Launch } @BuildStep(onlyIf = { GlobalDevServicesConfig.Enabled.class, IsDevelopment.class }) - CardPageBuildItem createDevUILink(List systemPropertyBuildItems) { - Optional dataindex_url_prop = getProperty(systemPropertyBuildItems, "kogito.data-index.url"); - if (dataindex_url_prop.isPresent()) { - CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); - cardPageBuildItem.addPage(Page.externalPageBuilder("Data Index GraphQL UI") - .url(dataindex_url_prop.get() + "/q/graphql-ui/") - .isHtmlContent() - .icon("font-awesome-solid:signs-post")); - return cardPageBuildItem; + CardPageBuildItem createDataIndexDevUILink(Capabilities capabilities, + KogitoWorkflowBuildTimeConfig kogitoBuildTimeConfig, + List systemPropertyBuildItems) { + + Optional dataIndexUrlProp = getProperty(systemPropertyBuildItems, KOGITO_DATA_INDEX); + + if (capabilities.isPresent(DATA_INDEX_CAPABILITY) || !areDevServicesEnabled(kogitoBuildTimeConfig) || dataIndexUrlProp.isEmpty()) { + return null; } - return null; + + CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); + cardPageBuildItem.addPage(Page.externalPageBuilder("Data Index GraphQL UI") + .url(dataIndexUrlProp.get() + "/q/graphql-ui/") + .isHtmlContent() + .icon("font-awesome-solid:signs-post")); + return cardPageBuildItem; + } + + private boolean areDevServicesEnabled(KogitoWorkflowBuildTimeConfig kogitoBuildTimeConfig) { + return kogitoBuildTimeConfig.devservices.enabled.orElse(true); } } diff --git a/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/AbstractDevServicesProcessor.java b/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/AbstractDevServicesProcessor.java index 6bbb90352cc..7517da1c86d 100644 --- a/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/AbstractDevServicesProcessor.java +++ b/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/AbstractDevServicesProcessor.java @@ -60,7 +60,7 @@ public abstract class AbstractDevServicesProcessor { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractDevServicesProcessor.class); private static final ContainerLocator LOCATOR = new ContainerLocator(DataIndexInMemoryContainer.DEV_SERVICE_LABEL, DataIndexInMemoryContainer.PORT); - private static final String DATA_INDEX_CAPABILITY = "org.kie.kogito.data-index"; + protected static final String DATA_INDEX_CAPABILITY = "org.kie.kogito.data-index"; static Closeable closeable; static DataIndexDevServiceConfig cfg; static volatile boolean first = true;