Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Change queue attributes
0003  *
0004  * @file cmd_mqch.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 <ndrxdcmn.h>
0045 #include <atmi_int.h>
0046 #include <gencall.h>
0047 #include <utlist.h>
0048 #include <Exfields.h>
0049 
0050 #include "xa_cmn.h"
0051 #include <ndrx.h>
0052 #include <qcommon.h>
0053 #include <nclopt.h>
0054 /*---------------------------Externs------------------------------------*/
0055 /*---------------------------Macros-------------------------------------*/
0056 /*---------------------------Enums--------------------------------------*/
0057 /*---------------------------Typedefs-----------------------------------*/
0058 /*---------------------------Globals------------------------------------*/
0059 /*---------------------------Statics------------------------------------*/
0060 exprivate char M_qspace[XATMI_SERVICE_NAME_LENGTH+1] = "";
0061 /*---------------------------Prototypes---------------------------------*/
0062 
0063 /**
0064  * Change queue settings (by using config string)
0065  * @param p_cmd_map
0066  * @param argc
0067  * @param argv
0068  * @return SUCCEED
0069  */
0070 expublic int cmd_mqch(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0071 {
0072     int ret = EXSUCCEED;
0073     char qconf[512];
0074     short srvid, nodeid;
0075     UBFH *p_ub = NULL;
0076     char cmd = TMQ_CMD_MQCH;
0077     char qspacesvc[XATMI_SERVICE_NAME_LENGTH+1]; /* real service name */
0078     long rsplen;    
0079     
0080     ncloptmap_t clopt[] =
0081     {
0082         {'n', BFLD_SHORT, (char *)&nodeid, 0, 
0083                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Cluster node id"},
0084         {'i', BFLD_SHORT, (char *)&srvid, 0, 
0085                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Server ID"},
0086         {'q', BFLD_STRING, qconf, sizeof(qconf), 
0087                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Queue config string"},
0088         {0}
0089     };
0090     
0091     /* parse command line */
0092     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0093     {
0094         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0095         EXFAIL_OUT(ret);
0096     }
0097     
0098     /* we need to init TP subsystem... */
0099     if (EXSUCCEED!=tpinit(NULL))
0100     {
0101         fprintf(stderr, "Failed to tpinit(): %s", tpstrerror(tperrno));
0102         NDRX_LOG(log_error, "Failed to tpinit(): %s", tpstrerror(tperrno));
0103         EXFAIL_OUT(ret);
0104     }
0105     
0106     /* Setup the FB & call the server.. */
0107     p_ub = (UBFH *)tpalloc("UBF", "", 1024);
0108          
0109     if (NULL==p_ub)
0110     {
0111         fprintf(stderr, "Failed to alloc call buffer%s", tpstrerror(tperrno));
0112         NDRX_LOG(log_error,"Failed to alloc call buffer%s", tpstrerror(tperrno));
0113         EXFAIL_OUT(ret);
0114     }
0115 
0116     if (EXSUCCEED!=Bchg(p_ub, EX_QCMD, 0, &cmd, 0L))
0117     {
0118         fprintf(stderr, "Failed to set command: %s", Bstrerror(Berror));
0119         NDRX_LOG(log_error,"Failed to set command: %s", Bstrerror(Berror));
0120         EXFAIL_OUT(ret);
0121     }
0122     
0123     if (EXSUCCEED!=CBchg(p_ub, EX_DATA, 0, qconf, 0L, BFLD_STRING))
0124     {
0125         fprintf(stderr, "Failed to set data: %s", Bstrerror(Berror));
0126         NDRX_LOG(log_error,"Failed to set data: %s", Bstrerror(Berror));
0127         EXFAIL_OUT(ret);
0128     }
0129     
0130     snprintf(qspacesvc, sizeof(qspacesvc), NDRX_SVC_TMQ, (long)nodeid, (int)srvid);
0131     
0132     NDRX_LOG(log_info, "Calling: %s", qspacesvc);
0133 
0134     if (EXSUCCEED!=tpcall(qspacesvc, (char *)p_ub, 0L, 
0135             (char **)&p_ub, &rsplen, TPNOTRAN))
0136     {
0137         NDRX_LOG(log_error,"Failed: %s", tpstrerror(tperrno));
0138         
0139         printf("Failed: %s\n", tpstrerror(tperrno));
0140     }
0141     else
0142     {
0143         printf("OK\n");
0144     }
0145     
0146 out:
0147     return ret;
0148 }
0149 
0150 /* vim: set ts=4 sw=4 et smartindent: */