Skip to content

Commit

Permalink
xml is now a string
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Oct 22, 2024
1 parent 66fb633 commit 60d40ff
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 45 deletions.
8 changes: 5 additions & 3 deletions examples/compound_job_simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
simulation = wrench.Simulation()

# Starting the simulation, with this simulated process running on the host ControllerHost
simulation.start(platform_file_path, "ControllerHost")
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
simulation.start(xml_string, "ControllerHost")

hosts = simulation.get_all_hostnames()
print(f"Hosts in the platform are: {hosts}")
Expand Down Expand Up @@ -142,12 +144,12 @@

print("Synchronously waiting for the next simulation event...")
event = simulation.wait_for_next_event()
print(f" - Event: {event}")
print(f"\t- Event: {event}")
print(f"Time is {simulation.get_simulated_time()}")

print("Synchronously waiting for the next simulation event...")
event = simulation.wait_for_next_event()
print(f" - Event: {event}")
print(f"\t- Event: {event}")
print(f"Time is {simulation.get_simulated_time()}")

# print("Synchronously waiting for the next simulation event...")
Expand Down
8 changes: 5 additions & 3 deletions examples/json_workflow_simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ def main():
print(f"Starting the simulation using the XML platform file...")
current_dir = pathlib.Path(__file__).parent.resolve()
platform_file_path = pathlib.Path(current_dir / "one_host_and_several_clusters.xml")
simulation.start(platform_file_path, user_host)
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
simulation.start(xml_string, user_host)

# Get the list of all hostnames in the platform
print(f"Getting the list of all hostnames...")
list_of_hostnames = simulation.get_all_hostnames()

if not "UserHost" in list_of_hostnames:
if "UserHost" not in list_of_hostnames:
raise Exception("This simulator assumes that the XML platform files has a host with hostname UserHost that"
" has a disk mounted at '/'")
list_of_hostnames.remove("UserHost")
Expand Down Expand Up @@ -183,7 +185,7 @@ def main():
# Wait for next event
event = simulation.wait_for_next_event()
if event["event_type"] != "standard_job_completion":
print(f" - Event: {event}") # Should make sure it's a job completion
print(f"\t- Event: {event}") # Should make sure it's a job completion
raise wrench.WRENCHException("Received an unexpected event")
else:
completed_job = event["standard_job"]
Expand Down
11 changes: 6 additions & 5 deletions examples/simple_simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
simulation = wrench.Simulation()

# Starting the simulation, with this simulated process running on the host ControllerHost
simulation.start(platform_file_path, "ControllerHost")
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
simulation.start(xml_string, "ControllerHost")

print(f"Simulation, time is {simulation.get_simulated_time()}")

Expand Down Expand Up @@ -121,7 +123,7 @@
print("Getting simulation events that have occurred while I slept...")
events = simulation.get_events()
for event in events:
print(f" - Event: {event}")
print(f"\t- Event: {event}")

print("Creating another task")
task2 = workflow.add_task("task2", 100.0, 1, 1, 0)
Expand All @@ -131,7 +133,7 @@

print("Creating a VM on the cloud compute service...")
my_vm = ccs.create_vm(1, 100,
{"CloudComputeServiceProperty::VM_BOOT_OVERHEAD": "5s"},{})
{"CloudComputeServiceProperty::VM_BOOT_OVERHEAD": "5s"}, {})

print("Starting the VM...")
vm_cs = my_vm.start()
Expand All @@ -141,7 +143,7 @@

print("Synchronously waiting for the next simulation event...")
event = simulation.wait_for_next_event()
print(f" - Event: {event}")
print(f"\t- Event: {event}")

print(f"Time is {simulation.get_simulated_time()}")

Expand All @@ -158,7 +160,6 @@
# if (my_sleep_action_1.get_state_as_string() == "RUNNING"):
# print("Action is still running!")


print("Terminating simulation")

simulation.terminate()
Expand Down
4 changes: 3 additions & 1 deletion tests/bare_metal_compute_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

simulation = wrench.Simulation()

with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
try:
simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")
except wrench.WRENCHException as e:
sys.stderr.write(f"Error: {e}\n")
exit(1)
Expand Down
4 changes: 3 additions & 1 deletion tests/batch_compute_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
platform_file_path = pathlib.Path(current_dir / "sample_platform.xml")

simulation = wrench.Simulation()
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
try:
simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")
except wrench.WRENCHException as e:
sys.stderr.write(f"Error: {e}\n")
exit(1)
Expand Down
4 changes: 3 additions & 1 deletion tests/cloud_compute_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
platform_file_path = pathlib.Path(current_dir / "sample_platform.xml")

simulation = wrench.Simulation()
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
try:
simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")
except wrench.WRENCHException as e:
sys.stderr.write(f"Error: {e}\n")
exit(1)
Expand Down
4 changes: 3 additions & 1 deletion tests/compound_job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
simulation = wrench.Simulation()

# Starting the simulation, with this simulated process running on the host ControllerHost
simulation.start(platform_file_path, "ControllerHost")
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
simulation.start(xml_string, "ControllerHost")

