amfutil.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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 su_cnt = 0;
  250. int sg_cnt = 0;
  251. int comp_env_var_cnt = 0;
  252. int comp_cs_type_cnt = 0;
  253. int csi_attr_cnt = 0;
  254. int csi_dependencies_cnt = 0;
  255. char *error_reason = NULL;
  256. char *value;
  257. filename = getenv("OPENAIS_AMF_CONFIG_FILE");
  258. if (!filename) {
  259. filename = "/etc/ais/amf.conf";
  260. }
  261. fp = fopen (filename, "r");
  262. if (fp == 0) {
  263. sprintf (buf, "Can't read %s file reason = (%s).\n",
  264. filename, strerror (errno));
  265. *error_string = buf;
  266. return NULL;
  267. }
  268. cluster = amf_cluster_create ();
  269. assert (cluster != NULL);
  270. while (fgets (buf, 255, fp)) {
  271. line_number += 1;
  272. line = buf;
  273. line[strlen(line) - 1] = '\0';
  274. /*
  275. * Clear out comments and empty lines
  276. */
  277. if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') {
  278. continue;
  279. }
  280. /*
  281. * Clear out white space and tabs
  282. */
  283. for (i = strlen (line) - 1; i > -1; i--) {
  284. if (line[i] == '\t' || line[i] == ' ') {
  285. line[i] = '\0';
  286. } else {
  287. break;
  288. }
  289. }
  290. /* Trim whitespace from beginning of string */
  291. line = rm_beginning_ws(line);
  292. error_reason = line;
  293. error_reason = NULL;
  294. switch (current_parse) {
  295. case AMF_HEAD:
  296. if ((loc = strstr_rs (line, "safAmfCluster=")) != 0) {
  297. setSaNameT (&cluster->name, trim_str (loc));
  298. current_parse = AMF_CLUSTER;
  299. } else {
  300. goto parse_error;
  301. }
  302. break;
  303. case AMF_CLUSTER:
  304. if ((loc = strstr_rs (line, "saAmfClusterClmCluster=")) != 0) {
  305. setSaNameT (&cluster->saAmfClusterClmCluster, loc);
  306. } else if ((loc = strstr_rs (line, "saAmfClusterStartupTimeout=")) != 0) {
  307. cluster->saAmfClusterStartupTimeout = atol(loc);
  308. } else if ((loc = strstr_rs (line, "safAmfNode=")) != 0) {
  309. node = calloc (1, sizeof (struct amf_node));
  310. node->next = cluster->node_head;
  311. cluster->node_head = node;
  312. node->saAmfNodeAdminState = SA_AMF_ADMIN_UNLOCKED;
  313. node->saAmfNodeAutoRepair = SA_TRUE;
  314. node->cluster = cluster;
  315. node->saAmfNodeSuFailOverProb = -1;
  316. node->saAmfNodeSuFailoverMax = ~0;
  317. setSaNameT (&node->name, trim_str (loc));
  318. current_parse = AMF_NODE;
  319. } else if ((loc = strstr_rs (line, "safApp=")) != 0) {
  320. app = calloc (1, sizeof (struct amf_application));
  321. app->next = cluster->application_head;
  322. cluster->application_head = app;
  323. app->cluster = cluster;
  324. app->saAmfApplicationAdminState = SA_AMF_ADMIN_UNLOCKED;
  325. setSaNameT (&app->name, trim_str (loc));
  326. current_parse = AMF_APPLICATION;
  327. sg_cnt = 0;
  328. } else if (strstr_rs (line, "}")) {
  329. if (cluster->saAmfClusterStartupTimeout == -1) {
  330. error_reason = "saAmfClusterStartupTimeout missing";
  331. goto parse_error;
  332. }
  333. /* spec: set to default value if zero */
  334. if (cluster->saAmfClusterStartupTimeout == 0) {
  335. cluster->saAmfClusterStartupTimeout = OPENAIS_CLUSTER_STARTUP_TIMEOUT;
  336. }
  337. current_parse = AMF_HEAD;
  338. } else {
  339. goto parse_error;
  340. }
  341. break;
  342. case AMF_NODE:
  343. if ((loc = strstr_rs (line, "saAmfNodeSuFailOverProb")) != 0) {
  344. node->saAmfNodeSuFailOverProb = atol(loc);
  345. } else if ((loc = strstr_rs (line, "saAmfNodeSuFailoverMax")) != 0) {
  346. node->saAmfNodeSuFailoverMax = atol(loc);
  347. } else if ((loc = strstr_rs (line, "saAmfNodeAutoRepair=")) != 0) {
  348. if (strcmp (loc, "true") == 0) {
  349. node->saAmfNodeAutoRepair = SA_TRUE;
  350. } else if (strcmp (loc, "false") == 0) {
  351. node->saAmfNodeAutoRepair = SA_FALSE;
  352. } else {
  353. goto parse_error;
  354. }
  355. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnTerminationFailure=")) != 0) {
  356. if (strcmp (loc, "true") == 0) {
  357. node->saAmfNodeRebootOnTerminationFailure = SA_TRUE;
  358. } else if (strcmp (loc, "false") == 0) {
  359. node->saAmfNodeRebootOnTerminationFailure = SA_FALSE;
  360. } else {
  361. goto parse_error;
  362. }
  363. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnInstantiationFailure=")) != 0) {
  364. if (strcmp (loc, "true") == 0) {
  365. node->saAmfNodeRebootOnInstantiationFailure = SA_TRUE;
  366. } else if (strcmp (loc, "false") == 0) {
  367. node->saAmfNodeRebootOnInstantiationFailure = SA_FALSE;
  368. } else {
  369. goto parse_error;
  370. }
  371. } else if (strstr_rs (line, "}")) {
  372. if (node->saAmfNodeSuFailOverProb == -1) {
  373. error_reason = "saAmfNodeSuFailOverProb missing";
  374. goto parse_error;
  375. }
  376. if (node->saAmfNodeSuFailoverMax == ~0) {
  377. error_reason = "saAmfNodeSuFailoverMax missing";
  378. goto parse_error;
  379. }
  380. current_parse = AMF_CLUSTER;
  381. } else {
  382. goto parse_error;
  383. }
  384. break;
  385. case AMF_APPLICATION:
  386. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  387. strcpy (app->clccli_path, loc);
  388. } else if ((loc = strstr_rs (line, "safSg=")) != 0) {
  389. sg_cnt++;
  390. sg = calloc (1, sizeof (struct amf_sg));
  391. sg->next = app->sg_head;
  392. app->sg_head = sg;
  393. sg->saAmfSGAdminState = SA_AMF_ADMIN_UNLOCKED;
  394. sg->saAmfSGNumPrefActiveSUs = 1;
  395. sg->saAmfSGNumPrefStandbySUs = 1;
  396. sg->saAmfSGNumPrefInserviceSUs = ~0;
  397. sg->saAmfSGCompRestartProb = -1;
  398. sg->saAmfSGCompRestartMax = ~0;
  399. sg->saAmfSGSuRestartProb = -1;
  400. sg->saAmfSGSuRestartMax = ~0;
  401. sg->saAmfSGAutoAdjustProb = -1;
  402. sg->saAmfSGAutoRepair = SA_TRUE;
  403. sg->application = app;
  404. current_parse = AMF_SG;
  405. su_cnt = 0;
  406. setSaNameT (&sg->name, trim_str (loc));
  407. } else if ((loc = strstr_rs (line, "safSi=")) != 0) {
  408. si = calloc (1, sizeof (struct amf_si));
  409. si->next = app->si_head;
  410. app->si_head = si;
  411. si->application = app;
  412. si->saAmfSIPrefActiveAssignments = 1;
  413. si->saAmfSIPrefStandbyAssignments = 1;
  414. setSaNameT (&si->name, trim_str (loc));
  415. si->saAmfSIAdminState = SA_AMF_ADMIN_UNLOCKED;
  416. current_parse = AMF_SI;
  417. } else if ((loc = strstr_rs (line, "safCSType=")) != 0) {
  418. current_parse = AMF_CS_TYPE;
  419. } else if (strstr_rs (line, "}")) {
  420. if (sg_cnt == 1) {
  421. for (si = app->si_head; si != NULL; si = si->next) {
  422. memcpy (&si->saAmfSIProtectedbySG, &sg->name,
  423. sizeof (SaNameT));
  424. }
  425. } else {
  426. for (si = app->si_head; si != NULL; si = si->next) {
  427. if (si->saAmfSIProtectedbySG.length == 0) {
  428. error_reason = "saAmfSIProtectedbySG not set in SI"
  429. ", needed when several SGs are specified.";
  430. goto parse_error;
  431. }
  432. }
  433. }
  434. current_parse = AMF_CLUSTER;
  435. } else {
  436. goto parse_error;
  437. }
  438. break;
  439. case AMF_SG:
  440. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  441. strcpy (sg->clccli_path, loc);
  442. } else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) {
  443. if (strcmp (loc, "2n") == 0) {
  444. sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL;
  445. } else if (strcmp (loc, "nplusm") == 0) {
  446. sg->saAmfSGRedundancyModel = SA_AMF_NPM_REDUNDANCY_MODEL;
  447. } else if (strcmp (loc, "nway") == 0) {
  448. error_reason = "nway redundancy model not supported";
  449. goto parse_error;
  450. } else if (strcmp (loc, "nwayactive") == 0) {
  451. error_reason = "nway active redundancy model not supported";
  452. goto parse_error;
  453. } else if (strcmp (loc, "noredundancy") == 0) {
  454. sg->saAmfSGRedundancyModel = SA_AMF_NO_REDUNDANCY_MODEL;
  455. } else {
  456. goto parse_error;
  457. }
  458. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefActiveSUs=")) != 0) {
  459. sg->saAmfSGNumPrefActiveSUs = atoi (loc);
  460. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefStandbySUs=")) != 0) {
  461. sg->saAmfSGNumPrefStandbySUs = atoi (loc);
  462. } else if ((loc = strstr_rs (line, "saAmfSGMaxActiveSIsperSUs=")) != 0) {
  463. sg->saAmfSGMaxActiveSIsperSUs = atoi (loc);
  464. } else if ((loc = strstr_rs (line, "saAmfSGMaxStandbySIsperSUs=")) != 0) {
  465. sg->saAmfSGMaxStandbySIsperSUs = atoi (loc);
  466. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartProb=")) != 0) {
  467. sg->saAmfSGCompRestartProb = atoi (loc);
  468. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartMax=")) != 0) {
  469. sg->saAmfSGCompRestartMax = atoi (loc);
  470. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartProb=")) != 0) {
  471. sg->saAmfSGSuRestartProb = atoi (loc);
  472. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartMax=")) != 0) {
  473. sg->saAmfSGSuRestartMax = atoi (loc);
  474. } else if ((loc = strstr_rs (line, "saAmfSGAutoAdjustProb=")) != 0) {
  475. sg->saAmfSGAutoAdjustProb = atoi (loc);
  476. } else if ((loc = strstr_rs (line, "saAmfSGAutoRepair=")) != 0) {
  477. sg->saAmfSGAutoRepair = atoi (loc);
  478. } else if ((loc = strstr_rs (line, "safSu=")) != 0) {
  479. su = calloc (1, sizeof (struct amf_su));
  480. su_cnt++;
  481. su->next = sg->su_head;
  482. sg->su_head = su;
  483. su->sg = sg;
  484. su->saAmfSUAdminState = SA_AMF_ADMIN_UNLOCKED;
  485. su->saAmfSUOperState = SA_AMF_OPERATIONAL_DISABLED;
  486. su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  487. su->restart_control_state = SU_RC_ESCALATION_LEVEL_0;
  488. su->saAmfSUFailover = 1;
  489. setSaNameT (&su->name, trim_str (loc));
  490. current_parse = AMF_SU;
  491. } else if (strstr_rs (line, "}")) {
  492. if (sg->saAmfSGRedundancyModel == 0) {
  493. error_reason = "saAmfSGRedundancyModel missing";
  494. goto parse_error;
  495. }
  496. if (sg->saAmfSGCompRestartProb == -1) {
  497. error_reason = "saAmfSGCompRestartProb missing";
  498. goto parse_error;
  499. }
  500. if (sg->saAmfSGCompRestartMax == ~0) {
  501. error_reason = "saAmfSGCompRestartMax missing";
  502. goto parse_error;
  503. }
  504. if (sg->saAmfSGSuRestartProb == -1) {
  505. error_reason = "saAmfSGSuRestartProb missing";
  506. goto parse_error;
  507. }
  508. if (sg->saAmfSGSuRestartMax == ~0) {
  509. error_reason = "saAmfSGSuRestartMax missing";
  510. goto parse_error;
  511. }
  512. if (sg->saAmfSGAutoAdjustProb == -1) {
  513. error_reason = "saAmfSGAutoAdjustProb missing";
  514. goto parse_error;
  515. }
  516. if (sg->saAmfSGAutoRepair > 1) {
  517. error_reason = "saAmfSGAutoRepair erroneous";
  518. goto parse_error;
  519. }
  520. if (sg->saAmfSGNumPrefInserviceSUs == ~0) {
  521. sg->saAmfSGNumPrefInserviceSUs = su_cnt;
  522. }
  523. current_parse = AMF_APPLICATION;
  524. } else {
  525. goto parse_error;
  526. }
  527. break;
  528. case AMF_SU:
  529. if ((loc = strstr_rs (line, "saAmfSUNumComponents=")) != 0) {
  530. su->saAmfSUNumComponents = atoi (loc);
  531. } else if ((loc = strstr_rs (line, "saAmfSUIsExternal=")) != 0) {
  532. su->saAmfSUIsExternal = atoi (loc);
  533. } else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) {
  534. su->saAmfSUFailover = atoi (loc);
  535. } else if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  536. strcpy (su->clccli_path, loc);
  537. } else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) {
  538. setSaNameT (&su->saAmfSUHostedByNode, loc);
  539. } else if ((loc = strstr_rs (line, "safComp=")) != 0) {
  540. comp = amf_comp_create (su);
  541. comp_env_var_cnt = 0;
  542. comp_cs_type_cnt = 0;
  543. setSaNameT (&comp->name, trim_str (loc));
  544. current_parse = AMF_COMP;
  545. } else if (strstr_rs (line, "}")) {
  546. if (su->saAmfSUNumComponents == 0) {
  547. error_reason = "saAmfSUNumComponents missing";
  548. goto parse_error;
  549. }
  550. if (su->saAmfSUIsExternal > 1) {
  551. error_reason = "saAmfSUIsExternal erroneous";
  552. goto parse_error;
  553. }
  554. if (su->saAmfSUFailover > 1) {
  555. error_reason = "saAmfSUFailover erroneous";
  556. goto parse_error;
  557. }
  558. if (strcmp ((char*)su->saAmfSUHostedByNode.value, "") == 0) {
  559. error_reason = "saAmfSUHostedByNode missing";
  560. goto parse_error;
  561. }
  562. current_parse = AMF_SG;
  563. } else {
  564. goto parse_error;
  565. }
  566. break;
  567. case AMF_COMP:
  568. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  569. strcpy (comp->clccli_path, loc);
  570. } else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) {
  571. current_parse = AMF_COMP_CS_TYPE;
  572. } else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) {
  573. if (init_category(comp, loc) != 0) {
  574. error_reason = "unknown category";
  575. goto parse_error;
  576. }
  577. } else if ((loc = strstr_rs (line, "saAmfCompCapability=")) != 0) {
  578. if (init_capability(comp, loc) != 0) {
  579. error_reason = "unknown capability model";
  580. goto parse_error;
  581. }
  582. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxActiveCsi=")) != 0) {
  583. comp->saAmfCompNumMaxActiveCsi = atol (loc);
  584. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxStandbyCsi=")) != 0) {
  585. comp->saAmfCompNumMaxStandbyCsi = atol (loc);
  586. } else if ((loc = strstr_rs (line, "saAmfCompCmdEnv{")) != 0) {
  587. current_parse = AMF_COMP_ENV_VAR;
  588. } else if ((loc = strstr_rs(line, "saAmfCompDefaultClcCliTimeout=")) != 0) {
  589. comp->saAmfCompDefaultClcCliTimeout = atol (loc);
  590. } else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) {
  591. comp->saAmfCompDefaultCallbackTimeOut = atol (loc);
  592. } else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) {
  593. comp->saAmfCompInstantiateCmdArgv = malloc (strlen(loc) + 1);
  594. strcpy (comp->saAmfCompInstantiateCmdArgv, loc);
  595. } else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) {
  596. comp->saAmfCompInstantiateCmd = malloc (strlen(loc) + 1);
  597. strcpy (comp->saAmfCompInstantiateCmd, loc);
  598. } else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) {
  599. comp->saAmfCompInstantiateTimeout = atol (loc);
  600. } else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) {
  601. comp->saAmfCompInstantiationLevel = atol (loc);
  602. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithoutDelay=")) != 0) {
  603. comp->saAmfCompNumMaxInstantiateWithoutDelay = atol (loc);
  604. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithDelay=")) != 0) {
  605. comp->saAmfCompNumMaxInstantiateWithDelay = atol (loc);
  606. } else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) {
  607. comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc);
  608. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) {
  609. comp->saAmfCompTerminateCmdArgv = malloc (strlen(loc) + 1);
  610. strcpy (comp->saAmfCompTerminateCmdArgv, loc);
  611. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) {
  612. comp->saAmfCompTerminateCmd = malloc (strlen(loc) + 1);
  613. strcpy (comp->saAmfCompTerminateCmd, loc);
  614. } else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) {
  615. comp->saAmfCompTerminateTimeout = atol (loc);
  616. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) {
  617. comp->saAmfCompCleanupCmdArgv = malloc (strlen(loc) + 1);
  618. strcpy (comp->saAmfCompCleanupCmdArgv, loc);
  619. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) {
  620. comp->saAmfCompCleanupCmd = malloc (strlen(loc) + 1);
  621. strcpy (comp->saAmfCompCleanupCmd, loc);
  622. } else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) {
  623. comp->saAmfCompCleanupTimeout = atol (loc);
  624. } else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) {
  625. comp->saAmfCompTerminateCallbackTimeout = atol (loc);
  626. } else if ((loc = strstr_rs(line, "saAmfCompCSISetCallbackTimeout=")) != 0) {
  627. comp->saAmfCompCSISetCallbackTimeout = atol (loc);
  628. } else if ((loc = strstr_rs(line, "saAmfCompQuiescingCompleteTimeout=")) != 0) {
  629. comp->saAmfCompQuiescingCompleteTimeout = atol (loc);
  630. } else if ((loc = strstr_rs(line, "saAmfCompCSIRmvCallbackTimeout=")) != 0) {
  631. comp->saAmfCompCSIRmvCallbackTimeout = atol (loc);
  632. } else if ((loc = strstr_rs (line, "saAmfCompRecoveryOnError=")) != 0) {
  633. if (init_recovery_on_error (comp, loc) != 0) {
  634. error_reason = "bad value";
  635. goto parse_error;
  636. }
  637. } else if ((loc = strstr_rs (line, "saAmfCompDisableRestart")) != 0) {
  638. if (strcmp (loc, "false") == 0) {
  639. comp->saAmfCompDisableRestart = SA_FALSE;
  640. } else if (strcmp (loc, "true") == 0) {
  641. comp->saAmfCompDisableRestart = SA_TRUE;
  642. } else {
  643. error_reason = "bad value";
  644. goto parse_error;
  645. }
  646. } else if ((loc = strstr_rs (line, "saAmfCompProxyCsi=")) != 0) {
  647. setSaNameT (&comp->saAmfCompProxyCsi, loc);
  648. } else if ((loc = strstr_rs (line, "safHealthcheckKey=")) != 0) {
  649. healthcheck = calloc (1, sizeof (struct amf_healthcheck));
  650. healthcheck->next = comp->healthcheck_head;
  651. comp->healthcheck_head = healthcheck;
  652. healthcheck->comp = comp;
  653. strcpy ((char *)healthcheck->safHealthcheckKey.key, trim_str (loc));
  654. healthcheck->safHealthcheckKey.keyLen = strlen (loc);
  655. current_parse = AMF_HEALTHCHECK;
  656. } else if (strstr_rs (line, "}")) {
  657. if (comp->saAmfCompCategory == 0) {
  658. error_reason = "category missing";
  659. goto parse_error;
  660. }
  661. if (comp->saAmfCompCapability == 0) {
  662. error_reason = "capability model missing";
  663. goto parse_error;
  664. }
  665. if (comp->saAmfCompCategory == SA_AMF_COMP_SA_AWARE) {
  666. comp->comptype = clc_component_sa_aware;
  667. } else if (comp->saAmfCompCategory == SA_AMF_COMP_PROXY) {
  668. if (comp->saAmfCompCapability == SA_AMF_COMP_NON_PRE_INSTANTIABLE) {
  669. comp->comptype = clc_component_proxied_non_pre;
  670. } else {
  671. comp->comptype = clc_component_proxied_pre;
  672. }
  673. } else if (comp->saAmfCompCategory == SA_AMF_COMP_LOCAL) {
  674. comp->comptype = clc_component_non_proxied_non_sa_aware;
  675. }
  676. if (comp->saAmfCompNumMaxActiveCsi == 0) {
  677. error_reason = "saAmfCompNumMaxActiveCsi missing";
  678. goto parse_error;
  679. }
  680. if (comp->saAmfCompNumMaxStandbyCsi == 0) {
  681. error_reason = "saAmfCompNumMaxStandbyCsi missing";
  682. goto parse_error;
  683. }
  684. if (comp->saAmfCompDefaultClcCliTimeout == 0) {
  685. error_reason = "saAmfCompDefaultClcCliTimeout missing or erroneous";
  686. goto parse_error;
  687. }
  688. if (comp->saAmfCompDefaultCallbackTimeOut == 0) {
  689. error_reason = "saAmfCompDefaultCallbackTimeOut missing or erroneous";
  690. goto parse_error;
  691. }
  692. if (comp->saAmfCompRecoveryOnError == 0) {
  693. error_reason = "saAmfCompRecoveryOnError missing";
  694. goto parse_error;
  695. }
  696. post_init_comp (comp);
  697. current_parse = AMF_SU;
  698. } else {
  699. error_reason = line;
  700. goto parse_error;
  701. }
  702. break;
  703. case AMF_COMP_CS_TYPE:
  704. if (strstr_rs (line, "}")) {
  705. current_parse = AMF_COMP;
  706. } else {
  707. comp_cs_type_cnt++;
  708. comp->saAmfCompCsTypes = realloc (comp->saAmfCompCsTypes,
  709. (comp_cs_type_cnt + 1) * sizeof(SaNameT));
  710. comp->saAmfCompCsTypes[comp_cs_type_cnt] = NULL;
  711. comp->saAmfCompCsTypes[comp_cs_type_cnt - 1] = malloc (sizeof(SaNameT));
  712. setSaNameT (comp->saAmfCompCsTypes[comp_cs_type_cnt - 1], line);
  713. }
  714. break;
  715. case AMF_COMP_ENV_VAR:
  716. if (strstr_rs (line, "}")) {
  717. current_parse = AMF_COMP;
  718. } else if ((loc = strchr (line, '=')) != 0) {
  719. comp_env_var_cnt++;
  720. comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv,
  721. (comp_env_var_cnt + 1) * sizeof(SaStringT));
  722. comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL;
  723. env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = malloc (strlen (line) + 1);
  724. strcpy (env_var, line);
  725. } else {
  726. goto parse_error;
  727. }
  728. break;
  729. case AMF_HEALTHCHECK:
  730. if ((loc = strstr_rs (line, "saAmfHealthcheckPeriod=")) != 0) {
  731. healthcheck->saAmfHealthcheckPeriod = atoi (loc);
  732. } else if ((loc = strstr_rs (line, "saAmfHealthcheckMaxDuration=")) != 0) {
  733. healthcheck->saAmfHealthcheckMaxDuration = atoi (loc);
  734. } else if (strstr_rs (line, "}")) {
  735. current_parse = AMF_COMP;
  736. } else {
  737. goto parse_error;
  738. }
  739. break;
  740. case AMF_SI:
  741. if ((loc = strstr_rs (line, "safRankedSu=")) != 0) {
  742. si_ranked_su = calloc (1, sizeof(struct amf_si_ranked_su));
  743. si_ranked_su->si_next = si->ranked_sus;
  744. si->ranked_sus = si_ranked_su;
  745. si_ranked_su->si = si;
  746. setSaNameT (&si_ranked_su->name, trim_str (loc));
  747. current_parse = AMF_SI_RANKED_SU;
  748. } else if ((loc = strstr_rs (line, "safDepend=")) != 0) {
  749. si_dependency = calloc (1, sizeof(struct amf_si_dependency));
  750. si_dependency->next = si->depends_on;
  751. si->depends_on = si_dependency;
  752. setSaNameT (&si_dependency->name, trim_str (loc));
  753. current_parse = AMF_SI_DEPENDENCY;
  754. } else if ((loc = strstr_rs (line, "safCsi=")) != 0) {
  755. csi = calloc (1, sizeof(struct amf_csi));
  756. csi->next = si->csi_head;
  757. si->csi_head = csi;
  758. csi->si = si;
  759. setSaNameT (&csi->name, trim_str (loc));
  760. current_parse = AMF_CSI;
  761. } else if ((loc = strstr_rs (line, "saAmfSIProtectedbySG{")) != 0) {
  762. setSaNameT (&si->saAmfSIProtectedbySG, loc);
  763. } else if ((loc = strstr_rs (line, "saAmfSIRank{")) != 0) {
  764. si->saAmfSIRank = atoi (loc);
  765. } else if ((loc = strstr_rs (line, "saAmfSINumCSIs=")) != 0) {
  766. si->saAmfSINumCSIs = atoi (loc);
  767. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  768. si->saAmfSIPrefActiveAssignments = atoi (loc);
  769. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  770. si->saAmfSIPrefStandbyAssignments = atoi (loc);
  771. } else if (strstr_rs (line, "}")) {
  772. if (si->saAmfSINumCSIs == 0) {
  773. error_reason = "saAmfSINumCSIs missing";
  774. goto parse_error;
  775. }
  776. current_parse = AMF_APPLICATION;
  777. } else {
  778. goto parse_error;
  779. }
  780. break;
  781. case AMF_SI_RANKED_SU:
  782. if ((loc = strstr_rs (line, "saAmfRank=")) != 0) {
  783. si_ranked_su->saAmfRank = atoi (loc);
  784. } else if (strstr_rs (line, "}")) {
  785. current_parse = AMF_SI;
  786. } else {
  787. goto parse_error;
  788. }
  789. break;
  790. case AMF_SI_DEPENDENCY:
  791. if ((loc = strstr_rs (line, "saAmfToleranceTime=")) != 0) {
  792. si_dependency->saAmfToleranceTime = atoi (loc);
  793. } else if (strstr_rs (line, "}")) {
  794. current_parse = AMF_SI;
  795. } else {
  796. goto parse_error;
  797. }
  798. break;
  799. case AMF_CSI:
  800. if ((loc = strstr_rs (line, "saAmfCSTypeName=")) != 0) {
  801. setSaNameT (&csi->saAmfCSTypeName, loc);
  802. } else if ((loc = strstr_rs (line, "safCSIAttr=")) != 0) {
  803. attribute = calloc (1, sizeof(struct amf_csi_attribute));
  804. attribute->next = csi->attributes_head;
  805. csi->attributes_head = attribute;
  806. attribute->name = malloc (strlen (loc) + 1);
  807. strcpy (attribute->name, trim_str (loc));
  808. csi_attr_cnt = 1;
  809. current_parse = AMF_CSI_ATTRIBUTE;
  810. } else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) {
  811. csi_dependencies_cnt = 0;
  812. current_parse = AMF_CSI_DEPENDENCIES;
  813. } else if (strstr_rs (line, "}")) {
  814. if (strcmp(getSaNameT(&csi->saAmfCSTypeName), "") == 0) {
  815. error_reason = "saAmfCSTypeName missing";
  816. goto parse_error;
  817. }
  818. current_parse = AMF_SI;
  819. } else {
  820. goto parse_error;
  821. }
  822. break;
  823. case AMF_CSI_DEPENDENCIES:
  824. if (strstr_rs (line, "}")) {
  825. current_parse = AMF_CSI;
  826. } else if ((loc = strstr_rs (line, "saAmfCSIDependency=")) != 0) {
  827. csi_dependencies_cnt++;
  828. csi->saAmfCSIDependencies = realloc (csi->saAmfCSIDependencies,
  829. (csi_dependencies_cnt + 1) * sizeof(SaNameT));
  830. csi->saAmfCSIDependencies[csi_dependencies_cnt] = NULL;
  831. csi->saAmfCSIDependencies[csi_dependencies_cnt - 1] =
  832. malloc (sizeof(SaNameT));
  833. setSaNameT (
  834. csi->saAmfCSIDependencies[csi_dependencies_cnt - 1], loc);
  835. } else {
  836. goto parse_error;
  837. }
  838. break;
  839. case AMF_CSI_ATTRIBUTE:
  840. if ((loc = strstr_rs (line, "}")) != 0) {
  841. current_parse = AMF_CSI;
  842. } else {
  843. value = rm_beginning_ws (line);
  844. attribute->value = realloc (attribute->value,
  845. sizeof (SaStringT) * (csi_attr_cnt + 1));
  846. attribute->value[csi_attr_cnt - 1] =
  847. malloc (strlen (value) + 1);
  848. strcpy (attribute->value[csi_attr_cnt - 1], value);
  849. attribute->value[csi_attr_cnt] = NULL;
  850. csi_attr_cnt++;
  851. }
  852. break;
  853. case AMF_CS_TYPE:
  854. if ((loc = strstr_rs (line, "}")) != 0) {
  855. current_parse = AMF_APPLICATION;
  856. }
  857. break;
  858. default:
  859. error_reason = "Invalid state\n";
  860. goto parse_error;
  861. break;
  862. }
  863. }
  864. fclose (fp);
  865. return cluster;
  866. parse_error:
  867. sprintf (buf, "parse error at %s: %d: %s\n",
  868. filename, line_number, error_reason);
  869. *error_string = buf;
  870. fclose (fp);
  871. return NULL;
  872. }
  873. static void print_csi_assignment (struct amf_comp *comp,
  874. struct amf_csi_assignment *csi_assignment)
  875. {
  876. log_printf (LOG_INFO, " safCSI=%s\n", csi_assignment->csi->name.value);
  877. log_printf (LOG_INFO, " HA state: %s\n",
  878. ha_state_text[csi_assignment->saAmfCSICompHAState]);
  879. }
  880. static void print_si_assignment (struct amf_su *su,
  881. struct amf_si_assignment *si_assignment)
  882. {
  883. log_printf (LOG_INFO, " safSi=%s\n", si_assignment->si->name.value);
  884. log_printf (LOG_INFO, " HA state: %s\n",
  885. ha_state_text[si_assignment->saAmfSISUHAState]);
  886. }
  887. void amf_runtime_attributes_print (struct amf_cluster *cluster)
  888. {
  889. struct amf_node *node;
  890. struct amf_application *app;
  891. struct amf_sg *sg;
  892. struct amf_su *su;
  893. struct amf_comp *comp;
  894. struct amf_si *si;
  895. struct amf_csi *csi;
  896. log_printf (LOG_INFO, "AMF runtime attributes:");
  897. log_printf (LOG_INFO, "===================================================");
  898. log_printf (LOG_INFO, "safCluster=%s", getSaNameT(&cluster->name));
  899. log_printf (LOG_INFO, " admin state: %s\n",
  900. admin_state_text[cluster->saAmfClusterAdminState]);
  901. for (node = cluster->node_head; node != NULL; node = node->next) {
  902. log_printf (LOG_INFO, " safNode=%s\n", getSaNameT (&node->name));
  903. log_printf (LOG_INFO, " admin state: %s\n",
  904. admin_state_text[node->saAmfNodeAdminState]);
  905. log_printf (LOG_INFO, " oper state: %s\n",
  906. oper_state_text[node->saAmfNodeOperState]);
  907. }
  908. for (app = cluster->application_head; app != NULL; app = app->next) {
  909. log_printf (LOG_INFO, " safApp=%s\n", getSaNameT(&app->name));
  910. log_printf (LOG_INFO, " admin state: %s\n",
  911. admin_state_text[app->saAmfApplicationAdminState]);
  912. log_printf (LOG_INFO, " num_sg: %d\n", app->saAmfApplicationCurrNumSG);
  913. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  914. log_printf (LOG_INFO, " safSG=%s\n", getSaNameT(&sg->name));
  915. log_printf (LOG_INFO, " admin state: %s\n",
  916. admin_state_text[sg->saAmfSGAdminState]);
  917. log_printf (LOG_INFO, " assigned SUs %d\n",
  918. sg->saAmfSGNumCurrAssignedSUs);
  919. log_printf (LOG_INFO, " non inst. spare SUs %d\n",
  920. sg->saAmfSGNumCurrNonInstantiatedSpareSUs);
  921. log_printf (LOG_INFO, " inst. spare SUs %d\n",
  922. sg->saAmfSGNumCurrInstantiatedSpareSUs);
  923. for (su = sg->su_head; su != NULL; su = su->next) {
  924. log_printf (LOG_INFO, " safSU=%s\n", getSaNameT(&su->name));
  925. log_printf (LOG_INFO, " oper state: %s\n",
  926. oper_state_text[su->saAmfSUOperState]);
  927. log_printf (LOG_INFO, " admin state: %s\n",
  928. admin_state_text[su->saAmfSUAdminState]);
  929. log_printf (LOG_INFO, " readiness state: %s\n",
  930. readiness_state_text[amf_su_get_saAmfSUReadinessState (su)]);
  931. log_printf (LOG_INFO, " presence state: %s\n",
  932. presence_state_text[su->saAmfSUPresenceState]);
  933. log_printf (LOG_INFO, " hosted by node %s\n",
  934. su->saAmfSUHostedByNode.value);
  935. log_printf (LOG_INFO, " num active SIs %d\n",
  936. amf_su_get_saAmfSUNumCurrActiveSIs (su));
  937. log_printf (LOG_INFO, " num standby SIs %d\n",
  938. amf_su_get_saAmfSUNumCurrStandbySIs (su));
  939. log_printf (LOG_INFO, " restart count %d\n",
  940. su->saAmfSURestartCount);
  941. log_printf (LOG_INFO, " restart control state %d\n",
  942. su->restart_control_state);
  943. log_printf (LOG_INFO, " SU failover cnt %d\n", su->su_failover_cnt);
  944. log_printf (LOG_INFO, " assigned SIs:");
  945. amf_su_foreach_si_assignment (su, print_si_assignment);
  946. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  947. log_printf (LOG_INFO, " safComp=%s\n", getSaNameT(&comp->name));
  948. log_printf (LOG_INFO, " oper state: %s\n",
  949. oper_state_text[comp->saAmfCompOperState]);
  950. log_printf (LOG_INFO, " readiness state: %s\n",
  951. readiness_state_text[amf_comp_get_saAmfCompReadinessState (comp)]);
  952. log_printf (LOG_INFO, " presence state: %s\n",
  953. presence_state_text[comp->saAmfCompPresenceState]);
  954. log_printf (LOG_INFO, " num active CSIs %d\n",
  955. amf_comp_get_saAmfCompNumCurrActiveCsi (comp));
  956. log_printf (LOG_INFO, " num standby CSIs %d\n",
  957. amf_comp_get_saAmfCompNumCurrStandbyCsi (comp));
  958. log_printf (LOG_INFO, " restart count %d\n",
  959. comp->saAmfCompRestartCount);
  960. log_printf (LOG_INFO, " assigned CSIs:");
  961. amf_comp_foreach_csi_assignment (
  962. comp, print_csi_assignment);
  963. }
  964. }
  965. }
  966. for (si = app->si_head; si != NULL; si = si->next) {
  967. log_printf (LOG_INFO, " safSi=%s\n", getSaNameT(&si->name));
  968. log_printf (LOG_INFO, " admin state: %s\n",
  969. admin_state_text[si->saAmfSIAdminState]);
  970. log_printf (LOG_INFO, " assignm. state: %s\n",
  971. assignment_state_text[
  972. amf_si_get_saAmfSIAssignmentState (si)]);
  973. log_printf (LOG_INFO, " active assignments: %d\n",
  974. amf_si_get_saAmfSINumCurrActiveAssignments (si));
  975. log_printf (LOG_INFO, " standby assignments: %d\n",
  976. amf_si_get_saAmfSINumCurrStandbyAssignments (si));
  977. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  978. log_printf (LOG_INFO, " safCsi=%s\n", getSaNameT(&csi->name));
  979. }
  980. }
  981. }
  982. log_printf (LOG_INFO, "===================================================");
  983. }
  984. /* to be removed... */
  985. int amf_enabled (struct objdb_iface_ver0 *objdb)
  986. {
  987. unsigned int object_service_handle;
  988. char *value;
  989. int enabled = 0;
  990. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  991. if (objdb->object_find (
  992. OBJECT_PARENT_HANDLE,
  993. "amf",
  994. strlen ("amf"),
  995. &object_service_handle) == 0) {
  996. value = NULL;
  997. if ( !objdb->object_key_get (object_service_handle,
  998. "mode",
  999. strlen ("mode"),
  1000. (void *)&value,
  1001. NULL) && value) {
  1002. if (strcmp (value, "enabled") == 0) {
  1003. enabled = 1;
  1004. } else
  1005. if (strcmp (value, "disabled") == 0) {
  1006. enabled = 0;
  1007. }
  1008. }
  1009. }
  1010. return enabled;
  1011. }
  1012. const char *amf_admin_state (int state)
  1013. {
  1014. return admin_state_text[state];
  1015. }
  1016. const char *amf_op_state (int state)
  1017. {
  1018. return oper_state_text[state];
  1019. }
  1020. const char *amf_presence_state (int state)
  1021. {
  1022. return presence_state_text[state];
  1023. }
  1024. const char *amf_ha_state (int state)
  1025. {
  1026. return ha_state_text[state];
  1027. }
  1028. const char *amf_readiness_state (int state)
  1029. {
  1030. return readiness_state_text[state];
  1031. }
  1032. const char *amf_assignment_state (int state)
  1033. {
  1034. return assignment_state_text[state];
  1035. }