def main():

  monitorhandle = None
 
  while True: 
    identity = experimentlib.create_identity_from_key_files(PUBLICKEY_FILENAME)

    # Get a list of nodes advertising under the public key. Some of these
    # nodes may be unreachable or may have gone offline since they advertised.
    # This won't try to communicate with the actual nodes.
    nodelocation_list = experimentlib.lookup_node_locations_by_identity(identity)
    
    # Contact each node and find out which vessels are usable by this identity/key. 
    vesselhandle_list = experimentlib.find_vessels_on_nodes(identity, nodelocation_list)
  
    print("Lookup and vessel discovery shows " + str(len(vesselhandle_list)) + " active vessels.")

    # Either register a monitor if this is the first time through the loop or
    # just add the vesselhandles to the existing monitor. Adding the vesselhandles
    # will not remove the old one and duplicates will be ignored.
    if monitorhandle is None:
      monitorhandle = vesselstatusmonitor.register_vessel_status_monitor(identity, vesselhandle_list, vessel_status_callback,
                                                                         waittime=MONITOR_SLEEP_SECONDS)
      print("Vessel status monitor registered.")
    else:
      vesselstatusmonitor.add_to_vessel_status_monitor(monitorhandle, vesselhandle_list)  

    time.sleep(LOOKUP_SLEEP_SECONDS)
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))
Beispiel #3
0
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 the
  # uploading of files and speed things up, but for simplicity we do each
  # upload sequentially.

  for vesselhandle in vesselhandle_list:
    try:
      nodeid, vesselname = experimentlib.get_nodeid_and_vesselname(vesselhandle)
      nodelocation = experimentlib.get_node_location(nodeid)
      
      for local_filename in FILES_TO_UPLOAD:
        experimentlib.upload_file_to_vessel(vesselhandle, identity, local_filename)
        print("Uploaded " + local_filename + " to " + nodelocation + " vessel " + vesselname)
      
    except experimentlib.SeattleExperimentError, e:
      print("Failure on vessel " + vesselhandle + ". Error was: " + str(e))
Beispiel #4
0
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)))

    for vesselhandle in vesselhandle_list:
        try:
            # Generate the vessel directory name with format: host_port_vesselname
            nodeid, vesselname = experimentlib.get_nodeid_and_vesselname(
                vesselhandle)
            nodelocation = experimentlib.get_node_location(nodeid)
            host, port = experimentlib.get_host_and_port(nodelocation)
            dirname = host + "_" + str(port) + "_" + vesselname

            # Create the vessel directory if it doesn't already exist.
            vessel_directory = os.path.join(DOWNLOAD_DIRECTORY, dirname)
            if not os.path.exists(vessel_directory):
                os.mkdir(vessel_directory)

            # Get a list of files on the vessel.
            filelist = experimentlib.get_vessel_file_list(
                vesselhandle, identity)

            print("Files on " + nodelocation + " " + vesselname + ": " +
                  str(filelist))

            for remote_filename in filelist:
                local_filename = os.path.join(vessel_directory,
                                              remote_filename)
                experimentlib.download_file_from_vessel(
                    vesselhandle, identity, remote_filename, local_filename)
                print("Downloaded " + local_filename)

        except experimentlib.SeattleExperimentError, e:
            print("Failure on vessel " + vesselhandle + ". Error was: " +
                  str(e))
Beispiel #5
0
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 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)))

  for vesselhandle in vesselhandle_list:
    try:
      # Generate the vessel directory name with format: host_port_vesselname
      nodeid, vesselname = experimentlib.get_nodeid_and_vesselname(vesselhandle)
      nodelocation = experimentlib.get_node_location(nodeid)
      host, port = experimentlib.get_host_and_port(nodelocation)
      dirname = host + "_" + str(port) + "_" + vesselname
      
      # Create the vessel directory if it doesn't already exist.
      vessel_directory = os.path.join(DOWNLOAD_DIRECTORY, dirname)
      if not os.path.exists(vessel_directory):
        os.mkdir(vessel_directory)
        
      # Get a list of files on the vessel.
      filelist = experimentlib.get_vessel_file_list(vesselhandle, identity)
      
      print("Files on " + nodelocation + " " + vesselname + ": " + str(filelist))
      
      for remote_filename in filelist:
        local_filename = os.path.join(vessel_directory, remote_filename)
        experimentlib.download_file_from_vessel(vesselhandle, identity, remote_filename, local_filename)
        print("Downloaded " + local_filename)
        
    except experimentlib.SeattleExperimentError, e:
      print("Failure on vessel " + vesselhandle + ". Error was: " + str(e))
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)))

    for vesselhandle in vesselhandle_list:
        try:
            nodeid, vesselname = experimentlib.get_nodeid_and_vesselname(vesselhandle)
            nodelocation = experimentlib.get_node_location(nodeid)

            print("====================================================================")
            print("Log from " + nodelocation + " " + vesselname)
            logcontents = experimentlib.get_vessel_log(vesselhandle, identity)
            print(logcontents)

        except experimentlib.SeattleExperimentError, e:
            print("Failure on vessel " + vesselhandle + ". Error was: " + str(e))
