amfutil.c 39 KB

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