Example #1
0
int process_node(

  boost::ptr_vector<std::string>& status,
  xmlNode        *node)

  {
  char               *attr_value;
  char               *role_value;
  xmlNode            *child;
  xmlNode            *segments;
  xmlNode            *segment_child;
  std::string        features = "";
  char                buf[MAXLINE];
  int                 num_procs     = 0;
  int                 avail_procs   = 0;
  unsigned long       memory        = 0;
  unsigned long long  mem_kb;
  char               *rsv_id        = NULL;

    {
    std::string *str = new std::string("node=");
    attr_value = (char *)xmlGetProp(node, (const xmlChar *)node_id);
    *str += attr_value;
    status.push_back(str);
    free(attr_value);
    }

  /* check to see if the role is interactive - report these as down */
  role_value = (char *)xmlGetProp(node, (const xmlChar *)role);

    {
    std::string *str = new std::string("ARCH=");
    attr_value = (char *)xmlGetProp(node, (const xmlChar *)architecture);
    *str += attr_value;
    status.push_back(str);
    free(attr_value);
    }

    {
    std::string *str = new std::string("name=");
    attr_value = (char *)xmlGetProp(node, (const xmlChar *)name);
    *str += attr_value;
    status.push_back(str);
    free(attr_value);
    }

  /* process the children */
  for (child = node->children; child != NULL; child = child->next)
    {
    if (!strcmp((const char *)child->name, segment_array))
      {
      for (segments = child->children; segments != NULL; segments = segments->next)
        {
        for (segment_child = segments->children; segment_child != NULL; segment_child = segment_child->next)
          {
          if (!strcmp((const char *)segment_child->name, processor_array))
            process_processor_array(segment_child, &num_procs, &avail_procs, &rsv_id);
          else if (!strcmp((const char *)segment_child->name, memory_array))
            process_memory_array(segment_child, &memory);
          else if (!strcmp((const char *)segment_child->name, label_array))
            process_label_array(features, segment_child);
          }
        }
      }
    else if (!strcmp((const char *)child->name, processor_array))
      {
      process_processor_array(child, &num_procs, &avail_procs, &rsv_id);
      }
    else if (!strcmp((const char *)child->name, memory_array))
      {
      process_memory_array(child, &memory);
      }
    else if (!strcmp((const char *)child->name, label_array))
      {
      process_label_array(features, child);
      }
    else if (!strcmp((const char *)child->name, accelerator_array))
      {
      process_accelerator_array(status, child);
      }
    } /* END the loop for processing the children */

  /* once done, add the procs, available procs, memory info, reservation, and features */
  snprintf(buf, sizeof(buf), "CPROC=%d", num_procs);
  status.push_back(new std::string(buf));

  snprintf(buf, sizeof(buf), "APROC=%d", avail_procs);
  status.push_back(new std::string(buf));

  snprintf(buf, sizeof(buf), "CMEMORY=%lu", memory);
  status.push_back(new std::string(buf));

  mem_kb = memory * 1024;

  snprintf(buf, sizeof(buf), "totmem=%llukb", mem_kb);
  status.push_back(new std::string(buf));

  snprintf(buf, sizeof(buf), "physmem=%llukb", mem_kb);
  status.push_back(new std::string(buf));

  if (rsv_id != NULL)
    {
    /* don't write the reservation id if we're in interactive mode */
    if ((role_value == NULL) ||
        (strcmp(role_value, interactive_caps)))
      {
      std::string *str = new std::string("reservation_id=");
      *str += rsv_id;
      status.push_back(str);
      }

    free(rsv_id);

    /* if there's a reservation on this node, the state is busy */
    status.push_back(new std::string("state=BUSY"));
    
    snprintf(buf, sizeof(buf), "availmem=0kb");
    status.push_back(new std::string("availmem=0kb"));
    }
  else
    {
    /* no reservation, evaluate the state normally */
    std::string *str = new std::string("state=");
    attr_value = (char *)xmlGetProp(node, (const xmlChar *)state);
    
    if ((role_value != NULL) &&
        (!strcmp(role_value, interactive_caps)))
      {
      *str += "DOWN";
      status.push_back(str);
      
      snprintf(buf, sizeof(buf), "availmem=0kb");
      status.push_back(new std::string(buf));
      }
    else
      {
      *str += attr_value;
      status.push_back(str);
     
      snprintf(buf, sizeof(buf), "availmem=%llukb", mem_kb);
      status.push_back(new std::string(buf));
      }

    free(attr_value);
    }

  if (role_value != NULL)
    free(role_value);

  if (features.length() > 0)
    {
    std::string *str = new std::string("feature_list=");
    *str += features.c_str();
    status.push_back(str);
    }

  return(PBSE_NONE);
  } /* END process_node() */
