def main():

    identity = experimentlib.create_identity_from_key_files(
        SEATTLECLEARINGHOUSE_PUBLICKEY_FILENAME)

    nodelocation_list = experimentlib.lookup_node_locations_by_identity(
        identity)
    print("Number of advertising nodes: " + str(len(nodelocation_list)))

    if MAX_NODES_TO_LOOK_AT is not None:
        print("DEBUG: only looking at " + str(MAX_NODES_TO_LOOK_AT) +
              " nodes.")
        nodelocation_list = nodelocation_list[:MAX_NODES_TO_LOOK_AT]

    # Talk to each nodemanager to find out vessel information.
    browse_successlist, failurelist = \
        experimentlib.run_parallelized(nodelocation_list, browse_node_for_available_vessels)

    # Create a dictionary whose keys are the nodeids and values are lists of
    # vesseldicts of the available vessels on that node.
    available_vesseldicts_by_node = {}
    for (nodeid, available_vesseldicts) in browse_successlist:
        if available_vesseldicts:
            available_vesseldicts_by_node[nodeid] = available_vesseldicts

    print("Number of nodes that SeattleGENI vessels are available on: " +
          str(len(available_vesseldicts_by_node.keys())))
Пример #2
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():

  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)
Пример #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)))

  # 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))
def main():

    identity = experimentlib.create_identity_from_key_files(PUBLICKEY_FILENAME)

    nodelocation_list = experimentlib.lookup_node_locations_by_identity(identity)

    print("Number of nodes advertising their location under this key: " + str(len(nodelocation_list)))

    for nodelocation in nodelocation_list:
        print(nodelocation)
Пример #6
0
def main():

    identity = experimentlib.create_identity_from_key_files(PUBLICKEY_FILENAME)

    nodelocation_list = experimentlib.lookup_node_locations_by_identity(
        identity)

    print("Number of nodes advertising their location under this key: " +
          str(len(nodelocation_list)))

    for nodelocation in nodelocation_list:
        print(nodelocation)
Пример #7
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))
Пример #8
0
def advertising_lookup(identity, retries):
    """
  <Purpose>
    Attempts to retrieve the list of nodes advertising under a given identity
    and returns then list if successful.

  <Arguments>
    identity:
        An Experiment Library identity for looking up node locations.

    retries:
        An integer giving the number of times to retry the lookup if it fails
        or returns an empty list.

  <Exceptions>
    None.

  <Side Effects>
    None.

  <Returns>
    None if all tries result in exceptions, and a list of the nodes advertising
    under the given identity otherwise.
  """

    # Every once in a while, a lookup returns an empty list when it shouldn't.
    # This is presumably due to something timing out. We don't want to see that
    # all the nodes suddenly stopped advertising when this obviously isn't the
    # case, so we should retry the lookup when the returned list is empty.
    # However, some lookups may legitimately return an empty list, so the calling
    # function should pick a reasonable value for the maximum number of retries.

    locationlist = None

    while retries >= 0 and (locationlist is None or len(locationlist) == 0):
        try:
            locationlist = experimentlib.lookup_node_locations_by_identity(
                identity)
        except Exception, e:
            pass
        retries -= 1
Пример #9
0
def advertising_lookup(identity, retries):
  """
  <Purpose>
    Attempts to retrieve the list of nodes advertising under a given identity
    and returns then list if successful.

  <Arguments>
    identity:
        An Experiment Library identity for looking up node locations.

    retries:
        An integer giving the number of times to retry the lookup if it fails
        or returns an empty list.

  <Exceptions>
    None.

  <Side Effects>
    None.

  <Returns>
    None if all tries result in exceptions, and a list of the nodes advertising
    under the given identity otherwise.
  """

  # Every once in a while, a lookup returns an empty list when it shouldn't.
  # This is presumably due to something timing out. We don't want to see that
  # all the nodes suddenly stopped advertising when this obviously isn't the
  # case, so we should retry the lookup when the returned list is empty.
  # However, some lookups may legitimately return an empty list, so the calling
  # function should pick a reasonable value for the maximum number of retries.

  locationlist = None

  while retries >= 0 and (locationlist is None or len(locationlist) == 0):
    try:
      locationlist = experimentlib.lookup_node_locations_by_identity(identity)
    except Exception, e:
      pass
    retries -= 1
