Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Un-advertise related command back-end
0003  *
0004  * @file cmd_unadv.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 <ndrxd.h>
0044 #include <ndrxdcmn.h>
0045 #include <atmi.h>
0046 #include <cmd_processor.h>
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/
0049 /*---------------------------Enums--------------------------------------*/
0050 /*---------------------------Typedefs-----------------------------------*/
0051 /*---------------------------Globals------------------------------------*/
0052 /*---------------------------Statics------------------------------------*/
0053 /*---------------------------Prototypes---------------------------------*/
0054 
0055 
0056 /**
0057  * Unadvertise service, call from xadmin.
0058  * @param args
0059  * @return 
0060  */
0061 expublic int cmd_xadunadv (command_call_t * call, char *data, size_t len, int context)
0062 {
0063     int ret=EXSUCCEED;
0064     command_dynadvertise_t *unadv_xa = (command_dynadvertise_t *)call;
0065     command_dynadvertise_t call_srv;
0066     pm_node_t * p_pm;
0067     
0068     memset(&call_srv, 0, sizeof(call_srv));
0069     
0070     if (NULL==(p_pm = get_pm_from_srvid(unadv_xa->srvid)))
0071     {
0072         NDRXD_set_error_fmt(NDRXD_EINVPARAM, "Invalid server id %d",
0073                                     unadv_xa->srvid);
0074         ret=EXFAIL;
0075         goto out;
0076     }
0077     
0078     /*Fill some details for unadvertise*/
0079     NDRX_STRCPY_SAFE(call_srv.svc_nm, unadv_xa->svc_nm);
0080     
0081     /* Call the server */
0082     ret = cmd_generic_call(NDRXD_COM_NXDUNADV_RQ, NDRXD_SRC_ADMIN,
0083             NDRXD_CALL_TYPE_GENERIC,
0084             (command_call_t *)&call_srv, sizeof(call_srv),
0085             G_command_state.listenq_str,
0086             G_command_state.listenq,
0087             (mqd_t)EXFAIL,
0088             get_srv_admin_q(p_pm),
0089             0, NULL,
0090             NULL,
0091             NULL,
0092             NULL,
0093             EXFALSE);
0094 out:
0095     if (EXSUCCEED!=simple_command_reply(call, ret, 0L, NULL, NULL, 0L, 0, NULL))
0096     {
0097         userlog("Failed to send reply back to [%s]", call->reply_queue);
0098     }
0099 
0100     NDRX_LOG(log_warn, "cmd_unadv_xadmin returns with status %d", ret);
0101     
0102     return EXSUCCEED; /* Do not want to break the system! */
0103 }
0104 
0105 /**
0106  * Unadvertise service, requested by server - remove from service array
0107  * and remove from shm.
0108  * @param call
0109  * @param data
0110  * @param len
0111  * @param context
0112  * @return  
0113  */
0114 expublic int cmd_srvunadv (command_call_t * call, char *data, size_t len, int context)
0115 {
0116     int ret=EXSUCCEED;
0117     command_dynadvertise_t * unadv = (command_dynadvertise_t *)call;
0118     pm_node_t *p_pm = get_pm_from_srvid(unadv->srvid);
0119     
0120     if (NULL==p_pm)
0121     {
0122         NDRX_LOG(log_error, "No such server with id: %d", unadv->srvid);
0123     }
0124     else
0125     {
0126         NDRX_LOG(log_error, "Server id=%d ok, binary: [%s], removing service: [%s]", 
0127                 unadv->srvid, p_pm->binary_name, unadv->svc_nm);
0128         remove_startfail_process(p_pm, unadv->svc_nm, NULL);
0129     }
0130     
0131 out:
0132     return ret;
0133 }
0134 /* vim: set ts=4 sw=4 et smartindent: */