Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Server data grabber
0003  *
0004  * @file server.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
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 /*---------------------------Externs------------------------------------*/
0058 /*---------------------------Macros-------------------------------------*/
0059 /*---------------------------Enums--------------------------------------*/
0060 /*---------------------------Typedefs-----------------------------------*/
0061     
0062 /**
0063  * Image of the server
0064  */
0065 typedef struct 
0066 {
0067     char lmid[MAXTIDENT+1];     /**< Machine / cluster node id              */
0068     long srvid;                 /**< Server ID                              */
0069     char rqaddr[128+1];   /**< Request address if any, used by SysV   */
0070     char state[3+1];            /**< Server state                           */
0071     long timerestart;           /**< Santiy cycles from last start          */ 
0072     long pid;                   /**< Server process PID                     */
0073     char servername[78+1];      /**< binary name                            */
0074     char clopt[256+1];          /**< Clopt / real name                      */
0075     long generation;            /**< Number of restarts for the server proc */
0076 } ndrx_adm_server_t;
0077 
0078 /**
0079  * Client class infos mapping table
0080  */
0081 expublic ndrx_adm_elmap_t ndrx_G_server_map[] =
0082 {  
0083     /* Driving of the Preparing: */
0084     {TA_LMID,                      TPADM_EL(ndrx_adm_server_t, lmid)}
0085     ,{TA_SRVID,                      TPADM_EL(ndrx_adm_server_t, srvid)}
0086     ,{TA_RQADDR,                    TPADM_EL(ndrx_adm_server_t, rqaddr)}
0087     ,{TA_STATE,                     TPADM_EL(ndrx_adm_server_t, state)}
0088     ,{TA_TIMERESTART,               TPADM_EL(ndrx_adm_server_t, timerestart)}
0089     ,{TA_PID,                       TPADM_EL(ndrx_adm_server_t, pid)}
0090     ,{TA_SERVERNAME,                TPADM_EL(ndrx_adm_server_t, servername)}
0091     ,{TA_CLOPT,                     TPADM_EL(ndrx_adm_server_t, clopt)}
0092     ,{TA_GENERATION,                TPADM_EL(ndrx_adm_server_t, generation)}
0093     ,{BBADFLDID}
0094 };
0095 
0096 /*---------------------------Globals------------------------------------*/
0097 /*---------------------------Statics------------------------------------*/
0098 
0099 exprivate ndrx_adm_cursors_t *M_cursnew;
0100 exprivate int M_idx = 0;    /**< Current growlist index */
0101 /*---------------------------Prototypes---------------------------------*/
0102 
0103 /**
0104  * Fill any cluster data here, filter by bridge processes
0105  * @param reply
0106  * @param reply_len
0107  * @return 
0108  */
0109 exprivate int ndrx_adm_server_proc_list(command_reply_t *reply, size_t reply_len)
0110 {
0111     command_reply_ppm_t * ppm_info = (command_reply_ppm_t*)reply;
0112     int ret = EXSUCCEED;
0113     
0114     if (NDRXD_CALL_TYPE_PM_PPM!=reply->msg_type)
0115     {
0116         /* not payload */
0117         goto out;
0118     }
0119     
0120     NDRX_LOG(log_debug, "ppm out: [%s]", ppm_info->binary_name);
0121     
0122     ndrx_adm_server_t srv;
0123     memset(&srv, 0, sizeof(srv));
0124 
0125     srv.srvid = ppm_info->srvid;
0126     srv.pid = ppm_info->pid;
0127     NDRX_STRCPY_SAFE(srv.rqaddr, ppm_info->rqaddress);
0128     srv.timerestart = ppm_info->state_changed;
0129     srv.generation = ppm_info->exec_seq_try + 1; /* number of consecutive restarts */
0130     snprintf(srv.lmid, sizeof(srv.lmid), "%ld", tpgetnodeid());
0131 
0132     if (NDRXD_PM_RUNNING_OK==ppm_info->state)
0133     {
0134         NDRX_STRCPY_SAFE(srv.state, "ACT");
0135     }
0136     else if (NDRXD_PM_STARTING==ppm_info->state)
0137     {
0138         NDRX_STRCPY_SAFE(srv.state, "RES");
0139     }
0140     else if (NDRXD_PM_STOPPING==ppm_info->state)
0141     {
0142         NDRX_STRCPY_SAFE(srv.state, "CLE");
0143     }
0144     else if (NDRXD_PM_NOT_STARTED==ppm_info->state || NDRXD_PM_EXIT==ppm_info->state)
0145     {
0146         NDRX_STRCPY_SAFE(srv.state, "INA");
0147     }
0148     else
0149     {
0150         NDRX_STRCPY_SAFE(srv.state, "DEA");
0151     }
0152 
0153     NDRX_STRCPY_SAFE(srv.servername, ppm_info->binary_name);
0154     NDRX_STRCPY_SAFE(srv.clopt, ppm_info->binary_name_real);
0155 
0156     if (EXSUCCEED!=ndrx_growlist_add(&M_cursnew->list, (void *)&srv, M_idx))
0157     {
0158         NDRX_LOG(log_error, "Growlist failed - out of memory?");
0159         EXFAIL_OUT(ret);
0160     }
0161 
0162     NDRX_LOG(log_debug, "Server [%s]/%ld state %s added", srv.servername, 
0163             srv.srvid, srv.state);
0164     M_idx++;    
0165 out:
0166     return ret;
0167 }
0168 
0169 /**
0170  * Read server data
0171  * @param clazz class name
0172  * @param cursnew this is new cursor domain model
0173  * @param flags not used
0174  */
0175 expublic int ndrx_adm_server_get(char *clazz, ndrx_adm_cursors_t *cursnew, long flags)
0176 {
0177     int ret = EXSUCCEED;
0178 
0179     /* init cursor */
0180     M_idx = 0;
0181     
0182     ndrx_growlist_init(&cursnew->list, 100, sizeof(ndrx_adm_server_t));
0183     
0184     M_cursnew = cursnew;
0185     cursnew->map = ndrx_G_server_map;
0186     
0187     if (EXSUCCEED!=ndrx_adm_list_call(ndrx_adm_server_proc_list, 
0188             NDRXD_COM_XAPPM_RQ, NDRXD_COM_XAPPM_RP, ndrx_get_G_atmi_conf()->ndrxd_q_str))
0189     {
0190         NDRX_LOG(log_error, "Failed to call PPM");
0191         EXFAIL_OUT(ret);
0192     }
0193     
0194 out:
0195 
0196     if (EXSUCCEED!=ret)
0197     {
0198         ndrx_growlist_free(&M_cursnew->list);
0199     }
0200 
0201     return ret;
0202 }
0203 
0204 /* vim: set ts=4 sw=4 et smartindent: */