int process_node(

  dynamic_string *status,
  xmlNode        *node)

  {
  char               *attr_value;
  char               *role_value;
  xmlNode            *child;
  xmlNode            *segments;
  xmlNode            *segment_child;
  dynamic_string     *features;
  char                buf[MAXLINE];
  int                 num_procs     = 0;
  int                 avail_procs   = 0;
  unsigned long       memory        = 0;
  unsigned long long  mem_kb;
  char               *rsv_id        = NULL;

  if ((features = get_dynamic_string(-1, NULL)) == NULL)
    return(ENOMEM);

  copy_to_end_of_dynamic_string(status, "node=");
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)node_id);
  append_dynamic_string(status, attr_value);
  free(attr_value);

  /* check to see if the role is interactive - report these as down */
  role_value = (char *)xmlGetProp(node, (const xmlChar *)role);

  copy_to_end_of_dynamic_string(status, "ARCH=");
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)architecture);
  append_dynamic_string(status, attr_value);
  free(attr_value);

  copy_to_end_of_dynamic_string(status, "name=");
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)name);
  append_dynamic_string(status, attr_value);
  free(attr_value);

  /* process the children */
  for (child = node->children; child != NULL; child = child->next)
    {
    if (!strcmp((const char *)child->name, segment_array))
      {
      for (segments = child->children; segments != NULL; segments = segments->next)
        {
        for (segment_child = segments->children; segment_child != NULL; segment_child = segment_child->next)
          {
          if (!strcmp((const char *)segment_child->name, processor_array))
            process_processor_array(segment_child, &num_procs, &avail_procs, &rsv_id);
          else if (!strcmp((const char *)segment_child->name, memory_array))
            process_memory_array(segment_child, &memory);
          else if (!strcmp((const char *)segment_child->name, label_array))
            process_label_array(features, segment_child);
          }
        }
      }
    else if (!strcmp((const char *)child->name, processor_array))
      {
      process_processor_array(child, &num_procs, &avail_procs, &rsv_id);
      }
    else if (!strcmp((const char *)child->name, memory_array))
      {
      process_memory_array(child, &memory);
      }
    else if (!strcmp((const char *)child->name, label_array))
      {
      process_label_array(features, child);
      }
    else if (!strcmp((const char *)child->name, accelerator_array))
      {
      process_accelerator_array(status, child);
      }
    } /* END the loop for processing the children */

  /* once done, add the procs, available procs, memory info, reservation, and features */
  snprintf(buf, sizeof(buf), "CPROC=%d", num_procs);
  copy_to_end_of_dynamic_string(status, buf);

  snprintf(buf, sizeof(buf), "APROC=%d", avail_procs);
  copy_to_end_of_dynamic_string(status, buf);

  snprintf(buf, sizeof(buf), "CMEMORY=%lu", memory);
  copy_to_end_of_dynamic_string(status, buf);

  mem_kb = memory * 1024;

  snprintf(buf, sizeof(buf), "totmem=%llukb", mem_kb);
  copy_to_end_of_dynamic_string(status, buf);

  snprintf(buf, sizeof(buf), "physmem=%llukb", mem_kb);
  copy_to_end_of_dynamic_string(status, buf);

  if (rsv_id != NULL)
    {
    /* don't write the reservation id if we're in interactive mode */
    if ((role_value == NULL) ||
        (strcmp(role_value, interactive_caps)))
      {
      copy_to_end_of_dynamic_string(status, "reservation_id=");
      append_dynamic_string(status, rsv_id);
      }

    free(rsv_id);

    /* if there's a reservation on this node, the state is busy */
    copy_to_end_of_dynamic_string(status, "state=BUSY");
    
    snprintf(buf, sizeof(buf), "availmem=0kb");
    copy_to_end_of_dynamic_string(status, buf);
    }
  else
    {
    /* no reservation, evaluate the state normally */
    copy_to_end_of_dynamic_string(status, "state=");
    attr_value = (char *)xmlGetProp(node, (const xmlChar *)state);
    
    if ((role_value != NULL) &&
        (!strcmp(role_value, interactive_caps)))
      {
      append_dynamic_string(status, "DOWN");
      
      snprintf(buf, sizeof(buf), "availmem=0kb");
      copy_to_end_of_dynamic_string(status, buf);
      }
    else
      {
      append_dynamic_string(status, attr_value);
     
      snprintf(buf, sizeof(buf), "availmem=%llukb", mem_kb);
      copy_to_end_of_dynamic_string(status, buf);
      }

    free(attr_value);
    }

  if (role_value != NULL)
    free(role_value);

  if (features->used > 0)
    {
    copy_to_end_of_dynamic_string(status, "feature_list=");
    append_dynamic_string(status, features->str);
    }

  free_dynamic_string(features);

  return(PBSE_NONE);
  } /* END process_node() */
