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

feat: adding intermediate results to hmi-server #1684

Merged
merged 17 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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 @@ -247,6 +247,8 @@ import * as d3 from 'd3';
import { IProject, ProjectAssetTypes } from '@/types/Project';
import { Dataset, Model } from '@/types/Types';
import { useDragEvent } from '@/services/drag-drop';
import { EventSourcePolyfill } from 'event-source-polyfill';
import useAuthStore from '@/stores/auth';
import { DatasetOperation } from './dataset-operation';
import TeraDatasetNode from './tera-dataset-node.vue';
import TeraStratifyNode from './tera-stratify-node.vue';
Expand Down Expand Up @@ -424,6 +426,27 @@ function updateWorkflowNodeState(node: WorkflowNode, state: any) {
const testNode = (node: WorkflowNode) => {
const value = (node.inputs[0].value?.[0] ?? 0) + Math.round(Math.random() * 10);
appendOutputPort(node, { type: 'number', label: value.toString(), value });

console.log('Checking MQ');
const auth = useAuthStore();
const ttt = new EventSourcePolyfill('/api/simulations/123/partial-result', {
headers: {
Authorization: `Bearer ${auth.token}`
}
});
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
ttt.onerror = (e) => {
console.log('An error occurred while attempting to connect.');
console.log(e);
ttt.close();
console.log('Closing ttt');
};
ttt.onmessage = (event) => {
console.log(event);
const json = event.data;
console.log(json);
ttt.close();
console.log('Closing ttt');
};
};

const drilldown = (event: WorkflowNode) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package software.uncharted.terarium.hmiserver.models;

import lombok.Data;
import lombok.experimental.Accessors;
import com.fasterxml.jackson.annotation.JsonAlias;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class CalibrationIntermediateResults implements Serializable {
@JsonAlias("job_id")
private String jobId;
private float progress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.groups.MultiSelect;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.reactivestreams.Publisher;
import org.jboss.resteasy.annotations.SseElementType;
import software.uncharted.terarium.hmiserver.models.dataservice.PresignedURL;
import software.uncharted.terarium.hmiserver.models.dataservice.ResourceType;
import software.uncharted.terarium.hmiserver.models.dataservice.Simulation;
Expand All @@ -18,6 +24,7 @@
import software.uncharted.terarium.hmiserver.proxies.dataservice.SimulationProxy;
import software.uncharted.terarium.hmiserver.resources.SnakeCaseResource;
import software.uncharted.terarium.hmiserver.utils.Converter;
import software.uncharted.terarium.hmiserver.models.CalibrationIntermediateResults;

import javax.inject.Inject;
import javax.ws.rs.*;
Expand All @@ -43,6 +50,9 @@ public class SimulationResource implements SnakeCaseResource {
@RestClient
DatasetProxy datasetProxy;

@Inject
@Channel("simulations") Publisher<CalibrationIntermediateResults> events;

@POST
public Simulation createSimulation(final Simulation simulation){
return proxy.createSimulation(Converter.convertObjectToSnakeCaseJsonNode(simulation));
Expand Down Expand Up @@ -141,4 +151,16 @@ public Response createFromSimulationResult(
.build();
}
}

@GET
@Path("/{jobId}/partial-result")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.APPLICATION_JSON)
@Tag(name = "Stream partial/intermediate simulation result associated with run ID")
public Publisher<CalibrationIntermediateResults> stream(
@PathParam("jobId") final String jobId
) {
// return Multi.createFrom().publisher(events);
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
return Multi.createFrom().publisher(events).select().where(event -> event.getJobId == jobId);
}
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@ rabbitmq-username=${terarium-mq-username:terarium}
rabbitmq-password=${terarium-mq-password:terarium123}
mp.messaging.outgoing.user-event.connector=smallrye-rabbitmq
mp.messaging.outgoing.user-event.exchange.name=user-event
mp.messaging.incoming.simulations.connector=smallrye-rabbitmq
mp.messaging.incoming.simulations.queue.name=simulation-status
########################################################################################################################
googleanalytics.id=G-TWXM1CJCNM