Skip to content

Commit a7c7090

Browse files
committed
feat: adding online runtime behavior
1 parent fed0de4 commit a7c7090

File tree

25 files changed

+289
-141
lines changed

25 files changed

+289
-141
lines changed

.idea/codeStyles/Project.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/cirrina__run_.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compose.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3.7'
2+
configs:
3+
telegraf_config:
4+
file: ./telegraf.conf
5+
services:
6+
influxdb:
7+
image: "influxdb:2"
8+
ports:
9+
- "8086:8086"
10+
environment:
11+
- DOCKER_INFLUXDB_INIT_MODE=setup
12+
- DOCKER_INFLUXDB_INIT_USERNAME=admin
13+
- DOCKER_INFLUXDB_INIT_PASSWORD=adminadmin
14+
- DOCKER_INFLUXDB_INIT_ORG=org
15+
- DOCKER_INFLUXDB_INIT_BUCKET=bucket
16+
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=bzO10KmR8x
17+
telegraf:
18+
image: "telegraf:latest"
19+
ports:
20+
- "4317:4317"
21+
configs:
22+
- source: telegraf_config
23+
target: /etc/telegraf/telegraf.conf
24+
nats:
25+
image: "nats:latest"
26+
command:
27+
- "-js"
28+
ports:
29+
- "4222:4222"
30+
- "6222:6222"

src/main/java/at/ac/uibk/dps/cirrina/cirrina/CirrinaRuntime.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ public void run() {
4444

4545
logger.info("Starting runtime: {}", name);
4646

47-
// Run, will return when finished
48-
//runtime.run();
47+
runtime.startFromPath(
48+
EnvironmentVariables.INSTANCE.getCsmPath().get(),
49+
EnvironmentVariables.INSTANCE.getInstantiate().get()
50+
);
4951

5052
logger.info("Done running");
5153
}

