Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Service data grabber -> basic info about services in system.
0003  *
0004  * @file service.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 
0054 #include "tpadmsv.h"
0055 #include "expr.h"
0056 #include "atmi_shm.h"
0057 /*---------------------------Externs------------------------------------*/
0058 /*---------------------------Macros-------------------------------------*/
0059 /*---------------------------Enums--------------------------------------*/
0060 /*---------------------------Typedefs-----------------------------------*/
0061 
0062 /**
0063  * Image of the queue
0064  * + OID HASH.
0065  */
0066 typedef struct 
0067 {
0068     char lmid[MAXTIDENT+1];     /**< Service / cluster node id (reported from) */
0069     char service[MAXTIDENT+1];  /**< Service name                              */
0070     char state[3+1];            /**< Service state ACT only                    */
0071 } ndrx_adm_service_t;
0072 
0073 /**
0074  * Service class infos mapping table
0075  */
0076 expublic ndrx_adm_elmap_t ndrx_G_service_map[] =
0077 {  
0078     /* Driving of the Preparing: */
0079      {TA_LMID,                   TPADM_EL(ndrx_adm_service_t, lmid)}
0080     ,{TA_SERVICENAME,            TPADM_EL(ndrx_adm_service_t, service)}
0081     ,{TA_STATE,                  TPADM_EL(ndrx_adm_service_t, state)}
0082     ,{BBADFLDID}
0083 };
0084 
0085 /*---------------------------Globals------------------------------------*/
0086 /*---------------------------Statics------------------------------------*/
0087 /*---------------------------Prototypes---------------------------------*/
0088 
0089 /**
0090  * Read service data
0091  * @param clazz class name
0092  * @param cursnew this is new cursor domain model
0093  * @param flags not used
0094  */
0095 expublic int ndrx_adm_service_get(char *clazz, ndrx_adm_cursors_t *cursnew, long flags)
0096 {
0097     int ret = EXSUCCEED;
0098     shm_svcinfo_t *svcinfo = (shm_svcinfo_t *) G_svcinfo.mem;
0099     int i;
0100     ndrx_adm_service_t svc;
0101     int idx = 0;
0102     
0103     cursnew->map = ndrx_G_service_map;
0104     
0105     ndrx_growlist_init(&cursnew->list, 100, sizeof(ndrx_adm_service_t));
0106     
0107     if (!ndrx_shm_is_attached(&G_svcinfo))
0108     {
0109         /* no SHM infos */
0110         NDRX_LOG(log_debug, "SHM not attached -> no service count");
0111         ret=EXFAIL;
0112         goto out;
0113     }
0114     
0115     /* Scan the service memory and add some infos up here...
0116      * well will not show dead services and they might be overwritten with
0117      * out lock.
0118      */
0119     for (i=0; i< G_max_svcs; i++)
0120     {
0121         shm_svcinfo_t* ent = SHM_SVCINFO_INDEX(svcinfo, i);
0122 
0123         if (ent->flags & NDRXD_SVCINFO_INIT)
0124         {
0125             memset(&svc, 0, sizeof(svc));
0126             
0127             /* WARNING ! we might get incomplete readings here! */
0128             NDRX_STRCPY_SAFE(svc.service, ent->service);
0129             
0130             if (ent->srvs > 0)
0131             {
0132                 NDRX_STRCPY_SAFE(svc.state, "ACT");
0133             }
0134             else
0135             {
0136                 NDRX_STRCPY_SAFE(svc.state, "INA");
0137             }
0138             snprintf(svc.lmid, sizeof(svc.lmid), "%ld", tpgetnodeid());
0139 
0140             if (EXSUCCEED!=ndrx_growlist_add(&cursnew->list, (void *)&svc, idx))
0141             {
0142                 NDRX_LOG(log_error, "Growlist failed - out of memory?");
0143                 EXFAIL_OUT(ret);
0144             }
0145             idx++;
0146         }
0147     }
0148     
0149 out:
0150 
0151     if (EXSUCCEED!=ret)
0152     {
0153         ndrx_growlist_free(&cursnew->list);
0154     }
0155 
0156     return ret;
0157 }
0158 
0159 /* vim: set ts=4 sw=4 et smartindent: */