Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Reload configuration call
0003  *
0004  * @file cmd_reload.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 
0039 #include <ndrstandard.h>
0040 
0041 #include "ndebug.h"
0042 #include "userlog.h"
0043 #include "cmd_processor.h"
0044 #include <ndrxd.h>
0045 /*---------------------------Externs------------------------------------*/
0046 /*---------------------------Macros-------------------------------------*/
0047 /*---------------------------Enums--------------------------------------*/
0048 /*---------------------------Typedefs-----------------------------------*/
0049 /*---------------------------Globals------------------------------------*/
0050 /*---------------------------Statics------------------------------------*/
0051 /*---------------------------Prototypes---------------------------------*/
0052 
0053 /**
0054  * Modify reply according the data.
0055  * @param call
0056  * @param pm
0057  */
0058 expublic void reload_reply_mod(command_reply_t *reply, size_t *send_size, mod_param_t *paramsg)
0059 {
0060     mod_param5_t *params = (mod_param5_t *)paramsg;
0061             
0062     command_reply_reload_t * err_info = (command_reply_reload_t *)reply;
0063    
0064     reply->msg_type = NDRXD_CALL_TYPE_PM_RELERR;
0065     /* calculate new send size */
0066     *send_size += (sizeof(command_reply_reload_t) - sizeof(command_reply_t));
0067 
0068     if (NULL!=params->mod_param1)
0069         NDRX_STRCPY_SAFE(err_info->old_binary, params->mod_param1);
0070 
0071     if (NULL!=params->mod_param3)
0072         NDRX_STRCPY_SAFE(err_info->new_binary, params->mod_param3);
0073 
0074     err_info->error = params->param2;
0075     err_info->srvid = (int)params->param4;
0076     /* error msg... */
0077     NDRX_STRCPY_SAFE(err_info->msg, params->param5);
0078 
0079     NDRX_LOG(log_debug, "magic: %ld", err_info->rply.magic);
0080 }
0081 
0082 /**
0083  * Callback to report startup progress
0084  * @param call
0085  * @param pm
0086  * @return
0087  */
0088 expublic void reload_error(command_call_t * call, int srvid, char *old_bin, 
0089         char *new_bin, int error, char *msg)
0090 {
0091     int ret=EXSUCCEED;
0092     mod_param5_t params;
0093 
0094     NDRX_LOG(log_debug, "reload_error enter");
0095     memset(&params, 0, sizeof(mod_param_t));
0096 
0097     /* pass to reply process model node */
0098     params.mod_param1 = old_bin;
0099     params.param2 = error;
0100     params.mod_param3 = new_bin;
0101     params.param4 = srvid;
0102     NDRX_STRCPY_SAFE(params.param5, msg);
0103 
0104     if (EXSUCCEED!=simple_command_reply(call, ret, NDRXD_CALL_FLAGS_RSPHAVE_MORE,
0105                             /* hook up the reply */
0106                             (mod_param_t*)&params, reload_reply_mod, 0L, 0, NULL))
0107     {
0108         userlog("Failed to send progress back to [%s]", call->reply_queue);
0109     }
0110 
0111     NDRX_LOG(log_debug, "reload_error exit");
0112 }
0113 
0114 /**
0115  * Reload configuration
0116  * @param args
0117  * @return
0118  */
0119 expublic int cmd_testcfg (command_call_t * call, char *data, size_t len, int context)
0120 {
0121     int ret=EXSUCCEED;
0122 
0123     ret = test_config(EXFALSE, call, reload_error);
0124 
0125     if (EXSUCCEED!=simple_command_reply(call, ret, 0L, NULL, NULL, 0L, 0, NULL))
0126     {
0127         userlog("Failed to send reply back to [%s]", call->reply_queue);
0128     }
0129 
0130     NDRX_LOG(log_warn, "cmd_testcfg returns with status %d", ret);
0131 
0132     return EXSUCCEED; /* Do not want to break the system! */
0133 }
0134 
0135 
0136 /**
0137  * Reload configuration
0138  * @param args
0139  * @return 
0140  */
0141 expublic int cmd_reload (command_call_t * call, char *data, size_t len, int context)
0142 {
0143     int ret=EXSUCCEED;
0144 
0145     ret = test_config(EXTRUE, call, reload_error);
0146 
0147     if (EXSUCCEED!=simple_command_reply(call, ret, 0L, NULL, NULL, 0L, 0, NULL))
0148     {
0149         userlog("Failed to send reply back to [%s]", call->reply_queue);
0150     }
0151 
0152     NDRX_LOG(log_warn, "cmd_reload returns with status %d", ret);
0153     
0154     return EXSUCCEED; /* Do not want to break the system! */
0155 }
0156 /* vim: set ts=4 sw=4 et smartindent: */