Beispiel #8
0
def main():

    monitorhandle = None

    while True:
        identity = experimentlib.create_identity_from_key_files(
            PUBLICKEY_FILENAME)

        # Get a list of nodes advertising under the public key. Some of these
        # nodes may be unreachable or may have gone offline since they advertised.
        # This won't try to communicate with the actual nodes.
        nodelocation_list = experimentlib.lookup_node_locations_by_identity(
            identity)

        # Contact each node and find out which vessels are usable by this identity/key.
        vesselhandle_list = experimentlib.find_vessels_on_nodes(
            identity, nodelocation_list)

        print("Lookup and vessel discovery shows " +
              str(len(vesselhandle_list)) + " active vessels.")

        # Either register a monitor if this is the first time through the loop or
        # just add the vesselhandles to the existing monitor. Adding the vesselhandles
        # will not remove the old one and duplicates will be ignored.
        if monitorhandle is None:
            monitorhandle = vesselstatusmonitor.register_vessel_status_monitor(
                identity,
                vesselhandle_list,
                vessel_status_callback,
                waittime=MONITOR_SLEEP_SECONDS)
            print("Vessel status monitor registered.")
        else:
            vesselstatusmonitor.add_to_vessel_status_monitor(
                monitorhandle, vesselhandle_list)

        time.sleep(LOOKUP_SLEEP_SECONDS)
Beispiel #9
0
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)))

  for vesselhandle in vesselhandle_list:
    try:
      nodeid, vesselname = experimentlib.get_nodeid_and_vesselname(vesselhandle)
      nodelocation = experimentlib.get_node_location(nodeid)
      
      print("====================================================================")
      print("Log from " + nodelocation + " " + vesselname)
      logcontents = experimentlib.get_vessel_log(vesselhandle, identity)
      print(logcontents)
        
    except experimentlib.SeattleExperimentError, e:
      print("Failure on vessel " + vesselhandle + ". Error was: " + str(e))
def main():

    identity = experimentlib.create_identity_from_key_files(PUBLICKEY_FILENAME, PRIVATEKEY_FILENAME)

    # Get a list of nodes advertising under the public key. Some of these
    # nodes may be unreachable or may have gone offline since they advertised.
    # This won't try to communicate with the actual nodes.
    nodelocation_list = experimentlib.lookup_node_locations_by_identity(identity)

    print("nodelocation_list:" + str(nodelocation_list))

    # Talk to each advertising node to find out which vessels we have on each.
    # We get back a list of dictionaries, where each dictionary describes a
    # vessel. There may be multiple vessels from any single node in this list.
    active_vesselhandle_list = experimentlib.find_vessels_on_nodes(identity, nodelocation_list)

    print("active_vesselhandle_list:" + str(active_vesselhandle_list))

    # Now we want to find out which vessels we've acquired through seattlegeni
    # that are not in our list. We may, for example, want to release those
    # vessels because we consider them unusable.

    try:
        expected_vesselhandle_list = experimentlib.seattlegeni_get_acquired_vessels(identity)

        print("expected_vesselhandle_list:" + str(expected_vesselhandle_list))

        # If we already have enough usable vessels, we're done.
        if len(active_vesselhandle_list) >= MIN_VESSELS_TO_KEEP:
            print(
                "There are already "
                + str(len(active_vesselhandle_list))
                + " active vessels "
                + "and our MIN_VESSELS_TO_KEEP is "
                + str(MIN_VESSELS_TO_KEEP)
            )
            return

        # We assume all of our vessels come from seattlegeni, so if any vessels we
        # should have access to according to seattlegeni aren't accessible or
        # otherwise usable, then release them.
        vesselhandles_to_release = []
        for vesselhandle in expected_vesselhandle_list:
            if vesselhandle not in active_vesselhandle_list:
                vesselhandles_to_release.append(vesselhandle)

        if vesselhandles_to_release:
            print(
                str(len(vesselhandles_to_release))
                + " vessels were inaccessible, so will try to release them:"
                + str(vesselhandles_to_release)
            )
            try:
                experimentlib.seattlegeni_release_vessels(identity, vesselhandles_to_release)
            except experimentlib.SeattleClearinghouseError, e:
                print("Failed to release vessels: " + str(e))
            else:
                print("Vessels successfully released.")

        # Determine the maximum number of vessels we can acquire through seattlegeni.
        max_vessels_allowed = experimentlib.seattlegeni_max_vessels_allowed(identity)
        print("max_vessels_allowed: " + str(max_vessels_allowed))

        # Determine the number of vessels we already have acquired through seattlegeni.
        num_currently_acquired = len(experimentlib.seattlegeni_get_acquired_vessels(identity))
        print("currently_acquired_count: " + str(num_currently_acquired))

        # Let's try to get as close to MIN_VESSELS_TO_KEEP without requesting more
        # than is allowed by this account.
        num_vessels_to_request = min(max_vessels_allowed, MIN_VESSELS_TO_KEEP) - num_currently_acquired

        if num_vessels_to_request <= 0:
            print("This account doesn't have enough vessel credits to request more vessels.")
            return
        else:
            print("Will try to acquire " + str(num_vessels_to_request) + " vessels.")

        vessel_type = experimentlib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_WAN
        acquired_vessels = experimentlib.seattlegeni_acquire_vessels(identity, vessel_type, num_vessels_to_request)

        print("Acquired " + str(num_vessels_to_request) + " vessels: " + str(acquired_vessels))
