amfcluster.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /** @file amfcluster.c
  2. *
  3. * Copyright (c) 2006 Ericsson AB.
  4. * Author: Hans Feldt
  5. * - Refactoring of code into several AMF files
  6. * Author: Anders Eriksson
  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 Cluster Class Implementation
  38. *
  39. * This file contains functions for handling the AMF cluster. It can be
  40. * viewed as the implementation of the AMF Cluster class
  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. * - to start the cluster initially
  47. * - to handle the administrative operation support for the cluster (FUTURE)
  48. *
  49. * The cluster class contains the following state machines:
  50. * - administrative state machine (ADSM)
  51. * - availability control state machine (ACSM)
  52. *
  53. * The administrative state machine will be implemented in the future.
  54. *
  55. * ACSM handles initial start of the cluster. In the future it will also handle
  56. * administrative commands on the cluster as described in paragraph 7.4 of the
  57. * spec. ACSM includes two stable states (UNINSTANTIATED and STARTED) and a
  58. * number of states to control the transition between the stable states.
  59. *
  60. * The cluster is in state UNINSTANTIATED when the cluster starts. (In the
  61. * future this state will also be assumed after the LOCK_INSTANTIATION
  62. * administrative command.)
  63. *
  64. * State STARTED is assumed when the cluster has been initially started and
  65. * will in the future be re-assumed after the administrative command RESTART
  66. * have been executed.
  67. */
  68. #include <stdlib.h>
  69. #include <errno.h>
  70. #include "print.h"
  71. #include "amf.h"
  72. #include "util.h"
  73. #include "main.h"
  74. /**
  75. * Determine if all applications are started
  76. * @param cluster
  77. *
  78. * @return int
  79. */
  80. static int all_applications_started (struct amf_cluster *cluster)
  81. {
  82. int all_started = 1;
  83. struct amf_application *app;
  84. struct amf_sg *sg;
  85. struct amf_su *su;
  86. for (app = cluster->application_head; app != NULL; app = app->next) {
  87. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  88. for (su = sg->su_head; su != NULL; su = su->next) {
  89. if (su->saAmfSUPresenceState != SA_AMF_PRESENCE_INSTANTIATED) {
  90. all_started = 0;
  91. goto done;
  92. }
  93. }
  94. }
  95. }
  96. done:
  97. return all_started;
  98. }
  99. static void timer_function_cluster_assign_workload_tmo (void *_cluster)
  100. {
  101. struct amf_application *app;
  102. struct amf_cluster *cluster = _cluster;
  103. dprintf("2nd Cluster start timer expired, assigning workload to application\n");
  104. for (app = cluster->application_head; app != NULL; app = app->next) {
  105. amf_application_assign_workload (app, this_amf_node);
  106. }
  107. }
  108. static void timer_function_cluster_startup_tmo (void *_cluster)
  109. {
  110. struct amf_cluster *cluster = _cluster;
  111. struct amf_application *app;
  112. dprintf("1st Cluster start timer expired, starting applications");
  113. for (app = cluster->application_head; app != NULL; app = app->next) {
  114. amf_application_start (app, this_amf_node);
  115. }
  116. /* wait a while before assigning workload */
  117. poll_timer_add (aisexec_poll_handle,
  118. cluster->saAmfClusterStartupTimeout,
  119. cluster,
  120. timer_function_cluster_assign_workload_tmo,
  121. &cluster->timeout_handle);
  122. }
  123. void amf_cluster_start (struct amf_cluster *cluster)
  124. {
  125. /* wait a while before starting applications */
  126. poll_timer_add (aisexec_poll_handle,
  127. cluster->saAmfClusterStartupTimeout,
  128. cluster,
  129. timer_function_cluster_startup_tmo,
  130. &cluster->timeout_handle);
  131. }
  132. void amf_cluster_init (void)
  133. {
  134. log_init ("AMF");
  135. }
  136. void amf_cluster_application_started (
  137. struct amf_cluster *cluster, struct amf_application *application)
  138. {
  139. ENTER ("application '%s' started", application->name.value);
  140. if (cluster->timeout_handle) {
  141. poll_timer_delete (aisexec_poll_handle, cluster->timeout_handle);
  142. }
  143. if (all_applications_started (cluster)) {
  144. struct amf_application *app;
  145. dprintf("All applications started, assigning workload.");
  146. for (app = cluster->application_head; app != NULL; app = app->next) {
  147. amf_application_assign_workload (app, this_amf_node);
  148. }
  149. }
  150. }
  151. struct amf_cluster *amf_cluster_create (void)
  152. {
  153. struct amf_cluster *cluster = calloc (1, sizeof (struct amf_cluster));
  154. if (cluster == NULL) {
  155. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  156. }
  157. cluster->saAmfClusterStartupTimeout = -1;
  158. cluster->saAmfClusterAdminState = SA_AMF_ADMIN_UNLOCKED;
  159. return cluster;
  160. }
  161. void amf_cluster_application_workload_assigned (
  162. struct amf_cluster *cluster, struct amf_application *app)
  163. {
  164. ENTER ("'%s'", app->name.value);
  165. }