Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Command's `appconfig' backend
0003  *   Allow dynamically change ndrxconfig's appconfig section values
0004  *
0005  * @file cmd_appconfig.c
0006  */
0007 /* -----------------------------------------------------------------------------
0008  * Enduro/X Middleware Platform for Distributed Transaction Processing
0009  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0010  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0011  * This software is released under one of the following licenses:
0012  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0013  * See LICENSE file for full text.
0014  * -----------------------------------------------------------------------------
0015  * AGPL license:
0016  *
0017  * This program is free software; you can redistribute it and/or modify it under
0018  * the terms of the GNU Affero General Public License, version 3 as published
0019  * by the Free Software Foundation;
0020  *
0021  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0022  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0023  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0024  * for more details.
0025  *
0026  * You should have received a copy of the GNU Affero General Public License along 
0027  * with this program; if not, write to the Free Software Foundation, Inc.,
0028  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0029  *
0030  * -----------------------------------------------------------------------------
0031  * A commercial use license is available from Mavimax, Ltd
0032  * contact@mavimax.com
0033  * -----------------------------------------------------------------------------
0034  */
0035 #include <string.h>
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <memory.h>
0039 #include <utlist.h>
0040 
0041 #include <ndrstandard.h>
0042 
0043 #include <ndebug.h>
0044 #include <userlog.h>
0045 #include <ndrxd.h>
0046 #include <ndrxdcmn.h>
0047 
0048 #include "cmd_processor.h"
0049 #include <atmi_shm.h>
0050 /*---------------------------Externs------------------------------------*/
0051 /*---------------------------Macros-------------------------------------*/
0052 #define OFSZ(s,e)   EXOFFSET(s,e), EXELEM_SIZE(s,e)
0053 /*---------------------------Enums--------------------------------------*/
0054 /*---------------------------Typedefs-----------------------------------*/
0055 /*---------------------------Globals------------------------------------*/
0056 /*---------------------------Statics------------------------------------*/
0057 /**
0058  * Config field mappings
0059  */
0060 static ndrx_args_loader_t M_appcfg_map[] = 
0061 {
0062     {OFSZ(config_t,sanity),         "sanity",           NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0063     {OFSZ(config_t,checkpm),        "checkpm",          NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0064     {OFSZ(config_t,brrefresh),      "brrefresh",        NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0065     {OFSZ(config_t,restart_min),    "restart_min",      NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0066     {OFSZ(config_t,restart_step),   "restart_step",     NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0067     {OFSZ(config_t,restart_max),    "restart_max",      NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0068     {OFSZ(config_t,restart_to_check),"restart_to_check",NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0069     {OFSZ(config_t,gather_pq_stats), "gather_pq_stats", NDRX_ARGS_BOOL, 0, 0, 0, 0},
0070     {OFSZ(config_t,rqaddrttl),      "rqaddrttl",        NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0071     {EXFAIL}
0072 };
0073 
0074 /*---------------------------Prototypes---------------------------------*/
0075 
0076 /**
0077  * Modify reply according the data.
0078  * @param call
0079  * @param pm
0080  */
0081 expublic void appconfig_reply_mod(command_reply_t *reply, size_t *send_size, 
0082         mod_param_t *params)
0083 {
0084     command_reply_appconfig_t * rply = (command_reply_appconfig_t *)reply;
0085     command_appconfig_t *req = (command_appconfig_t *)params->mod_param1;
0086     
0087     reply->msg_type = NDRXD_CALL_TYPE_APPCONFIG;
0088     /* calculate new send size */
0089     *send_size += (sizeof(command_reply_appconfig_t) - sizeof(command_reply_t));
0090     
0091     /* fill up the data */
0092     NDRX_STRCPY_SAFE(rply->setting, req->setting);
0093     
0094     /* setting value is buffer in request structure... */
0095     NDRX_STRCPY_SAFE(rply->svalue, req->svalue);
0096     
0097     NDRX_LOG(log_debug, "magic: %ld", rply->rply.magic);
0098 }
0099 
0100 
0101 /**
0102  * Call to appconfig command
0103  * @param args
0104  * @return
0105  */
0106 expublic int cmd_appconfig (command_call_t * call, char *data, size_t len, 
0107         int context)
0108 {
0109     int ret=EXSUCCEED;
0110     command_appconfig_t *cfg = (command_appconfig_t *)call;
0111     mod_param_t params;
0112     /*
0113      * Re-use admin error library
0114     char errbuf[RPLY_ERR_MSG_MAX] = {EXEOS};
0115     int error_code = NDRXD_EMINVAL;
0116      * */
0117     char *errbuf;
0118     int *error_code;
0119     int errbufsz;
0120     
0121     memset(&params, 0, sizeof(mod_param_t));
0122     params.mod_param1 = (void *)call;
0123     
0124     errbuf =  NDRXD_error_res_get(&error_code, &errbufsz);
0125     
0126     /* process argument mapping 
0127      * if value is empty is empty, then it is get
0128      * if value is not empty, then it it set
0129      */
0130     /* test is config loaded? */
0131     if (NULL==G_app_config)
0132     {
0133         NDRXD_set_error_msg(NDRXD_ECFGLDED, "App config not loaded - idle instance");
0134     }
0135     else if (EXEOS!=cfg->svalue[0])
0136     {
0137         if (EXSUCCEED!=ndrx_args_loader_set(M_appcfg_map, G_app_config, 
0138             cfg->setting, cfg->svalue, errbuf, errbufsz))
0139         {
0140             *error_code = NDRXD_EINVAL;
0141             NDRX_LOG(log_error, "Failed to apply [%s] setting", cfg->setting);
0142         }
0143     }
0144     else
0145     {
0146         if (EXSUCCEED!=ndrx_args_loader_get(M_appcfg_map, G_app_config, 
0147             cfg->setting, cfg->svalue, sizeof(cfg->svalue), errbuf, errbufsz))
0148         {
0149             *error_code = NDRXD_EINVAL;
0150             NDRX_LOG(log_error, "Failed to get [%s] setting", cfg->setting);
0151         }
0152     }
0153 
0154     if (EXSUCCEED!=simple_command_reply(call, ret, 0L, &params, appconfig_reply_mod, 
0155             0L, 0, NULL))
0156     {
0157         userlog("Failed to send reply back to [%s]", call->reply_queue);
0158     }
0159     
0160 out:
0161     NDRX_LOG(log_warn, "cmd_appconfig returns with status %d", ret);
0162     return ret;
0163 }
0164 
0165 /* vim: set ts=4 sw=4 et smartindent: */