amfutil.c 36 KB

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