amfcluster.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. static void timer_function_cluster_assign_workload_tmo (void *_cluster)
  75. {
  76. struct amf_application *app;
  77. struct amf_cluster *cluster = _cluster;
  78. dprintf("2nd Cluster start timer expired, assigning workload to application\n");
  79. for (app = cluster->application_head; app != NULL; app = app->next) {
  80. amf_application_assign_workload (app, this_amf_node);
  81. }
  82. }
  83. static void timer_function_cluster_startup_tmo (void *_cluster)
  84. {
  85. struct amf_cluster *cluster = _cluster;
  86. struct amf_application *app;
  87. dprintf("1st Cluster start timer expired, starting applications");
  88. for (app = cluster->application_head; app != NULL; app = app->next) {
  89. amf_application_start (app, this_amf_node);
  90. }
  91. /* wait a while before assigning workload */
  92. openais_timer_add (
  93. cluster->saAmfClusterStartupTimeout,
  94. cluster,
  95. timer_function_cluster_assign_workload_tmo,
  96. &cluster->timeout_handle);
  97. }
  98. void amf_cluster_start (struct amf_cluster *cluster)
  99. {
  100. /* wait a while before starting applications */
  101. openais_timer_add (
  102. cluster->saAmfClusterStartupTimeout,
  103. cluster,
  104. timer_function_cluster_startup_tmo,
  105. &cluster->timeout_handle);
  106. }
  107. void amf_cluster_init (void)
  108. {
  109. log_init ("AMF");
  110. }