Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Domain data grabber
0003  *
0004  * @file domain.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 
0043 #include <ndebug.h>
0044 #include <atmi.h>
0045 #include <atmi_int.h>
0046 #include <typed_buf.h>
0047 #include <ndrstandard.h>
0048 #include <ubf.h>
0049 #include <Exfields.h>
0050 #include <Excompat.h>
0051 #include <ubfutil.h>
0052 #include <sys_unix.h>
0053 #include <atmi_shm.h>
0054 
0055 #include "tpadmsv.h"
0056 #include "expr.h"
0057 /*---------------------------Externs------------------------------------*/
0058 /*---------------------------Macros-------------------------------------*/
0059 /*---------------------------Enums--------------------------------------*/
0060 /*---------------------------Typedefs-----------------------------------*/
0061 
0062 /**
0063  * Image of the machine
0064  */
0065 typedef struct 
0066 {
0067     char domainid[MAXTIDENT+1];/**< cluster node id                            */
0068     char state[3+1];           /**< current number of open conversations       */
0069     long curqueues;            /**< current number of queue                    */
0070     long curservers;           /**< number of server in domain (local)         */
0071     long curservices;          /**< number of services, including cluster      */
0072     
0073 } ndrx_adm_domain_t;
0074 
0075 /**
0076  * Client class infos mapping table
0077  */
0078 expublic ndrx_adm_elmap_t ndrx_G_domain_map[] =
0079 {  
0080     /* Driving of the Preparing: */
0081     {TA_DOMAINID,               TPADM_EL(ndrx_adm_domain_t, domainid)}
0082     ,{TA_STATE,                 TPADM_EL(ndrx_adm_domain_t, state)}
0083     ,{TA_CURQUEUES,             TPADM_EL(ndrx_adm_domain_t, curqueues)}
0084     ,{TA_CURSERVERS,            TPADM_EL(ndrx_adm_domain_t, curservers)}
0085     ,{TA_CURSERVICES,           TPADM_EL(ndrx_adm_domain_t, curservices)}
0086     ,{BBADFLDID}
0087 };
0088 
0089 /*---------------------------Globals------------------------------------*/
0090 /*---------------------------Statics------------------------------------*/
0091 /*---------------------------Prototypes---------------------------------*/
0092 
0093 /**
0094  * Read domain data
0095  * @param clazz class name
0096  * @param cursnew this is new cursor domain model
0097  * @param flags not used
0098  */
0099 expublic int ndrx_adm_domain_get(char *clazz, ndrx_adm_cursors_t *cursnew, long flags)
0100 {
0101     int ret = EXSUCCEED;
0102     ndrx_adm_domain_t dom;
0103     string_list_t* qlist = NULL;
0104     string_list_t* elt = NULL;
0105     int typ;
0106     /* this is single entry... */
0107     
0108     cursnew->map = ndrx_G_domain_map;
0109     
0110     memset(&dom, 0, sizeof(dom));
0111     
0112     ndrx_growlist_init(&cursnew->list, 100, sizeof(ndrx_adm_domain_t));
0113     
0114     snprintf(dom.domainid, sizeof(dom.domainid), "%ld", tpgetnodeid());
0115     NDRX_STRCPY_SAFE(dom.state, "ACT");
0116     
0117     /* counter number of queues: */
0118     qlist = ndrx_sys_mqueue_list_make(G_atmi_env.qpath, &ret);
0119     
0120     if (EXSUCCEED!=ret)
0121     {
0122         NDRX_LOG(log_error, "posix queue listing failed!");
0123         EXFAIL_OUT(ret);
0124     }
0125     
0126     /* get the usage states / check queues... */
0127     LL_FOREACH(qlist,elt)
0128     {
0129         /* if not print all, then skip this queue */
0130         if (0!=strncmp(elt->qname, 
0131                 G_atmi_env.qprefix_match, G_atmi_env.qprefix_match_len))
0132         {
0133             continue;
0134         }
0135         dom.curqueues++;
0136         
0137         /* extract server reply queues */
0138         typ = ndrx_q_type_get(elt->qname);
0139         
0140         if (NDRX_QTYPE_SRVADM==typ)
0141         {
0142             dom.curservers++;
0143         }
0144     }
0145     
0146     /* get count of services, from ndrxd? */
0147     dom.curservices = ndrx_shm_get_svc_count();
0148     
0149     
0150     if (EXSUCCEED!=ndrx_growlist_add(&cursnew->list, (void *)&dom, 0))
0151     {
0152         NDRX_LOG(log_error, "Growlist failed for domain - out of memory?");
0153         EXFAIL_OUT(ret);
0154     }
0155     
0156 out:
0157 
0158     if (NULL!=qlist)
0159     {
0160         ndrx_string_list_free(qlist);
0161     }
0162 
0163     if (EXSUCCEED!=ret)
0164     {
0165         ndrx_growlist_free(&cursnew->list);
0166     }
0167 
0168     return ret;
0169 }
0170 
0171 /* vim: set ts=4 sw=4 et smartindent: */