Example #3
0
int process_node(

  xmlNode                  *node)

  {
  char               *attr_value;
  char               *role_value;
  xmlNode            *child;
  xmlNode            *segments;
  xmlNode            *segment_child;
  xmlNode            *sockets;
  xmlNode            *socket_child;
  xmlNode            *compute_units;
  xmlNode            *compute_unit_child;
  std::string         features = "";
  std::string         node_state = "";
  std::string         node_name;
  std::string         node_id_string;
  int                 nid;
  std::string         numa_cfg_val;
  std::string         mcdram_cfg_val;
  char                buf[MAXLINE];
  int                 num_procs         = 0;
  int                 avail_procs       = 0;
  int                 num_compute_units = 0;
  unsigned long       memory            = 0;
  unsigned long long  mem_kb;
  char               *rsv_id        = NULL;
  alps_node_info      ani;
  std::set<std::string>::iterator iter;
    
  ani.index = "node=";
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)node_id);
  if (attr_value != NULL)
    {
    node_id_string = attr_value;
    ani.index += node_id_string;
    nid = strtol(attr_value, NULL, 10);
    free(attr_value);
    }

  /* check to see if the role is interactive - report these as down */
  role_value = (char *)xmlGetProp(node, (const xmlChar *)role);

  ani.arch = "ARCH=";
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)architecture);
  if (attr_value != NULL)
    {
    ani.arch += attr_value;
    free(attr_value);
    }

  ani.name = "name=";
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)name);
  if (attr_value != NULL)
    {
    node_name = attr_value;
    ani.name += node_name;
    free(attr_value);
    }

  /* process the children */
  for (child = node->children; child != NULL; child = child->next)
    {

    /* 1.3 socket (does not exist in previous protocol versions) */
    if (!strcmp((const char *)child->name, socket_array))
      {
      for (sockets = child->children; sockets != NULL; sockets = sockets->next)
        {
        if (!strcmp((const char *)sockets->name, socket_name))
          {
          for (socket_child = sockets->children; socket_child != NULL; socket_child = socket_child->next)
            {
            if (!strcmp((const char *)socket_child->name, segment_array))
              {
              for (segments = socket_child->children; segments != NULL; segments = segments->next)
                {
                for (segment_child = segments->children; segment_child != NULL; segment_child = segment_child->next)
                  {
                  if (!strcmp((const char *)segment_child->name, compute_unit_array))
                    {
                    for (compute_units = segment_child->children; compute_units != NULL; compute_units = compute_units->next)
                      {
                      /* tally compute units */
                      if (!strcmp((const char *)compute_units->name, compute_unit))
                        num_compute_units++;

                      for (compute_unit_child = compute_units->children; compute_unit_child != NULL; compute_unit_child = compute_unit_child->next)
                        {
                        if (!strcmp((const char *)compute_unit_child->name, processor_array))
                          process_processor_array(compute_unit_child, &num_procs, &avail_procs, &rsv_id);
                        }
                      }
                    }
                  else if (!strcmp((const char *)segment_child->name, memory_array))
                    process_memory_array(segment_child, memory);
                  else if (!strcmp((const char *)segment_child->name, label_array))
                    process_label_array(features, segment_child);
                  }
                }
              }
            }
          }
        }
      }

    /* 1.1/1.2 segment */
    else if (!strcmp((const char *)child->name, segment_array))
      {
      for (segments = child->children; segments != NULL; segments = segments->next)
        {
        for (segment_child = segments->children; segment_child != NULL; segment_child = segment_child->next)
          {
          if (!strcmp((const char *)segment_child->name, processor_array))
            process_processor_array(segment_child, &num_procs, &avail_procs, &rsv_id);
          else if (!strcmp((const char *)segment_child->name, memory_array))
            process_memory_array(segment_child, memory);
          else if (!strcmp((const char *)segment_child->name, label_array))
            process_label_array(features, segment_child);
          }
        }
      }

    /* 1.0 tags (no SegmentArray tag) */
    else if (!strcmp((const char *)child->name, processor_array))
      {
      process_processor_array(child, &num_procs, &avail_procs, &rsv_id);
      }
    else if (!strcmp((const char *)child->name, memory_array))
      {
      process_memory_array(child, memory);
      }
    else if (!strcmp((const char *)child->name, label_array))
      {
      process_label_array(features, child);
      }

    /* 1.0-1.3 */
    else if (!strcmp((const char *)child->name, accelerator_array))
      {
      process_accelerator_array(ani, child);
      }
    } /* END the loop for processing the children */

  /* once done, add the procs, available procs, compute unit count, memory info, reservation, and features */

  /* note that CCU should come before CPROC */
  snprintf(buf, sizeof(buf), "CCU=%d", num_compute_units);
  ani.ccu = buf;

  snprintf(buf, sizeof(buf), "CPROC=%d", num_procs);
  ani.cproc = buf;

  snprintf(buf, sizeof(buf), "APROC=%d", avail_procs);
  ani.aproc = buf;

  snprintf(buf, sizeof(buf), "CMEMORY=%lu", memory);
  ani.cmem = buf;

  mem_kb = memory * 1024;

  snprintf(buf, sizeof(buf), "totmem=%llukb", mem_kb);
  ani.totmem = buf;

  snprintf(buf, sizeof(buf), "physmem=%llukb", mem_kb);
  ani.physmem = buf;

  if (rsv_id != NULL)
    {
    /* only write the reservation id if we're in batch mode (or role was not supplied) */
    if ((role_value == NULL) ||
        (!strcmp(role_value, batch_caps)))
      {
      ani.rsv = "reservation_id=";
      ani.rsv += rsv_id;
      }

    free(rsv_id);

    // if there's a reservation on this node, the state is busy and no memory is available
    node_state = "BUSY";
    ani.state = "state=BUSY";
    ani.availmem = "availmem=0kb";
    }
  else
    {
    /* no reservation, evaluate the state normally */
    ani.state = "state=";
    attr_value = (char *)xmlGetProp(node, (const xmlChar *)state);

    /* state is down if we're not in batch mode */
    if ((role_value != NULL) &&
        (strcmp(role_value, batch_caps)))
      {
      node_state = "DOWN";
      ani.state += "DOWN";
    
      ani.availmem = "availmem=0kb";
      }
    else
      {
      ani.state += attr_value;
      node_state = attr_value;
     
      snprintf(buf, sizeof(buf), "availmem=%llukb", mem_kb);
      ani.availmem = buf;
      }

    free(attr_value);
    }

  /* Record whenever an ALPS node is reported as entering a DOWN state */
  if (LOGLEVEL >= 3)
    {
    iter = down_nodes.find(node_id_string);

    /* Check to see if a node's state has changed. All nodes in a DOWN state are
     * recorded in the down_nodes structure. We can see if the node has changed status
     * based on whether its ID can be found in the down_nodes structure.
     */
    if (node_state == "DOWN")
      {
      if (iter == down_nodes.end())
        {
        down_nodes.insert(node_id_string);

        snprintf(buf, sizeof(buf), "ALPS node %s (%s) is reported as being DOWN", node_name.c_str(), node_id_string.c_str());
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_NODE, __func__, buf);
        }
      }
    else
      {
      if (iter != down_nodes.end())
        {
        snprintf(buf, sizeof(buf), "ALPS node %s (%s) is online again", node_name.c_str(), node_id_string.c_str());
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_NODE, __func__, buf);
        down_nodes.erase(iter);
        }
      }

    }

  /* Verbose debug output, log every single ALPS node's state */
  if (LOGLEVEL >= 7)
    {
    snprintf(buf, sizeof(buf), "ALPS node %s (%s) is reported as being %s", node_name.c_str(), node_id_string.c_str(), node_state.c_str());
    log_record(PBSEVENT_SYSTEM, 0, __func__, buf);
    }

  if (role_value != NULL)
    free(role_value);

  if (features.length() > 0)
    {
    ani.features = "feature_list=";
    ani.features += features.c_str();
    }

  alps_nodes[nid] = ani;

  return(PBSE_NONE);
  } /* END process_node() */