amfnode.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /** @file amfnode.c
  2. *
  3. * Copyright (c) 2006 Ericsson AB.
  4. * Author: Hans Feldt, Anders Eriksson, Lars Holm
  5. * - Constructors/destructors
  6. * - Serializers/deserializers
  7. *
  8. * All rights reserved.
  9. *
  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. * AMF Node Class Implementation
  38. *
  39. * This file contains functions for handling AMF nodes. It can be
  40. * viewed as the implementation of the AMF Node class (called NODE)
  41. * as described in SAI-Overview-B.02.01. The SA Forum specification
  42. * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour
  43. * and is referred to as 'the spec' below.
  44. *
  45. * The functions in this file are responsible for:
  46. * - controlling the instantiation of the SUs hosted on current node and
  47. * controlling the assigning of workload to them when a node joins the
  48. * cluster (cluster start is controlled by the Cluster Class)
  49. * - controlling node level recovery and repair functions
  50. * - implementing error escallation level 2 and 3 (paragraph 3.12.2.2 and
  51. * 3.12.2.3 in the spec)
  52. * - handling run time attributes of the AMF NODE; cached
  53. * attributes are stored as variables and sent to the IMM service (future)
  54. * upon the changes described in the specification
  55. *
  56. * The node class contains the following state machines:
  57. * - administrative state machine (ADSM)
  58. * - operational state machine (OPSM)
  59. * - availability control state machine (ACSM)
  60. *
  61. * The administrative state machine will be implemented in the future.
  62. *
  63. * The operational state machine is primarily used to report status of the
  64. * node.
  65. *
  66. * The availability control state machine is used for control purposes.
  67. * ACSM contains three states of which two are composite.
  68. * Being a composite state means that the state contains substates.
  69. * ACSM states are:
  70. * - REPAIR_NEEDED
  71. * - ESCALLATION_LEVEL (LEVEL_0, LEVEL_2 and LEVEL_3)
  72. * - MANAGING_HOSTED_SERVICE_UNITS (
  73. * . FAILING_FAST (REBOOTING_NODE and ACTIVATING_STANDBY_NODE)
  74. * . FAILING_GRACEFULLY (SWITCHING_OVER, FAILING_OVER and REBOOTING_NODE)
  75. * . LEAVING_SPONTANEOUSLY (DEACTIVATE_DEPENDENT and
  76. * WAITING_FOR_NODE_TO_JOIN)
  77. * . JOINING (STARTING_SERVICE_UNITS, ASSIGNING_ACTIVE_WORKLOAD and
  78. * ASSIGNING_STANDBY_WORKLOAD)
  79. *
  80. * REPAIR_NEEDED indicates the node needs a manual repair and this state will
  81. * maintained until the administrative command REPAIRED is entered
  82. * (implemented in the future)
  83. *
  84. * ESCALLATION_LEVEL is a kind of idle state where no actions are performed
  85. * and used only to remember the escallation level. Substate LEVEL_0 indicates
  86. * no escallation. LEVEL_2 indicates that so many component restarts have been
  87. * executed recently that a new component restart request will escalate
  88. * to service unit restart action. Node will request a service unit restart
  89. * from SU.
  90. * LEVEL_3 will be entered if either there are too many service unit restarts
  91. * been made or a component failover recovery action is requested. On level 3
  92. * the recovery action performed is service unit failover (paragraph 3.12.1.3).
  93. *
  94. * FAILING_FAST state executes a node re-boot and waits for the node to join
  95. * the cluster again.
  96. *
  97. * FAILING_GRACEFULLY state requests all SGs which have SUs hosted on current
  98. * node to switch or failover according to the procedures described in
  99. * paragraphs 3.12.1.3 before re-boot is executed. Then the confirmation is
  100. * awaited from all concerned SGs and finally a node re-boot is executed as
  101. * the repair action (see paragraph 2.12.1.4).
  102. *
  103. * LEAVING_SPONTANEOUSLY state handles the spontaneous leave of a node.
  104. *
  105. * JOINING state handles the start of a node in all cases except cluster start,
  106. * which is handled by the CLUSTER class.
  107. *
  108. */
  109. #include <stdlib.h>
  110. #include <assert.h>
  111. #include "amf.h"
  112. #include "util.h"
  113. #include "print.h"
  114. /**
  115. * Node constructor
  116. * @param loc
  117. * @param cluster
  118. * @param node
  119. */
  120. struct amf_node *amf_node_new (struct amf_cluster *cluster, char *name)
  121. {
  122. struct amf_node *node = calloc (1, sizeof (struct amf_node));
  123. if (node == NULL) {
  124. openais_exit_error(AIS_DONE_OUT_OF_MEMORY);
  125. }
  126. node->next = cluster->node_head;
  127. node->saAmfNodeAdminState = SA_AMF_ADMIN_UNLOCKED;
  128. node->saAmfNodeOperState = SA_AMF_OPERATIONAL_ENABLED;
  129. node->saAmfNodeAutoRepair = SA_TRUE;
  130. node->cluster = cluster;
  131. node->saAmfNodeSuFailOverProb = -1;
  132. node->saAmfNodeSuFailoverMax = ~0;
  133. setSaNameT (&node->name, name);
  134. return node;
  135. }
  136. void *amf_node_serialize (struct amf_node *node, int *len)
  137. {
  138. int objsz = sizeof (struct amf_node);
  139. struct amf_node *copy;
  140. copy = amf_malloc (objsz);
  141. memcpy (copy, node, objsz);
  142. *len = objsz;
  143. TRACE8 ("%s", copy->name.value);
  144. return copy;
  145. }
  146. struct amf_node *amf_node_deserialize (
  147. struct amf_cluster *cluster, char *buf, int size)
  148. {
  149. int objsz = sizeof (struct amf_node);
  150. if (objsz > size) {
  151. return NULL;
  152. } else {
  153. struct amf_node *obj = amf_node_new (cluster, "");
  154. if (obj == NULL) {
  155. return NULL;
  156. }
  157. memcpy (obj, buf, objsz);
  158. TRACE8 ("%s", obj->name.value);
  159. obj->cluster = cluster;
  160. obj->next = cluster->node_head;
  161. cluster->node_head = obj;
  162. return obj;
  163. }
  164. }
  165. void amf_node_sync_ready (struct amf_node *node)
  166. {
  167. struct amf_application *app;
  168. assert (node != NULL);
  169. log_printf(LOG_NOTICE, "Node %s sync ready, starting hosted SUs.",
  170. node->name.value);
  171. for (app = amf_cluster->application_head; app != NULL; app = app->next) {
  172. amf_application_start (app, node);
  173. }
  174. }
  175. void amf_node_init (void)
  176. {
  177. log_init ("AMF");
  178. }
  179. struct amf_node *amf_node_find (SaNameT *name)
  180. {
  181. struct amf_node *node;
  182. ENTER ("");
  183. for (node = amf_cluster->node_head; node != NULL; node = node->next) {
  184. if (name_match (&node->name, name)) {
  185. return node;
  186. }
  187. }
  188. return NULL;
  189. }