def main():

    identity = experimentlib.create_identity_from_key_files(
        PUBLICKEY_FILENAME, PRIVATEKEY_FILENAME)

    # Get a list of nodes advertising under the public key. Some of these
    # nodes may be unreachable or may have gone offline since they advertised.
    # This won't try to communicate with the actual nodes.
    nodelocation_list = experimentlib.lookup_node_locations_by_identity(
        identity)

    print("nodelocation_list:" + str(nodelocation_list))

    # Talk to each advertising node to find out which vessels we have on each.
    # We get back a list of dictionaries, where each dictionary describes a
    # vessel. There may be multiple vessels from any single node in this list.
    active_vesselhandle_list = experimentlib.find_vessels_on_nodes(
        identity, nodelocation_list)

    print("active_vesselhandle_list:" + str(active_vesselhandle_list))

    # Now we want to find out which vessels we've acquired through seattlegeni
    # that are not in our list. We may, for example, want to release those
    # vessels because we consider them unusable.

    try:
        expected_vesselhandle_list = experimentlib.seattlegeni_get_acquired_vessels(
            identity)

        print("expected_vesselhandle_list:" + str(expected_vesselhandle_list))

        # If we already have enough usable vessels, we're done.
        if len(active_vesselhandle_list) >= MIN_VESSELS_TO_KEEP:
            print("There are already " + str(len(active_vesselhandle_list)) +
                  " active vessels " + "and our MIN_VESSELS_TO_KEEP is " +
                  str(MIN_VESSELS_TO_KEEP))
            return

        # We assume all of our vessels come from seattlegeni, so if any vessels we
        # should have access to according to seattlegeni aren't accessible or
        # otherwise usable, then release them.
        vesselhandles_to_release = []
        for vesselhandle in expected_vesselhandle_list:
            if vesselhandle not in active_vesselhandle_list:
                vesselhandles_to_release.append(vesselhandle)

        if vesselhandles_to_release:
            print(
                str(len(vesselhandles_to_release)) +
                " vessels were inaccessible, so will try to release them:" +
                str(vesselhandles_to_release))
            try:
                experimentlib.seattlegeni_release_vessels(
                    identity, vesselhandles_to_release)
            except experimentlib.SeattleClearinghouseError, e:
                print("Failed to release vessels: " + str(e))
            else:
                print("Vessels successfully released.")

        # Determine the maximum number of vessels we can acquire through seattlegeni.
        max_vessels_allowed = experimentlib.seattlegeni_max_vessels_allowed(
            identity)
        print("max_vessels_allowed: " + str(max_vessels_allowed))

        # Determine the number of vessels we already have acquired through seattlegeni.
        num_currently_acquired = len(
            experimentlib.seattlegeni_get_acquired_vessels(identity))
        print("currently_acquired_count: " + str(num_currently_acquired))

        # Let's try to get as close to MIN_VESSELS_TO_KEEP without requesting more
        # than is allowed by this account.
        num_vessels_to_request = min(
            max_vessels_allowed, MIN_VESSELS_TO_KEEP) - num_currently_acquired

        if num_vessels_to_request <= 0:
            print(
                "This account doesn't have enough vessel credits to request more vessels."
            )
            return
        else:
            print("Will try to acquire " + str(num_vessels_to_request) +
                  " vessels.")

        vessel_type = experimentlib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_WAN
        acquired_vessels = experimentlib.seattlegeni_acquire_vessels(
            identity, vessel_type, num_vessels_to_request)

        print("Acquired " + str(num_vessels_to_request) + " vessels: " +
              str(acquired_vessels))