amfconfig.c 31 KB

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