Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Command's `ppm' backend
0003  *
0004  * @file cmd_ppm.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 <utlist.h>
0039 
0040 #include <ndrstandard.h>
0041 
0042 #include <ndebug.h>
0043 #include <userlog.h>
0044 #include <ndrxd.h>
0045 #include <ndrxdcmn.h>
0046 
0047 #include "cmd_processor.h"
0048 #include <atmi_shm.h>
0049 /*---------------------------Externs------------------------------------*/
0050 /*---------------------------Macros-------------------------------------*/
0051 /*---------------------------Enums--------------------------------------*/
0052 /*---------------------------Typedefs-----------------------------------*/
0053 /*---------------------------Globals------------------------------------*/
0054 /*---------------------------Statics------------------------------------*/
0055 /*---------------------------Prototypes---------------------------------*/
0056 
0057 /**
0058  * Modify reply according the data.
0059  * @param call
0060  * @param pm
0061  */
0062 expublic void ppm_reply_mod(command_reply_t *reply, size_t *send_size, mod_param_t *params)
0063 {
0064     command_reply_ppm_t * ppm_info = (command_reply_ppm_t *)reply;
0065     pm_node_t *p_pm = (pm_node_t *)params->mod_param1;
0066     pm_node_svc_t *elt;
0067     ndrx_procgroup_t* p_procgrp = ndrx_ndrxconf_procgroups_resolveno(G_app_config->procgroups
0068         , p_pm->conf->procgrp_no);
0069     ndrx_procgroup_t* p_procgrp_lp = ndrx_ndrxconf_procgroups_resolveno(G_app_config->procgroups
0070         , p_pm->conf->procgrp_lp_no);
0071     
0072     reply->msg_type = NDRXD_CALL_TYPE_PM_PPM;
0073     /* calculate new send size */
0074     *send_size += (sizeof(command_reply_ppm_t) - sizeof(command_reply_t));
0075 
0076     /* Copy data to reply structure */
0077     NDRX_STRCPY_SAFE(ppm_info->binary_name, p_pm->binary_name);
0078     NDRX_STRCPY_SAFE(ppm_info->binary_name_real, p_pm->binary_name_real);
0079     NDRX_STRCPY_SAFE(ppm_info->rqaddress, p_pm->rqaddress);
0080     ppm_info->srvid = p_pm->srvid;
0081     ppm_info->state = p_pm->state;
0082     ppm_info->reqstate = p_pm->reqstate;
0083     ppm_info->autostart = p_pm->autostart;   
0084     ppm_info->exec_seq_try = p_pm->exec_seq_try;
0085     ppm_info->last_startup = p_pm->rspstwatch;
0086     ppm_info->num_term_sigs = p_pm->num_term_sigs;
0087     ppm_info->last_sig = p_pm->last_sig;
0088     ppm_info->autokill = p_pm->autokill;
0089     ppm_info->pid = p_pm->pid;
0090     ppm_info->svpid = p_pm->svpid;
0091     ppm_info->state_changed = p_pm->state_changed;
0092     ppm_info->flags = p_pm->flags;
0093     ppm_info->nodeid = p_pm->nodeid;
0094     ppm_info->procgrp_no = p_pm->conf->procgrp_no;
0095     ppm_info->procgrp_lp_no = p_pm->conf->procgrp_lp_no;
0096     ppm_info->procgrp_lp_no_act = p_pm->procgrp_lp_no;
0097 
0098     if (NULL!=p_procgrp)
0099     {
0100         NDRX_STRCPY_SAFE(ppm_info->procgrp, p_procgrp->grpname);
0101     }
0102     else
0103     {
0104         ppm_info->procgrp[0] = EXEOS;
0105     }
0106 
0107     if (NULL!=p_procgrp_lp)
0108     {
0109         NDRX_STRCPY_SAFE(ppm_info->procgrp_lp, p_procgrp_lp->grpname);
0110     }
0111     else
0112     {
0113         ppm_info->procgrp_lp[0] = EXEOS;
0114     }
0115 
0116     NDRX_LOG(log_debug, "magic: %ld", ppm_info->rply.magic);
0117 }
0118 
0119 /**
0120  * Callback to report startup progress
0121  * @param call
0122  * @param pm
0123  * @return
0124  */
0125 exprivate void ppm_progress(command_call_t * call, pm_node_t *pm)
0126 {
0127     int ret=EXSUCCEED;
0128     mod_param_t params;
0129 
0130     NDRX_LOG(log_debug, "ppm_progress enter");
0131     memset(&params, 0, sizeof(mod_param_t));
0132 
0133     /* pass to reply process model node */
0134     params.mod_param1 = (void *)pm;
0135 
0136     if (EXSUCCEED!=simple_command_reply(call, ret, NDRXD_CALL_FLAGS_RSPHAVE_MORE,
0137                             /* hook up the reply */
0138                             &params, ppm_reply_mod, 0L, 0, NULL))
0139     {
0140         userlog("Failed to send progress back to [%s]", call->reply_queue);
0141     }
0142 
0143     NDRX_LOG(log_debug, "ppm_progress exit");
0144 }
0145 
0146 /**
0147  * Call to psc command
0148  * @param args
0149  * @return
0150  */
0151 expublic int cmd_ppm (command_call_t * call, char *data, size_t len, int context)
0152 {
0153     int ret=EXSUCCEED;
0154     pm_node_t *pm;
0155     
0156     /* list all services from all servers, right? */
0157     DL_FOREACH(G_process_model, pm)
0158     {
0159         ppm_progress(call, pm);
0160     }
0161 
0162     if (EXSUCCEED!=simple_command_reply(call, ret, 0L, NULL, NULL, 0L, 0, NULL))
0163     {
0164         userlog("Failed to send reply back to [%s]", call->reply_queue);
0165     }
0166     
0167     NDRX_LOG(log_warn, "cmd_ppm returns with status %d", ret);
0168     
0169 out:
0170     return ret;
0171 }
0172 
0173 /* vim: set ts=4 sw=4 et smartindent: */