Skip to content

Commit

Permalink
kie-issues#1033: Fix sonataflow-quarkus-devui-extension to adapt it t…
Browse files Browse the repository at this point in the history
…o the Quarkus 3.8 Dev UI (#2212)
  • Loading branch information
paulovmr authored Mar 27, 2024
1 parent 507e974 commit 9fc9d1c
Show file tree
Hide file tree
Showing 13 changed files with 424 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
package org.kie.sonataflow.swf.tools.deployment;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

import io.quarkus.deployment.Capabilities;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import org.kie.sonataflow.swf.tools.runtime.config.DevUIStaticArtifactsRecorder;

import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -32,54 +38,25 @@
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.LiveReloadBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.util.WebJarUtil;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.runtime.devmode.DevConsoleRecorder;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig;
import org.kie.sonataflow.swf.tools.runtime.rpc.SonataFlowQuarkusExtensionJsonRPCService;

public class DevConsoleProcessor {

private static final String STATIC_RESOURCES_PATH = "dev-static/";
private static final String BASE_RELATIVE_URL = "/q/dev-v1/org.apache.kie.sonataflow.sonataflow-quarkus-devui-extension";

@BuildStep(onlyIf = IsDevelopment.class)
public CardPageBuildItem pages(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig,
LaunchModeBuildItem launchModeBuildItem,
ConfigurationBuildItem configurationBuildItem) throws UnsupportedEncodingException {

String uiPath = nonApplicationRootPathBuildItem.resolveManagementPath(BASE_RELATIVE_URL,
managementInterfaceBuildTimeConfig, launchModeBuildItem, true);

String devUIUrl = getProperty(configurationBuildItem, "kogito.dev-ui.url");
String devUIUrlQueryParam = devUIUrl != null ? "&devUIUrl=" + URLEncoder.encode(devUIUrl, "UTF-8") : "";

String dataIndexUrl = getProperty(configurationBuildItem, "kogito.data-index.url");
String dataIndexUrlQueryParam = dataIndexUrl != null ? "&dataIndexUrl=" + URLEncoder.encode(dataIndexUrl, "UTF-8") : "";

CardPageBuildItem cardPageBuildItem = new CardPageBuildItem();

cardPageBuildItem.addPage(Page.externalPageBuilder("Workflows")
.url(uiPath + "/index.html?page=Workflows" + devUIUrlQueryParam + dataIndexUrlQueryParam, uiPath)
.isHtmlContent()
.icon("font-awesome-solid:diagram-project"));

cardPageBuildItem.addPage(Page.externalPageBuilder("Monitoring")
.url(uiPath + "/index.html?page=Monitoring" + devUIUrlQueryParam + dataIndexUrlQueryParam, uiPath)
.isHtmlContent()
.icon("font-awesome-solid:gauge-high"));

return cardPageBuildItem;
}
private static final String BASE_RELATIVE_URL = "/q/dev-ui/org.apache.kie.sonataflow.sonataflow-quarkus-devui-extension";

@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.RUNTIME_INIT)
public void deployStaticResources(final DevConsoleRecorder recorder,
public void deployStaticResources(final DevUIStaticArtifactsRecorder devUIStaticArtifactsRecorder,
final CurateOutcomeBuildItem curateOutcomeBuildItem,
final LiveReloadBuildItem liveReloadBuildItem,
final LaunchModeBuildItem launchMode,
Expand All @@ -97,14 +74,65 @@ public void deployStaticResources(final DevConsoleRecorder recorder,
STATIC_RESOURCES_PATH,
true);

routeBuildItemBuildProducer.produce(new RouteBuildItem.Builder()
.route(BASE_RELATIVE_URL + "/resources/*")
.handler(devUIStaticArtifactsRecorder.handler(devConsoleStaticResourcesDeploymentPath.toString(),
shutdownContext))
.build());

routeBuildItemBuildProducer.produce(new RouteBuildItem.Builder()
.route(BASE_RELATIVE_URL + "/*")
.handler(recorder.devConsoleHandler(devConsoleStaticResourcesDeploymentPath.toString(),
.handler(devUIStaticArtifactsRecorder.handler(devConsoleStaticResourcesDeploymentPath.toString(),
shutdownContext))
.build());
}

@BuildStep(onlyIf = IsDevelopment.class)
public JsonRPCProvidersBuildItem createJsonRPCServiceForJBPMDevUi() {
return new JsonRPCProvidersBuildItem(SonataFlowQuarkusExtensionJsonRPCService.class);
}

@BuildStep(onlyIf = IsDevelopment.class)
public CardPageBuildItem pages(
final NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
final ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig,
final LaunchModeBuildItem launchModeBuildItem,
final ConfigurationBuildItem configurationBuildItem,
final List<SystemPropertyBuildItem> systemPropertyBuildItems,
final Capabilities capabilities) {

CardPageBuildItem cardPageBuildItem = new CardPageBuildItem();

String uiPath = nonApplicationRootPathBuildItem.resolveManagementPath(BASE_RELATIVE_URL,
managementInterfaceBuildTimeConfig, launchModeBuildItem, true);

String openapiPath = getProperty(configurationBuildItem, systemPropertyBuildItems, "quarkus.smallrye-openapi.path");
String devUIUrl = getProperty(configurationBuildItem, systemPropertyBuildItems, "kogito.dev-ui.url");
String dataIndexUrl = getProperty(configurationBuildItem, systemPropertyBuildItems, "kogito.data-index.url");

cardPageBuildItem.addBuildTimeData("extensionBasePath", uiPath);
cardPageBuildItem.addBuildTimeData("openapiPath", openapiPath);
cardPageBuildItem.addBuildTimeData("devUIUrl", devUIUrl);
cardPageBuildItem.addBuildTimeData("dataIndexUrl", dataIndexUrl);

cardPageBuildItem.addPage(Page.webComponentPageBuilder()
.componentLink("qwc-sonataflow-quarkus-devui.js")
.metadata("page", "Workflows")
.title("Workflows")
.icon("font-awesome-solid:diagram-project")
.dynamicLabelJsonRPCMethodName("queryWorkflowsCount"));

cardPageBuildItem.addPage(Page.webComponentPageBuilder()
.componentLink("qwc-sonataflow-quarkus-devui.js")
.metadata("page", "Monitoring")
.title("Monitoring")
.icon("font-awesome-solid:chart-simple"));

return cardPageBuildItem;
}

private static String getProperty(ConfigurationBuildItem configurationBuildItem,
List<SystemPropertyBuildItem> systemPropertyBuildItems,
String propertyKey) {

String propertyValue = configurationBuildItem
Expand All @@ -128,6 +156,12 @@ private static String getProperty(ConfigurationBuildItem configurationBuildItem,
.get(propertyKey);
}

return propertyValue;
if (propertyValue != null) {
return propertyValue;
}

return systemPropertyBuildItems.stream().filter(property -> property.getKey().equals(propertyKey))
.findAny()
.map(SystemPropertyBuildItem::getValue).orElse(null);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates.
*
* Licensed 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.
*/

import { html, LitElement } from "lit";
import { dataIndexUrl, devUIUrl, extensionBasePath, openapiPath } from "build-time-data";
import { RouterController } from "router-controller";

export class QwcSonataflowQuarkusDevui extends LitElement {
_routerController = new RouterController(this);

constructor() {
super();
}

render() {
return html` <div id="envelope-app" style="height: 100%"></div>`;
}

async connectedCallback() {
super.connectedCallback();
await this.updateComplete;
if (!document.querySelector("#sonataflow-devui-script")) {
const script = document.createElement("script");
script.setAttribute("async", "");
script.setAttribute("id", "sonataflow-devui-script");
script.setAttribute("src", `${extensionBasePath}/resources/webapp/standalone.js`);
script.addEventListener("load", () => {
this.initUI();
});
document.head.appendChild(script);
} else {
this.initUI();
}
}

initUI() {
const metadata = this._routerController.getCurrentMetaData();
const container = this.renderRoot.querySelector("#envelope-app");
RuntimeToolsDevUI.open({
container: container,
isDataIndexAvailable: true,
dataIndexUrl: `${dataIndexUrl ?? window.location.origin}/graphql`,
page: metadata.page ?? "Workflows",
devUIUrl: `${devUIUrl ?? window.location.origin}`,
openApiBaseUrl: `${devUIUrl ?? window.location.origin}`,
openApiPath: `${openapiPath ?? "q/openapi.json"}`,
availablePages: ["Workflows", "Monitoring", "CustomDashboard"],
});
}
}

customElements.define("qwc-sonataflow-quarkus-devui", QwcSonataflowQuarkusDevui);
Loading

0 comments on commit 9fc9d1c

Please sign in to comment.