Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief `shm_psvc' command implementation - SHM - print services
0003  *
0004  * @file cmd_shm_psvc.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 <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <sys/param.h>
0039 
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042 #include <nstdutil.h>
0043 
0044 #include <ndrx.h>
0045 #include <ndrxdcmn.h>
0046 #include <atmi_int.h>
0047 #include <gencall.h>
0048 #include <nclopt.h>
0049 
0050 #include "nstopwatch.h"
0051 /*---------------------------Externs------------------------------------*/
0052 /*---------------------------Macros-------------------------------------*/
0053 /*---------------------------Enums--------------------------------------*/
0054 /*---------------------------Typedefs-----------------------------------*/
0055 /*---------------------------Globals------------------------------------*/
0056 /*---------------------------Statics------------------------------------*/
0057 exprivate int M_resources;  /**< should we print resources to stdout    */
0058 /*---------------------------Prototypes---------------------------------*/
0059 
0060 
0061 /**
0062  * Print header
0063  * TODO: Print resources for poll srvid/ for System V qids
0064  * @return
0065  */
0066 exprivate void print_hdr(void)
0067 {
0068     fprintf(stderr, "  SLOT SERVICE NAME NSRV FLAGS CSRVS TCLST CMAX CNODES\n");
0069     fprintf(stderr, "------ ------------ ---- ----- ----- ----- ---- --------------------------------\n");
0070 }
0071 
0072 /**
0073  * Generate cluster map
0074  * @param reply
0075  * @return 
0076  */
0077 exprivate char *gen_clstr_map(command_reply_shm_psvc_t * reply)
0078 {
0079     static char map[CONF_NDRX_NODEID_COUNT+1];
0080     char tmp[6];
0081     int i;
0082     map[0] = EXEOS;
0083     
0084     for (i=0; i<CONF_NDRX_NODEID_COUNT; i++)
0085     {
0086         if (reply->cnodes[i].srvs < 10)
0087         {
0088             snprintf(tmp, sizeof(tmp), "%d", reply->cnodes[i].srvs);
0089         }
0090         else
0091         {
0092             NDRX_STRCPY_SAFE(tmp, "+");
0093         }
0094         strcat(map, tmp);
0095     }
0096     
0097     return map;
0098 }
0099 
0100 /**
0101  * Process response back.
0102  * @param reply
0103  * @param reply_len
0104  * @return
0105  */
0106 expublic int shm_psvc_rsp_process(command_reply_t *reply, size_t reply_len)
0107 {
0108     int i;
0109     char svc[12+1];
0110     
0111     if (NDRXD_CALL_TYPE_PM_SHM_PSVC==reply->msg_type)
0112     {
0113         command_reply_shm_psvc_t * shm_psvc_info = (command_reply_shm_psvc_t*)reply;
0114         
0115         FIX_SVC_NM(shm_psvc_info->service, svc, (sizeof(svc)-1));
0116                 
0117         fprintf(stdout, "%6d %-12.12s %4.4s %5d %5d %5d %4d %-*.*s\n", 
0118             shm_psvc_info->slot, 
0119             svc,
0120             ndrx_decode_num(shm_psvc_info->srvs, 0, 0, 1),
0121             shm_psvc_info->flags,
0122             shm_psvc_info->csrvs, shm_psvc_info->totclustered,
0123             shm_psvc_info->cnodes_max_id, 
0124             CONF_NDRX_NODEID_COUNT,
0125             CONF_NDRX_NODEID_COUNT, gen_clstr_map(shm_psvc_info));
0126         
0127         /* print only if -r flag applied (resources) for system v & pool */
0128         /* This is poll mode, provide info about individual serves: */
0129         
0130         if (M_resources && shm_psvc_info->resids[0].resid)
0131         {
0132             fprintf(stderr, "\t\n");
0133             fprintf(stderr, "\tRES NO IDENTIFIER SERVERS\n");
0134             fprintf(stderr, "\t------ ---------- -------\n");
0135             for (i=0; i<shm_psvc_info->resnr; i++)
0136             {
0137                 fprintf(stdout, "\t%6d %10d %7hd\n", 
0138                         i, shm_psvc_info->resids[i].resid,
0139                         shm_psvc_info->resids[i].cnt);
0140             }
0141             fprintf(stderr, "\t\n");
0142             
0143             /* home some header more... */
0144             print_hdr();
0145         }
0146     }
0147     
0148     return EXSUCCEED;
0149 }
0150 
0151 /**
0152  * Get service listings
0153  * @param p_cmd_map
0154  * @param argc
0155  * @param argv
0156  * @return EXSUCCEED/EXFAIL
0157  */
0158 expublic int cmd_shm_psvc(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0159 {
0160     int ret = EXSUCCEED;
0161     command_call_t call;
0162     
0163     ncloptmap_t clopt[] =
0164     {
0165         {'r', BFLD_INT, (void *)&M_resources, sizeof(M_resources), 
0166                                 NCLOPT_OPT, "Print resources"},
0167         {0}
0168     };
0169     
0170     M_resources = EXFALSE;
0171             
0172     /* parse command line */
0173     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0174     {
0175         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0176         EXFAIL_OUT(ret);
0177     }
0178     
0179     memset(&call, 0, sizeof(call));
0180 
0181     /* Print header at first step! */
0182     print_hdr();
0183     /* Then get listing... */
0184     ret=cmd_generic_listcall(p_cmd_map->ndrxd_cmd, NDRXD_SRC_ADMIN,
0185                         NDRXD_CALL_TYPE_GENERIC,
0186                         &call, sizeof(call),
0187                         G_config.reply_queue_str,
0188                         G_config.reply_queue,
0189                         G_config.ndrxd_q,
0190                         G_config.ndrxd_q_str,
0191                         argc, argv,
0192                         p_have_next,
0193                         G_call_args,
0194                         EXFALSE,
0195                         G_config.listcall_flags);
0196 out:
0197     return ret;
0198 }
0199 
0200 /* vim: set ts=4 sw=4 et smartindent: */