amfutil.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. /** @file exec/amfutil.c
  2. *
  3. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  4. * Author: Steven Dake (sdake@mvista.com)
  5. *
  6. * Copyright (c) 2006 Ericsson AB.
  7. * Author: Hans Feldt
  8. * Description:
  9. * - Reworked to match AMF B.02 information model Description:
  10. * - Refactoring of code into several AMF files
  11. *
  12. * All rights reserved.
  13. *
  14. * This software licensed under BSD license, the text of which follows:
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted provided that the following conditions are met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  25. * contributors may be used to endorse or promote products derived from this
  26. * software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  34. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  35. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  38. * THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * AMF utility functions
  41. *
  42. * This file contains functions that provide different services used by other
  43. * AMF files. For example parsing the configuration file, printing state etc.
  44. *
  45. */
  46. #include <stdio.h>
  47. #include <string.h>
  48. #include <stdlib.h>
  49. #include <errno.h>
  50. #include "../include/saAis.h"
  51. #include "../include/saAmf.h"
  52. #include "../include/ipc_amf.h"
  53. #include "../include/list.h"
  54. #include "util.h"
  55. #include "amf.h"
  56. #include "totem.h"
  57. #include "print.h"
  58. typedef enum {
  59. AMF_HEAD,
  60. AMF_APPLICATION,
  61. AMF_CLUSTER,
  62. AMF_NODE,
  63. AMF_SG,
  64. AMF_SU,
  65. AMF_COMP,
  66. AMF_COMP_ENV_VAR,
  67. AMF_COMP_CS_TYPE,
  68. AMF_SI,
  69. AMF_SI_RANKED_SU,
  70. AMF_SI_DEPENDENCY,
  71. AMF_CSI,
  72. AMF_CSI_ATTRIBUTE,
  73. AMF_HEALTHCHECK,
  74. AMF_CSI_DEPENDENCIES,
  75. AMF_CS_TYPE,
  76. } amf_parse_t;
  77. #ifndef OPENAIS_CLUSTER_STARTUP_TIMEOUT
  78. #define OPENAIS_CLUSTER_STARTUP_TIMEOUT 5000
  79. #endif
  80. static const char *presence_state_text[] = {
  81. "UNKNOWN",
  82. "UNINSTANTIATED",
  83. "INSTANTIATING",
  84. "INSTANTIATED",
  85. "TERMINATING",
  86. "RESTARTING",
  87. "INSTANTION_FAILED",
  88. "TERMINIATION-FAILED"
  89. };
  90. static const char *oper_state_text[] = {
  91. "UNKNOWN",
  92. "ENABLED",
  93. "DISABLED"
  94. };
  95. static const char *admin_state_text[] = {
  96. "UNKNOWN",
  97. "UNLOCKED",
  98. "LOCKED",
  99. "LOCKED-INSTANTIATION",
  100. "SHUTTING-DOWN"
  101. };
  102. static const char *readiness_state_text[] = {
  103. "UNKNOWN",
  104. "OUT-OF-SERVICE",
  105. "IN-SERVICE",
  106. };
  107. static const char *ha_state_text[] = {
  108. "UNKNOWN",
  109. "ACTIVE",
  110. "STANDBY",
  111. "QUIESCED",
  112. "QUIESCING",
  113. };
  114. static const char *assignment_state_text[] = {
  115. "UNKNOWN",
  116. "UNASSIGNED",
  117. "FULLY-ASSIGNED",
  118. "PARTIALLY-ASSIGNED"
  119. };
  120. static int init_category (struct amf_comp *comp, char *loc)
  121. {
  122. if (strcmp (loc, "sa_aware") == 0) {
  123. comp->saAmfCompCategory = SA_AMF_COMP_SA_AWARE;
  124. } else if (strcmp (loc, "proxy") == 0) {
  125. comp->saAmfCompCategory = SA_AMF_COMP_PROXY;
  126. } else if (strcmp (loc, "proxied") == 0) {
  127. comp->saAmfCompCategory = SA_AMF_COMP_PROXIED;
  128. } else if (strcmp (loc, "local") == 0) {
  129. comp->saAmfCompCategory = SA_AMF_COMP_LOCAL;
  130. } else {
  131. return -1;
  132. }
  133. return 0;
  134. }
  135. static int init_capability (struct amf_comp *comp, char *loc)
  136. {
  137. if (strcmp (loc, "x_active_and_y_standby") == 0) {
  138. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE_AND_Y_STANDBY;
  139. } else if (strcmp (loc, "x_active_or_y_standby") == 0) {
  140. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE_OR_Y_STANDBY;
  141. } else if (strcmp (loc, "one_active_or_y_standby") == 0) {
  142. comp->saAmfCompCapability = SA_AMF_COMP_ONE_ACTIVE_OR_Y_STANDBY;
  143. } else if (strcmp (loc, "one_active_or_one_standby") == 0) {
  144. comp->saAmfCompCapability = SA_AMF_COMP_ONE_ACTIVE_OR_ONE_STANDBY;
  145. } else if (strcmp (loc, "x_active") == 0) {
  146. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE;
  147. } else if (strcmp (loc, "1_active") == 0) {
  148. comp->saAmfCompCapability = SA_AMF_COMP_1_ACTIVE;
  149. } else if (strcmp (loc, "non_preinstantiable") == 0) {
  150. comp->saAmfCompCapability = SA_AMF_COMP_NON_PRE_INSTANTIABLE;
  151. } else {
  152. return -1;
  153. }
  154. return 0;
  155. }
  156. static int init_recovery_on_error (struct amf_comp *comp, char *loc)
  157. {
  158. if (strcmp (loc, "component_restart") == 0) {
  159. comp->saAmfCompRecoveryOnError = SA_AMF_COMPONENT_RESTART;
  160. } else if (strcmp (loc, "component_failover") == 0) {
  161. comp->saAmfCompRecoveryOnError = SA_AMF_COMPONENT_FAILOVER;
  162. } else if (strcmp (loc, "node_switchover") == 0) {
  163. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_SWITCHOVER;
  164. } else if (strcmp (loc, "node_failover") == 0) {
  165. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_FAILOVER;
  166. } else if (strcmp (loc, "node_failfast") == 0) {
  167. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_FAILFAST;
  168. } else if (strcmp (loc, "application_restart") == 0) {
  169. comp->saAmfCompRecoveryOnError = SA_AMF_APPLICATION_RESTART;
  170. } else if (strcmp (loc, "cluster_reset") == 0) {
  171. comp->saAmfCompRecoveryOnError = SA_AMF_CLUSTER_RESET;
  172. } else {
  173. return -1;
  174. }
  175. return 0;
  176. }
  177. static void post_init_comp(struct amf_comp *comp)
  178. {
  179. if (comp->saAmfCompInstantiateTimeout == 0) {
  180. comp->saAmfCompInstantiateTimeout = comp->saAmfCompDefaultClcCliTimeout;
  181. }
  182. if (comp->saAmfCompTerminateTimeout == 0) {
  183. comp->saAmfCompTerminateTimeout = comp->saAmfCompDefaultClcCliTimeout;
  184. }
  185. if (comp->saAmfCompCleanupTimeout == 0) {
  186. comp->saAmfCompCleanupTimeout = comp->saAmfCompDefaultClcCliTimeout;
  187. }
  188. if (comp->saAmfCompAmStartTimeout == 0) {
  189. comp->saAmfCompAmStartTimeout = comp->saAmfCompDefaultClcCliTimeout;
  190. }
  191. if (comp->saAmfCompAmStopTimeout == 0) {
  192. comp->saAmfCompAmStopTimeout = comp->saAmfCompDefaultClcCliTimeout;
  193. }
  194. if (comp->saAmfCompTerminateCallbackTimeout == 0) {
  195. comp->saAmfCompTerminateCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  196. }
  197. if (comp->saAmfCompCSISetCallbackTimeout == 0) {
  198. comp->saAmfCompCSISetCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  199. }
  200. if (comp->saAmfCompCSIRmvCallbackTimeout == 0) {
  201. comp->saAmfCompCSIRmvCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  202. }
  203. }
  204. static char *trim_str(char *str)
  205. {
  206. char *s = str + strlen (str) - 1;
  207. while (*s == '\t' || *s == ' ' || *s == '{') {
  208. *s = '\0';
  209. s--;
  210. }
  211. return str;
  212. }
  213. static char *rm_beginning_ws(char *str)
  214. {
  215. char *s = str + strlen (str) - 1;
  216. while (*s == '\t' || *s == ' ') {
  217. *s = '\0';
  218. s--;
  219. }
  220. s = str;
  221. while (*s == '\t' || *s == ' ') {
  222. s++;
  223. }
  224. return s;
  225. }
  226. struct amf_cluster *amf_config_read (char **error_string)
  227. {
  228. char buf[1024];
  229. char *line;
  230. FILE *fp;
  231. char *filename;
  232. amf_parse_t current_parse = AMF_HEAD;
  233. int line_number = 0;
  234. char *loc;
  235. int i;
  236. struct amf_cluster *cluster;
  237. struct amf_application *app = 0;
  238. struct amf_node *node = 0;
  239. struct amf_sg *sg = 0;
  240. struct amf_su *su = 0;
  241. struct amf_comp *comp = 0;
  242. struct amf_si *si = 0;
  243. struct amf_si_ranked_su *si_ranked_su = 0;
  244. struct amf_si_dependency *si_dependency = 0;
  245. struct amf_healthcheck *healthcheck = 0;
  246. struct amf_csi *csi = 0;
  247. struct amf_csi_attribute *attribute = 0;
  248. SaStringT env_var;
  249. int comp_env_var_cnt = 0;
  250. int comp_cs_type_cnt = 0;
  251. int csi_attr_cnt = 0;
  252. int csi_dependencies_cnt = 0;
  253. char *error_reason = NULL;
  254. char *value;
  255. filename = getenv("OPENAIS_AMF_CONFIG_FILE");
  256. if (!filename) {
  257. filename = "/etc/ais/amf.conf";
  258. }
  259. fp = fopen (filename, "r");
  260. if (fp == 0) {
  261. sprintf (buf, "Can't read %s file reason = (%s).\n",
  262. filename, strerror (errno));
  263. *error_string = buf;
  264. return NULL;
  265. }
  266. cluster = amf_cluster_create ();
  267. assert (cluster != NULL);
  268. while (fgets (buf, 255, fp)) {
  269. line_number += 1;
  270. line = buf;
  271. line[strlen(line) - 1] = '\0';
  272. /*
  273. * Clear out comments and empty lines
  274. */
  275. if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') {
  276. continue;
  277. }
  278. /*
  279. * Clear out white space and tabs
  280. */
  281. for (i = strlen (line) - 1; i > -1; i--) {
  282. if (line[i] == '\t' || line[i] == ' ') {
  283. line[i] = '\0';
  284. } else {
  285. break;
  286. }
  287. }
  288. /* Trim whitespace from beginning of string */
  289. line = rm_beginning_ws(line);
  290. error_reason = line;
  291. error_reason = NULL;
  292. switch (current_parse) {
  293. case AMF_HEAD:
  294. if ((loc = strstr_rs (line, "safAmfCluster=")) != 0) {
  295. setSaNameT (&cluster->name, trim_str (loc));
  296. current_parse = AMF_CLUSTER;
  297. } else {
  298. goto parse_error;
  299. }
  300. break;
  301. case AMF_CLUSTER:
  302. if ((loc = strstr_rs (line, "saAmfClusterClmCluster=")) != 0) {
  303. setSaNameT (&cluster->saAmfClusterClmCluster, loc);
  304. } else if ((loc = strstr_rs (line, "saAmfClusterStartupTimeout=")) != 0) {
  305. cluster->saAmfClusterStartupTimeout = atol(loc);
  306. } else if ((loc = strstr_rs (line, "safAmfNode=")) != 0) {
  307. node = calloc (1, sizeof (struct amf_node));
  308. node->next = cluster->node_head;
  309. cluster->node_head = node;
  310. node->saAmfNodeAdminState = SA_AMF_ADMIN_UNLOCKED;
  311. node->saAmfNodeAutoRepair = SA_TRUE;
  312. node->cluster = cluster;
  313. node->saAmfNodeSuFailOverProb = -1;
  314. node->saAmfNodeSuFailoverMax = ~0;
  315. setSaNameT (&node->name, trim_str (loc));
  316. current_parse = AMF_NODE;
  317. } else if ((loc = strstr_rs (line, "safApp=")) != 0) {
  318. app = calloc (1, sizeof (struct amf_application));
  319. app->next = cluster->application_head;
  320. cluster->application_head = app;
  321. app->cluster = cluster;
  322. app->saAmfApplicationAdminState = SA_AMF_ADMIN_UNLOCKED;
  323. setSaNameT (&app->name, trim_str (loc));
  324. current_parse = AMF_APPLICATION;
  325. } else if (strstr_rs (line, "}")) {
  326. if (cluster->saAmfClusterStartupTimeout == -1) {
  327. error_reason = "saAmfClusterStartupTimeout missing";
  328. goto parse_error;
  329. }
  330. /* spec: set to default value if zero */
  331. if (cluster->saAmfClusterStartupTimeout == 0) {
  332. cluster->saAmfClusterStartupTimeout = OPENAIS_CLUSTER_STARTUP_TIMEOUT;
  333. }
  334. current_parse = AMF_HEAD;
  335. } else {
  336. goto parse_error;
  337. }
  338. break;
  339. case AMF_NODE:
  340. if ((loc = strstr_rs (line, "saAmfNodeSuFailOverProb")) != 0) {
  341. node->saAmfNodeSuFailOverProb = atol(loc);
  342. } else if ((loc = strstr_rs (line, "saAmfNodeSuFailoverMax")) != 0) {
  343. node->saAmfNodeSuFailoverMax = atol(loc);
  344. } else if ((loc = strstr_rs (line, "saAmfNodeAutoRepair=")) != 0) {
  345. if (strcmp (loc, "true") == 0) {
  346. node->saAmfNodeAutoRepair = SA_TRUE;
  347. } else if (strcmp (loc, "false") == 0) {
  348. node->saAmfNodeAutoRepair = SA_FALSE;
  349. } else {
  350. goto parse_error;
  351. }
  352. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnTerminationFailure=")) != 0) {
  353. if (strcmp (loc, "true") == 0) {
  354. node->saAmfNodeRebootOnTerminationFailure = SA_TRUE;
  355. } else if (strcmp (loc, "false") == 0) {
  356. node->saAmfNodeRebootOnTerminationFailure = SA_FALSE;
  357. } else {
  358. goto parse_error;
  359. }
  360. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnInstantiationFailure=")) != 0) {
  361. if (strcmp (loc, "true") == 0) {
  362. node->saAmfNodeRebootOnInstantiationFailure = SA_TRUE;
  363. } else if (strcmp (loc, "false") == 0) {
  364. node->saAmfNodeRebootOnInstantiationFailure = SA_FALSE;
  365. } else {
  366. goto parse_error;
  367. }
  368. } else if (strstr_rs (line, "}")) {
  369. if (node->saAmfNodeSuFailOverProb == -1) {
  370. error_reason = "saAmfNodeSuFailOverProb missing";
  371. goto parse_error;
  372. }
  373. if (node->saAmfNodeSuFailoverMax == ~0) {
  374. error_reason = "saAmfNodeSuFailoverMax missing";
  375. goto parse_error;
  376. }
  377. current_parse = AMF_CLUSTER;
  378. } else {
  379. goto parse_error;
  380. }
  381. break;
  382. case AMF_APPLICATION:
  383. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  384. strcpy (app->clccli_path, loc);
  385. } else if ((loc = strstr_rs (line, "safSg=")) != 0) {
  386. sg = calloc (1, sizeof (struct amf_sg));
  387. sg->next = app->sg_head;
  388. app->sg_head = sg;
  389. sg->saAmfSGAdminState = SA_AMF_ADMIN_UNLOCKED;
  390. sg->saAmfSGNumPrefActiveSUs = 1;
  391. sg->saAmfSGNumPrefStandbySUs = 1;
  392. sg->saAmfSGCompRestartProb = -1;
  393. sg->saAmfSGCompRestartMax = ~0;
  394. sg->saAmfSGSuRestartProb = -1;
  395. sg->saAmfSGSuRestartMax = ~0;
  396. sg->saAmfSGAutoAdjustProb = -1;
  397. sg->saAmfSGAutoRepair = SA_TRUE;
  398. sg->application = app;
  399. current_parse = AMF_SG;
  400. setSaNameT (&sg->name, trim_str (loc));
  401. } else if ((loc = strstr_rs (line, "safSi=")) != 0) {
  402. si = calloc (1, sizeof (struct amf_si));
  403. si->next = app->si_head;
  404. app->si_head = si;
  405. si->application = app;
  406. si->saAmfSIPrefActiveAssignments = 1;
  407. si->saAmfSIPrefStandbyAssignments = 1;
  408. setSaNameT (&si->name, trim_str (loc));
  409. si->saAmfSIAdminState = SA_AMF_ADMIN_UNLOCKED;
  410. si->saAmfSIAssignmentState = SA_AMF_ASSIGNMENT_UNASSIGNED;
  411. current_parse = AMF_SI;
  412. } else if ((loc = strstr_rs (line, "safCSType=")) != 0) {
  413. current_parse = AMF_CS_TYPE;
  414. } else if (strstr_rs (line, "}")) {
  415. current_parse = AMF_CLUSTER;
  416. } else {
  417. goto parse_error;
  418. }
  419. break;
  420. case AMF_SG:
  421. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  422. strcpy (sg->clccli_path, loc);
  423. } else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) {
  424. if (strcmp (loc, "2n") == 0) {
  425. sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL;
  426. } else if (strcmp (loc, "nplusm") == 0) {
  427. sg->saAmfSGRedundancyModel = SA_AMF_NPM_REDUNDANCY_MODEL;
  428. } else if (strcmp (loc, "nway") == 0) {
  429. error_reason = "nway redundancy model not supported";
  430. goto parse_error;
  431. } else if (strcmp (loc, "nwayactive") == 0) {
  432. error_reason = "nway active redundancy model not supported";
  433. goto parse_error;
  434. } else if (strcmp (loc, "noredundancy") == 0) {
  435. sg->saAmfSGRedundancyModel = SA_AMF_NO_REDUNDANCY_MODEL;
  436. } else {
  437. goto parse_error;
  438. }
  439. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefActiveSUs=")) != 0) {
  440. sg->saAmfSGNumPrefActiveSUs = atoi (loc);
  441. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefStandbySUs=")) != 0) {
  442. sg->saAmfSGNumPrefStandbySUs = atoi (loc);
  443. } else if ((loc = strstr_rs (line, "saAmfSGMaxActiveSIsperSUs=")) != 0) {
  444. sg->saAmfSGMaxActiveSIsperSUs = atoi (loc);
  445. } else if ((loc = strstr_rs (line, "saAmfSGMaxStandbySIsperSUs=")) != 0) {
  446. sg->saAmfSGMaxStandbySIsperSUs = atoi (loc);
  447. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartProb=")) != 0) {
  448. sg->saAmfSGCompRestartProb = atoi (loc);
  449. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartMax=")) != 0) {
  450. sg->saAmfSGCompRestartMax = atoi (loc);
  451. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartProb=")) != 0) {
  452. sg->saAmfSGSuRestartProb = atoi (loc);
  453. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartMax=")) != 0) {
  454. sg->saAmfSGSuRestartMax = atoi (loc);
  455. } else if ((loc = strstr_rs (line, "saAmfSGAutoAdjustProb=")) != 0) {
  456. sg->saAmfSGAutoAdjustProb = atoi (loc);
  457. } else if ((loc = strstr_rs (line, "saAmfSGAutoRepair=")) != 0) {
  458. sg->saAmfSGAutoRepair = atoi (loc);
  459. } else if ((loc = strstr_rs (line, "safSu=")) != 0) {
  460. su = calloc (1, sizeof (struct amf_su));
  461. su->next = sg->su_head;
  462. sg->su_head = su;
  463. su->sg = sg;
  464. su->saAmfSUAdminState = SA_AMF_ADMIN_UNLOCKED;
  465. su->saAmfSUOperState = SA_AMF_OPERATIONAL_DISABLED;
  466. su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  467. su->escalation_level = ESCALATION_LEVEL_NO_ESCALATION;
  468. su->saAmfSUFailover = 1;
  469. setSaNameT (&su->name, trim_str (loc));
  470. current_parse = AMF_SU;
  471. } else if (strstr_rs (line, "}")) {
  472. if (sg->saAmfSGRedundancyModel == 0) {
  473. error_reason = "saAmfSGRedundancyModel missing";
  474. goto parse_error;
  475. }
  476. if (sg->saAmfSGCompRestartProb == -1) {
  477. error_reason = "saAmfSGCompRestartProb missing";
  478. goto parse_error;
  479. }
  480. if (sg->saAmfSGCompRestartMax == ~0) {
  481. error_reason = "saAmfSGCompRestartMax missing";
  482. goto parse_error;
  483. }
  484. if (sg->saAmfSGSuRestartProb == -1) {
  485. error_reason = "saAmfSGSuRestartProb missing";
  486. goto parse_error;
  487. }
  488. if (sg->saAmfSGSuRestartMax == ~0) {
  489. error_reason = "saAmfSGSuRestartMax missing";
  490. goto parse_error;
  491. }
  492. if (sg->saAmfSGAutoAdjustProb == -1) {
  493. error_reason = "saAmfSGAutoAdjustProb missing";
  494. goto parse_error;
  495. }
  496. if (sg->saAmfSGAutoRepair > 1) {
  497. error_reason = "saAmfSGAutoRepair erroneous";
  498. goto parse_error;
  499. }
  500. current_parse = AMF_APPLICATION;
  501. } else {
  502. goto parse_error;
  503. }
  504. break;
  505. case AMF_SU:
  506. if ((loc = strstr_rs (line, "saAmfSUNumComponents=")) != 0) {
  507. su->saAmfSUNumComponents = atoi (loc);
  508. } else if ((loc = strstr_rs (line, "saAmfSUIsExternal=")) != 0) {
  509. su->saAmfSUIsExternal = atoi (loc);
  510. } else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) {
  511. su->saAmfSUFailover = atoi (loc);
  512. } else if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  513. strcpy (su->clccli_path, loc);
  514. } else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) {
  515. setSaNameT (&su->saAmfSUHostedByNode, loc);
  516. } else if ((loc = strstr_rs (line, "safComp=")) != 0) {
  517. comp = amf_comp_create (su);
  518. comp_env_var_cnt = 0;
  519. comp_cs_type_cnt = 0;
  520. setSaNameT (&comp->name, trim_str (loc));
  521. current_parse = AMF_COMP;
  522. } else if (strstr_rs (line, "}")) {
  523. if (su->saAmfSUNumComponents == 0) {
  524. error_reason = "saAmfSUNumComponents missing";
  525. goto parse_error;
  526. }
  527. if (su->saAmfSUIsExternal > 1) {
  528. error_reason = "saAmfSUIsExternal erroneous";
  529. goto parse_error;
  530. }
  531. if (su->saAmfSUFailover > 1) {
  532. error_reason = "saAmfSUFailover erroneous";
  533. goto parse_error;
  534. }
  535. if (strcmp ((char*)su->saAmfSUHostedByNode.value, "") == 0) {
  536. error_reason = "saAmfSUHostedByNode missing";
  537. goto parse_error;
  538. }
  539. current_parse = AMF_SG;
  540. } else {
  541. goto parse_error;
  542. }
  543. break;
  544. case AMF_COMP:
  545. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  546. strcpy (comp->clccli_path, loc);
  547. } else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) {
  548. current_parse = AMF_COMP_CS_TYPE;
  549. } else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) {
  550. if (init_category(comp, loc) != 0) {
  551. error_reason = "unknown category";
  552. goto parse_error;
  553. }
  554. } else if ((loc = strstr_rs (line, "saAmfCompCapability=")) != 0) {
  555. if (init_capability(comp, loc) != 0) {
  556. error_reason = "unknown capability model";
  557. goto parse_error;
  558. }
  559. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxActiveCsi=")) != 0) {
  560. comp->saAmfCompNumMaxActiveCsi = atol (loc);
  561. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxStandbyCsi=")) != 0) {
  562. comp->saAmfCompNumMaxStandbyCsi = atol (loc);
  563. } else if ((loc = strstr_rs (line, "saAmfCompCmdEnv{")) != 0) {
  564. current_parse = AMF_COMP_ENV_VAR;
  565. } else if ((loc = strstr_rs(line, "saAmfCompDefaultClcCliTimeout=")) != 0) {
  566. comp->saAmfCompDefaultClcCliTimeout = atol (loc);
  567. } else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) {
  568. comp->saAmfCompDefaultCallbackTimeOut = atol (loc);
  569. } else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) {
  570. comp->saAmfCompInstantiateCmdArgv = malloc (strlen(loc) + 1);
  571. strcpy (comp->saAmfCompInstantiateCmdArgv, loc);
  572. } else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) {
  573. comp->saAmfCompInstantiateCmd = malloc (strlen(loc) + 1);
  574. strcpy (comp->saAmfCompInstantiateCmd, loc);
  575. } else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) {
  576. comp->saAmfCompInstantiateTimeout = atol (loc);
  577. } else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) {
  578. comp->saAmfCompInstantiationLevel = atol (loc);
  579. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithoutDelay=")) != 0) {
  580. comp->saAmfCompNumMaxInstantiateWithoutDelay = atol (loc);
  581. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithDelay=")) != 0) {
  582. comp->saAmfCompNumMaxInstantiateWithDelay = atol (loc);
  583. } else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) {
  584. comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc);
  585. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) {
  586. comp->saAmfCompTerminateCmdArgv = malloc (strlen(loc) + 1);
  587. strcpy (comp->saAmfCompTerminateCmdArgv, loc);
  588. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) {
  589. comp->saAmfCompTerminateCmd = malloc (strlen(loc) + 1);
  590. strcpy (comp->saAmfCompTerminateCmd, loc);
  591. } else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) {
  592. comp->saAmfCompTerminateTimeout = atol (loc);
  593. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) {
  594. comp->saAmfCompCleanupCmdArgv = malloc (strlen(loc) + 1);
  595. strcpy (comp->saAmfCompCleanupCmdArgv, loc);
  596. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) {
  597. comp->saAmfCompCleanupCmd = malloc (strlen(loc) + 1);
  598. strcpy (comp->saAmfCompCleanupCmd, loc);
  599. } else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) {
  600. comp->saAmfCompCleanupTimeout = atol (loc);
  601. } else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) {
  602. comp->saAmfCompTerminateCallbackTimeout = atol (loc);
  603. } else if ((loc = strstr_rs(line, "saAmfCompCSISetCallbackTimeout=")) != 0) {
  604. comp->saAmfCompCSISetCallbackTimeout = atol (loc);
  605. } else if ((loc = strstr_rs(line, "saAmfCompQuiescingCompleteTimeout=")) != 0) {
  606. comp->saAmfCompQuiescingCompleteTimeout = atol (loc);
  607. } else if ((loc = strstr_rs(line, "saAmfCompCSIRmvCallbackTimeout=")) != 0) {
  608. comp->saAmfCompCSIRmvCallbackTimeout = atol (loc);
  609. } else if ((loc = strstr_rs (line, "saAmfCompRecoveryOnError=")) != 0) {
  610. if (init_recovery_on_error (comp, loc) != 0) {
  611. error_reason = "bad value";
  612. goto parse_error;
  613. }
  614. } else if ((loc = strstr_rs (line, "saAmfCompDisableRestart")) != 0) {
  615. if (strcmp (loc, "false") == 0) {
  616. comp->saAmfCompDisableRestart = SA_FALSE;
  617. } else if (strcmp (loc, "true") == 0) {
  618. comp->saAmfCompDisableRestart = SA_TRUE;
  619. } else {
  620. error_reason = "bad value";
  621. goto parse_error;
  622. }
  623. } else if ((loc = strstr_rs (line, "saAmfCompProxyCsi=")) != 0) {
  624. setSaNameT (&comp->saAmfCompProxyCsi, loc);
  625. } else if ((loc = strstr_rs (line, "safHealthcheckKey=")) != 0) {
  626. healthcheck = calloc (1, sizeof (struct amf_healthcheck));
  627. healthcheck->next = comp->healthcheck_head;
  628. comp->healthcheck_head = healthcheck;
  629. healthcheck->comp = comp;
  630. strcpy ((char *)healthcheck->safHealthcheckKey.key, trim_str (loc));
  631. healthcheck->safHealthcheckKey.keyLen = strlen (loc);
  632. current_parse = AMF_HEALTHCHECK;
  633. } else if (strstr_rs (line, "}")) {
  634. if (comp->saAmfCompCategory == 0) {
  635. error_reason = "category missing";
  636. goto parse_error;
  637. }
  638. if (comp->saAmfCompCapability == 0) {
  639. error_reason = "capability model missing";
  640. goto parse_error;
  641. }
  642. if (comp->saAmfCompCategory == SA_AMF_COMP_SA_AWARE) {
  643. comp->comptype = clc_component_sa_aware;
  644. } else if (comp->saAmfCompCategory == SA_AMF_COMP_PROXY) {
  645. if (comp->saAmfCompCapability == SA_AMF_COMP_NON_PRE_INSTANTIABLE) {
  646. comp->comptype = clc_component_proxied_non_pre;
  647. } else {
  648. comp->comptype = clc_component_proxied_pre;
  649. }
  650. } else if (comp->saAmfCompCategory == SA_AMF_COMP_LOCAL) {
  651. comp->comptype = clc_component_non_proxied_non_sa_aware;
  652. }
  653. if (comp->saAmfCompNumMaxActiveCsi == 0) {
  654. error_reason = "saAmfCompNumMaxActiveCsi missing";
  655. goto parse_error;
  656. }
  657. if (comp->saAmfCompNumMaxStandbyCsi == 0) {
  658. error_reason = "saAmfCompNumMaxStandbyCsi missing";
  659. goto parse_error;
  660. }
  661. if (comp->saAmfCompDefaultClcCliTimeout == 0) {
  662. error_reason = "saAmfCompDefaultClcCliTimeout missing or erroneous";
  663. goto parse_error;
  664. }
  665. if (comp->saAmfCompDefaultCallbackTimeOut == 0) {
  666. error_reason = "saAmfCompDefaultCallbackTimeOut missing or erroneous";
  667. goto parse_error;
  668. }
  669. if (comp->saAmfCompRecoveryOnError == 0) {
  670. error_reason = "saAmfCompRecoveryOnError missing";
  671. goto parse_error;
  672. }
  673. post_init_comp (comp);
  674. current_parse = AMF_SU;
  675. } else {
  676. error_reason = line;
  677. goto parse_error;
  678. }
  679. break;
  680. case AMF_COMP_CS_TYPE:
  681. if (strstr_rs (line, "}")) {
  682. current_parse = AMF_COMP;
  683. } else {
  684. comp_cs_type_cnt++;
  685. comp->saAmfCompCsTypes = realloc (comp->saAmfCompCsTypes,
  686. (comp_cs_type_cnt + 1) * sizeof(SaNameT));
  687. comp->saAmfCompCsTypes[comp_cs_type_cnt] = NULL;
  688. comp->saAmfCompCsTypes[comp_cs_type_cnt - 1] = malloc (sizeof(SaNameT));
  689. setSaNameT (comp->saAmfCompCsTypes[comp_cs_type_cnt - 1], line);
  690. }
  691. break;
  692. case AMF_COMP_ENV_VAR:
  693. if (strstr_rs (line, "}")) {
  694. current_parse = AMF_COMP;
  695. } else if ((loc = strchr (line, '=')) != 0) {
  696. comp_env_var_cnt++;
  697. comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv,
  698. (comp_env_var_cnt + 1) * sizeof(SaStringT));
  699. comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL;
  700. env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = malloc (strlen (line) + 1);
  701. strcpy (env_var, line);
  702. } else {
  703. goto parse_error;
  704. }
  705. break;
  706. case AMF_HEALTHCHECK:
  707. if ((loc = strstr_rs (line, "saAmfHealthcheckPeriod=")) != 0) {
  708. healthcheck->saAmfHealthcheckPeriod = atoi (loc);
  709. } else if ((loc = strstr_rs (line, "saAmfHealthcheckMaxDuration=")) != 0) {
  710. healthcheck->saAmfHealthcheckMaxDuration = atoi (loc);
  711. } else if (strstr_rs (line, "}")) {
  712. current_parse = AMF_COMP;
  713. } else {
  714. goto parse_error;
  715. }
  716. break;
  717. case AMF_SI:
  718. if ((loc = strstr_rs (line, "safRankedSu=")) != 0) {
  719. si_ranked_su = calloc (1, sizeof(struct amf_si_ranked_su));
  720. si_ranked_su->si_next = si->ranked_sus;
  721. si->ranked_sus = si_ranked_su;
  722. si_ranked_su->si = si;
  723. setSaNameT (&si_ranked_su->name, trim_str (loc));
  724. current_parse = AMF_SI_RANKED_SU;
  725. } else if ((loc = strstr_rs (line, "safDepend=")) != 0) {
  726. si_dependency = calloc (1, sizeof(struct amf_si_dependency));
  727. si_dependency->next = si->depends_on;
  728. si->depends_on = si_dependency;
  729. setSaNameT (&si_dependency->name, trim_str (loc));
  730. current_parse = AMF_SI_DEPENDENCY;
  731. } else if ((loc = strstr_rs (line, "safCsi=")) != 0) {
  732. csi = calloc (1, sizeof(struct amf_csi));
  733. csi->next = si->csi_head;
  734. si->csi_head = csi;
  735. csi->si = si;
  736. setSaNameT (&csi->name, trim_str (loc));
  737. current_parse = AMF_CSI;
  738. } else if ((loc = strstr_rs (line, "saAmfSIProtectedbySG{")) != 0) {
  739. setSaNameT (&si->saAmfSIProtectedbySG, loc);
  740. } else if ((loc = strstr_rs (line, "saAmfSIRank{")) != 0) {
  741. si->saAmfSIRank = atoi (loc);
  742. } else if ((loc = strstr_rs (line, "saAmfSINumCSIs=")) != 0) {
  743. si->saAmfSINumCSIs = atoi (loc);
  744. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  745. si->saAmfSIPrefActiveAssignments = atoi (loc);
  746. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  747. si->saAmfSIPrefStandbyAssignments = atoi (loc);
  748. } else if (strstr_rs (line, "}")) {
  749. if (si->saAmfSINumCSIs == 0) {
  750. error_reason = "saAmfSINumCSIs missing";
  751. goto parse_error;
  752. }
  753. current_parse = AMF_APPLICATION;
  754. } else {
  755. goto parse_error;
  756. }
  757. break;
  758. case AMF_SI_RANKED_SU:
  759. if ((loc = strstr_rs (line, "saAmfRank=")) != 0) {
  760. si_ranked_su->saAmfRank = atoi (loc);
  761. } else if (strstr_rs (line, "}")) {
  762. current_parse = AMF_SI;
  763. } else {
  764. goto parse_error;
  765. }
  766. break;
  767. case AMF_SI_DEPENDENCY:
  768. if ((loc = strstr_rs (line, "saAmfToleranceTime=")) != 0) {
  769. si_dependency->saAmfToleranceTime = atoi (loc);
  770. } else if (strstr_rs (line, "}")) {
  771. current_parse = AMF_SI;
  772. } else {
  773. goto parse_error;
  774. }
  775. break;
  776. case AMF_CSI:
  777. if ((loc = strstr_rs (line, "saAmfCSTypeName=")) != 0) {
  778. setSaNameT (&csi->saAmfCSTypeName, loc);
  779. } else if ((loc = strstr_rs (line, "safCSIAttr=")) != 0) {
  780. attribute = calloc (1, sizeof(struct amf_csi_attribute));
  781. attribute->next = csi->attributes_head;
  782. csi->attributes_head = attribute;
  783. attribute->name = malloc (strlen (loc) + 1);
  784. strcpy (attribute->name, trim_str (loc));
  785. csi_attr_cnt = 1;
  786. current_parse = AMF_CSI_ATTRIBUTE;
  787. } else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) {
  788. csi_dependencies_cnt = 0;
  789. current_parse = AMF_CSI_DEPENDENCIES;
  790. } else if (strstr_rs (line, "}")) {
  791. if (strcmp(getSaNameT(&csi->saAmfCSTypeName), "") == 0) {
  792. error_reason = "saAmfCSTypeName missing";
  793. goto parse_error;
  794. }
  795. current_parse = AMF_SI;
  796. } else {
  797. goto parse_error;
  798. }
  799. break;
  800. case AMF_CSI_DEPENDENCIES:
  801. if (strstr_rs (line, "}")) {
  802. current_parse = AMF_CSI;
  803. } else if ((loc = strstr_rs (line, "saAmfCSIDependency=")) != 0) {
  804. csi_dependencies_cnt++;
  805. csi->saAmfCSIDependencies = realloc (csi->saAmfCSIDependencies,
  806. (csi_dependencies_cnt + 1) * sizeof(SaNameT));
  807. csi->saAmfCSIDependencies[csi_dependencies_cnt] = NULL;
  808. csi->saAmfCSIDependencies[csi_dependencies_cnt - 1] = malloc (sizeof(SaNameT));
  809. setSaNameT (csi->saAmfCSIDependencies[csi_dependencies_cnt - 1], loc);
  810. } else {
  811. goto parse_error;
  812. }
  813. break;
  814. case AMF_CSI_ATTRIBUTE:
  815. if ((loc = strstr_rs (line, "}")) != 0) {
  816. current_parse = AMF_CSI;
  817. } else {
  818. value = rm_beginning_ws (line);
  819. attribute->value = realloc (attribute->value,
  820. sizeof (SaStringT) * (csi_attr_cnt + 1));
  821. attribute->value[csi_attr_cnt - 1] = malloc (strlen (value) + 1);
  822. strcpy (attribute->value[csi_attr_cnt - 1], value);
  823. attribute->value[csi_attr_cnt] = NULL;
  824. csi_attr_cnt++;
  825. }
  826. break;
  827. case AMF_CS_TYPE:
  828. if ((loc = strstr_rs (line, "}")) != 0) {
  829. current_parse = AMF_APPLICATION;
  830. }
  831. break;
  832. default:
  833. error_reason = "Invalid state\n";
  834. goto parse_error;
  835. break;
  836. }
  837. }
  838. fclose (fp);
  839. return cluster;
  840. parse_error:
  841. sprintf (buf, "parse error at %s: %d: %s\n",
  842. filename, line_number, error_reason);
  843. *error_string = buf;
  844. fclose (fp);
  845. return NULL;
  846. }
  847. void amf_runtime_attributes_print (struct amf_cluster *cluster)
  848. {
  849. struct amf_node *node;
  850. struct amf_application *app;
  851. struct amf_sg *sg;
  852. struct amf_su *su;
  853. struct amf_comp *comp;
  854. struct amf_si *si;
  855. struct amf_csi *csi;
  856. struct amf_si_assignment *si_assignment;
  857. struct amf_csi_assignment *csi_assignment;
  858. dprintf("AMF runtime attributes:");
  859. dprintf("===================================================");
  860. dprintf("safCluster=%s", getSaNameT(&cluster->name));
  861. dprintf(" admin state: %s\n", admin_state_text[cluster->saAmfClusterAdminState]);
  862. for (node = cluster->node_head; node != NULL; node = node->next) {
  863. dprintf(" safNode=%s\n", getSaNameT (&node->name));
  864. dprintf(" admin state: %s\n", admin_state_text[node->saAmfNodeAdminState]);
  865. dprintf(" oper state: %s\n", oper_state_text[node->saAmfNodeOperState]);
  866. }
  867. for (app = cluster->application_head; app != NULL; app = app->next) {
  868. dprintf(" safApp=%s\n", getSaNameT(&app->name));
  869. dprintf(" admin state: %s\n", admin_state_text[app->saAmfApplicationAdminState]);
  870. dprintf(" num_sg: %d\n", app->saAmfApplicationCurrNumSG);
  871. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  872. dprintf(" safSG=%s\n", getSaNameT(&sg->name));
  873. dprintf(" admin state: %s\n", admin_state_text[sg->saAmfSGAdminState]);
  874. dprintf(" assigned SUs %d\n", sg->saAmfSGNumCurrAssignedSUs);
  875. dprintf(" non inst. spare SUs %d\n", sg->saAmfSGNumCurrNonInstantiatedSpareSUs);
  876. dprintf(" inst. spare SUs %d\n", sg->saAmfSGNumCurrInstantiatedSpareSUs);
  877. for (su = sg->su_head; su != NULL; su = su->next) {
  878. dprintf(" safSU=%s\n", getSaNameT(&su->name));
  879. dprintf(" oper state: %s\n", oper_state_text[su->saAmfSUOperState]);
  880. dprintf(" admin state: %s\n", admin_state_text[su->saAmfSUAdminState]);
  881. dprintf(" readiness state: %s\n", readiness_state_text[su->saAmfSUReadinessState]);
  882. dprintf(" presence state: %s\n", presence_state_text[su->saAmfSUPresenceState]);
  883. dprintf(" hosted by node %s\n", su->saAmfSUHostedByNode.value);
  884. dprintf(" num active SIs %d\n", su->saAmfSUNumCurrActiveSIs);
  885. dprintf(" num standby SIs %d\n", su->saAmfSUNumCurrStandbySIs);
  886. dprintf(" restart count %d\n", su->saAmfSURestartCount);
  887. dprintf(" escalation level %d\n", su->escalation_level);
  888. dprintf(" SU failover cnt %d\n", su->su_failover_cnt);
  889. dprintf(" assigned SIs:");
  890. for (si_assignment = su->assigned_sis; si_assignment != NULL;
  891. si_assignment = si_assignment->next) {
  892. dprintf(" safSi=%s\n", si_assignment->si->name.value);
  893. dprintf(" HA state: %s\n",
  894. ha_state_text[si_assignment->saAmfSISUHAState]);
  895. }
  896. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  897. dprintf(" safComp=%s\n", getSaNameT(&comp->name));
  898. dprintf(" oper state: %s\n",
  899. oper_state_text[comp->saAmfCompOperState]);
  900. dprintf(" readiness state: %s\n",
  901. readiness_state_text[comp->saAmfCompReadinessState]);
  902. dprintf(" presence state: %s\n",
  903. presence_state_text[comp->saAmfCompPresenceState]);
  904. dprintf(" num active CSIs %d\n",
  905. comp->saAmfCompNumCurrActiveCsi);
  906. dprintf(" num standby CSIs %d\n",
  907. comp->saAmfCompNumCurrStandbyCsi);
  908. dprintf(" restart count %d\n", comp->saAmfCompRestartCount);
  909. dprintf(" assigned CSIs:");
  910. for (csi_assignment = comp->assigned_csis; csi_assignment != NULL;
  911. csi_assignment = csi_assignment->comp_next) {
  912. dprintf(" safCSI=%s\n", csi_assignment->csi->name.value);
  913. dprintf(" HA state: %s\n",
  914. ha_state_text[csi_assignment->saAmfCSICompHAState]);
  915. }
  916. }
  917. }
  918. }
  919. for (si = app->si_head; si != NULL; si = si->next) {
  920. dprintf(" safSi=%s\n", getSaNameT(&si->name));
  921. dprintf(" admin state: %s\n", admin_state_text[si->saAmfSIAdminState]);
  922. dprintf(" assignm. state: %s\n", assignment_state_text[si->saAmfSIAssignmentState]);
  923. dprintf(" active assignments: %d\n", si->saAmfSINumCurrActiveAssignments);
  924. dprintf(" standby assignments: %d\n", si->saAmfSINumCurrStandbyAssignments);
  925. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  926. dprintf(" safCsi=%s\n", getSaNameT(&csi->name));
  927. }
  928. }
  929. }
  930. dprintf("===================================================");
  931. }
  932. /* to be removed... */
  933. int amf_enabled (struct objdb_iface_ver0 *objdb)
  934. {
  935. unsigned int object_service_handle;
  936. char *value;
  937. int enabled = 0;
  938. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  939. if (objdb->object_find (
  940. OBJECT_PARENT_HANDLE,
  941. "amf",
  942. strlen ("amf"),
  943. &object_service_handle) == 0) {
  944. value = NULL;
  945. if ( !objdb->object_key_get (object_service_handle,
  946. "mode",
  947. strlen ("mode"),
  948. (void *)&value,
  949. NULL) && value) {
  950. if (strcmp (value, "enabled") == 0) {
  951. enabled = 1;
  952. } else
  953. if (strcmp (value, "disabled") == 0) {
  954. enabled = 0;
  955. }
  956. }
  957. }
  958. return enabled;
  959. }
  960. const char *amf_admin_state (int state)
  961. {
  962. return admin_state_text[state];
  963. }
  964. const char *amf_op_state (int state)
  965. {
  966. return oper_state_text[state];
  967. }
  968. const char *amf_presence_state (int state)
  969. {
  970. return presence_state_text[state];
  971. }
  972. const char *amf_ha_state (int state)
  973. {
  974. return ha_state_text[state];
  975. }
  976. const char *amf_readiness_state (int state)
  977. {
  978. return readiness_state_text[state];
  979. }