-
Notifications
You must be signed in to change notification settings - Fork 190
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
kie-issues#1669: jBPM Quarkus DevUI seems to not update the # of items #2781
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.jbpm.quarkus.devui.runtime.rpc; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.ext.web.client.WebClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DataIndexCounter { | ||
private static final String DATA_INDEX_URL = "kogito.data-index.url"; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(DataIndexCounter.class); | ||
|
||
private Multi<String> multi; | ||
private WebClient dataIndexWebClient; | ||
|
||
public DataIndexCounter(String query, String graphname, BroadcastProcessor<String> stream,WebClient dataIndexWebClient, JBPMDevUIEventPublisher eventPublisher) { | ||
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. The Also, you can format the parameters with a space between each one: 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. Done. Incorporated in new PR |
||
this.dataIndexWebClient = dataIndexWebClient; | ||
|
||
Vertx vertx = Vertx.vertx(); | ||
this.multi = Multi.createFrom().emitter(emitter -> { | ||
vertx.setPeriodic(1000, id -> emitter.emit("Initial data emitted")); | ||
}); | ||
|
||
|
||
vertx.setPeriodic(1000, id -> refreshData(stream,query,graphname)); | ||
} | ||
|
||
private void refreshData(BroadcastProcessor<String> stream, String query, String graphname ) { | ||
LOGGER.info("Refreshing data for query: {}", query); | ||
|
||
doQuery(query, graphname).toCompletionStage() | ||
.thenAccept(result -> { | ||
stream.onNext(result); | ||
}); | ||
} | ||
|
||
private Future<String> doQuery(String query, String graphModelName) { | ||
if(dataIndexWebClient == null) { | ||
LOGGER.warn("Cannot perform '{}' query, dataIndexWebClient couldn't be set. Is DataIndex correctly? Please verify '{}' value", graphModelName, DATA_INDEX_URL); | ||
return Future.succeededFuture("-"); | ||
} | ||
return this.dataIndexWebClient.post("/graphql") | ||
.putHeader("content-type", "application/json") | ||
.sendJson(new JsonObject(query)) | ||
.map(response -> { | ||
if(response.statusCode() == 200) { | ||
JsonObject responseData = response.bodyAsJsonObject().getJsonObject("data"); | ||
return String.valueOf(responseData.getJsonArray(graphModelName).size()); | ||
} | ||
return "-"; | ||
}); | ||
} | ||
|
||
public Multi<String> getMulti() { | ||
return multi; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.jbpm.quarkus.devui.runtime.rpc; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Default; | ||
|
||
import org.kie.kogito.event.DataEvent; | ||
import org.kie.kogito.event.EventPublisher; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
@Default | ||
@ApplicationScoped | ||
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. Please add the @IfBuildProfile("dev") here, to make sure that this bean is only available in dev mode! 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. 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. This broke the build, @pefernan . Maybe more changes need to be made or it need to have a prod bean? I don't know. 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. Done. Incorporated in new PR |
||
public class JBPMDevUIEventPublisher implements EventPublisher { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(JBPMDevUIEventPublisher.class); | ||
private Runnable onProcessEvent; | ||
private Runnable onTaskEvent; | ||
private Runnable onJobEvent; | ||
|
||
@Override | ||
public void publish(DataEvent<?> event) { | ||
switch (event.getType()) { | ||
case "ProcessInstanceStateDataEvent": | ||
maybeRun(onProcessEvent); | ||
break; | ||
case "UserTaskInstanceStateDataEvent": | ||
maybeRun(onTaskEvent); | ||
break; | ||
case "JobEvent": | ||
maybeRun(onJobEvent); | ||
break; | ||
default: | ||
LOGGER.debug("Unknown type of event '{}', ignoring for this publisher", event.getType()); | ||
} | ||
} | ||
|
||
@Override | ||
public void publish(Collection<DataEvent<?>> events) { | ||
events.forEach(this::publish); | ||
} | ||
|
||
private void maybeRun(Runnable runnable) { | ||
if(Objects.nonNull(runnable)) { | ||
runnable.run(); | ||
} | ||
} | ||
|
||
public void setOnProcessEventListener(Runnable onProcessEvent) { | ||
this.onProcessEvent = onProcessEvent; | ||
} | ||
|
||
public void setOnTaskEventListener(Runnable onTaskEvent) { | ||
this.onTaskEvent = onTaskEvent; | ||
} | ||
|
||
public void setOnJobEventListener(Runnable onJobEvent) { | ||
this.onJobEvent = onJobEvent; | ||
} | ||
} |
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.
You can set those fields as
final
, since their instances are not changed.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.
Done. Incorporated in new PR