def main(): identity = experimentlib.create_identity_from_key_files(PUBLICKEY_FILENAME, PRIVATEKEY_FILENAME) nodelocation_list = experimentlib.lookup_node_locations_by_identity(identity) print("Number of advertising nodes: " + str(len(nodelocation_list))) vesselhandle_list = experimentlib.find_vessels_on_nodes(identity, nodelocation_list) print("Number of active vessels: " + str(len(vesselhandle_list))) # Note that we could use experimentlib.run_parallelized() to parallelize # this, but for simplicity we do each sequentially. for vesselhandle in vesselhandle_list: try: nodeid, vesselname = experimentlib.get_nodeid_and_vesselname(vesselhandle) nodelocation = experimentlib.get_node_location(nodeid) # Note: you may want to reset_vessel(). experimentlib.upload_file_to_vessel(vesselhandle, identity, PROGRAM_FILE) print("Uploaded " + PROGRAM_FILE + " to " + nodelocation + " vessel " + vesselname) experimentlib.start_vessel(vesselhandle, identity, PROGRAM_FILE, ARGUMENTS_TO_START_PROGRAM_WITH) print("Program started on " + nodelocation + " vessel " + vesselname) except experimentlib.SeattleExperimentError, e: print("Failure on vessel " + vesselhandle + ". Error was: " + str(e))
def _run_on_vessels(self, vessel, filename, *vessel_args): try: vessel_args = [str(arg) for arg in list(vessel_args)] explib.start_vessel(vessel, self.config["identity"], filename, vessel_args) except explib.SeattleExperimentError: self.logger.error("Failed to start '" + filename + "' on vessel " + self.vessel_location(vessel)) else: self.logger.debug("Successfully started '" + filename + "' on vessel " + self.vessel_location(vessel)) self.successful_handlers.append(vessel)
def _run_on_vessels(self, vessel, filename, *vessel_args): try: vessel_args = [str(arg) for arg in list(vessel_args)] explib.start_vessel(vessel, self.config['identity'], filename, vessel_args) except explib.SeattleExperimentError: self.logger.error("Failed to start '" + filename + "' on vessel " + self.vessel_location(vessel)) else: self.logger.debug("Successfully started '" + filename + "' on vessel " + self.vessel_location(vessel)) self.successful_handlers.append(vessel)
def run_on_vessels(vesselhandle_list, filename, *args): """ <Purpose> Runs a program on a set of vessels. A batch wrapper around the Experiment Library function run_parallelized, with logging support. <Arguments> vesselhandle_list A list of vesselhandles of vessels to which a file is to be uploaded. filename The filename of the program to run. *args Optional additional arguments required by the program to be run on vessels. <Exceptions> None <Side Effects> None <Returns> A tuple of: (successlist, failurelist) where successlist and failedlist are lists of vesselhandles of vessels on which the program succeeded and failed to run, respectively. """ # Log the fact that program execution is occurring config['logfile'].write(str(time.time()) + ': Starting program on ' + str(len(vesselhandle_list)) + ' vessel(s)...\n') config['logfile'].flush() # Initialize empty return lists success_list = [] failed_list = [] # Attempt to run program on each vessel for vh in vesselhandle_list: try: # Note: list comp used to turn *args tuple into list of strings explib.start_vessel(vh, config['identity'], filename, [str(i) for i in list(args)]) except explib.SeattleExperimentError, e: # If failure detected, add vessel to failed_list failed_list.append(vh) else: # If execution successful, add vessel to success_list success_list.append(vh)
def main(): identity = experimentlib.create_identity_from_key_files( PUBLICKEY_FILENAME, PRIVATEKEY_FILENAME) nodelocation_list = experimentlib.lookup_node_locations_by_identity( identity) print("Number of advertising nodes: " + str(len(nodelocation_list))) vesselhandle_list = experimentlib.find_vessels_on_nodes( identity, nodelocation_list) print("Number of active vessels: " + str(len(vesselhandle_list))) # Note that we could use experimentlib.run_parallelized() to parallelize # this, but for simplicity we do each sequentially. for vesselhandle in vesselhandle_list: try: nodeid, vesselname = experimentlib.get_nodeid_and_vesselname( vesselhandle) nodelocation = experimentlib.get_node_location(nodeid) # Note: you may want to reset_vessel(). experimentlib.upload_file_to_vessel(vesselhandle, identity, PROGRAM_FILE) print("Uploaded " + PROGRAM_FILE + " to " + nodelocation + " vessel " + vesselname) experimentlib.start_vessel(vesselhandle, identity, PROGRAM_FILE, ARGUMENTS_TO_START_PROGRAM_WITH) print("Program started on " + nodelocation + " vessel " + vesselname) except experimentlib.SeattleExperimentError, e: print("Failure on vessel " + vesselhandle + ". Error was: " + str(e))