# Creating a compute services
bmcs = simulation.create_bare_metal_compute_service(
Expand Down
4 changes: 3 additions & 1 deletion tests/file_registry_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

simulation = wrench.Simulation()

with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
try:
simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")
except wrench.WRENCHException as e:
sys.stderr.write(f"Error: {e}\n")
exit(1)
Expand Down
4 changes: 3 additions & 1 deletion tests/simulation_events_test.py_DISABLED
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ if __name__ == "__main__":
platform_file_path = pathlib.Path(current_dir / "sample_platform.xml")

simulation = wrench.Simulation()
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()

try:
simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")
except wrench.WRENCHException as e:
sys.stderr.write(f"Error: {e}\n")
exit(1)
Expand Down
4 changes: 3 additions & 1 deletion tests/storage_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

simulation = wrench.Simulation()

simulation.start(platform_file_path, "ControllerHost")
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
simulation.start(xml_string, "ControllerHost")

ss = simulation.create_simple_storage_service("StorageHost", ["/"])
# Coverage
Expand Down
4 changes: 3 additions & 1 deletion tests/workflow_job_task_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
platform_file_path = pathlib.Path(current_dir / "sample_platform.xml")

simulation = wrench.Simulation()
with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
try:
simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")
except wrench.WRENCHException as e:
sys.stderr.write(f"Error: {e}\n")
exit(1)
Expand Down
18 changes: 12 additions & 6 deletions tests/workflow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,27 @@

simulation = wrench.Simulation()

with open(platform_file_path, "r") as platform_file:
bogus_xml_string = platform_file.read() + "BOGUS"
try:
simulation_bogus = wrench.Simulation()
simulation_bogus.start(pathlib.Path("bogus/path/to/file"), "ControllerHost")
raise wrench.WRENCHException("Should be able to start a simulation with a bogus xml file")
simulation_bogus.start(bogus_xml_string, "ControllerHost")
raise wrench.WRENCHException("Should be able to start a simulation with a bogus xml")
except wrench.WRENCHException as e:
pass

with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
try:
simulation_bogus = wrench.Simulation()
simulation_bogus.start(platform_file_path, "ControllerHost_BOGUS")
simulation_bogus.start(xml_string, "ControllerHost_BOGUS")
raise wrench.WRENCHException("Should be able to start a simulation with a bogus xml file")
except wrench.WRENCHException as e:
pass

simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")
# Bogus restart that does nothing
simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")

workflow1 = simulation.create_workflow()
file1 = simulation.add_file("file1", 1024)
Expand Down Expand Up @@ -97,8 +101,10 @@

simulation.terminate()

with open(platform_file_path, "r") as platform_file:
xml_string = platform_file.read()
try:
simulation.start(platform_file_path, "ControllerHost")
simulation.start(xml_string, "ControllerHost")
raise wrench.WRENCHException("Shouldn't be able to restart a simulation")
except wrench.WRENCHException as e:
pass
Expand Down
2 changes: 1 addition & 1 deletion wrench/compound_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def add_file_write_action(self, name: str, file: File, storage_service: StorageS
return self._simulation._add_file_write_action(self, name, file, storage_service)

def add_file_read_action(self, name: str, file: File, storage_service: StorageService,
num_bytes_to_read=-1.0) -> FileReadAction:
num_bytes_to_read=0.0) -> FileReadAction:
"""
Add a file write action to the compound job
Expand Down
30 changes: 11 additions & 19 deletions wrench/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ def __send_request_to_daemon(requests_method, route, json_data):
r = requests_method(route, json=json_data)
return r
except Exception as e: # pragma no cover
raise WRENCHException("Connection to wrench-daemon severed: " + str(e) + "\n"
"This could be an error on the "
"wrench-daemon side (likely an uncaught maestro exception, e.g., a deadlock). Enable "
"logging with the --simulation-logging and --daemon-logging "
"command-line arguments")
raise WRENCHException("Connection to wrench-daemon severed: " +
str(e) + "\n"
"This could be an error on the "
"wrench-daemon side (likely an uncaught maestro exception, e.g., a deadlock). Enable "
"logging with the --simulation-logging and --daemon-logging "
"command-line arguments")

def start(self, platform_file_path: pathlib.Path,
controller_hostname: str) -> None:
def start(self, platform_xml: str, controller_hostname: str) -> None:
"""
Start a new simulation (will do nothing if simulation has already started)
:param platform_file_path: path of a file that contains the simulated platform's description in XML
:type platform_file_path: pathlib.Path
:param platform_xml: platform description string in XML
:type platform_xml: str
:param controller_hostname: the name of the (simulated) host in the platform on which the
simulation controller will run
:type controller_hostname: str
Expand All @@ -108,14 +108,7 @@ def start(self, platform_file_path: pathlib.Path,
raise WRENCHException("This simulation has been terminated.")

if not self.started:
# Read the platform XML
try:
with open(platform_file_path, "r") as platform_file:
xml = platform_file.read()
except Exception as e:
raise WRENCHException(f"Cannot read platform file '{platform_file_path.absolute().name}' ({str(e)})")

self.spec = {"platform_xml": xml, "controller_hostname": controller_hostname}
self.spec = {"platform_xml": platform_xml, "controller_hostname": controller_hostname}
try:
r = requests.post(f"{self.daemon_url}/startSimulation", json=self.spec)
except Exception: # pragma: no cover
Expand Down Expand Up @@ -1627,8 +1620,7 @@ def _add_entry_to_file_registry_service(self, file_registry_service: FileRegistr
raise WRENCHException(response["failure_cause"])
return

def _lookup_entry_in_file_registry_service(self, file_registry_service: FileRegistryService, file: File) -> List[
StorageService]:
def _lookup_entry_in_file_registry_service(self, file_registry_service: FileRegistryService, file: File) -> List[StorageService]:
"""
Blah
:param file_registry_service:
Expand Down
1 change: 1 addition & 0 deletions wrench/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from typing import List


# noinspection GrazieInspection
class Workflow(SimulationItem):
"""
Expand Down

0 comments on commit 60d40ff

Please sign in to comment.