src/main/java/at/ac/uibk/dps/cirrina/cirrina/EnvironmentVariables.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ object EnvironmentVariables {
3030
val natsPersistentContextUrl = EnvironmentVariable<String>("NATS_PERSISTENT_CONTEXT_URL", default = "nats://localhost:4222")
3131
val natsPersistentContextBucket = EnvironmentVariable<String>("NATS_PERSISTENT_CONTEXT_BUCKET", default = "persistent")
3232

33+
<<<<<<< Updated upstream
3334
// General environment variables
3435
val eventProvider = EnvironmentVariable<EventProvider>(name = "EVENT_PROVIDER", required = true, mapper = { value ->
3536
try {
@@ -48,6 +49,45 @@ object EnvironmentVariables {
4849
val healthPort = EnvironmentVariable<Int>("HEALTH_PORT", default = 0xCAFE) {
4950
it.toInt()
5051
}
52+
=======
53+
// General environment variables
54+
val csmPath = EnvironmentVariable<String>("CSM_PATH", required = true)
55+
val instantiate =
56+
EnvironmentVariable(
57+
name = "INSTANTIATE",
58+
default = emptyList(),
59+
mapper = { value -> value.split(",").map { it.trim() }.filter { it.isNotEmpty() } },
60+
)
61+
val eventProvider =
62+
EnvironmentVariable(
63+
name = "EVENT_PROVIDER",
64+
default = EventProvider.NATS,
65+
mapper = { value ->
66+
try {
67+
EventProvider.valueOf(value.uppercase())
68+
} catch (_: IllegalArgumentException) {
69+
throw IllegalStateException(
70+
"Invalid EVENT_PROVIDER: '$value'. Allowed: ${EventProvider.entries}"
71+
)
72+
}
73+
},
74+
)
75+
val persistentContextProvider =
76+
EnvironmentVariable(
77+
name = "PERSISTENT_CONTEXT_PROVIDER",
78+
default = PersistentContextProvider.NATS,
79+
mapper = { value ->
80+
try {
81+
PersistentContextProvider.valueOf(value.uppercase())
82+
} catch (_: IllegalArgumentException) {
83+
throw IllegalStateException(
84+
"Invalid PERSISTENT_CONTEXT_PROVIDER: '$value'. Allowed: ${PersistentContextProvider.entries}"
85+
)
86+
}
87+
},
88+
)
89+
val healthPort = EnvironmentVariable("HEALTH_PORT", default = 0xCAFE) { it.toInt() }
90+
>>>>>>> Stashed changes
5191
}
5292

5393

src/main/java/at/ac/uibk/dps/cirrina/classes/statemachine/StateMachineClass.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import at.ac.uibk.dps.cirrina.classes.transition.OnTransitionClass;
55
import at.ac.uibk.dps.cirrina.classes.transition.TransitionClass;
66
import at.ac.uibk.dps.cirrina.csml.description.Csml.ContextDescription;
7-
import at.ac.uibk.dps.cirrina.execution.object.action.InvokeAction;
8-
import at.ac.uibk.dps.cirrina.execution.object.action.RaiseAction;
7+
import at.ac.uibk.dps.cirrina.execution.object.action.EventRaisingAction;
98
import at.ac.uibk.dps.cirrina.execution.object.event.Event;
109
import at.ac.uibk.dps.cirrina.io.plantuml.Exportable;
1110
import at.ac.uibk.dps.cirrina.io.plantuml.PlantUmlVisitor;
@@ -192,31 +191,21 @@ public List<String> getInputEvents() {
192191
}
193192

194193
/**
195-
* Returns the events that may be raised from this state.
194+
* Returns the events that may be raised from this state machine.
196195
*
197196
* @return Output events.
198197
*/
199198
public List<Event> getOutputEvents() {
200199
return Stream.concat(
201-
// Raise action events
202-
Stream.concat(
203-
vertexSet()
204-
.stream()
205-
.flatMap(v -> v.getActionsOfType(RaiseAction.class).stream()),
206-
edgeSet()
207-
.stream()
208-
.flatMap(e -> e.getActionsOfType(RaiseAction.class).stream())
209-
).map(RaiseAction::getEvent),
210-
// Invoke action events
211-
Stream.concat(
212-
vertexSet()
213-
.stream()
214-
.flatMap(v -> v.getActionsOfType(InvokeAction.class).stream()),
215-
edgeSet()
216-
.stream()
217-
.flatMap(e -> e.getActionsOfType(InvokeAction.class).stream())
218-
).flatMap(invokeAction -> invokeAction.getDone().stream())
219-
).toList();
200+
vertexSet()
201+
.stream()
202+
.flatMap(v -> v.getActionsOfType(EventRaisingAction.class).stream()),
203+
edgeSet()
204+
.stream()
205+
.flatMap(e -> e.getActionsOfType(EventRaisingAction.class).stream())
206+
)
207+
.flatMap(action -> action.raises().stream())
208+
.toList();
220209
}
221210

222211
/**

src/main/java/at/ac/uibk/dps/cirrina/execution/command/ActionTimeoutResetCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public final class ActionTimeoutResetCommand extends ActionCommand {
1717

1818
@Override
1919
public List<ActionCommand> execute() throws UnsupportedOperationException {
20-
return List.of(this);
20+
// Handled in StateMachine
21+
return List.of();
2122
}
2223

2324
public TimeoutResetAction getTimeoutResetAction() {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package at.ac.uibk.dps.cirrina.execution.`object`.action
2+
3+
import at.ac.uibk.dps.cirrina.execution.`object`.event.Event
4+
5+
interface EventRaisingAction {
6+
fun raises(): List<Event>
7+
}

src/main/java/at/ac/uibk/dps/cirrina/execution/object/action/InvokeAction.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import at.ac.uibk.dps.cirrina.execution.object.context.ContextVariable;
55
import at.ac.uibk.dps.cirrina.execution.object.event.Event;
66
import java.util.List;
7+
import org.jetbrains.annotations.NotNull;
78

89
/**
910
* Invoke action, invokes a service type.
1011
*/
11-
public final class InvokeAction extends Action {
12+
public final class InvokeAction extends Action implements EventRaisingAction {
1213

1314
private final String serviceType;
1415

@@ -48,6 +49,12 @@ public List<ContextVariableReferenceDescription> getOutput() {
4849
return output;
4950
}
5051

52+
@Override
53+
@NotNull
54+
public List<Event> raises() {
55+
return done;
56+
}
57+
5158
public record Parameters(
5259
String serviceType,
5360
boolean isLocal,

src/main/java/at/ac/uibk/dps/cirrina/execution/object/action/MatchAction.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package at.ac.uibk.dps.cirrina.execution.object.action;
22

3+
import at.ac.uibk.dps.cirrina.execution.object.event.Event;
34
import at.ac.uibk.dps.cirrina.execution.object.expression.Expression;
5+
import java.util.List;
46
import java.util.Map;
7+
import org.jetbrains.annotations.NotNull;
58

6-
public final class MatchAction extends Action {
9+
public final class MatchAction extends Action implements EventRaisingAction {
710

811
private final Expression value;
912

@@ -22,5 +25,17 @@ public Map<Expression, Action> getCase() {
2225
return casee;
2326
}
2427

28+
@Override
29+
@NotNull
30+
public List<Event> raises() {
31+
return casee
32+
.values()
33+
.stream()
34+
.filter(a -> a instanceof EventRaisingAction)
35+
.map(a -> (EventRaisingAction) a)
36+
.flatMap(a -> a.raises().stream())
37+
.toList();
38+
}
39+
2540
public record Parameters(Expression value, Map<Expression, Action> casee) {}
2641
}

0 commit comments

Comments
 (0)