Skip to content

Commit

Permalink
feat: throw error if omnetpp.ini file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
hoelger committed Nov 6, 2024
1 parent 695fc1c commit 6d88aea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

import org.apache.commons.lang3.ObjectUtils;

import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.annotation.Nonnull;

/**
Expand All @@ -43,8 +46,11 @@ public OmnetppAmbassador(AmbassadorParameter ambassadorParameter) {

@Nonnull
@Override
public FederateExecutor createFederateExecutor(String host, int port, OperatingSystem os) {
String omnetppConfigFileName = ObjectUtils.defaultIfNull(config.federateConfigurationFile, "omnetpp.ini");
public FederateExecutor createFederateExecutor(String host, int port, OperatingSystem os) throws FileNotFoundException {
String omnetppConfigFileName = ObjectUtils.defaultIfNull(config.federateConfigurationFile, "omnetpp.ini"); // default // this one is required
if(!Files.exists(Paths.get(this.ambassadorParameter.configuration.getParent(), omnetppConfigFileName))) {
throw new FileNotFoundException(omnetppConfigFileName + " missing");
}
String omnetppConfigFilePath = "omnetpp-federate/simulations/" + omnetppConfigFileName;
String inetSourceDirectories = "inet:omnetpp-federate/src";
switch (os) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.concurrent.PriorityBlockingQueue;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -210,7 +211,7 @@ public DockerFederateExecutor createDockerFederateExecutor(String imageName, CLo
*/
@Nonnull
@Override
public FederateExecutor createFederateExecutor(String host, int port, CLocalHost.OperatingSystem os) {
public FederateExecutor createFederateExecutor(String host, int port, CLocalHost.OperatingSystem os) throws FileNotFoundException {
log.trace("createFederateStarter(String host, int port, CLocalHost.OperatingSystem os); host: {}, port: {}, os: {}", host, port, os);
return new NopFederateExecutor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.mosaic.rti.api.parameters.FederateDescriptor;
import org.eclipse.mosaic.rti.config.CLocalHost.OperatingSystem;

import java.io.FileNotFoundException;
import java.io.InputStream;
import javax.annotation.Nonnull;

Expand All @@ -41,7 +42,7 @@ public interface FederateAmbassador extends Comparable<FederateAmbassador> {
* @return the {@link FederateExecutor} which starts the federate
*/
@Nonnull
FederateExecutor createFederateExecutor(String host, int port, OperatingSystem os);
FederateExecutor createFederateExecutor(String host, int port, OperatingSystem os) throws FileNotFoundException;

/**
* If the federate or simulator can be executed as a docker container, this method returns a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private FederateDescriptor loadFederate(Path scenarioDirectory, CRuntime.CFedera
return descriptor;
}

private void initializeFederate(CRuntime.CFederate federate, FederateDescriptor descriptor) {
private void initializeFederate(CRuntime.CFederate federate, FederateDescriptor descriptor) throws FileNotFoundException {

final FederateAmbassador ambassador = descriptor.getAmbassador();
final CLocalHost host = descriptor.getHost();
Expand Down

0 comments on commit 6d88aea

Please sign in to comment.