4 #include "lutf_common.h"
6 #define MAX_NUM_AGENTS 1024
11 #define LUTF_AGENT_STATE_ALIVE (1 << 0)
12 #define LUTF_AGENT_HB_CHANNEL_CONNECTED (1 << 1)
13 #define LUTF_AGENT_RPC_CHANNEL_CONNECTED (1 << 2)
14 #define LUTF_AGENT_WORK_IN_PROGRESS (1 << 3)
15 #define LUTF_AGENT_ZOMBIE (1 << 4)
17 typedef struct lutf_agent_blk_s {
18 pthread_mutex_t mutex;
21 unsigned int telnet_port;
22 unsigned int listen_port;
23 char name[MAX_STR_LEN];
24 char hostname[MAX_STR_LEN];
27 struct timeval time_stamp;
28 struct sockaddr_in addr;
30 unsigned int ref_count;
31 lutf_type_t node_type;
34 /* lutf_agent_get_highest_fd
35 * Find the highest connected FD in all connected agents.
37 int lutf_agent_get_highest_fd(void);
42 char *agent_state2str(lutf_agent_blk_t *agent);
45 * gets the local IP address being used to send messages to the master
50 * get_next_active_agent
51 * given an index start searching from that point on to find an
53 * To reset the loop start the index from 0
55 int get_next_active_agent(int idx, lutf_agent_blk_t **out);
58 * find_agent_blk_by_id
59 * Find the agent blk given an internal ID
60 * Agent ref-count is incremented
62 lutf_agent_blk_t *find_agent_blk_by_id(int idx);
65 * find_agent_blk_by_ip
66 * Find the agent blk given its IP address
67 * Agent ref-count is incremented
69 lutf_agent_blk_t *find_agent_blk_by_ip(char *ip);
72 * find_agent_blk_by_name
73 * Find the agent blk given its name
74 * Agent ref-count is incremented
76 lutf_agent_blk_t *find_agent_blk_by_name(char *name);
79 * find_create_agent_blk_by_addr
80 * return an agent block with this address or create a new one
82 lutf_agent_blk_t *find_create_agent_blk_by_addr(struct sockaddr_in *addr);
86 * Find a free agent block
88 lutf_agent_blk_t *find_free_agent_blk(struct sockaddr_in *addr);
92 * Free an agent blk that no longer is needed
94 void free_agent_blk(int id);
98 * acquire the agent for work
100 void acquire_agent_blk(lutf_agent_blk_t *agent);
104 * Release the agent blk
106 void release_agent_blk(lutf_agent_blk_t *agent);
110 * Returns the ip string representation
112 char *agent_ip2str(lutf_agent_blk_t *agent);
116 * Given a time struct insure that the agent doesn't exceed the HB
119 void agent_hb_check(struct timeval *t, lutf_type_t whoami);
125 void agent_disable_hb(void);
131 void agent_enable_hb(void);
134 * get the number of registered agents
136 int get_num_agents(void);
139 * Connect to masterIP:masterPort and get the number of agents connected
142 int get_num_agents_remote(char *masterIP, int masterPort);
145 * wait for the agents specified to be connected. If we don't get the full
146 * list within the time specified then fail
148 lutf_rc_t wait_for_agents(struct cYAML *agents, int timeout);
153 * convenience function to set the agent state
155 void set_agent_state(lutf_agent_blk_t *agent, unsigned int state);
160 * unset the state and check if the agent is a zombie and
161 * it has not pending work. If so then free it
163 void unset_agent_state(lutf_agent_blk_t *agent, unsigned int state);
167 * send an RPC message and wait for the RPC response
168 * RPCs always come in request/response pairs. This function will send
169 * the request and will block until it gets the response. If it doesn't
170 * get a response in the specified timeout it'll fail.
172 * target: name of the agent to send to
173 * yaml: NULL terminated string to send to the target
174 * timeout: to wait for response
178 * Returns a string YAML block
180 lutf_rc_t lutf_send_rpc(char *agent, char *yaml, int timeout, char **rsp);
184 * send a response to the RPC origin.
186 * target: name of the agent to send to
187 * yaml: NULL terminated string to send to the target
189 lutf_rc_t lutf_send_rpc_rsp(char *agent, char *yaml);
193 * Initialize the agent module
195 void agent_init(void);
197 #endif /* LUTF_AGENTS_H */