int set_rendezvous_state(Node n) { int error; int i; Node child,parent; int status = 1; if (n -> type == RENDEZVOUS) { for(i = 0; i < ListSize(n -> predecessors); i++) { parent = (Node) ListIndex(n -> predecessors,i); if (STATE(parent) != ACT_DONE) { status = 0; } } if (status == 1) { set_node_state(n, ACT_DONE, &error); //only raise error when Node type is ACTION set_node_state(n -> matching, ACT_DONE, &error); for(i = 0; i< ListSize(n -> successors); i++) { child = (Node) ListIndex(n -> successors,i); if (child -> type == JOIN) { propogate_join_done(child, ACT_DONE); } mark_successors(child,ACT_READY); set_rendezvous_state(child); } } } return 1; }
int mark_successors(Node n, vm_act_state state) { int error; int i; Node child; if (n -> type == ACTION) { set_node_state(n, state, &error); if (error) return 0; mark_iter_nodes(n); return 1; } else if ((n -> type == BRANCH) || (n -> type == SELECTION) || (n -> type == JOIN)) { if ((n->type == BRANCH) || (n->type == SELECTION)) { set_node_state(n, state, &error); if (error) return 0; mark_iter_nodes(n); set_node_state(n -> matching, state, &error); if (error) return 0; } for(i = 0; i < ListSize(n -> successors); i++) { child = (Node) ListIndex(n -> successors, i); mark_successors(child,state); } } return 1; }
vm_exit_code handle_resource_event(int pid, char *action, vm_resource_event event) { int error; Graph g; Node n; peos_context_t *context = peos_get_context(pid); g = context -> process_graph; if(g == NULL) { fprintf(stderr,"Handle Action Error: Unable to find graph"); return VM_INTERNAL_ERROR; } n = find_node(g,action); if(n != NULL) { if(event == REQUIRES_TRUE) { if(STATE(n) == ACT_BLOCKED) { set_node_state(n, ACT_READY, &error); if (error) { return VM_INTERNAL_ERROR; } return VM_CONTINUE; } else { if((STATE(n) != ACT_READY) && (STATE(n) != ACT_RUN) && (STATE(n) != ACT_PENDING) && (STATE(n) != ACT_SUSPEND) && (STATE(n) != ACT_DONE)) { set_node_state(n, ACT_AVAILABLE, &error); //only raise error when state is set to ready and done } return VM_CONTINUE; } } else { if(event == PROVIDES_TRUE) { if((STATE(n) == ACT_PENDING)) { set_node_state(n, ACT_DONE, &error); if (error) { return VM_INTERNAL_ERROR; } } else { if((STATE(n) != ACT_DONE) && (n -> provides != NULL)) { set_node_state(n, ACT_SATISFIED, &error); if (error) { fprintf(stderr,"Handle Action Error: Unable to find graph"); return VM_INTERNAL_ERROR; } } } return VM_CONTINUE; } else return VM_INTERNAL_ERROR; } } else return VM_INTERNAL_ERROR; }
vm_exit_code set_act_state_graph(Graph g, char *action, vm_act_state state) { int error; Node n; switch(state) { case ACT_DONE: return action_done(g,action); case ACT_READY: n = find_node(g,action); if (n!=NULL) { set_node_state(n, ACT_READY, &error); if (!error) return VM_CONTINUE; } return VM_INTERNAL_ERROR; case ACT_RUN: if (action_run(g,action) > 0) return VM_CONTINUE; return VM_INTERNAL_ERROR; case ACT_NONE: n = find_node(g,action); if (n != NULL) { set_node_state(n, ACT_NONE, &error); if (!error) return VM_CONTINUE; } return VM_INTERNAL_ERROR; case ACT_SUSPEND: n = find_node(g,action); if (n != NULL) { set_node_state(n, ACT_SUSPEND, &error); if (!error) return VM_CONTINUE; } return VM_INTERNAL_ERROR; case ACT_ABORT: n = find_node(g,action); if (n != NULL) { if (STATE(n) == ACT_RUN) { set_node_state(n, ACT_NONE, &error); if (error) return VM_INTERNAL_ERROR; update_process_state(PID(n)); } return VM_CONTINUE; } return VM_INTERNAL_ERROR; default : fprintf(stderr, "Error Changing Action : Invalid Action State\n"); return -1; } }
vm_exit_code handle_resource_event(int pid, char *action, vm_resource_event event) { int error; Graph g; Node n; peos_context_t *context = peos_get_context(pid); g = context -> process_graph; if (g == NULL) { peos_error("handle_resource_event: process graph is null"); return VM_INTERNAL_ERROR; } n = find_node(g,action); if (n == NULL) { return VM_INTERNAL_ERROR; } if (event == REQUIRES_TRUE) { if (STATE(n) == ACT_BLOCKED) { set_node_state(n, ACT_READY, &error); if (error) { return VM_INTERNAL_ERROR; } } else { if ((STATE(n) != ACT_READY) && (STATE(n) != ACT_RUN) && (STATE(n) != ACT_PENDING) && (STATE(n) != ACT_SUSPEND) && (STATE(n) != ACT_DONE)) { set_node_state(n, ACT_AVAILABLE, &error); /* only raise error when state is set to ready and done */ } } return VM_CONTINUE; } else if (event == PROVIDES_TRUE) { if ((STATE(n) == ACT_PENDING)) { set_node_state(n, ACT_DONE, &error); if (error) { return VM_INTERNAL_ERROR; } } else if ((STATE(n) != ACT_DONE) && (n -> provides != NULL)) { set_node_state(n, ACT_SATISFIED, &error); if (error) { return VM_INTERNAL_ERROR; } } return VM_CONTINUE; } else { peos_error("handle_resource_event: unknown event %d", event); return VM_INTERNAL_ERROR; } }
int set_super_nodes_run(Node n) { int error; Node super; int i; for(i = 0; i < ListSize(SUPER_NODES(n)); i++) { super = (Node) ListIndex(SUPER_NODES(n),i); set_node_state(super, ACT_RUN, &error); if (error) return 0; set_node_state(super -> matching, ACT_RUN, &error); if (error) return 0; mark_iter_nodes(super); } return 1; }
int propogate_join_done(Node n, vm_act_state state_set) { int error; int i; Node child; if (n -> type == JOIN) { set_node_state(n, state_set, &error); if (error) return 0; set_node_state(n -> matching, state_set, &error); if (error) return 0; for(i = 0; i < ListSize(n->successors); i++) { child = (Node) ListIndex(n->successors,i); propogate_join_done(child, state_set); set_rendezvous_state(child); } } return 1; }
vm_exit_code action_done(Graph g, char *act_name) { int error; Node n; Node child; int i,num_successors; vm_act_state state_set; if (action_run(g, act_name) == -1) return VM_INTERNAL_ERROR; n = find_node(g,act_name); if (n != NULL) { state_set = set_node_state(n, ACT_DONE, &error); if (error) return VM_INTERNAL_ERROR; num_successors = ListSize(n -> successors); for(i = 0; i < num_successors; i++) { child = (Node) ListIndex(n -> successors, i); /* * (num_successors == 1) is a check to see that it is * not an iteration. */ if (state_set == ACT_DONE) { if ((child -> type == JOIN) && (num_successors == 1)) { propogate_join_done(child, state_set); } } if (child -> type != RENDEZVOUS) { /* * if a child is not a rendezvous or a join, it has to * be a selection or branch or action, so mark it ready. If * its sink, that is handled again by set_process_state(..) */ mark_successors(child, ACT_READY); } else { if (num_successors == 1) set_rendezvous_state(child); } } if (num_successors == 1) set_process_state(g); } else { fprintf(stderr, "Error in action_done"); return VM_INTERNAL_ERROR; } if (STATE(g->source) == ACT_DONE) { return VM_DONE; } else return VM_CONTINUE; }
int make_other_run_suspend(Graph g, char *act_name) { int error; Node n; for(n = g -> source; n != NULL; n = n -> next) { if (n->type == ACTION) { if (STATE(n) == ACT_RUN) { if (strcmp(n->name, act_name) != 0) { set_node_state(n, ACT_SUSPEND, &error); //only raise error when state is set to ready and done } } } } return 1; }
int action_run(Graph g, char *act_name) { int error; Node n; n = find_node(g, act_name); if (n != NULL) { set_node_state(n, ACT_RUN, &error); //only raise error when state is set to ready and done make_other_run_suspend(g, act_name); mark_iter_nodes(n); /* handle iterations */ handle_selection(n); /* handle selections */ set_super_nodes_run(n); /*set super nodes to run */ sanitize(g); /* sanitize the markers used */ } else { return -1; } return 1; }
/* * * query_node_info - collect information from a batch_status and * put it in a node_info struct for easier access * * node - a node returned from a pbs_statnode() call * * returns a node_info filled with information from node * */ node_info *query_node_info(struct batch_status *node, server_info *sinfo) { node_info *ninfo; /* the new node_info */ struct attrl *attrp; /* used to cycle though attribute list */ if ((ninfo = new_node_info()) == NULL) return NULL; attrp = node -> attribs; ninfo -> name = string_dup(node -> name); ninfo -> server = sinfo; while (attrp != NULL) { /* Node State... i.e. offline down free etc */ if (!strcmp(attrp -> name, ATTR_NODE_state)) set_node_state(ninfo, attrp -> value); /* properties from the servers nodes file */ else if (!strcmp(attrp -> name, ATTR_NODE_properties)) ninfo -> properties = break_comma_list(attrp -> value); /* the jobs running on the node */ else if (!strcmp(attrp -> name, ATTR_NODE_jobs)) ninfo -> jobs = break_comma_list(attrp -> value); /* the node type... i.e. timesharing or cluster */ else if (!strcmp(attrp -> name, ATTR_NODE_ntype)) set_node_type(ninfo, attrp -> value); attrp = attrp -> next; } return ninfo; }