Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Machine data grabber
0003  *
0004  * @file svcgrp.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  * + OID HASH
0064  * Image of the service group / dynamic service info
0065  */
0066 typedef struct 
0067 {
0068     char servicename[MAXTIDENT+1];      /**< Service name                     */
0069     char srvgrp[MAXTIDENT+1];           /**< Server group                     */
0070     char state[3+1];                    /**< Current service state, "ACT" const */
0071     char lmid[MAXTIDENT+1];             /**< Node id                          */
0072     long srvid;                         /**< Server process id                */
0073     char svcrname[MAXTIDENT+1];         /**< Function name                    */
0074     long ncompleted;                    /**< Requests completed succ + fail   */
0075     long totsuccnum;                    /**< Total success calls              */
0076     long totsfailnum;                   /**< Total number failures            */
0077     long lastexectimeusec;              /**< Last exec time                   */
0078     long maxexectimeusec;               /**< max exec time                    */
0079     long minexectimeusec;               /**< min exec time                    */
0080 } ndrx_adm_svcgrp_t;
0081 
0082 /**
0083  * Service group class infos mapping table
0084  */
0085 expublic ndrx_adm_elmap_t ndrx_G_svcgrp_map[] =
0086 {  
0087     /* Driving of the Preparing: */
0088      {TA_LMID,                  TPADM_EL(ndrx_adm_svcgrp_t, lmid)}
0089     ,{TA_SERVICENAME,            TPADM_EL(ndrx_adm_svcgrp_t, servicename)}
0090     ,{TA_SRVGRP,                TPADM_EL(ndrx_adm_svcgrp_t, srvgrp)}
0091     ,{TA_STATE,                 TPADM_EL(ndrx_adm_svcgrp_t, state)}
0092     ,{TA_SRVID,                 TPADM_EL(ndrx_adm_svcgrp_t, srvid)}
0093     ,{TA_SVCRNAM,               TPADM_EL(ndrx_adm_svcgrp_t, svcrname)}
0094     ,{TA_NCOMPLETED,            TPADM_EL(ndrx_adm_svcgrp_t, ncompleted)}
0095     ,{TA_TOTSUCCNUM,            TPADM_EL(ndrx_adm_svcgrp_t, totsuccnum)}
0096     ,{TA_TOTSFAILNUM,           TPADM_EL(ndrx_adm_svcgrp_t, totsfailnum)}
0097     ,{TA_LASTEXECTIMEUSEC,      TPADM_EL(ndrx_adm_svcgrp_t, lastexectimeusec)}
0098     ,{TA_MAXEXECTIMEUSEC,       TPADM_EL(ndrx_adm_svcgrp_t, maxexectimeusec)}
0099     ,{TA_MINEXECTIMEUSEC,       TPADM_EL(ndrx_adm_svcgrp_t, minexectimeusec)}
0100     ,{BBADFLDID}
0101 };
0102 
0103 /*---------------------------Globals------------------------------------*/
0104 /*---------------------------Statics------------------------------------*/
0105 
0106 exprivate ndrx_adm_cursors_t *M_cursnew;
0107 exprivate int M_idx = 0;    /**< Current growlist index */
0108 /*---------------------------Prototypes---------------------------------*/
0109 
0110 /**
0111  * Fill any cluster data here, filter by bridge processes
0112  * @param reply
0113  * @param reply_len
0114  * @return 
0115  */
0116 exprivate int ndrx_adm_svcgrp_proc_list(command_reply_t *reply, size_t reply_len)
0117 {
0118     command_reply_psc_t * psc_info = (command_reply_psc_t*)reply;
0119     int ret = EXSUCCEED;
0120     int i;
0121     if (NDRXD_CALL_TYPE_SVCINFO!=reply->msg_type)
0122     {
0123         /* not payload */
0124         goto out;
0125     }
0126     
0127     NDRX_LOG(log_debug, "psc out srvid: [%d]", psc_info->srvid);
0128     
0129     for (i=0; i<psc_info->svc_count; i++)
0130     {
0131         
0132         ndrx_adm_svcgrp_t svc;
0133         memset(&svc, 0, sizeof(svc));
0134         
0135         NDRX_STRCPY_SAFE(svc.servicename, psc_info->svcdet[i].svc_nm);
0136         snprintf(svc.srvgrp, sizeof(svc.srvgrp), "%d/%d", psc_info->nodeid, 
0137                 psc_info->srvid);
0138         NDRX_STRCPY_SAFE(svc.state, "ACT");
0139         snprintf(svc.lmid, sizeof(svc.lmid), "%d", psc_info->nodeid);
0140         svc.srvid = psc_info->srvid;
0141         NDRX_STRCPY_SAFE(svc.svcrname,psc_info->svcdet[i].fn_nm);
0142         svc.ncompleted = psc_info->svcdet[i].done+psc_info->svcdet[i].fail;
0143         
0144         if (svc.ncompleted < -1)
0145         {
0146             svc.ncompleted = -1;
0147         }
0148         svc.totsuccnum = psc_info->svcdet[i].done;
0149         svc.totsfailnum = psc_info->svcdet[i].fail;
0150         svc.lastexectimeusec = psc_info->svcdet[i].last *1000; /* msec -> usec */
0151         svc.maxexectimeusec = psc_info->svcdet[i].max*1000; /* msec -> usec */
0152         svc.minexectimeusec = psc_info->svcdet[i].min*1000; /* msec -> usec */
0153         
0154         if (svc.lastexectimeusec < -1)
0155         {
0156             svc.lastexectimeusec = -1;
0157         }
0158         
0159         if (svc.maxexectimeusec < -1)
0160         {
0161             svc.maxexectimeusec = -1;
0162         }
0163         
0164         if (svc.minexectimeusec < -1)
0165         {
0166             svc.minexectimeusec = -1;
0167         }
0168         
0169         if (EXSUCCEED!=ndrx_growlist_add(&M_cursnew->list, (void *)&svc, M_idx))
0170         {
0171             NDRX_LOG(log_error, "Growlist failed - out of memory?");
0172             EXFAIL_OUT(ret);
0173         }
0174 
0175         NDRX_LOG(log_debug, "Service added [%s] / [%s]", svc.servicename, svc.srvgrp);
0176         M_idx++;
0177         
0178     }
0179     
0180 out:
0181     return ret;
0182 }
0183 
0184 /**
0185  * Read svcgrp data
0186  * @param clazz class name
0187  * @param cursnew this is new cursor domain model
0188  * @param flags not used
0189  */
0190 expublic int ndrx_adm_svcgrp_get(char *clazz, ndrx_adm_cursors_t *cursnew, long flags)
0191 {
0192     int ret = EXSUCCEED;
0193     
0194     /* init cursor */
0195     M_idx = 0;
0196     
0197     ndrx_growlist_init(&cursnew->list, 100, sizeof(ndrx_adm_svcgrp_t));
0198     
0199     M_cursnew = cursnew;
0200     cursnew->map = ndrx_G_svcgrp_map;
0201     
0202     if (EXSUCCEED!=ndrx_adm_list_call(ndrx_adm_svcgrp_proc_list, 
0203             NDRXD_COM_PSC_RQ, NDRXD_COM_PSC_RP, ndrx_get_G_atmi_conf()->ndrxd_q_str))
0204     {
0205         NDRX_LOG(log_error, "Failed to call PSC");
0206         EXFAIL_OUT(ret);
0207     }
0208     
0209 out:
0210     
0211     if (EXSUCCEED!=ret)
0212     {
0213         ndrx_growlist_free(&M_cursnew->list);
0214     }
0215 
0216     return ret;
0217 }
0218 
0219 /* vim: set ts=4 sw=4 et smartindent: */