Skip to content

Commit 10376ef

Browse files
committed
Submitted containerIDs altered
1 parent d4b2458 commit 10376ef

File tree

5 files changed

+118
-9
lines changed

5 files changed

+118
-9
lines changed

src/main/java/org/hobbit/sdk/examples/dummybenchmark/test/DummyBenchmarkTestRunner.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,19 @@ private void checkHealth(Boolean dockerize) throws Exception {
126126

127127
//comment the .systemAdapter(systemAdapter) line below to use the code for running from python
128128
commandQueueListener.setCommandReactions(
129-
commandReactionsBuilder.buildDockerCommandsReaction(),
129+
commandReactionsBuilder.buildStartCommandsReaction(),
130+
commandReactionsBuilder.buildTerminateCommandsReaction(),
130131
commandReactionsBuilder.buildPlatformCommandsReaction()
131132
);
132133

133134
componentsExecutor.submit(commandQueueListener);
134135
commandQueueListener.waitForInitialisation();
135136

136-
commandQueueListener.createContainer(DUMMY_BENCHMARK_IMAGE_NAME, new String[]{ HOBBIT_EXPERIMENT_URI_KEY+"="+EXPERIMENT_URI, Constants.BENCHMARK_PARAMETERS_MODEL_KEY+"="+ createBenchmarkParameters() });
137-
commandQueueListener.createContainer(systemImageName, new String[]{ Constants.SYSTEM_PARAMETERS_MODEL_KEY+"="+ createSystemParameters() });
137+
String benchmarkContainerId = commandQueueListener.createContainer(DUMMY_BENCHMARK_IMAGE_NAME, new String[]{ HOBBIT_EXPERIMENT_URI_KEY+"="+EXPERIMENT_URI, Constants.BENCHMARK_PARAMETERS_MODEL_KEY+"="+ createBenchmarkParameters() });
138+
String systemContainerId = commandQueueListener.createContainer(systemImageName, new String[]{ Constants.SYSTEM_PARAMETERS_MODEL_KEY+"="+ createSystemParameters() });
139+
140+
environmentVariables.set("BENCHMARK_CONTAINER_ID", benchmarkContainerId);
141+
environmentVariables.set("SYSTEM_CONTAINER_ID", systemContainerId);
138142

139143
commandQueueListener.waitForTermination();
140144
commandQueueListener.terminate();

src/main/java/org/hobbit/sdk/utils/commandreactions/CommandReactionsBuilder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ public CommandReactionsBuilder evalModuleImageName(String value){
105105
return this;
106106
}
107107

108-
public DockerCommandsReaction buildDockerCommandsReaction(){
109-
return new DockerCommandsReaction(this);
108+
public StartContainerCommandReaction buildStartCommandsReaction(){
109+
return new StartContainerCommandReaction(this);
110+
}
111+
112+
public TerminateContainerCommandReaction buildTerminateCommandsReaction(){
113+
return new TerminateContainerCommandReaction(this);
110114
}
111115

112116
public PlatformCommandsReaction buildPlatformCommandsReaction(){

src/main/java/org/hobbit/sdk/utils/commandreactions/PlatformCommandsReaction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public PlatformCommandsReaction(CommandReactionsBuilder builder){
7373
@Override
7474
public void handleCmd(Byte command, byte[] bytes, String replyTo) throws Exception {
7575

76-
7776
if (command == Commands.BENCHMARK_FINISHED_SIGNAL){
7877
logger.debug("BENCHMARK_FINISHED_SIGNAL received");
7978
try {
@@ -108,6 +107,8 @@ public void handleCmd(Byte command, byte[] bytes, String replyTo) throws Excepti
108107
if (command == Commands.SYSTEM_READY_SIGNAL) {
109108
systemReady = true;
110109
logger.debug("SYSTEM_READY_SIGNAL signal received");
110+
if(!System.getenv().containsKey("SYSTEM_CONTAINER_ID"))
111+
throw new Exception("SYSTEM_CONTAINER_ID is not specified as env variable. Specify it where you submit system/create system container in checkHealth");
111112
}
112113

113114
synchronized (this){
@@ -120,7 +121,7 @@ public void handleCmd(Byte command, byte[] bytes, String replyTo) throws Excepti
120121
try {
121122
logger.debug("sending START_BENCHMARK_SIGNAL");
122123

123-
new CommandSender(Commands.START_BENCHMARK_SIGNAL, systemAdapterImageName+"_0").send();
124+
new CommandSender(Commands.START_BENCHMARK_SIGNAL, System.getenv().get("SYSTEM_CONTAINER_ID")).send();
124125
} catch (Exception e) {
125126
logger.error(e.getMessage());
126127
//Assert.fail(e.getMessage());

src/main/java/org/hobbit/sdk/utils/commandreactions/DockerCommandsReaction.java renamed to src/main/java/org/hobbit/sdk/utils/commandreactions/StartContainerCommandReaction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222

23-
public class DockerCommandsReaction implements CommandReaction {
23+
public class StartContainerCommandReaction implements CommandReaction {
2424
private static final Logger logger = LoggerFactory.getLogger(PlatformCommandsReaction.class);
2525

2626
private ComponentsExecutor componentsExecutor;
@@ -50,7 +50,7 @@ public class DockerCommandsReaction implements CommandReaction {
5050
private Map<String, Integer> customContainersRunning = new HashMap<>();
5151
//private String systemContainerId = null;
5252

53-
public DockerCommandsReaction(CommandReactionsBuilder builder){
53+
public StartContainerCommandReaction(CommandReactionsBuilder builder){
5454
this.componentsExecutor = builder.componentsExecutor;
5555
this.commandQueueListener = builder.commandQueueListener;
5656

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package org.hobbit.sdk.utils.commandreactions;
2+
3+
import com.google.gson.Gson;
4+
import com.rabbitmq.client.MessageProperties;
5+
import org.hobbit.core.Commands;
6+
import org.hobbit.core.components.Component;
7+
import org.hobbit.core.data.StartCommandData;
8+
import org.hobbit.core.rabbit.RabbitMQUtils;
9+
import org.hobbit.sdk.docker.AbstractDockerizer;
10+
import org.hobbit.sdk.utils.CommandQueueListener;
11+
import org.hobbit.sdk.utils.CommandSender;
12+
import org.hobbit.sdk.utils.ComponentsExecutor;
13+
import org.junit.Assert;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
16+
17+
import java.nio.ByteBuffer;
18+
import java.util.ArrayList;
19+
import java.util.Arrays;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
public class TerminateContainerCommandReaction implements CommandReaction {
24+
private static final Logger logger = LoggerFactory.getLogger(PlatformCommandsReaction.class);
25+
26+
27+
28+
public TerminateContainerCommandReaction(CommandReactionsBuilder builder){
29+
30+
//
31+
32+
33+
}
34+
35+
@Override
36+
public void handleCmd(Byte command, byte[] bytes, String replyTo) throws Exception {
37+
38+
39+
if(command==Commands.DOCKER_CONTAINER_TERMINATED){
40+
CommandSender commandSender = null;
41+
ByteBuffer buffer = ByteBuffer.wrap(bytes);
42+
String containerName = RabbitMQUtils.readString(buffer);
43+
44+
logger.debug("DOCKER_CONTAINER_TERMINATED {} received", containerName);
45+
46+
if(!System.getenv().containsKey("BENCHMARK_CONTAINER_ID"))
47+
throw new Exception("BENCHMARK_CONTAINER_ID is not specified as env variable. Specify it where you submit benchmark/create benchmark container in checkHealth");
48+
49+
String commandToSend = null;
50+
// //if(containerName.equals(dataGenContainerId))
51+
// if(dataGeneratorImageName!=null && containerName.startsWith(dataGeneratorImageName)){
52+
// dataGeneratorsCount--;
53+
// if(dataGeneratorsCount==0) {
54+
// //commandSender = new CommandSender(Commands.DATA_GENERATION_FINISHED);
55+
// //commandToSend = "DATA_GENERATION_FINISHED";
56+
// }
57+
// }
58+
//
59+
// //if(containerName.equals(taskGenContainerId))
60+
// if(taskGeneratorImageName!=null && containerName.startsWith(taskGeneratorImageName)) {
61+
// taskGeneratorsCount--;
62+
// if(taskGeneratorsCount==0){
63+
// //commandSender = new CommandSender(Commands.TASK_GENERATION_FINISHED);
64+
// //commandToSend = "TASK_GENERATION_FINISHED";
65+
// }
66+
// }
67+
//
68+
// if(containerName.equals(systemAdapterImageName)){
69+
// //if(systemContainersCount>0) {
70+
// systemContainersCount--;
71+
// //if (systemContainersCount == 0) {
72+
// //commandSender = new CommandSender(Commands.DOCKER_CONTAINER_TERMINATED, systemAdapterImageName.getBytes());
73+
// //commandToSend = "SYSTEM_CONTAINERS_FINISHED";
74+
// //}
75+
// //}
76+
// }
77+
78+
if(containerName.equals(System.getenv().get("BENCHMARK_CONTAINER_ID"))){
79+
commandSender = new CommandSender(Commands.BENCHMARK_FINISHED_SIGNAL);
80+
commandToSend = "BENCHMARK_FINISHED_SIGNAL";
81+
}
82+
83+
synchronized (this){
84+
if (commandSender!=null){
85+
try {
86+
logger.debug("Sending "+commandToSend+" signal");
87+
commandSender.send();
88+
} catch (Exception e) {
89+
//Assert.fail(e.getMessage());
90+
logger.error(e.getMessage());
91+
}
92+
}
93+
}
94+
}
95+
96+
97+
}
98+
99+
100+
}

0 commit comments

Comments
 (0)