2 * Copyright (c) 2002-2003 MontaVista Software, Inc.
3 * Copyright (c) 2006 Sun Microsystems, Inc.
7 * Author: Steven Dake (sdake@mvista.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/types.h>
42 #include <sys/socket.h>
46 #include "ais_types.h"
51 SaAmfHealthcheckKeyT key0
= {
55 SaNameT compNameGlobal
;
57 void printSaNameT (SaNameT
*name
)
61 for (i
= 0; i
< name
->length
; i
++) {
62 printf ("%c", name
->value
[i
]);
66 void setSanameT (SaNameT
*name
, char *str
) {
67 name
->length
= strlen (str
);
68 memcpy (name
->value
, str
, name
->length
);
71 static int health_flag
= -1;
72 static unsigned int healthcheck_count
= 0;
73 static unsigned int healthcheck_no
= 0;
76 void HealthcheckCallback (SaInvocationT invocation
,
77 const SaNameT
*compName
,
78 SaAmfHealthcheckKeyT
*healthcheckKey
)
83 printf ("Healthcheck %u for key '%s' for component ",
84 healthcheck_no
, healthcheckKey
->key
);
86 printSaNameT ((SaNameT
*)compName
);
88 res
= saAmfResponse (handle
, invocation
, SA_AIS_OK
);
90 printf ("response res is %d\n", res
);
92 if (healthcheck_no
== 20) {
93 res
= saAmfHealthcheckStop (handle
, &compNameGlobal
, &key0
);
96 printf ("done res = %d\n", res
);
101 void ComponentTerminateCallback (
102 SaInvocationT invocation
,
103 const SaNameT
*compName
)
105 printf ("ComponentTerminateCallback\n");
109 void CSISetCallback (
110 SaInvocationT invocation
,
111 const SaNameT
*compName
,
112 SaAmfHAStateT haState
,
113 SaAmfCSIDescriptorT
*csiDescriptor
)
117 case SA_AMF_HA_ACTIVE
:
118 printf ("CSISetCallback:");
119 printf ("for CSI '");
120 printSaNameT ((SaNameT
*)&csiDescriptor
->csiName
);
121 printf ("' for component ");
122 printSaNameT ((SaNameT
*)compName
);
124 printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
125 res
= saAmfResponse (handle
, invocation
, SA_AIS_OK
);
128 case SA_AMF_HA_STANDBY
:
129 printf ("CSISetCallback:");
130 printf ("for CSI '");
131 printSaNameT ((SaNameT
*)compName
);
132 printf ("' for component ");
133 printSaNameT ((SaNameT
*)compName
);
135 printf (" requested to enter hastate SA_AMF_STANDBY.\n");
136 saAmfResponse (handle
, invocation
, SA_AIS_OK
);
142 void CSIRemoveCallback (
143 SaInvocationT invocation
,
144 const SaNameT
*compName
,
145 const SaNameT
*csiName
,
146 const SaAmfCSIFlagsT
*csiFlags
)
148 printf ("CSIRemoveCallback for component '");
149 printSaNameT ((SaNameT
*)compName
);
150 printf ("' in CSI '");
151 printSaNameT ((SaNameT
*)csiName
);
153 saAmfResponse (invocation
, SA_OK
);
156 void ProtectionGroupTrackCallback (
157 const SaNameT
*csiName
,
158 SaAmfProtectionGroupNotificationT
*notificationBuffer
,
159 SaUint32T numberOfItems
,
160 SaUint32T numberOfMembers
,
165 printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems
, (int)numberOfMembers
);
166 printf ("buffer is %p\n", notificationBuffer
);
167 for (i
= 0; i
< numberOfItems
; i
++) {
168 printf ("component name");
169 printSaNameT (¬ificationBuffer
[i
].member
.compName
);
171 printf ("\treadiness state is %d\n", notificationBuffer
[i
].member
.readinessState
);
172 printf ("\thastate %d\n", notificationBuffer
[i
].member
.haState
);
173 printf ("\tchange is %d\n", notificationBuffer
[i
].change
);
178 void ExternalComponentRestartCallback (
179 const SaInvocationT invocation
,
180 const SaNameT
*externalCompName
)
182 printf ("ExternalComponentRestartCallback\n");
185 void ExternalComponentControlCallback (
186 const SaInvocationT invocation
,
187 const SaNameT
*externalCompName
,
188 SaAmfExternalComponentActionT controlAction
)
190 printf ("ExternalComponentControlCallback\n");
193 void PendingOperationConfirmCallback (
194 const SaInvocationT invocation
,
195 const SaNameT
*compName
,
196 SaAmfPendingOperationFlagsT pendingOperationFlags
)
198 printf ("PendingOperationConfirmCallback\n");
201 void PendingOperationExpiredCallback (
202 const SaNameT
*compName
,
203 SaAmfPendingOperationFlagsT pendingOperationFlags
)
205 printf ("PendingOperationExpiredCallback\n");
209 SaAmfCallbacksT amfCallbacks
= {
210 .saAmfHealthcheckCallback
= HealthcheckCallback
,
211 .saAmfCSISetCallback
= CSISetCallback
,
214 SaAmfCallbacksT amfCallbacks
;
216 SaVersionT version
= { 'B', 1, 1 };
218 #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
219 static struct sched_param sched_param
= {
224 void sigintr_handler (int signum
) {
228 int main (int argc
, char **argv
) {
230 SaSelectionObjectT select_fd
;
236 memset (&compNameGlobal
, 0, sizeof (SaNameT
));
237 signal (SIGINT
, sigintr_handler
);
238 #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
239 result
= sched_setscheduler (0, SCHED_RR
, &sched_param
);
241 printf ("couldn't set sched priority\n");
246 c
= getopt(argc
,argv
,"h:n:");
255 sscanf (optarg
,"%ud" ,&healthcheck_count
);
258 setSanameT (&compNameGlobal
, optarg
);
265 result
= saAmfInitialize (&handle
, &amfCallbacks
, &version
);
266 if (result
!= SA_OK
) {
267 printf ("initialize result is %d\n", result
);
272 saAmfSelectionObjectGet (handle
, &select_fd
);
273 FD_SET (select_fd
, &read_fds
);
274 if (compNameGlobal
.length
<= 0) {
275 setSanameT (&compNameGlobal
, "comp_a_in_su_2");
278 result
= saAmfHealthcheckStart (handle
,
281 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
282 SA_AMF_COMPONENT_FAILOVER
);
283 printf ("start %d\n", result
);
285 result
= saAmfHealthcheckStart (handle
,
288 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
289 SA_AMF_COMPONENT_FAILOVER
);
290 printf ("start %d\n", result
);
291 result
= saAmfComponentRegister (handle
, &compNameGlobal
, NULL
);
292 printf ("register result is %d (should be 1)\n", result
);
295 select (select_fd
+ 1, &read_fds
, 0, 0, 0);
296 saAmfDispatch (handle
, SA_DISPATCH_ALL
);
297 } while (result
&& stop
== 0);
300 result
= saAmfHealthcheckStart (handle
,
303 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
304 SA_AMF_COMPONENT_FAILOVER
);
307 select (select_fd
+ 1, &read_fds
, 0, 0, 0);
308 saAmfDispatch (handle
, SA_DISPATCH_ALL
);
311 saAmfFinalize (handle
);