Пример #10
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))
Пример #11
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)))

  browse_successlist, browse_failurelist = experimentlib.run_parallelized(nodelocation_list,
                                                                          experimentlib.browse_node, identity)

  vesseldict_list = []
  for (nodeid, vesseldicts_of_node) in browse_successlist:
    vesseldict_list += vesseldicts_of_node

  print("Good vessels: " + str(len(vesseldict_list)))

  set_keys_successlist, set_keys_failure_list = experimentlib.run_parallelized(vesseldict_list, set_keys, identity)
  print("Vessels with proper user keys: " + str(len(set_keys_successlist)))
  print("Vessels that failed user key setting: " + str(len(set_keys_failure_list)))

  print("Done.")
Пример #12
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))
Пример #13
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)
Пример #14
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))
Пример #15
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(SEATTLEGENI_PUBLICKEY_FILENAME)

  nodelocation_list = experimentlib.lookup_node_locations_by_identity(identity)
  print("Number of advertising nodes: " + str(len(nodelocation_list)))

  if MAX_NODES_TO_LOOK_AT is not None:
    print("DEBUG: only looking at " + str(MAX_NODES_TO_LOOK_AT) + " nodes.")
    nodelocation_list = nodelocation_list[:MAX_NODES_TO_LOOK_AT]

  # Talk to each nodemanager to find out vessel information.
  browse_successlist, failurelist = \
      experimentlib.run_parallelized(nodelocation_list, browse_node_for_available_vessels)

  # Create a dictionary whose keys are the nodeids and values are lists of
  # vesseldicts of the available vessels on that node.
  available_vesseldicts_by_node = {}
  for (nodeid, available_vesseldicts) in browse_successlist:
    if available_vesseldicts:
      available_vesseldicts_by_node[nodeid] = available_vesseldicts

  print("Number of nodes that SeattleGENI vessels are available on: " + 
        str(len(available_vesseldicts_by_node.keys())))
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))
Пример #18
0
def poll_data():
  """
  <Purpose>
    This is used to collect and store node/vessel data.
  <Arguments>
    None.
  <Exceptions>
    NodeLocationListEmptyError
      This error will be raised if we are unable to 
      lookup any node locations because there won't 
      be any nodes to look up any information on.
    ExperimentLibError
      If any experiment library errors occur they will
      be logged in 'fail_list.dat.gz' at the end of poll_data()
  <Side Effects>
    Creates a new folder at the users path (specified above) with a timestamp. 
    Inside that folder will exist 2 gzip files one called 'nodes_list.gz' and 
    one called 'fail_list.gz', these are compressed python pickles of the 
    objects used in this script.
  <Returns>
    None.
  """
  
  poll_identity = experimentlib.create_identity_from_key_files(PATH_TO_EXP_LIB +
                                                               "stat_lib/perc20.publickey")

  # Creates a list of IPs that are associated with this identity.
  nodelocation_list = experimentlib.lookup_node_locations_by_identity(poll_identity)

  # The format of the timestamp is of the form:
  # YYYYMMDD_HHMM, with single digits zero padded (5 -> 05).
  curr_time = datetime.datetime.now()
  
  # Converts datetime object to a formated string.
  folder_name = datetime.datetime.strftime(curr_time, "%Y%m%d_%H%M")
  month_folder = datetime.datetime.strftime(curr_time, "%Y_%m")

  # If a folder does not exist for the month of the poll, it is created.
  if not os.path.isdir(PATH_TO_EXP_LIB + "seattle_node_data/" + month_folder):
    os.mkdir(PATH_TO_EXP_LIB + "seattle_node_data/" + month_folder)
  
  # Create the folder for this poll data to be stored.
  data_storage_path = PATH_TO_EXP_LIB + "seattle_node_data/" + month_folder + "/" + folder_name
  os.mkdir(data_storage_path)
  
  # Checks to make sure we have enough node locations to continue with the
  # poll, if not a NodeLocationListEmpty Error is raised.
  if(len(nodelocation_list) < 0):
    raise NodeLocationListEmptyError("Node location list is empty, " +
                                     "poll_data stopped at: " + str(curr_time))
  
  # Creates initial gzip data files to be saved (appends if needed).
  nodes_file = gzip.open(data_storage_path + "/node_list.dat.gz",'ar')
  fail_file = gzip.open(data_storage_path + "/fail_list.dat.gz",'ar')

  # The initial data structures to be pickled.
  total_node_dicts = {}
  fail_dict = {}
  
  for node_ip in nodelocation_list:
    single_node_dict = {}
    single_node_dict['timestamp'] = curr_time
    
    time_before_browsenode = time.time()
    
    # If browse_node fails it will throw an ExperimentLibError which means we 
    # are not able to communicate with the node so it is added to the list 
    # of failed nodes.
    try:
      list_of_vessel_dicts = experimentlib.browse_node(node_ip)
    except experimentlib.SeattleExperimentError, err:
      time_atfail_browsenode = time.time()
      elapsed_time_fail = time_atfail_browsenode - time_before_browsenode
      fail_dict[str(node_ip)] = [err, elapsed_time_fail]
      time_before_browsenode = 0
      time_after_browsenode = 0
      continue
   
    time_after_browsenode = time.time()
    elapsed_time = time_after_browsenode - time_before_browsenode
    
    single_node_dict['responsetime'] = elapsed_time
    single_node_dict['nodelocation'] = node_ip
    single_node_dict['version'] = list_of_vessel_dicts[0].get('version')
    unique_id = list_of_vessel_dicts[0].get('nodeid')
    single_node_dict['nodeid'] = unique_id
    single_node_dict['vessels'] = list_of_vessel_dicts
    total_node_dicts[str(unique_id)] = single_node_dict
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))
Пример #20
0
def poll_data():
    """
  <Purpose>
    This is used to collect and store node/vessel data.
  <Arguments>
    None.
  <Exceptions>
    NodeLocationListEmptyError
      This error will be raised if we are unable to 
      lookup any node locations because there won't 
      be any nodes to look up any information on.
    ExperimentLibError
      If any experiment library errors occur they will
      be logged in 'fail_list.dat.gz' at the end of poll_data()
  <Side Effects>
    Creates a new folder at the users path (specified above) with a timestamp. 
    Inside that folder will exist 2 gzip files one called 'nodes_list.gz' and 
    one called 'fail_list.gz', these are compressed python pickles of the 
    objects used in this script.
  <Returns>
    None.
  """

    poll_identity = experimentlib.create_identity_from_key_files(
        PATH_TO_EXP_LIB + "stat_lib/perc20.publickey")

    # Creates a list of IPs that are associated with this identity.
    nodelocation_list = experimentlib.lookup_node_locations_by_identity(
        poll_identity)

    # The format of the timestamp is of the form:
    # YYYYMMDD_HHMM, with single digits zero padded (5 -> 05).
    curr_time = datetime.datetime.now()

    # Converts datetime object to a formated string.
    folder_name = datetime.datetime.strftime(curr_time, "%Y%m%d_%H%M")
    month_folder = datetime.datetime.strftime(curr_time, "%Y_%m")

    # If a folder does not exist for the month of the poll, it is created.
    if not os.path.isdir(PATH_TO_EXP_LIB + "seattle_node_data/" +
                         month_folder):
        os.mkdir(PATH_TO_EXP_LIB + "seattle_node_data/" + month_folder)

    # Create the folder for this poll data to be stored.
    data_storage_path = PATH_TO_EXP_LIB + "seattle_node_data/" + month_folder + "/" + folder_name
    os.mkdir(data_storage_path)

    # Checks to make sure we have enough node locations to continue with the
    # poll, if not a NodeLocationListEmpty Error is raised.
    if (len(nodelocation_list) < 0):
        raise NodeLocationListEmptyError("Node location list is empty, " +
                                         "poll_data stopped at: " +
                                         str(curr_time))

    # Creates initial gzip data files to be saved (appends if needed).
    nodes_file = gzip.open(data_storage_path + "/node_list.dat.gz", 'ar')
    fail_file = gzip.open(data_storage_path + "/fail_list.dat.gz", 'ar')

    # The initial data structures to be pickled.
    total_node_dicts = {}
    fail_dict = {}

    for node_ip in nodelocation_list:
        single_node_dict = {}
        single_node_dict['timestamp'] = curr_time

        time_before_browsenode = time.time()

        # If browse_node fails it will throw an ExperimentLibError which means we
        # are not able to communicate with the node so it is added to the list
        # of failed nodes.
        try:
            list_of_vessel_dicts = experimentlib.browse_node(node_ip)
        except experimentlib.SeattleExperimentError, err:
            time_atfail_browsenode = time.time()
            elapsed_time_fail = time_atfail_browsenode - time_before_browsenode
            fail_dict[str(node_ip)] = [err, elapsed_time_fail]
            time_before_browsenode = 0
            time_after_browsenode = 0
            continue

        time_after_browsenode = time.time()
        elapsed_time = time_after_browsenode - time_before_browsenode

        single_node_dict['responsetime'] = elapsed_time
        single_node_dict['nodelocation'] = node_ip
        single_node_dict['version'] = list_of_vessel_dicts[0].get('version')
        unique_id = list_of_vessel_dicts[0].get('nodeid')
        single_node_dict['nodeid'] = unique_id
        single_node_dict['vessels'] = list_of_vessel_dicts
        total_node_dicts[str(unique_id)] = single_node_dict