Expose confdb write to the library.
[openais.git] / test / testamf3.c
blob0ab6a3898913f610eae29f42f181c45cd136478a
1 /*
2 * Copyright (c) 2002-2003 MontaVista Software, Inc.
3 * Copyright (c) 2006 Sun Microsystems, Inc.
5 * All rights reserved.
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.
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <errno.h>
39 #include <signal.h>
40 #include <unistd.h>
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <sys/un.h>
44 #include <sched.h>
46 #include "ais_types.h"
47 #include "saAmf.h"
49 SaAmfHandleT handle;
51 SaAmfHealthcheckKeyT key0 = {
52 .key = "key1",
53 .keyLen = 4
55 SaNameT compNameGlobal;
57 void printSaNameT (SaNameT *name)
59 int i;
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;
75 int stop = 0;
76 void HealthcheckCallback (SaInvocationT invocation,
77 const SaNameT *compName,
78 SaAmfHealthcheckKeyT *healthcheckKey)
80 SaErrorT res;
82 healthcheck_no++;
83 printf ("Healthcheck %u for key '%s' for component ",
84 healthcheck_no, healthcheckKey->key);
86 printSaNameT ((SaNameT *)compName);
87 printf ("\n");
88 res = saAmfResponse (handle, invocation, SA_AIS_OK);
89 if (res != SA_OK) {
90 printf ("response res is %d\n", res);
92 if (healthcheck_no == 20) {
93 res = saAmfHealthcheckStop (handle, &compNameGlobal, &key0);
94 stop = 1;
96 printf ("done res = %d\n", res);
99 #ifdef COMPILE_OUT
101 void ComponentTerminateCallback (
102 SaInvocationT invocation,
103 const SaNameT *compName)
105 printf ("ComponentTerminateCallback\n");
108 #endif
109 void CSISetCallback (
110 SaInvocationT invocation,
111 const SaNameT *compName,
112 SaAmfHAStateT haState,
113 SaAmfCSIDescriptorT *csiDescriptor)
115 int res;
116 switch (haState) {
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);
123 printf ("'");
124 printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
125 res = saAmfResponse (handle, invocation, SA_AIS_OK);
126 break;
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);
134 printf ("'");
135 printf (" requested to enter hastate SA_AMF_STANDBY.\n");
136 saAmfResponse (handle, invocation, SA_AIS_OK);
137 break;
141 #ifdef COMPILE_OUT
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);
152 printf ("'\n");
153 saAmfResponse (invocation, SA_OK);
156 void ProtectionGroupTrackCallback (
157 const SaNameT *csiName,
158 SaAmfProtectionGroupNotificationT *notificationBuffer,
159 SaUint32T numberOfItems,
160 SaUint32T numberOfMembers,
161 SaErrorT error)
163 int i;
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 (&notificationBuffer[i].member.compName);
170 printf ("\n");
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");
207 #endif
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 = {
220 sched_priority: 99
222 #endif
224 void sigintr_handler (int signum) {
225 exit (0);
228 int main (int argc, char **argv) {
229 int result;
230 SaSelectionObjectT select_fd;
231 fd_set read_fds;
232 extern char *optarg;
233 extern int optind;
234 int c;
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);
240 if (result == -1) {
241 printf ("couldn't set sched priority\n");
243 #endif
245 for (;;){
246 c = getopt(argc,argv,"h:n:");
247 if (c==-1) {
248 break;
250 switch (c) {
251 case 0 :
252 break;
253 case 'h':
254 health_flag = 0;
255 sscanf (optarg,"%ud" ,&healthcheck_count);
256 break;
257 case 'n':
258 setSanameT (&compNameGlobal, optarg);
259 break;
260 default :
261 break;
265 result = saAmfInitialize (&handle, &amfCallbacks, &version);
266 if (result != SA_OK) {
267 printf ("initialize result is %d\n", result);
268 exit (1);
271 FD_ZERO (&read_fds);
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,
279 &compNameGlobal,
280 &key0,
281 SA_AMF_HEALTHCHECK_AMF_INVOKED,
282 SA_AMF_COMPONENT_FAILOVER);
283 printf ("start %d\n", result);
285 result = saAmfHealthcheckStart (handle,
286 &compNameGlobal,
287 &key0,
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);
294 do {
295 select (select_fd + 1, &read_fds, 0, 0, 0);
296 saAmfDispatch (handle, SA_DISPATCH_ALL);
297 } while (result && stop == 0);
299 sleep (5);
300 result = saAmfHealthcheckStart (handle,
301 &compNameGlobal,
302 &key0,
303 SA_AMF_HEALTHCHECK_AMF_INVOKED,
304 SA_AMF_COMPONENT_FAILOVER);
306 do {
307 select (select_fd + 1, &read_fds, 0, 0, 0);
308 saAmfDispatch (handle, SA_DISPATCH_ALL);
309 } while (result);
311 saAmfFinalize (handle);
313 exit (0);