amfsg.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /** @file amfsg.c
  2. *
  3. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  4. * Author: Steven Dake (sdake@mvista.com)
  5. *
  6. * Copyright (c) 2006 Ericsson AB.
  7. * Author: Hans Feldt
  8. * - Introduced AMF B.02 information model
  9. * - Use DN in API and multicast messages
  10. * - (Re-)Introduction of event based multicast messages
  11. * - Refactoring of code into several AMF files
  12. * Author: Anders Eriksson, Lars Holm
  13. * - Component/SU restart, SU failover
  14. *
  15. * All rights reserved.
  16. *
  17. *
  18. * This software licensed under BSD license, the text of which follows:
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions are met:
  22. *
  23. * - Redistributions of source code must retain the above copyright notice,
  24. * this list of conditions and the following disclaimer.
  25. * - Redistributions in binary form must reproduce the above copyright notice,
  26. * this list of conditions and the following disclaimer in the documentation
  27. * and/or other materials provided with the distribution.
  28. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  29. * contributors may be used to endorse or promote products derived from this
  30. * software without specific prior written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  36. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  39. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  40. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  42. * THE POSSIBILITY OF SUCH DAMAGE.
  43. *
  44. * AMF Service Group Class Implementation
  45. *
  46. * This file contains functions for handling AMF-service groups(SGs). It can be
  47. * viewed as the implementation of the AMF Service Group class (called SG)
  48. * as described in SAI-Overview-B.02.01. The SA Forum specification
  49. * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour
  50. * and is referred to as 'the spec' below.
  51. *
  52. * The functions in this file are responsible for:
  53. * -on request start the service group by instantiating the contained SUs
  54. * -on request assign the service instances it protects to the in-service
  55. * service units it contains respecting as many as possible of the configured
  56. * requirements for the group
  57. * -create and delete an SI-assignment object for each relation between
  58. * an SI and an SU
  59. * -order each contained SU to create and delete CSI-assignments
  60. * -request the Service Instance class (SI) to execute the transfer of the
  61. * HA-state set/remove requests to each component involved
  62. * -fully control the execution of component failover and SU failover
  63. * -on request control the execution of the initial steps of node switchover
  64. * and node failover
  65. * -fully handle the auto adjust procedure
  66. *
  67. * Currently only the 'n+m' redundancy model is implemented. It is the
  68. * ambition to identify n+m specific variables and functions and add the suffix
  69. * '_nplusm' to them so that they can be easily recognized.
  70. *
  71. * When SG is requested to assign workload to all SUs or all SUs hosted on
  72. * a specific node, a procedure containing several steps is executed:
  73. * <1> An algorithm is executed which assigns SIs to SUs respecting the rules
  74. * that has been configured for SG. The algorithm also has to consider
  75. * if assignments between som SIs and SUs already exist. The scope of this
  76. * algorithm is to create SI-assignments and set up requested HA-state for
  77. * each assignment but not to transfer those HA-states to the components.
  78. * <2> All SI-assignments with a requested HA state == ACTIVE are transferred
  79. * to the components concerned before any STANDBY assignments are
  80. * transferred. All components have to acknowledge the setting of the
  81. * ACTIVE HA state before the transfer of any STANDBY assignment is
  82. * initiated.
  83. * <3> All active assignments can not be transferred at the same time to the
  84. * different components because the rules for dependencies between SI and
  85. * SI application wide and CSI and CSI within one SI, has to be respected.
  86. *
  87. * SG is fully responsible for step <1> but not fully responsible for handling
  88. * step <2> and <3>. However, SG uses an attribute called 'dependency level'
  89. * when requsted to assign workload. This parameter refers to an integer that
  90. * has been calculated initially for each SI. The 'dependency level' indicates
  91. * to which extent an SI depends on other SIs such that an SI that depends on
  92. * no other SI is on dependecy_level == 1, an SI that depends only on an SI on
  93. * dependency_level == 1 is on dependency-level == 2.
  94. * An SI that depends on several SIs gets a
  95. * dependency_level that is one unit higher than the SI with the highest
  96. * dependency_level it depends on. When SG is requested to assign the workload
  97. * on a certain dependency level, it requests all SI objects on that level to
  98. * activate (all) SI-assignments that during step <1> has been requested to
  99. * assume the active HA state.
  100. *
  101. * SG contains the following state machines:
  102. * - administrative state machine (ADSM) (NOT IN THIS RELEASE)
  103. * - availability control state machine (ACSM)
  104. *
  105. * The availability control state machine contains two states and one of them
  106. * is composite. Being a composite state means that it contains substates.
  107. * The states are:
  108. * - IDLE (non composite state)
  109. * - MANAGING_SG (composite state)
  110. * MANAGING_SG is entered at several different events which has in common
  111. * the need to set up or change the assignment of SIs to SUs. Only one such
  112. * event can be handled at the time. If new events occur while one event is
  113. * being handled then the new event is saved and will be handled after the
  114. * handling of the first event is ready (return to IDLE state has been done).
  115. * MANAGING_SG handles the following events:
  116. * - start (requests SG to order SU to instantiate all SUs in SG and waits
  117. * for SU to indicate presence state change reports from the SUs and
  118. * finally responds 'started' to the requester)
  119. * - assign (requests SG to assign SIs to SUs according to pre-configured
  120. * rules (if not already done) and transfer the HA state of
  121. * the SIs on the requested SI dependency level. Then SG waits for
  122. * confirmation that the HA state has been succesfully set and
  123. * finally responds 'assigned' to the reqeuster)
  124. * - auto_adjust (this event indicates that the auto-adjust probation timer has
  125. * expired and that SG should evaluate current assignments of
  126. * SIs to SUs and if needed remove current assignments and
  127. * create new according to what is specified in paragraph
  128. * 3.7.1.2)
  129. * - failover_comp (requests SG to failover a specific component according to
  130. * the procedure described in paragraph 3.12.1.3)
  131. * - failover_su (requests SG to failover a specific SU according to the
  132. * procedure described in paragraph 3.12.1.3 and 3.12.1.4)
  133. * - switchover_node (requests SG to execute the recovery actions described
  134. * in 3.12.1.3 and respond to the requester when recovery
  135. * is completed)
  136. * - failover_node (requests SG to execute the recovery actions described
  137. * in 3.12.1.3 and respond to the requester when recovery is
  138. * completed)
  139. *
  140. */
  141. #include <stdlib.h>
  142. #include <errno.h>
  143. #include "amf.h"
  144. #include "print.h"
  145. #include "main.h"
  146. #include "util.h"
  147. /**
  148. * Delete all SI assignments and all CSI assignments
  149. * by requesting all contained components.
  150. * @param su
  151. */
  152. static void delete_si_assignments (struct amf_su *su)
  153. {
  154. struct amf_csi *csi;
  155. struct amf_si *si;
  156. struct amf_si_assignment *si_assignment;
  157. ENTER ("'%s'", su->name.value);
  158. for (si = su->sg->application->si_head; si != NULL; si = si->next) {
  159. if (!name_match (&si->saAmfSIProtectedbySG, &su->sg->name)) {
  160. continue;
  161. }
  162. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  163. amf_csi_delete_assignments (csi, su);
  164. }
  165. /*
  166. * TODO: this only works for n+m where each SI list has only two
  167. * assignments, one active and one standby.
  168. * TODO: use DN instead
  169. */
  170. if (si->assigned_sis->su == su) {
  171. si_assignment = si->assigned_sis;
  172. si->assigned_sis = si_assignment->next;
  173. dprintf ("first");
  174. } else {
  175. si_assignment = si->assigned_sis->next;
  176. si->assigned_sis->next = NULL;
  177. dprintf ("second");
  178. }
  179. dprintf ("%p, %d, %d",
  180. si_assignment, si_assignment->name.length,
  181. si->assigned_sis->name.length);
  182. assert (si_assignment != NULL);
  183. free (si_assignment);
  184. }
  185. }
  186. static int all_si_has_hastate (struct amf_su *su, SaAmfHAStateT hastate)
  187. {
  188. struct amf_si_assignment *si_assignment;
  189. int all_confirmed = 1;
  190. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  191. while (si_assignment != NULL) {
  192. if (si_assignment->saAmfSISUHAState != hastate) {
  193. all_confirmed = 0;
  194. break;
  195. }
  196. si_assignment = amf_su_get_next_si_assignment (su, si_assignment);
  197. }
  198. return all_confirmed;
  199. }
  200. /**
  201. * Callback function used by SI when an SI has been deactivated.
  202. * @param si_assignment
  203. * @param result
  204. */
  205. static void failover_su_si_deactivated_cbfn (
  206. struct amf_si_assignment *si_assignment, int result)
  207. {
  208. ENTER ("'%s', %d", si_assignment->si->name.value, result);
  209. /*
  210. * If all SI assignments for the SU are quiesced, goto next
  211. * state (TerminatingSuspected).
  212. */
  213. if (all_si_has_hastate (si_assignment->su, SA_AMF_HA_QUIESCED)) {
  214. si_assignment->su->sg->avail_state = SG_AC_TerminatingSuspected;
  215. /*
  216. * Terminate suspected SU(s)
  217. */
  218. amf_su_terminate (si_assignment->su);
  219. }
  220. }
  221. static int su_instantiated_count (struct amf_sg *sg)
  222. {
  223. int cnt = 0;
  224. struct amf_su *su;
  225. for (su = sg->su_head; su != NULL; su = su->next) {
  226. if (su->saAmfSUPresenceState == SA_AMF_PRESENCE_INSTANTIATED)
  227. cnt++;
  228. }
  229. return cnt;
  230. }
  231. static void standby_su_activated_cbfn (
  232. struct amf_si_assignment *si_assignment, int result)
  233. {
  234. struct amf_su *su;
  235. ENTER ("'%s', %d", si_assignment->si->name.value, result);
  236. /*
  237. * TODO: create SI assignment to spare and assign them
  238. */
  239. si_assignment->su->sg->avail_state = SG_AC_AssigningStandbyToSpare;
  240. si_assignment->su->sg->avail_state = SG_AC_ReparingSu;
  241. if (all_si_has_hastate (si_assignment->su, SA_AMF_HA_ACTIVE)) {
  242. for (su = si_assignment->su->sg->su_head; su != NULL; su = su->next) {
  243. if ((su->saAmfSUPresenceState == SA_AMF_PRESENCE_UNINSTANTIATED) &&
  244. (su_instantiated_count (si_assignment->su->sg) <
  245. si_assignment->su->sg->saAmfSGNumPrefInserviceSUs)) {
  246. amf_su_instantiate (su);
  247. }
  248. }
  249. }
  250. }
  251. static void assign_si_assumed_cbfn (
  252. struct amf_si_assignment *si_assignment, int result)
  253. {
  254. struct amf_si_assignment *tmp_si_assignment;
  255. struct amf_si *si;
  256. struct amf_sg *sg = si_assignment->su->sg;
  257. int si_assignment_cnt = 0;
  258. int confirmed_assignments = 0;
  259. ENTER ("'%s', %d", si_assignment->si->name.value, result);
  260. /*
  261. * Report to application when all SIs that this SG protects
  262. * has been assigned or go back to idle state if not cluster
  263. * start.
  264. */
  265. for (si = sg->application->si_head; si != NULL; si = si->next) {
  266. if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) {
  267. for (tmp_si_assignment = si->assigned_sis;
  268. tmp_si_assignment != NULL;
  269. tmp_si_assignment = tmp_si_assignment->next) {
  270. si_assignment_cnt++;
  271. if (tmp_si_assignment->requested_ha_state ==
  272. tmp_si_assignment->saAmfSISUHAState) {
  273. confirmed_assignments++;
  274. }
  275. }
  276. }
  277. }
  278. assert (confirmed_assignments != 0);
  279. switch (sg->avail_state) {
  280. case SG_AC_AssigningOnRequest:
  281. if (si_assignment_cnt == confirmed_assignments) {
  282. sg->avail_state = SG_AC_Idle;
  283. amf_application_sg_assigned (sg->application, sg);
  284. } else {
  285. dprintf ("%d, %d", si_assignment_cnt, confirmed_assignments);
  286. }
  287. break;
  288. case SG_AC_AssigningStandBy:
  289. {
  290. SaNameT dn;
  291. if (si_assignment_cnt == confirmed_assignments) {
  292. sg->avail_state = SG_AC_Idle;
  293. amf_su_dn_make (si_assignment->su, &dn);
  294. sg->avail_state = SG_AC_Idle;
  295. log_printf (
  296. LOG_NOTICE, "'%s' failover recovery action finished",
  297. dn.value);
  298. }
  299. break;
  300. }
  301. default:
  302. dprintf ("%d, %d, %d", sg->avail_state, si_assignment_cnt,
  303. confirmed_assignments);
  304. amf_runtime_attributes_print (amf_cluster);
  305. assert (0);
  306. }
  307. }
  308. /**
  309. * Find an SU assigned with standby workload and activate it.
  310. * @param su
  311. */
  312. static void standby_su_activate (struct amf_su *su)
  313. {
  314. struct amf_si_assignment *su_si_assignment;
  315. struct amf_si_assignment *si_assignment;
  316. ENTER ("Old SU '%s'", su->name.value);
  317. su->sg->avail_state = SG_AC_ActivatingStandby;
  318. /*
  319. * For each (active) SI assignment on the old SU, find a standby
  320. * SI assignment and activate it.
  321. */
  322. su_si_assignment = amf_su_get_next_si_assignment (su, NULL);
  323. while (su_si_assignment != NULL) {
  324. for (si_assignment = su_si_assignment->si->assigned_sis;
  325. si_assignment != NULL;
  326. si_assignment = si_assignment->next) {
  327. if (si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) {
  328. si_assignment->requested_ha_state = SA_AMF_HA_ACTIVE;
  329. amf_si_ha_state_assume (
  330. si_assignment, standby_su_activated_cbfn);
  331. break; /* one standby is enough */
  332. }
  333. }
  334. su_si_assignment = amf_su_get_next_si_assignment (su, su_si_assignment);
  335. }
  336. delete_si_assignments (su);
  337. LEAVE ("");
  338. }
  339. static inline int div_round (int a, int b)
  340. {
  341. int res;
  342. res = a / b;
  343. if ((a % b) != 0)
  344. res++;
  345. return res;
  346. }
  347. static int all_su_has_presence_state(
  348. struct amf_sg *sg, SaAmfPresenceStateT state)
  349. {
  350. struct amf_su *su;
  351. int all_set = 1;
  352. for (su = sg->su_head; su != NULL; su = su->next) {
  353. if (su->saAmfSUPresenceState != state) {
  354. all_set = 0;
  355. break;
  356. }
  357. }
  358. return all_set;
  359. }
  360. /**
  361. * Get number of SIs protected by the specified SG.
  362. * @param sg
  363. *
  364. * @return int
  365. */
  366. static int sg_si_count_get (struct amf_sg *sg)
  367. {
  368. struct amf_si *si;
  369. int cnt = 0;
  370. for (si = sg->application->si_head; si != NULL; si = si->next) {
  371. if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) {
  372. cnt += 1;
  373. }
  374. }
  375. return (cnt);
  376. }
  377. static void sg_assign_nm_active (struct amf_sg *sg, int su_active_assign)
  378. {
  379. struct amf_su *su;
  380. struct amf_si *si;
  381. int assigned = 0;
  382. int assign_per_su = 0;
  383. int total_assigned = 0;
  384. int si_cnt;
  385. ENTER ("'%s'", sg->name.value);
  386. si_cnt = sg_si_count_get (sg);
  387. assign_per_su = div_round (si_cnt, su_active_assign);
  388. if (assign_per_su > sg->saAmfSGMaxActiveSIsperSUs) {
  389. assign_per_su = sg->saAmfSGMaxActiveSIsperSUs;
  390. }
  391. si = sg->application->si_head;
  392. su = sg->su_head;
  393. while (su != NULL) {
  394. if (amf_su_get_saAmfSUReadinessState (su) !=
  395. SA_AMF_READINESS_IN_SERVICE ||
  396. amf_su_get_saAmfSUNumCurrActiveSIs (su) ==
  397. sg->saAmfSGMaxActiveSIsperSUs ||
  398. amf_su_get_saAmfSUNumCurrStandbySIs (su) > 0) {
  399. su = su->next;
  400. continue; /* Not in service */
  401. }
  402. assigned = 0;
  403. while (si != NULL &&
  404. assigned < assign_per_su &&
  405. total_assigned < si_cnt) {
  406. if (amf_si_get_saAmfSINumCurrActiveAssignments (si) == 0) {
  407. assigned += 1;
  408. total_assigned += 1;
  409. amf_su_assign_si (su, si, SA_AMF_HA_ACTIVE);
  410. }
  411. si = si->next;
  412. }
  413. su = su->next;
  414. }
  415. if (total_assigned == 0) {
  416. dprintf ("Info: No SIs assigned!");
  417. }
  418. }
  419. static void sg_assign_nm_standby (struct amf_sg *sg, int su_standby_assign)
  420. {
  421. struct amf_su *su;
  422. struct amf_si *si;
  423. int assigned = 0;
  424. int assign_per_su = 0;
  425. int total_assigned = 0;
  426. int si_cnt;
  427. ENTER ("'%s'", sg->name.value);
  428. if (su_standby_assign == 0) {
  429. return;
  430. }
  431. si_cnt = sg_si_count_get (sg);
  432. assign_per_su = div_round (si_cnt, su_standby_assign);
  433. if (assign_per_su > sg->saAmfSGMaxStandbySIsperSUs) {
  434. assign_per_su = sg->saAmfSGMaxStandbySIsperSUs;
  435. }
  436. si = sg->application->si_head;
  437. su = sg->su_head;
  438. while (su != NULL) {
  439. if (amf_su_get_saAmfSUReadinessState (su) !=
  440. SA_AMF_READINESS_IN_SERVICE ||
  441. amf_su_get_saAmfSUNumCurrActiveSIs (su) > 0 ||
  442. amf_su_get_saAmfSUNumCurrStandbySIs (su) ==
  443. sg->saAmfSGMaxStandbySIsperSUs) {
  444. su = su->next;
  445. continue; /* Not available for assignment */
  446. }
  447. assigned = 0;
  448. while (si != NULL && assigned < assign_per_su) {
  449. if (amf_si_get_saAmfSINumCurrStandbyAssignments (si) == 0) {
  450. assigned += 1;
  451. total_assigned += 1;
  452. amf_su_assign_si (su, si, SA_AMF_HA_STANDBY);
  453. }
  454. si = si->next;
  455. }
  456. su = su->next;
  457. }
  458. if (total_assigned == 0) {
  459. dprintf ("Info: No SIs assigned!");
  460. }
  461. }
  462. static int su_inservice_count_get (struct amf_sg *sg)
  463. {
  464. struct amf_su *su;
  465. int answer = 0;
  466. for (su = sg->su_head; su != NULL; su = su->next) {
  467. if (amf_su_get_saAmfSUReadinessState (su) ==
  468. SA_AMF_READINESS_IN_SERVICE) {
  469. answer += 1;
  470. }
  471. }
  472. return (answer);
  473. }
  474. /**
  475. * TODO: dependency_level not used, hard coded
  476. * @param sg
  477. * @param dependency_level
  478. */
  479. void amf_sg_assign_si (struct amf_sg *sg, int dependency_level)
  480. {
  481. int active_sus_needed;
  482. int standby_sus_needed;
  483. int inservice_count;
  484. int units_for_standby;
  485. int units_for_active;
  486. int ii_spare;
  487. int su_active_assign;
  488. int su_standby_assign;
  489. int su_spare_assign;
  490. ENTER ("'%s'", sg->name.value);
  491. if (sg->avail_state == SG_AC_Idle) {
  492. sg->avail_state = SG_AC_AssigningOnRequest;
  493. }
  494. /**
  495. * Phase 1: Calculate assignments and create all runtime objects in
  496. * information model. Do not do the actual assignment, done in
  497. * phase 2.
  498. */
  499. /**
  500. * Calculate number of SUs to assign to active or standby state
  501. */
  502. inservice_count = (float)su_inservice_count_get (sg);
  503. active_sus_needed = div_round (sg_si_count_get (sg),
  504. sg->saAmfSGMaxActiveSIsperSUs);
  505. standby_sus_needed = div_round (sg_si_count_get (sg),
  506. sg->saAmfSGMaxStandbySIsperSUs);
  507. units_for_active = inservice_count - sg->saAmfSGNumPrefStandbySUs;
  508. if (units_for_active < 0) {
  509. units_for_active = 0;
  510. }
  511. units_for_standby = inservice_count - sg->saAmfSGNumPrefActiveSUs;
  512. if (units_for_standby < 0) {
  513. units_for_standby = 0;
  514. }
  515. ii_spare = inservice_count - sg->saAmfSGNumPrefActiveSUs -
  516. sg->saAmfSGNumPrefStandbySUs;
  517. if (ii_spare < 0) {
  518. ii_spare = 0;
  519. }
  520. /**
  521. * Determine number of active and standby service units
  522. * to assign based upon reduction procedure
  523. */
  524. if ((inservice_count - active_sus_needed) < 0) {
  525. dprintf ("assignment VI - partial assignment with SIs drop outs\n");
  526. su_active_assign = active_sus_needed;
  527. su_standby_assign = 0;
  528. su_spare_assign = 0;
  529. } else
  530. if ((inservice_count - active_sus_needed - standby_sus_needed) < 0) {
  531. dprintf ("assignment V - partial assignment with reduction "
  532. "of standby units\n");
  533. su_active_assign = active_sus_needed;
  534. if (standby_sus_needed > units_for_standby) {
  535. su_standby_assign = units_for_standby;
  536. } else {
  537. su_standby_assign = standby_sus_needed;
  538. }
  539. su_spare_assign = 0;
  540. } else
  541. if ((sg->saAmfSGMaxStandbySIsperSUs * units_for_standby) <=
  542. sg_si_count_get (sg)) {
  543. dprintf ("IV: full assignment with reduction of active service units\n");
  544. su_active_assign = inservice_count - standby_sus_needed;
  545. su_standby_assign = standby_sus_needed;
  546. su_spare_assign = 0;
  547. } else
  548. if ((sg->saAmfSGMaxActiveSIsperSUs * units_for_active) <=
  549. sg_si_count_get (sg)) {
  550. dprintf ("III: full assignment with reduction of standby "
  551. "service units\n");
  552. su_active_assign = sg->saAmfSGNumPrefActiveSUs;
  553. su_standby_assign = units_for_standby;
  554. su_spare_assign = 0;
  555. } else
  556. if (ii_spare == 0) {
  557. dprintf ("II: full assignment with spare reduction\n");
  558. su_active_assign = sg->saAmfSGNumPrefActiveSUs;
  559. su_standby_assign = sg->saAmfSGNumPrefStandbySUs;
  560. su_spare_assign = 0;
  561. } else {
  562. dprintf ("I: full assignment with spares\n");
  563. su_active_assign = sg->saAmfSGNumPrefActiveSUs;
  564. su_standby_assign = sg->saAmfSGNumPrefStandbySUs;
  565. su_spare_assign = ii_spare;
  566. }
  567. dprintf ("(inservice=%d) (assigning active=%d) (assigning standby=%d)"
  568. " (assigning spares=%d)\n",
  569. inservice_count, su_active_assign, su_standby_assign, su_spare_assign);
  570. sg_assign_nm_active (sg, su_active_assign);
  571. sg_assign_nm_standby (sg, su_standby_assign);
  572. sg->saAmfSGNumCurrAssignedSUs = inservice_count;
  573. /**
  574. * Phase 2: do the actual assignment to the component
  575. * TODO: first do active, then standby
  576. */
  577. {
  578. struct amf_si *si;
  579. struct amf_si_assignment *si_assignment;
  580. for (si = sg->application->si_head; si != NULL; si = si->next) {
  581. if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) {
  582. for (si_assignment = si->assigned_sis; si_assignment != NULL;
  583. si_assignment = si_assignment->next) {
  584. if (si_assignment->requested_ha_state !=
  585. si_assignment->saAmfSISUHAState) {
  586. amf_si_ha_state_assume (
  587. si_assignment, assign_si_assumed_cbfn);
  588. }
  589. }
  590. }
  591. }
  592. }
  593. LEAVE ("'%s'", sg->name.value);
  594. }
  595. void amf_sg_start (struct amf_sg *sg, struct amf_node *node)
  596. {
  597. struct amf_su *su;
  598. ENTER ("'%s'", sg->name.value);
  599. sg->avail_state = SG_AC_InstantiatingServiceUnits;
  600. if (node == NULL) {
  601. /* Cluster start */
  602. for (su = sg->su_head; su != NULL; su = su->next) {
  603. amf_su_instantiate (su);
  604. }
  605. }
  606. }
  607. void amf_sg_su_state_changed (
  608. struct amf_sg *sg, struct amf_su *su, SaAmfStateT type, int state)
  609. {
  610. ENTER ("'%s' SU '%s' state %d", sg->name.value, su->name.value, state);
  611. if (type == SA_AMF_PRESENCE_STATE) {
  612. if (state == SA_AMF_PRESENCE_INSTANTIATED) {
  613. if (all_su_has_presence_state(su->sg,
  614. SA_AMF_PRESENCE_INSTANTIATED)) {
  615. if (sg->avail_state == SG_AC_InstantiatingServiceUnits) {
  616. su->sg->avail_state = SG_AC_Idle;
  617. amf_application_sg_started (
  618. sg->application, sg, this_amf_node);
  619. } else if (sg->avail_state == SG_AC_ReparingSu) {
  620. su->sg->avail_state = SG_AC_AssigningStandBy;
  621. amf_sg_assign_si (sg, 0);
  622. } else {
  623. assert (0);
  624. }
  625. }
  626. } else if (state == SA_AMF_PRESENCE_UNINSTANTIATED) {
  627. if (sg->avail_state == SG_AC_TerminatingSuspected) {
  628. standby_su_activate (su);
  629. } else {
  630. assert (0);
  631. }
  632. } else {
  633. assert (0);
  634. }
  635. } else {
  636. assert (0);
  637. }
  638. }
  639. void amf_sg_init (void)
  640. {
  641. log_init ("AMF");
  642. }
  643. void amf_sg_failover_su_req (
  644. struct amf_sg *sg, struct amf_su *su, struct amf_node *node)
  645. {
  646. struct amf_si_assignment *si_assignment;
  647. ENTER ("");
  648. sg->avail_state = SG_AC_DeactivatingDependantWorkload;
  649. /*
  650. * Deactivate workload for SU
  651. */
  652. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  653. while (si_assignment != NULL) {
  654. if (si_assignment->saAmfSISUHAState == SA_AMF_HA_ACTIVE) {
  655. si_assignment->requested_ha_state = SA_AMF_HA_QUIESCED;
  656. amf_si_ha_state_assume (
  657. si_assignment, failover_su_si_deactivated_cbfn);
  658. }
  659. si_assignment = amf_su_get_next_si_assignment (su, si_assignment);
  660. }
  661. }