Skip to content

Commit

Permalink
Merge pull request #1164 from lf-lang/restore-remote-rti
Browse files Browse the repository at this point in the history
Restore the ability to put the RTI on a remote machine
  • Loading branch information
edwardalee authored May 13, 2022
2 parents 29e1cda + c8c7499 commit 05084b5
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions org.lflang/src/org/lflang/federated/launcher/FedLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@

package org.lflang.federated.launcher;

import com.google.common.base.Objects;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.eclipse.xtext.xbase.lib.Exceptions;

import org.lflang.ErrorReporter;
import org.lflang.FileConfig;
import org.lflang.TargetConfig;
import org.lflang.TargetProperty;
import org.lflang.TargetProperty.ClockSyncMode;
import org.lflang.federated.FedFileConfig;
import org.lflang.federated.FederateInstance;
Expand Down Expand Up @@ -170,12 +168,12 @@ public void createLauncher(
target = user + "@" + host;
}

String RTILaunchString = getRtiCommand(federates);

shCode.append("#### Host is " + host);
// Launch the RTI in the foreground.
if (host.equals("localhost") || host.equals("0.0.0.0")) {
// FIXME: the paths below will not work on Windows
shCode.append(getLaunchCode(RTILaunchString) + "\n");
shCode.append(getLaunchCode(getRtiCommand(federates, false)) + "\n");
} else {
// Start the RTI on the remote machine.
// FIXME: Should $FEDERATION_ID be used to ensure unique directories, executables, on the remote host?
Expand All @@ -197,9 +195,9 @@ public void createLauncher(
// The cryptic 2>&1 reroutes stderr to stdout so that both are returned.
// The sleep at the end prevents screen from exiting before outgoing messages from
// the federate have had time to go out to the RTI through the socket.
RTILaunchString = getRtiCommand(federates);

shCode.append(getRemoteLaunchCode(host, target, logFileName, RTILaunchString) + "\n");
shCode.append(getRemoteLaunchCode(host, target, logFileName,
getRtiCommand(federates, true)) + "\n");
}

// Index used for storing pids of federates
Expand Down Expand Up @@ -317,10 +315,14 @@ private String getDistHeader() {
);
}

private String getRtiCommand(List<FederateInstance> federates) {
private String getRtiCommand(List<FederateInstance> federates, boolean isRemote) {
List<String> commands = new ArrayList<>();
if (isRemote) {
commands.add("RTI -i '${FEDERATION_ID}' \\");
} else {
commands.add("RTI -i ${FEDERATION_ID} \\");
}
commands.addAll(List.of(
"RTI -i ${FEDERATION_ID} \\",
" -n "+federates.size()+" \\",
" -c "+targetConfig.clockSync.toString()+" \\"
));
Expand Down Expand Up @@ -383,7 +385,7 @@ private String getRemoteLaunchCode(Object host, Object target, String logFileNam
"# Wait for the RTI to boot up before",
"# starting federates (this could be done by waiting for a specific output",
"# from the RTI, but here we use sleep)",
"sleep 1"
"sleep 5"
);
}

Expand Down

0 comments on commit 05084b5

Please sign in to comment.