amfconfig.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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 *sg;
  97. struct amf_su *su;
  98. struct amf_comp *comp = NULL;
  99. char *app_name;
  100. char *sg_name;
  101. char *su_name;
  102. char *comp_name;
  103. char *ptrptr;
  104. char *buf;
  105. /* malloc new buffer since strtok_r writes to its first argument */
  106. buf = malloc (name->length);
  107. memcpy (buf, name->value,name ->length);
  108. comp_name = strtok_r(buf, ",", &ptrptr);
  109. su_name = strtok_r(NULL, ",", &ptrptr);
  110. sg_name = strtok_r(NULL, ",", &ptrptr);
  111. app_name = strtok_r(NULL, ",", &ptrptr);
  112. if (comp_name == NULL || su_name == NULL || sg_name == NULL || app_name == NULL) {
  113. goto end;
  114. }
  115. comp_name += 8;
  116. su_name += 6;
  117. sg_name += 6;
  118. app_name += 7;
  119. for (app = cluster->application_head; app != NULL; app = app->next) {
  120. if (strncmp (app_name, (char*)app->name.value, app->name.length) == 0) {
  121. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  122. if (strncmp (sg_name, (char*)sg->name.value, sg->name.length) == 0) {
  123. for (su = sg->su_head; su != NULL; su = su->next) {
  124. if (strncmp (su_name, (char*)su->name.value, su->name.length) == 0) {
  125. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  126. if (strncmp (comp_name, (char*)comp->name.value, comp->name.length) == 0) {
  127. goto end;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
  136. end:
  137. free (buf);
  138. return comp;
  139. }
  140. static int init_category (struct amf_comp *comp, char *loc)
  141. {
  142. if (strcmp (loc, "sa_aware") == 0) {
  143. comp->saAmfCompCategory = SA_AMF_COMP_SA_AWARE;
  144. } else if (strcmp (loc, "proxy") == 0) {
  145. comp->saAmfCompCategory = SA_AMF_COMP_PROXY;
  146. } else if (strcmp (loc, "proxied") == 0) {
  147. comp->saAmfCompCategory = SA_AMF_COMP_PROXIED;
  148. } else if (strcmp (loc, "local") == 0) {
  149. comp->saAmfCompCategory = SA_AMF_COMP_LOCAL;
  150. } else {
  151. return -1;
  152. }
  153. return 0;
  154. }
  155. static int init_capability (struct amf_comp *comp, char *loc)
  156. {
  157. if (strcmp (loc, "x_active_and_y_standby") == 0) {
  158. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE_AND_Y_STANDBY;
  159. } else if (strcmp (loc, "x_active_or_y_standby") == 0) {
  160. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE_OR_Y_STANDBY;
  161. } else if (strcmp (loc, "one_active_or_y_standby") == 0) {
  162. comp->saAmfCompCapability = SA_AMF_COMP_ONE_ACTIVE_OR_Y_STANDBY;
  163. } else if (strcmp (loc, "one_active_or_one_standby") == 0) {
  164. comp->saAmfCompCapability = SA_AMF_COMP_ONE_ACTIVE_OR_ONE_STANDBY;
  165. } else if (strcmp (loc, "x_active") == 0) {
  166. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE;
  167. } else if (strcmp (loc, "1_active") == 0) {
  168. comp->saAmfCompCapability = SA_AMF_COMP_1_ACTIVE;
  169. } else if (strcmp (loc, "non_preinstantiable") == 0) {
  170. comp->saAmfCompCapability = SA_AMF_COMP_NON_PRE_INSTANTIABLE;
  171. } else {
  172. return -1;
  173. }
  174. return 0;
  175. }
  176. static int init_recovery_on_error (struct amf_comp *comp, char *loc)
  177. {
  178. if (strcmp (loc, "component_restart") == 0) {
  179. comp->saAmfCompRecoveryOnError = SA_AMF_COMPONENT_RESTART;
  180. } else if (strcmp (loc, "component_failover") == 0) {
  181. comp->saAmfCompRecoveryOnError = SA_AMF_COMPONENT_FAILOVER;
  182. } else if (strcmp (loc, "node_switchover") == 0) {
  183. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_SWITCHOVER;
  184. } else if (strcmp (loc, "node_failover") == 0) {
  185. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_FAILOVER;
  186. } else if (strcmp (loc, "node_failfast") == 0) {
  187. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_FAILFAST;
  188. } else if (strcmp (loc, "application_restart") == 0) {
  189. comp->saAmfCompRecoveryOnError = SA_AMF_APPLICATION_RESTART;
  190. } else if (strcmp (loc, "cluster_reset") == 0) {
  191. comp->saAmfCompRecoveryOnError = SA_AMF_CLUSTER_RESET;
  192. } else {
  193. return -1;
  194. }
  195. return 0;
  196. }
  197. static struct amf_comp *new_comp(struct amf_su *su)
  198. {
  199. struct amf_comp *comp = calloc (1, sizeof (struct amf_comp));
  200. if (comp == NULL) {
  201. openais_exit_error(AIS_DONE_OUT_OF_MEMORY);
  202. }
  203. comp->next = su->comp_head;
  204. su->comp_head = comp;
  205. comp->su = su;
  206. comp->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED;
  207. comp->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  208. comp->saAmfCompNumMaxInstantiateWithoutDelay = 2;
  209. comp->saAmfCompNumMaxAmStartAttempt = 2;
  210. comp->saAmfCompNumMaxAmStopAttempt = 2;
  211. return comp;
  212. }
  213. static void post_init_comp(struct amf_comp *comp)
  214. {
  215. if (comp->saAmfCompInstantiateTimeout == 0) {
  216. comp->saAmfCompInstantiateTimeout = comp->saAmfCompDefaultClcCliTimeout;
  217. }
  218. if (comp->saAmfCompTerminateTimeout == 0) {
  219. comp->saAmfCompTerminateTimeout = comp->saAmfCompDefaultClcCliTimeout;
  220. }
  221. if (comp->saAmfCompCleanupTimeout == 0) {
  222. comp->saAmfCompCleanupTimeout = comp->saAmfCompDefaultClcCliTimeout;
  223. }
  224. if (comp->saAmfCompAmStartTimeout == 0) {
  225. comp->saAmfCompAmStartTimeout = comp->saAmfCompDefaultClcCliTimeout;
  226. }
  227. if (comp->saAmfCompAmStopTimeout == 0) {
  228. comp->saAmfCompAmStopTimeout = comp->saAmfCompDefaultClcCliTimeout;
  229. }
  230. if (comp->saAmfCompTerminateCallbackTimeout == 0) {
  231. comp->saAmfCompTerminateCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  232. }
  233. if (comp->saAmfCompCSISetCallbackTimeout == 0) {
  234. comp->saAmfCompCSISetCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  235. }
  236. if (comp->saAmfCompCSIRmvCallbackTimeout == 0) {
  237. comp->saAmfCompCSIRmvCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  238. }
  239. }
  240. static char *trim_str(char *str)
  241. {
  242. char *s = str + strlen (str) - 1;
  243. while (*s == '\t' || *s == ' ' || *s == '{') {
  244. *s = '\0';
  245. s--;
  246. }
  247. return str;
  248. }
  249. static char *rm_beginning_ws(char *str)
  250. {
  251. char *s = str + strlen (str) - 1;
  252. while (*s == '\t' || *s == ' ') {
  253. *s = '\0';
  254. s--;
  255. }
  256. s = str;
  257. while (*s == '\t' || *s == ' ') {
  258. s++;
  259. }
  260. return s;
  261. }
  262. int amf_config_read (struct amf_cluster *cluster, char **error_string)
  263. {
  264. char buf[1024];
  265. char *line;
  266. FILE *fp;
  267. char *filename;
  268. amf_parse_t current_parse = AMF_HEAD;
  269. int line_number = 0;
  270. char *loc;
  271. int i;
  272. struct amf_application *app = 0;
  273. struct amf_node *node = 0;
  274. struct amf_sg *sg = 0;
  275. struct amf_su *su = 0;
  276. struct amf_comp *comp = 0;
  277. struct amf_si *si = 0;
  278. struct amf_si_ranked_su *si_ranked_su = 0;
  279. struct amf_si_dependency *si_dependency = 0;
  280. struct amf_healthcheck *healthcheck = 0;
  281. struct amf_csi *csi = 0;
  282. struct amf_csi_attribute *attribute = 0;
  283. SaStringT env_var;
  284. int comp_env_var_cnt = 0;
  285. int comp_cs_type_cnt = 0;
  286. int csi_attr_cnt = 0;
  287. int csi_dependencies_cnt = 0;
  288. char *error_reason = NULL;
  289. char *value;
  290. filename = getenv("OPENAIS_AMF_CONFIG_FILE");
  291. if (!filename) {
  292. filename = "/etc/ais/amf.conf";
  293. }
  294. fp = fopen (filename, "r");
  295. if (fp == 0) {
  296. sprintf (buf, "Can't read %s file reason = (%s).\n",
  297. filename, strerror (errno));
  298. *error_string = buf;
  299. return (-1);
  300. }
  301. cluster->saAmfClusterStartupTimeout = -1;
  302. cluster->saAmfClusterAdminState = SA_AMF_ADMIN_UNLOCKED;
  303. while (fgets (buf, 255, fp)) {
  304. line_number += 1;
  305. line = buf;
  306. line[strlen(line) - 1] = '\0';
  307. /*
  308. * Clear out comments and empty lines
  309. */
  310. if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') {
  311. continue;
  312. }
  313. /*
  314. * Clear out white space and tabs
  315. */
  316. for (i = strlen (line) - 1; i > -1; i--) {
  317. if (line[i] == '\t' || line[i] == ' ') {
  318. line[i] = '\0';
  319. } else {
  320. break;
  321. }
  322. }
  323. /* Trim whitespace from beginning of string */
  324. line = rm_beginning_ws(line);
  325. error_reason = line;
  326. error_reason = NULL;
  327. switch (current_parse) {
  328. case AMF_HEAD:
  329. if ((loc = strstr_rs (line, "safAmfCluster=")) != 0) {
  330. setSaNameT (&cluster->name, trim_str (loc));
  331. current_parse = AMF_CLUSTER;
  332. } else {
  333. goto parse_error;
  334. }
  335. break;
  336. case AMF_CLUSTER:
  337. if ((loc = strstr_rs (line, "saAmfClusterClmCluster=")) != 0) {
  338. setSaNameT (&cluster->saAmfClusterClmCluster, loc);
  339. } else if ((loc = strstr_rs (line, "saAmfClusterStartupTimeout=")) != 0) {
  340. cluster->saAmfClusterStartupTimeout = atol(loc);
  341. } else if ((loc = strstr_rs (line, "safAmfNode=")) != 0) {
  342. node = calloc (1, sizeof (struct amf_node));
  343. node->next = cluster->node_head;
  344. cluster->node_head = node;
  345. node->saAmfNodeAdminState = SA_AMF_ADMIN_UNLOCKED;
  346. node->saAmfNodeAutoRepair = SA_TRUE;
  347. node->cluster = cluster;
  348. node->saAmfNodeSuFailOverProb = -1;
  349. node->saAmfNodeSuFailoverMax = ~0;
  350. setSaNameT (&node->name, trim_str (loc));
  351. current_parse = AMF_NODE;
  352. } else if ((loc = strstr_rs (line, "safApp=")) != 0) {
  353. app = calloc (1, sizeof (struct amf_application));
  354. app->next = cluster->application_head;
  355. cluster->application_head = app;
  356. app->cluster = cluster;
  357. app->saAmfApplicationAdminState = SA_AMF_ADMIN_UNLOCKED;
  358. setSaNameT (&app->name, trim_str (loc));
  359. current_parse = AMF_APPLICATION;
  360. } else if (strstr_rs (line, "}")) {
  361. if (cluster->saAmfClusterStartupTimeout == -1) {
  362. error_reason = "saAmfClusterStartupTimeout missing";
  363. goto parse_error;
  364. }
  365. /* spec: set to default value if zero */
  366. if (cluster->saAmfClusterStartupTimeout == 0) {
  367. cluster->saAmfClusterStartupTimeout = OPENAIS_CLUSTER_STARTUP_TIMEOUT;
  368. }
  369. current_parse = AMF_HEAD;
  370. } else {
  371. goto parse_error;
  372. }
  373. break;
  374. case AMF_NODE:
  375. if ((loc = strstr_rs (line, "saAmfNodeSuFailOverProb")) != 0) {
  376. node->saAmfNodeSuFailOverProb = atol(loc);
  377. } else if ((loc = strstr_rs (line, "saAmfNodeSuFailoverMax")) != 0) {
  378. node->saAmfNodeSuFailoverMax = atol(loc);
  379. } else if ((loc = strstr_rs (line, "saAmfNodeAutoRepair=")) != 0) {
  380. if (strcmp (loc, "true") == 0) {
  381. node->saAmfNodeAutoRepair = SA_TRUE;
  382. } else if (strcmp (loc, "false") == 0) {
  383. node->saAmfNodeAutoRepair = SA_FALSE;
  384. } else {
  385. goto parse_error;
  386. }
  387. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnTerminationFailure=")) != 0) {
  388. if (strcmp (loc, "true") == 0) {
  389. node->saAmfNodeRebootOnTerminationFailure = SA_TRUE;
  390. } else if (strcmp (loc, "false") == 0) {
  391. node->saAmfNodeRebootOnTerminationFailure = SA_FALSE;
  392. } else {
  393. goto parse_error;
  394. }
  395. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnInstantiationFailure=")) != 0) {
  396. if (strcmp (loc, "true") == 0) {
  397. node->saAmfNodeRebootOnInstantiationFailure = SA_TRUE;
  398. } else if (strcmp (loc, "false") == 0) {
  399. node->saAmfNodeRebootOnInstantiationFailure = SA_FALSE;
  400. } else {
  401. goto parse_error;
  402. }
  403. } else if (strstr_rs (line, "}")) {
  404. if (node->saAmfNodeSuFailOverProb == -1) {
  405. error_reason = "saAmfNodeSuFailOverProb missing";
  406. goto parse_error;
  407. }
  408. if (node->saAmfNodeSuFailoverMax == ~0) {
  409. error_reason = "saAmfNodeSuFailoverMax missing";
  410. goto parse_error;
  411. }
  412. current_parse = AMF_CLUSTER;
  413. } else {
  414. goto parse_error;
  415. }
  416. break;
  417. case AMF_APPLICATION:
  418. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  419. strcpy (app->clccli_path, loc);
  420. } else if ((loc = strstr_rs (line, "safSg=")) != 0) {
  421. sg = calloc (1, sizeof (struct amf_sg));
  422. sg->next = app->sg_head;
  423. app->sg_head = sg;
  424. sg->saAmfSGAdminState = SA_AMF_ADMIN_UNLOCKED;
  425. sg->saAmfSGNumPrefActiveSUs = 1;
  426. sg->saAmfSGNumPrefStandbySUs = 1;
  427. sg->saAmfSGCompRestartProb = -1;
  428. sg->saAmfSGCompRestartMax = ~0;
  429. sg->saAmfSGSuRestartProb = -1;
  430. sg->saAmfSGSuRestartMax = ~0;
  431. sg->saAmfSGAutoAdjustProb = -1;
  432. sg->saAmfSGAutoRepair = SA_TRUE;
  433. sg->application = app;
  434. current_parse = AMF_SG;
  435. setSaNameT (&sg->name, trim_str (loc));
  436. } else if ((loc = strstr_rs (line, "safSi=")) != 0) {
  437. si = calloc (1, sizeof (struct amf_si));
  438. si->next = app->si_head;
  439. app->si_head = si;
  440. si->application = app;
  441. si->saAmfSIPrefActiveAssignments = 1;
  442. si->saAmfSIPrefStandbyAssignments = 1;
  443. setSaNameT (&si->name, trim_str (loc));
  444. si->saAmfSIAdminState = SA_AMF_ADMIN_UNLOCKED;
  445. si->saAmfSIAssignmentState = SA_AMF_ASSIGNMENT_UNASSIGNED;
  446. current_parse = AMF_SI;
  447. } else if ((loc = strstr_rs (line, "safCSType=")) != 0) {
  448. current_parse = AMF_CS_TYPE;
  449. } else if (strstr_rs (line, "}")) {
  450. current_parse = AMF_CLUSTER;
  451. } else {
  452. goto parse_error;
  453. }
  454. break;
  455. case AMF_SG:
  456. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  457. strcpy (sg->clccli_path, loc);
  458. } else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) {
  459. if (strcmp (loc, "2n") == 0) {
  460. sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL;
  461. } else if (strcmp (loc, "nplusm") == 0) {
  462. sg->saAmfSGRedundancyModel = SA_AMF_NPM_REDUNDANCY_MODEL;
  463. } else if (strcmp (loc, "nway") == 0) {
  464. error_reason = "nway redundancy model not supported";
  465. goto parse_error;
  466. } else if (strcmp (loc, "nwayactive") == 0) {
  467. error_reason = "nway active redundancy model not supported";
  468. goto parse_error;
  469. } else if (strcmp (loc, "noredundancy") == 0) {
  470. sg->saAmfSGRedundancyModel = SA_AMF_NO_REDUNDANCY_MODEL;
  471. } else {
  472. goto parse_error;
  473. }
  474. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefActiveSUs=")) != 0) {
  475. sg->saAmfSGNumPrefActiveSUs = atoi (loc);
  476. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefStandbySUs=")) != 0) {
  477. sg->saAmfSGNumPrefStandbySUs = atoi (loc);
  478. } else if ((loc = strstr_rs (line, "saAmfSGMaxActiveSIsperSUs=")) != 0) {
  479. sg->saAmfSGMaxActiveSIsperSUs = atoi (loc);
  480. } else if ((loc = strstr_rs (line, "saAmfSGMaxStandbySIsperSUs=")) != 0) {
  481. sg->saAmfSGMaxStandbySIsperSUs = atoi (loc);
  482. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartProb=")) != 0) {
  483. sg->saAmfSGCompRestartProb = atoi (loc);
  484. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartMax=")) != 0) {
  485. sg->saAmfSGCompRestartMax = atoi (loc);
  486. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartProb=")) != 0) {
  487. sg->saAmfSGSuRestartProb = atoi (loc);
  488. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartMax=")) != 0) {
  489. sg->saAmfSGSuRestartMax = atoi (loc);
  490. } else if ((loc = strstr_rs (line, "saAmfSGAutoAdjustProb=")) != 0) {
  491. sg->saAmfSGAutoAdjustProb = atoi (loc);
  492. } else if ((loc = strstr_rs (line, "saAmfSGAutoRepair=")) != 0) {
  493. sg->saAmfSGAutoRepair = atoi (loc);
  494. } else if ((loc = strstr_rs (line, "safSu=")) != 0) {
  495. su = calloc (1, sizeof (struct amf_su));
  496. su->next = sg->su_head;
  497. sg->su_head = su;
  498. su->sg = sg;
  499. su->saAmfSUAdminState = SA_AMF_ADMIN_UNLOCKED;
  500. su->saAmfSUOperState = SA_AMF_OPERATIONAL_DISABLED;
  501. su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  502. su->escalation_level = ESCALATION_LEVEL_NO_ESCALATION;
  503. su->saAmfSUFailover = 1;
  504. setSaNameT (&su->name, trim_str (loc));
  505. current_parse = AMF_SU;
  506. } else if (strstr_rs (line, "}")) {
  507. if (sg->saAmfSGRedundancyModel == 0) {
  508. error_reason = "saAmfSGRedundancyModel missing";
  509. goto parse_error;
  510. }
  511. if (sg->saAmfSGCompRestartProb == -1) {
  512. error_reason = "saAmfSGCompRestartProb missing";
  513. goto parse_error;
  514. }
  515. if (sg->saAmfSGCompRestartMax == ~0) {
  516. error_reason = "saAmfSGCompRestartMax missing";
  517. goto parse_error;
  518. }
  519. if (sg->saAmfSGSuRestartProb == -1) {
  520. error_reason = "saAmfSGSuRestartProb missing";
  521. goto parse_error;
  522. }
  523. if (sg->saAmfSGSuRestartMax == ~0) {
  524. error_reason = "saAmfSGSuRestartMax missing";
  525. goto parse_error;
  526. }
  527. if (sg->saAmfSGAutoAdjustProb == -1) {
  528. error_reason = "saAmfSGAutoAdjustProb missing";
  529. goto parse_error;
  530. }
  531. if (sg->saAmfSGAutoRepair > 1) {
  532. error_reason = "saAmfSGAutoRepair erroneous";
  533. goto parse_error;
  534. }
  535. current_parse = AMF_APPLICATION;
  536. } else {
  537. goto parse_error;
  538. }
  539. break;
  540. case AMF_SU:
  541. if ((loc = strstr_rs (line, "saAmfSUNumComponents=")) != 0) {
  542. su->saAmfSUNumComponents = atoi (loc);
  543. } else if ((loc = strstr_rs (line, "saAmfSUIsExternal=")) != 0) {
  544. su->saAmfSUIsExternal = atoi (loc);
  545. } else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) {
  546. su->saAmfSUFailover = atoi (loc);
  547. } else if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  548. strcpy (su->clccli_path, loc);
  549. } else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) {
  550. setSaNameT (&su->saAmfSUHostedByNode, loc);
  551. } else if ((loc = strstr_rs (line, "safComp=")) != 0) {
  552. comp = new_comp (su);
  553. comp_env_var_cnt = 0;
  554. comp_cs_type_cnt = 0;
  555. setSaNameT (&comp->name, trim_str (loc));
  556. current_parse = AMF_COMP;
  557. } else if (strstr_rs (line, "}")) {
  558. if (su->saAmfSUNumComponents == 0) {
  559. error_reason = "saAmfSUNumComponents missing";
  560. goto parse_error;
  561. }
  562. if (su->saAmfSUIsExternal > 1) {
  563. error_reason = "saAmfSUIsExternal erroneous";
  564. goto parse_error;
  565. }
  566. if (su->saAmfSUFailover > 1) {
  567. error_reason = "saAmfSUFailover erroneous";
  568. goto parse_error;
  569. }
  570. if (strcmp ((char*)su->saAmfSUHostedByNode.value, "") == 0) {
  571. error_reason = "saAmfSUHostedByNode missing";
  572. goto parse_error;
  573. }
  574. current_parse = AMF_SG;
  575. } else {
  576. goto parse_error;
  577. }
  578. break;
  579. case AMF_COMP:
  580. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  581. strcpy (comp->clccli_path, loc);
  582. } else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) {
  583. current_parse = AMF_COMP_CS_TYPE;
  584. } else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) {
  585. if (init_category(comp, loc) != 0) {
  586. error_reason = "unknown category";
  587. goto parse_error;
  588. }
  589. } else if ((loc = strstr_rs (line, "saAmfCompCapability=")) != 0) {
  590. if (init_capability(comp, loc) != 0) {
  591. error_reason = "unknown capability model";
  592. goto parse_error;
  593. }
  594. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxActiveCsi=")) != 0) {
  595. comp->saAmfCompNumMaxActiveCsi = atol (loc);
  596. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxStandbyCsi=")) != 0) {
  597. comp->saAmfCompNumMaxStandbyCsi = atol (loc);
  598. } else if ((loc = strstr_rs (line, "saAmfCompCmdEnv{")) != 0) {
  599. current_parse = AMF_COMP_ENV_VAR;
  600. } else if ((loc = strstr_rs(line, "saAmfCompDefaultClcCliTimeout=")) != 0) {
  601. comp->saAmfCompDefaultClcCliTimeout = atol (loc);
  602. } else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) {
  603. comp->saAmfCompDefaultCallbackTimeOut = atol (loc);
  604. } else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) {
  605. comp->saAmfCompInstantiateCmdArgv = malloc (strlen(loc) + 1);
  606. strcpy (comp->saAmfCompInstantiateCmdArgv, loc);
  607. } else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) {
  608. comp->saAmfCompInstantiateCmd = malloc (strlen(loc) + 1);
  609. strcpy (comp->saAmfCompInstantiateCmd, loc);
  610. } else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) {
  611. comp->saAmfCompInstantiateTimeout = atol (loc);
  612. } else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) {
  613. comp->saAmfCompInstantiationLevel = atol (loc);
  614. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithoutDelay=")) != 0) {
  615. comp->saAmfCompNumMaxInstantiateWithoutDelay = atol (loc);
  616. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithDelay=")) != 0) {
  617. comp->saAmfCompNumMaxInstantiateWithDelay = atol (loc);
  618. } else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) {
  619. comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc);
  620. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) {
  621. comp->saAmfCompTerminateCmdArgv = malloc (strlen(loc) + 1);
  622. strcpy (comp->saAmfCompTerminateCmdArgv, loc);
  623. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) {
  624. comp->saAmfCompTerminateCmd = malloc (strlen(loc) + 1);
  625. strcpy (comp->saAmfCompTerminateCmd, loc);
  626. } else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) {
  627. comp->saAmfCompTerminateTimeout = atol (loc);
  628. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) {
  629. comp->saAmfCompCleanupCmdArgv = malloc (strlen(loc) + 1);
  630. strcpy (comp->saAmfCompCleanupCmdArgv, loc);
  631. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) {
  632. comp->saAmfCompCleanupCmd = malloc (strlen(loc) + 1);
  633. strcpy (comp->saAmfCompCleanupCmd, loc);
  634. } else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) {
  635. comp->saAmfCompCleanupTimeout = atol (loc);
  636. } else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) {
  637. comp->saAmfCompTerminateCallbackTimeout = atol (loc);
  638. } else if ((loc = strstr_rs(line, "saAmfCompCSISetCallbackTimeout=")) != 0) {
  639. comp->saAmfCompCSISetCallbackTimeout = atol (loc);
  640. } else if ((loc = strstr_rs(line, "saAmfCompQuiescingCompleteTimeout=")) != 0) {
  641. comp->saAmfCompQuiescingCompleteTimeout = atol (loc);
  642. } else if ((loc = strstr_rs(line, "saAmfCompCSIRmvCallbackTimeout=")) != 0) {
  643. comp->saAmfCompCSIRmvCallbackTimeout = atol (loc);
  644. } else if ((loc = strstr_rs (line, "saAmfCompRecoveryOnError=")) != 0) {
  645. if (init_recovery_on_error (comp, loc) != 0) {
  646. error_reason = "bad value";
  647. goto parse_error;
  648. }
  649. } else if ((loc = strstr_rs (line, "saAmfCompDisableRestart")) != 0) {
  650. if (strcmp (loc, "false") == 0) {
  651. comp->saAmfCompDisableRestart = SA_FALSE;
  652. } else if (strcmp (loc, "true") == 0) {
  653. comp->saAmfCompDisableRestart = SA_TRUE;
  654. } else {
  655. error_reason = "bad value";
  656. goto parse_error;
  657. }
  658. } else if ((loc = strstr_rs (line, "saAmfCompProxyCsi=")) != 0) {
  659. setSaNameT (&comp->saAmfCompProxyCsi, loc);
  660. } else if ((loc = strstr_rs (line, "safHealthcheckKey=")) != 0) {
  661. healthcheck = calloc (1, sizeof (struct amf_healthcheck));
  662. healthcheck->next = comp->healthcheck_head;
  663. comp->healthcheck_head = healthcheck;
  664. healthcheck->comp = comp;
  665. strcpy ((char *)healthcheck->safHealthcheckKey.key, trim_str (loc));
  666. healthcheck->safHealthcheckKey.keyLen = strlen (loc);
  667. current_parse = AMF_HEALTHCHECK;
  668. } else if (strstr_rs (line, "}")) {
  669. if (comp->saAmfCompCategory == 0) {
  670. error_reason = "category missing";
  671. goto parse_error;
  672. }
  673. if (comp->saAmfCompCapability == 0) {
  674. error_reason = "capability model missing";
  675. goto parse_error;
  676. }
  677. if (comp->saAmfCompCategory == SA_AMF_COMP_SA_AWARE) {
  678. comp->comptype = clc_component_sa_aware;
  679. } else if (comp->saAmfCompCategory == SA_AMF_COMP_PROXY) {
  680. if (comp->saAmfCompCapability == SA_AMF_COMP_NON_PRE_INSTANTIABLE) {
  681. comp->comptype = clc_component_proxied_non_pre;
  682. } else {
  683. comp->comptype = clc_component_proxied_pre;
  684. }
  685. } else if (comp->saAmfCompCategory == SA_AMF_COMP_LOCAL) {
  686. comp->comptype = clc_component_non_proxied_non_sa_aware;
  687. }
  688. if (comp->saAmfCompNumMaxActiveCsi == 0) {
  689. error_reason = "saAmfCompNumMaxActiveCsi missing";
  690. goto parse_error;
  691. }
  692. if (comp->saAmfCompNumMaxStandbyCsi == 0) {
  693. error_reason = "saAmfCompNumMaxStandbyCsi missing";
  694. goto parse_error;
  695. }
  696. if (comp->saAmfCompDefaultClcCliTimeout == 0) {
  697. error_reason = "saAmfCompDefaultClcCliTimeout missing or erroneous";
  698. goto parse_error;
  699. }
  700. if (comp->saAmfCompDefaultCallbackTimeOut == 0) {
  701. error_reason = "saAmfCompDefaultCallbackTimeOut missing or erroneous";
  702. goto parse_error;
  703. }
  704. if (comp->saAmfCompRecoveryOnError == 0) {
  705. error_reason = "saAmfCompRecoveryOnError missing";
  706. goto parse_error;
  707. }
  708. post_init_comp (comp);
  709. current_parse = AMF_SU;
  710. } else {
  711. error_reason = line;
  712. goto parse_error;
  713. }
  714. break;
  715. case AMF_COMP_CS_TYPE:
  716. if (strstr_rs (line, "}")) {
  717. current_parse = AMF_COMP;
  718. } else {
  719. comp_cs_type_cnt++;
  720. comp->saAmfCompCsTypes = realloc (comp->saAmfCompCsTypes,
  721. (comp_cs_type_cnt + 1) * sizeof(SaNameT));
  722. comp->saAmfCompCsTypes[comp_cs_type_cnt] = NULL;
  723. comp->saAmfCompCsTypes[comp_cs_type_cnt - 1] = malloc (sizeof(SaNameT));
  724. setSaNameT (comp->saAmfCompCsTypes[comp_cs_type_cnt - 1], line);
  725. }
  726. break;
  727. case AMF_COMP_ENV_VAR:
  728. if (strstr_rs (line, "}")) {
  729. current_parse = AMF_COMP;
  730. } else if ((loc = strchr (line, '=')) != 0) {
  731. comp_env_var_cnt++;
  732. comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv,
  733. (comp_env_var_cnt + 1) * sizeof(SaStringT));
  734. comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL;
  735. env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = malloc (strlen (line + 1));
  736. strcpy (env_var, line);
  737. } else {
  738. goto parse_error;
  739. }
  740. break;
  741. case AMF_HEALTHCHECK:
  742. if ((loc = strstr_rs (line, "saAmfHealthcheckPeriod=")) != 0) {
  743. healthcheck->saAmfHealthcheckPeriod = atoi (loc);
  744. } else if ((loc = strstr_rs (line, "saAmfHealthcheckMaxDuration=")) != 0) {
  745. healthcheck->saAmfHealthcheckMaxDuration = atoi (loc);
  746. } else if (strstr_rs (line, "}")) {
  747. current_parse = AMF_COMP;
  748. } else {
  749. goto parse_error;
  750. }
  751. break;
  752. case AMF_SI:
  753. if ((loc = strstr_rs (line, "safRankedSu=")) != 0) {
  754. si_ranked_su = calloc (1, sizeof(struct amf_si_ranked_su));
  755. si_ranked_su->si_next = si->ranked_sus;
  756. si->ranked_sus = si_ranked_su;
  757. si_ranked_su->si = si;
  758. setSaNameT (&si_ranked_su->name, trim_str (loc));
  759. current_parse = AMF_SI_RANKED_SU;
  760. } else if ((loc = strstr_rs (line, "safDepend=")) != 0) {
  761. si_dependency = calloc (1, sizeof(struct amf_si_dependency));
  762. si_dependency->next = si->depends_on;
  763. si->depends_on = si_dependency;
  764. setSaNameT (&si_dependency->name, trim_str (loc));
  765. current_parse = AMF_SI_DEPENDENCY;
  766. } else if ((loc = strstr_rs (line, "safCsi=")) != 0) {
  767. csi = calloc (1, sizeof(struct amf_csi));
  768. csi->next = si->csi_head;
  769. si->csi_head = csi;
  770. csi->si = si;
  771. setSaNameT (&csi->name, trim_str (loc));
  772. current_parse = AMF_CSI;
  773. } else if ((loc = strstr_rs (line, "saAmfSIProtectedbySG{")) != 0) {
  774. setSaNameT (&si->saAmfSIProtectedbySG, loc);
  775. } else if ((loc = strstr_rs (line, "saAmfSIRank{")) != 0) {
  776. si->saAmfSIRank = atoi (loc);
  777. } else if ((loc = strstr_rs (line, "saAmfSINumCSIs=")) != 0) {
  778. si->saAmfSINumCSIs = atoi (loc);
  779. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  780. si->saAmfSIPrefActiveAssignments = atoi (loc);
  781. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  782. si->saAmfSIPrefStandbyAssignments = atoi (loc);
  783. } else if (strstr_rs (line, "}")) {
  784. if (si->saAmfSINumCSIs == 0) {
  785. error_reason = "saAmfSINumCSIs missing";
  786. goto parse_error;
  787. }
  788. current_parse = AMF_APPLICATION;
  789. } else {
  790. goto parse_error;
  791. }
  792. break;
  793. case AMF_SI_RANKED_SU:
  794. if ((loc = strstr_rs (line, "saAmfRank=")) != 0) {
  795. si_ranked_su->saAmfRank = atoi (loc);
  796. } else if (strstr_rs (line, "}")) {
  797. current_parse = AMF_SI;
  798. } else {
  799. goto parse_error;
  800. }
  801. break;
  802. case AMF_SI_DEPENDENCY:
  803. if ((loc = strstr_rs (line, "saAmfToleranceTime=")) != 0) {
  804. si_dependency->saAmfToleranceTime = atoi (loc);
  805. } else if (strstr_rs (line, "}")) {
  806. current_parse = AMF_SI;
  807. } else {
  808. goto parse_error;
  809. }
  810. break;
  811. case AMF_CSI:
  812. if ((loc = strstr_rs (line, "saAmfCSTypeName=")) != 0) {
  813. setSaNameT (&csi->saAmfCSTypeName, loc);
  814. } else if ((loc = strstr_rs (line, "safCSIAttr=")) != 0) {
  815. attribute = calloc (1, sizeof(struct amf_csi_attribute));
  816. attribute->next = csi->attributes_head;
  817. csi->attributes_head = attribute;
  818. attribute->name = malloc (strlen (loc) + 1);
  819. strcpy (attribute->name, trim_str (loc));
  820. csi_attr_cnt = 1;
  821. current_parse = AMF_CSI_ATTRIBUTE;
  822. } else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) {
  823. csi_dependencies_cnt = 0;
  824. current_parse = AMF_CSI_DEPENDENCIES;
  825. } else if (strstr_rs (line, "}")) {
  826. if (strcmp(getSaNameT(&csi->saAmfCSTypeName), "") == 0) {
  827. error_reason = "saAmfCSTypeName missing";
  828. goto parse_error;
  829. }
  830. current_parse = AMF_SI;
  831. } else {
  832. goto parse_error;
  833. }
  834. break;
  835. case AMF_CSI_DEPENDENCIES:
  836. if (strstr_rs (line, "}")) {
  837. current_parse = AMF_CSI;
  838. } else if ((loc = strstr_rs (line, "saAmfCSIDependency=")) != 0) {
  839. csi_dependencies_cnt++;
  840. csi->saAmfCSIDependencies = realloc (csi->saAmfCSIDependencies,
  841. (csi_dependencies_cnt + 1) * sizeof(SaNameT));
  842. csi->saAmfCSIDependencies[csi_dependencies_cnt] = NULL;
  843. csi->saAmfCSIDependencies[csi_dependencies_cnt - 1] = malloc (sizeof(SaNameT));
  844. setSaNameT (csi->saAmfCSIDependencies[csi_dependencies_cnt - 1], loc);
  845. } else {
  846. goto parse_error;
  847. }
  848. break;
  849. case AMF_CSI_ATTRIBUTE:
  850. if ((loc = strstr_rs (line, "}")) != 0) {
  851. current_parse = AMF_CSI;
  852. } else {
  853. value = rm_beginning_ws (line);
  854. attribute->value = realloc (attribute->value,
  855. sizeof (SaStringT) * csi_attr_cnt + 1);
  856. attribute->value[csi_attr_cnt - 1] = malloc (strlen (value) + 1);
  857. strcpy (attribute->value[csi_attr_cnt - 1], value);
  858. attribute->value[csi_attr_cnt] = NULL;
  859. csi_attr_cnt++;
  860. }
  861. break;
  862. case AMF_CS_TYPE:
  863. if ((loc = strstr_rs (line, "}")) != 0) {
  864. current_parse = AMF_APPLICATION;
  865. }
  866. break;
  867. default:
  868. error_reason = "Invalid state\n";
  869. goto parse_error;
  870. break;
  871. }
  872. }
  873. fclose (fp);
  874. return (0);
  875. parse_error:
  876. sprintf (buf, "parse error at %s: %d: %s\n",
  877. filename, line_number, error_reason);
  878. *error_string = buf;
  879. fclose (fp);
  880. return (-1);
  881. }