0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <stdio.h>
0035 #include <stdlib.h>
0036 #include <string.h>
0037 #include <errno.h>
0038 #include <regex.h>
0039 #include <utlist.h>
0040 #include <unistd.h>
0041 #include <signal.h>
0042 #include <fcntl.h>
0043
0044 #include <ndebug.h>
0045 #include <atmi.h>
0046 #include <atmi_int.h>
0047 #include <typed_buf.h>
0048 #include <ndrstandard.h>
0049 #include <ubf.h>
0050 #include <Exfields.h>
0051 #include <Excompat.h>
0052 #include <ubfutil.h>
0053 #include <sys_unix.h>
0054 #include <gencall.h>
0055 #include "tpadmsv.h"
0056 #include "expr.h"
0057
0058
0059
0060
0061
0062
0063
0064
0065 typedef struct
0066 {
0067 char lmid[MAXTIDENT+1];
0068 long curaccessers;
0069 long curclients;
0070 long curconv;
0071 char state[3+1];
0072 } ndrx_adm_machine_t;
0073
0074
0075
0076
0077 expublic ndrx_adm_elmap_t ndrx_G_machine_map[] =
0078 {
0079
0080 {TA_LMID, TPADM_EL(ndrx_adm_machine_t, lmid)}
0081 ,{TA_CURACCESSERS, TPADM_EL(ndrx_adm_machine_t, curaccessers)}
0082 ,{TA_CURCLIENTS, TPADM_EL(ndrx_adm_machine_t, curclients)}
0083 ,{TA_CURCONV, TPADM_EL(ndrx_adm_machine_t, curconv)}
0084 ,{TA_STATE, TPADM_EL(ndrx_adm_machine_t, state)}
0085 ,{BBADFLDID}
0086 };
0087
0088
0089
0090
0091 exprivate ndrx_adm_cursors_t *M_cursnew;
0092 exprivate int M_idx = 0;
0093
0094
0095
0096
0097
0098
0099
0100
0101 exprivate int ndrx_adm_machine_proc_list(command_reply_t *reply, size_t reply_len)
0102 {
0103 command_reply_ppm_t * ppm_info = (command_reply_ppm_t*)reply;
0104 int ret = EXSUCCEED;
0105
0106 if (NDRXD_CALL_TYPE_PM_PPM!=reply->msg_type)
0107 {
0108
0109 goto out;
0110 }
0111
0112 NDRX_LOG(log_debug, "ppm out: [%s]", ppm_info->binary_name);
0113 if (ppm_info->flags & SRV_KEY_FLAGS_BRIDGE)
0114 {
0115 ndrx_adm_machine_t mach;
0116 memset(&mach, 0, sizeof(mach));
0117
0118 mach.curaccessers = EXFAIL;
0119 mach.curclients = EXFAIL;
0120 mach.curconv = EXFAIL;
0121 snprintf(mach.lmid, sizeof(mach.lmid), "%hd", ppm_info->nodeid);
0122
0123
0124 if (ppm_info->flags & SRV_KEY_FLAGS_CONNECTED)
0125 {
0126 NDRX_STRCPY_SAFE(mach.state, "ACT");
0127 }
0128 else if (NDRXD_PM_RUNNING_OK==ppm_info->state)
0129 {
0130 NDRX_STRCPY_SAFE(mach.state, "PEN");
0131 }
0132 else
0133 {
0134 NDRX_STRCPY_SAFE(mach.state, "INA");
0135 }
0136
0137 if (EXSUCCEED!=ndrx_growlist_add(&M_cursnew->list, (void *)&mach, M_idx))
0138 {
0139 NDRX_LOG(log_error, "Growlist failed - out of memory?");
0140 EXFAIL_OUT(ret);
0141 }
0142
0143 NDRX_LOG(log_debug, "Machine/Node [%s] state %s added", mach.lmid, mach.state);
0144 M_idx++;
0145 }
0146
0147 out:
0148 return ret;
0149 }
0150
0151
0152
0153
0154
0155
0156
0157 expublic int ndrx_adm_machine_get(char *clazz, ndrx_adm_cursors_t *cursnew, long flags)
0158 {
0159 int ret = EXSUCCEED;
0160 ndrx_adm_machine_t mach;
0161
0162 string_list_t* qlist = NULL;
0163 string_list_t* elt = NULL;
0164
0165 int typ;
0166
0167 M_idx = 0;
0168
0169 ndrx_growlist_init(&cursnew->list, 100, sizeof(ndrx_adm_machine_t));
0170
0171 M_cursnew = cursnew;
0172 cursnew->map = ndrx_G_machine_map;
0173
0174 if (EXSUCCEED!=ndrx_adm_list_call(ndrx_adm_machine_proc_list,
0175 NDRXD_COM_XAPPM_RQ, NDRXD_COM_XAPPM_RP, ndrx_get_G_atmi_conf()->ndrxd_q_str))
0176 {
0177 NDRX_LOG(log_error, "Failed to call PPM");
0178 EXFAIL_OUT(ret);
0179 }
0180
0181
0182 memset(&mach, 0, sizeof(mach));
0183
0184 snprintf(mach.lmid, sizeof(mach.lmid), "%ld", tpgetnodeid());
0185 NDRX_STRCPY_SAFE(mach.state, "ACT");
0186
0187 qlist = ndrx_sys_mqueue_list_make(G_atmi_env.qpath, &ret);
0188
0189 if (EXSUCCEED!=ret)
0190 {
0191 NDRX_LOG(log_error, "posix queue listing failed!");
0192 EXFAIL_OUT(ret);
0193 }
0194
0195
0196 LL_FOREACH(qlist,elt)
0197 {
0198
0199
0200
0201 if (0!=strncmp(elt->qname,
0202 G_atmi_env.qprefix_match, G_atmi_env.qprefix_match_len))
0203 {
0204 continue;
0205 }
0206
0207 typ = ndrx_q_type_get(elt->qname);
0208
0209 switch (typ)
0210 {
0211 case NDRX_QTYPE_CLTRPLY:
0212 mach.curclients++;
0213 mach.curaccessers++;
0214 break;
0215 case NDRX_QTYPE_SRVRPLY:
0216 mach.curaccessers++;
0217 break;
0218 case NDRX_QTYPE_CONVINIT:
0219 mach.curconv++;
0220 break;
0221 }
0222 }
0223
0224 if (EXSUCCEED!=ndrx_growlist_add(&M_cursnew->list, (void *)&mach, M_idx))
0225 {
0226 NDRX_LOG(log_error, "Growlist failed - out of memory?");
0227 EXFAIL_OUT(ret);
0228 }
0229
0230 NDRX_LOG(log_debug, "Local Machine/Node [%s] state %s added "
0231 "curclients=%ld curaccessers=%ld curconv=%ld",
0232 mach.lmid, mach.state, mach.curclients, mach.curaccessers, mach.curconv);
0233 M_idx++;
0234
0235 out:
0236
0237 if (NULL!=qlist)
0238 {
0239 ndrx_string_list_free(qlist);
0240 }
0241
0242 if (EXSUCCEED!=ret)
0243 {
0244 ndrx_growlist_free(&M_cursnew->list);
0245 }
0246
0247 return ret;
0248 }
0249
0250