equilibrium-mgmt_ui.c

Go to the documentation of this file.
00001 /*
00002  * $Id: equilibrium-mgmt_ui.c 346460 2009-11-14 05:06:47Z ssiano $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  * 
00010  * Copyright (c) 2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013  
00014 
00022 #include <sync/common.h>
00023 #include <junoscript/xmllib_pub.h>
00024 #include <junoscript/xmlrpc.h>
00025 #include <junoscript/xmlstr.h>
00026 #include <ddl/defs.h>
00027 #include "equilibrium-mgmt_main.h"
00028 #include "equilibrium-mgmt_kcom.h"
00029 #include "equilibrium-mgmt_config.h"
00030 #include "equilibrium-mgmt_conn.h"
00031 #include "equilibrium-mgmt_logging.h"
00032 
00033 #include EQUILIBRIUM_ODL_H
00034 #include EQUILIBRIUM_OUT_H
00035 
00036 /*** Constants ***/
00037 
00038 
00039 /*** Data Structures ***/
00040 
00041 
00042 // See menu structure at the bottom of this file
00043 
00044 
00045 /*** STATIC/INTERNAL Functions ***/
00046 
00047 
00060 static void
00061 show_application_status(mgmt_sock_t * msp,
00062                         const char * ss_name,
00063                         const eq_app_t * app)
00064 {
00065     eq_server_t * server = NULL;
00066     struct in_addr addr;
00067     
00068     XML_OPEN(msp, ODCI_APPLICATION_STATUS);
00069     
00070     XML_ELT(msp, ODCI_SERVICE_SET_NAME, "%s", ss_name);
00071     XML_ELT(msp, ODCI_APPLICATION_NAME, "%s", app->application_name);
00072     
00073     if(app->servers != NULL) {
00074         
00075         XML_OPEN(msp, ODCI_SERVER_LIST);
00076         
00077         server = TAILQ_FIRST(app->servers);
00078         while(server != NULL) {
00079             
00080             XML_OPEN(msp, ODCI_SERVER);
00081             addr.s_addr = server->server_addr;
00082             XML_ELT(msp, ODCI_ADDRESS, "%s", inet_ntoa(addr));
00083             if(app->server_mon_params != NULL) {
00084                XML_ELT(msp, ODCI_STATE, "%s", (server->status) ? "up" : "down");
00085             } else {
00086                 XML_ELT(msp, ODCI_STATE, "%s", "up");
00087             }
00088             XML_CLOSE(msp, ODCI_SERVER);            
00089             
00090             server = TAILQ_NEXT(server, entries);
00091         }
00092         
00093         XML_CLOSE(msp, ODCI_SERVER_LIST);
00094     }
00095     
00096     XML_ELT(msp, ODCI_SESSION_COUNT, "%d", app->session_count);
00097     
00098     XML_CLOSE(msp, ODCI_APPLICATION_STATUS);
00099 }
00100 
00101 
00116 static int32_t
00117 equilibrium_show_status(mgmt_sock_t * msp,
00118                         parse_status_t * csb __unused,
00119                         char * unparsed)
00120 {
00121     char * ss_name = NULL;
00122     char * app_name = NULL;
00123     char * token;
00124     eq_serviceset_t * ss;
00125     eq_app_t * app;
00126     
00127     if(unparsed != NULL) {
00128         token = strtok(unparsed, " "); // parse the rest
00129         while(token != NULL) {
00130             if(strcmp(token, DDLNAME_SHOW_EQ_STATUS_SERVICE_SET) == 0) {
00131                 ss_name = strtok(NULL, " ");
00132             } else if(strcmp(token, DDLNAME_SHOW_EQ_STATUS_APPLICATION) == 0) {
00133                 app_name = strtok(NULL, " ");
00134             } else {
00135                 XML_RAW(msp, 0, xml_error_str(TRUE, NULL, NULL, NULL, NULL,
00136                         token, NULL, "Command was not parsed correctly"));
00137                 return 0;
00138             }
00139             token = strtok(NULL, " ");
00140         }
00141         
00142         if(app_name != NULL && ss_name == NULL) {
00143             // this is not allowed but we can't enforce it through DDL 
00144             //  in SDK apps currently
00145 
00146             XML_RAW(msp, 0, xml_error_str(FALSE, NULL, NULL, NULL, NULL, 
00147                "application", NULL, 
00148                "Service set must be specified if an application is specified"));
00149             
00150             return 0;
00151         }
00152     }
00153     
00154     XML_OPEN(msp, ODCI_EQUILIBRIUM_STATUS);
00155 
00156     if(ss_name == NULL) {
00157         // show all service sets
00158         ss = next_service_set(NULL);
00159         while(ss != NULL) {
00160             // show all applications of this service set
00161             app = next_application(ss, NULL);
00162             while(app != NULL) {
00163                 show_application_status(msp, ss->svc_set_name, app);
00164                 app = next_application(ss, app);
00165             }
00166             ss = next_service_set(ss);
00167         }
00168     } else {
00169         if((ss = find_service_set(ss_name)) != NULL) {
00170             // show only selected service set
00171             if(app_name == NULL) {
00172                 // show all applications
00173                 app = next_application(ss, NULL);
00174                 while(app != NULL) {
00175                     show_application_status(msp, ss->svc_set_name, app);
00176                     app = next_application(ss, app);
00177                 }
00178             } else {
00179                 // show only selected application
00180                 if((app = find_application(ss, app_name)) != NULL) {
00181                     show_application_status(msp, ss->svc_set_name, app);
00182                 } else {
00183                     XML_RAW(msp, 0, xml_error_str(FALSE, NULL, NULL, NULL, NULL, 
00184                        app_name, NULL, "Application not found"));
00185                 }
00186                 
00187             }
00188         } else {
00189             XML_RAW(msp, 0, xml_error_str(FALSE, NULL, NULL, NULL, NULL, 
00190                ss_name, NULL, "Service set not found"));
00191         }
00192     }
00193     
00194     XML_CLOSE(msp, ODCI_EQUILIBRIUM_STATUS);
00195     
00196     return 0;
00197 }
00198 
00199 
00200 /*** GLOBAL/EXTERNAL Functions ***/
00201 
00202 
00203 
00204 /******************************************************************************
00205  *                        Menu Structure
00206  *****************************************************************************/
00207 
00208 /*
00209  * format (from libjuniper's ms_parse.h):
00210  *   command,
00211  *   help desc (or NULL),
00212  *   user data arg block (or 0),
00213  *   child (next) menu (or NULL),
00214  *   handler for command(or 0)
00215  */
00216 
00217 
00221 static const parse_menu_t show_sync_equilibrium_menu[] = {
00222     { "status", NULL, 0, NULL, equilibrium_show_status },
00223     { NULL, NULL, 0, NULL, NULL }
00224 };
00225 
00229 static const parse_menu_t show_sync_menu[] = {
00230     { "equilibrium", NULL, 0, show_sync_equilibrium_menu, NULL },
00231     { NULL, NULL, 0, NULL, NULL }
00232 };
00233 
00237 static const parse_menu_t show_menu[] = {
00238     { "sync", NULL, 0, show_sync_menu, NULL },
00239     { NULL, NULL, 0, NULL, NULL }
00240 };
00241 
00245 const parse_menu_t master_menu[] = {
00246     { "show", NULL, 0, show_menu, NULL }, 
00247     { NULL, NULL, 0, NULL, NULL }
00248 };
00249 

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:57 2010 for SDK Your Net Corporation Equilibrium Load Balancer Example: equilibrium-mgmt 1.0 by Doxygen 1.5.1