1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4
5 #include <IceUtil/Thread.h>
6 #include <Ice/Ice.h>
7 #include <IceGrid/IceGrid.h>
8 #include <TestHelper.h>
9 #include <Test.h>
10
11 using namespace std;
12 using namespace Test;
13 using namespace IceGrid;
14
15 void
addProperty(const CommunicatorDescriptorPtr & communicator,const string & name,const string & value)16 addProperty(const CommunicatorDescriptorPtr& communicator, const string& name, const string& value)
17 {
18 PropertyDescriptor prop;
19 prop.name = name;
20 prop.value = value;
21 communicator->propertySet.properties.push_back(prop);
22 }
23
24 string
getProperty(const PropertyDescriptorSeq & properties,const string & name)25 getProperty(const PropertyDescriptorSeq& properties, const string& name)
26 {
27 for(PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q)
28 {
29 if(q->name == name)
30 {
31 return q->value;
32 }
33 }
34 return "";
35 }
36
37 PropertyDescriptor
createProperty(const string & name,const string & value)38 createProperty(const string& name, const string& value)
39 {
40 PropertyDescriptor prop;
41 prop.name = name;
42 prop.value = value;
43 return prop;
44 }
45
46 bool
hasProperty(const CommunicatorDescriptorPtr & desc,const string & name,const string & value)47 hasProperty(const CommunicatorDescriptorPtr& desc, const string& name, const string& value)
48 {
49 for(PropertyDescriptorSeq::const_iterator p = desc->propertySet.properties.begin();
50 p != desc->propertySet.properties.end(); ++p)
51 {
52 if(p->name == name)
53 {
54 return p->value == value;
55 }
56 }
57 return false;
58 }
59
60 void
allTests(Test::TestHelper * helper)61 allTests(Test::TestHelper* helper)
62 {
63 const Ice::CommunicatorPtr& communicator = helper->communicator();
64 IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(
65 communicator->stringToProxy(communicator->getDefaultLocator()->ice_getIdentity().category + "/Registry"));
66 test(registry);
67 AdminSessionPrx session = registry->createAdminSession("foo", "bar");
68
69 session->ice_getConnection()->setACM(registry->getACMTimeout(),
70 IceUtil::None,
71 Ice::ICE_ENUM(ACMHeartbeat, HeartbeatAlways));
72
73 AdminPrx admin = session->getAdmin();
74 test(admin);
75
76 Ice::PropertiesPtr properties = communicator->getProperties();
77
78 {
79 ApplicationDescriptor testApp;
80 testApp.name = "TestApp";
81 admin->addApplication(testApp);
82
83 ApplicationUpdateDescriptor empty;
84 empty.name = "TestApp";
85 NodeUpdateDescriptor node;
86 node.name = "localnode";
87 empty.nodes.push_back(node);
88
89 ApplicationUpdateDescriptor update = empty;
90
91 cout << "testing server add... " << flush;
92
93 ServerDescriptorPtr server = new ServerDescriptor();
94 server->id = "Server";
95 server->exe = properties->getProperty("ServerDir") + "/server";
96 server->pwd = ".";
97 server->applicationDistrib = false;
98 server->allocatable = false;
99 addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
100 AdapterDescriptor adapter;
101 adapter.name = "Server";
102 adapter.id = "ServerAdapter";
103 adapter.registerProcess = false;
104 adapter.serverLifetime = false;
105 addProperty(server, "Server.Endpoints", "default");
106 ObjectDescriptor object;
107 object.id = Ice::stringToIdentity("test");
108 object.type = "::Test::TestIntf";
109 adapter.objects.push_back(object);
110 server->adapters.push_back(adapter);
111 update.nodes[0].servers.push_back(server);
112 admin->updateApplication(update);
113
114 update.nodes[0].servers[0]->id = "Server2";
115 try
116 {
117 admin->updateApplication(update);
118 test(false);
119 }
120 catch(const DeploymentException&)
121 {
122 // Adapter already exists
123 }
124 catch(const Ice::Exception& ex)
125 {
126 cerr << ex << endl;
127 test(false);
128 }
129
130 update.nodes[0].servers[0]->adapters[0].id = "ServerAdapter2";
131 try
132 {
133 admin->updateApplication(update);
134 test(false);
135 }
136 catch(const DeploymentException&)
137 {
138 // Object already exists
139 }
140 catch(const Ice::Exception& ex)
141 {
142 cerr << ex << endl;
143 test(false);
144 }
145
146 update.nodes[0].servers[0]->adapters[0].objects[0].id = Ice::stringToIdentity("test2");
147 try
148 {
149 admin->updateApplication(update);
150 }
151 catch(const Ice::Exception& ex)
152 {
153 cerr << ex << endl;
154 test(false);
155 }
156
157 TemplateDescriptor templ;
158 templ.parameters.push_back("name");
159 templ.descriptor = new ServerDescriptor();
160 server = ServerDescriptorPtr::dynamicCast(templ.descriptor);
161 server->id = "${name}";
162 server->exe = "${test.dir}/server";
163 server->pwd = ".";
164 server->applicationDistrib = false;
165 server->allocatable = false;
166 addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
167 adapter = AdapterDescriptor();
168 adapter.name = "Server";
169 adapter.id = "${server}";
170 adapter.registerProcess = false;
171 adapter.serverLifetime = false;
172 addProperty(server, "Server.Endpoints", "default");
173 object = ObjectDescriptor();
174 object.id = Ice::stringToIdentity("${server}");
175 object.type = "::Test::TestIntf";
176 adapter.objects.push_back(object);
177 server->adapters.push_back(adapter);
178 update = empty;
179 update.serverTemplates["ServerTemplate"] = templ;
180 try
181 {
182 admin->updateApplication(update);
183 }
184 catch(const Ice::Exception& ex)
185 {
186 cerr << ex << endl;
187 test(false);
188 }
189
190 update = empty;
191 ServerInstanceDescriptor instance;
192 instance._cpp_template = "ServerTemplate";
193 update.nodes[0].serverInstances.push_back(instance);
194 try
195 {
196 admin->updateApplication(update);
197 test(false);
198 }
199 catch(const DeploymentException&)
200 {
201 // Missing parameter
202 }
203 catch(const Ice::Exception& ex)
204 {
205 cerr << ex << endl;
206 test(false);
207 }
208
209 update = empty;
210 update.variables["test.dir"] = properties->getProperty("ServerDir");
211 update.variables["variable"] = "";
212 instance = ServerInstanceDescriptor();
213 instance._cpp_template = "ServerTemplate";
214 instance.parameterValues["name"] = "Server1";
215 update.nodes[0].serverInstances.push_back(instance);
216 try
217 {
218 admin->updateApplication(update);
219 }
220 catch(const Ice::Exception& ex)
221 {
222 cerr << ex << endl;
223 test(false);
224 }
225
226 cout << "ok" << endl;
227
228 cout << "testing server remove... " << flush;
229 update = empty;
230 update.nodes[0].removeServers.push_back("Server2");
231 try
232 {
233 admin->updateApplication(update);
234 }
235 catch(const Ice::Exception& ex)
236 {
237 cerr << ex << endl;
238 test(false);
239 }
240
241 try
242 {
243 admin->getServerInfo("Server2");
244 test(false);
245 }
246 catch(const ServerNotExistException&)
247 {
248 }
249
250 try
251 {
252 admin->updateApplication(update);
253 }
254 catch(const DeploymentException& ex)
255 {
256 cerr << ex.reason << endl;
257 test(false);
258 }
259 catch(const Ice::Exception& ex)
260 {
261 cerr << ex << endl;
262 test(false);
263 }
264
265 update = empty;
266 update.removeServerTemplates.push_back("ServerTemplate");
267 try
268 {
269 admin->updateApplication(update);
270 test(false);
271 }
272 catch(const DeploymentException&)
273 {
274 // Server without template!
275 }
276 catch(const Ice::Exception& ex)
277 {
278 cerr << ex << endl;
279 test(false);
280 }
281
282 update = empty;
283 update.nodes[0].removeServers.push_back("Server1");
284 try
285 {
286 admin->updateApplication(update);
287 }
288 catch(const Ice::Exception& ex)
289 {
290 cerr << ex << endl;
291 test(false);
292 }
293
294 try
295 {
296 admin->getServerInfo("Server1");
297 test(false);
298 }
299 catch(const ServerNotExistException&)
300 {
301 }
302
303 update = empty;
304 update.removeServerTemplates.push_back("ServerTemplate");
305 try
306 {
307 admin->updateApplication(update);
308 }
309 catch(const Ice::Exception& ex)
310 {
311 cerr << ex << endl;
312 test(false);
313 }
314 cout << "ok" << endl;
315
316 cout << "testing server update... " << flush;
317
318 ServerInfo info = admin->getServerInfo("Server");
319 test(info.descriptor);
320 addProperty(info.descriptor, "test", "test");
321 update = empty;
322 update.nodes[0].servers.push_back(info.descriptor);
323 try
324 {
325 admin->updateApplication(update);
326 }
327 catch(const Ice::Exception& ex)
328 {
329 cerr << ex << endl;
330 test(false);
331 }
332 info = admin->getServerInfo("Server");
333 test(info.descriptor);
334 test(getProperty(info.descriptor->propertySet.properties, "test") == "test");
335
336 update = empty;
337 update.serverTemplates["ServerTemplate"] = templ;
338 instance = ServerInstanceDescriptor();
339 instance._cpp_template = "ServerTemplate";
340 instance.parameterValues["name"] = "Server1";
341 update.nodes[0].serverInstances.push_back(instance);
342 try
343 {
344 admin->updateApplication(update);
345 }
346 catch(const Ice::Exception& ex)
347 {
348 cerr << ex << endl;
349 test(false);
350 }
351
352 update = empty;
353 addProperty(server, "test", "test");
354 assert(templ.descriptor == server);
355 update.serverTemplates["ServerTemplate"] = templ;
356 try
357 {
358 admin->updateApplication(update);
359 }
360 catch(const Ice::Exception& ex)
361 {
362 cerr << ex << endl;
363 test(false);
364 }
365
366 info = admin->getServerInfo("Server1");
367 test(info.descriptor);
368 test(getProperty(info.descriptor->propertySet.properties, "test") == "test");
369
370 info = admin->getServerInfo("Server");
371 test(info.descriptor);
372 adapter = AdapterDescriptor();
373 adapter.id = "Server1";
374 adapter.serverLifetime = false;
375 adapter.registerProcess = false;
376 info.descriptor->adapters.push_back(adapter);
377 update = empty;
378 update.nodes[0].servers.push_back(info.descriptor);
379 try
380 {
381 admin->updateApplication(update);
382 test(false);
383 }
384 catch(const DeploymentException&)
385 {
386 // Adapter already exists
387 }
388 catch(const Ice::Exception& ex)
389 {
390 cerr << ex << endl;
391 test(false);
392 }
393
394 info = admin->getServerInfo("Server");
395 test(info.descriptor);
396 adapter = AdapterDescriptor();
397 adapter.id = "ServerX";
398 adapter.serverLifetime = false;
399 adapter.registerProcess = false;
400 object = ObjectDescriptor();
401 object.id = Ice::stringToIdentity("test");
402 adapter.objects.push_back(object);
403 info.descriptor->adapters.push_back(adapter);
404 update = empty;
405 update.nodes[0].servers.push_back(info.descriptor);
406 try
407 {
408 admin->updateApplication(update);
409 test(false);
410 }
411 catch(const DeploymentException&)
412 {
413 // Object already exists
414 }
415 catch(const Ice::Exception& ex)
416 {
417 cerr << ex << endl;
418 test(false);
419 }
420
421 info = admin->getServerInfo("Server");
422 test(info.descriptor);
423 object = ObjectDescriptor();
424 object.id = Ice::stringToIdentity("test");
425 info.descriptor->adapters[0].objects.push_back(object);
426 update = empty;
427 update.nodes[0].servers.push_back(info.descriptor);
428 try
429 {
430 admin->updateApplication(update);
431 test(false);
432 }
433 catch(const DeploymentException&)
434 {
435 // Object already exists
436 }
437 catch(const Ice::Exception& ex)
438 {
439 cerr << ex << endl;
440 test(false);
441 }
442
443 info = admin->getServerInfo("Server");
444 test(info.descriptor);
445 object = ObjectDescriptor();
446 object.id = Ice::stringToIdentity("test1");
447 info.descriptor->adapters[0].allocatables.push_back(object);
448 update = empty;
449 update.nodes[0].servers.push_back(info.descriptor);
450 try
451 {
452 admin->updateApplication(update);
453 test(true);
454 }
455 catch(const Ice::Exception& ex)
456 {
457 cerr << ex << endl;
458 test(false);
459 }
460
461 info = admin->getServerInfo("Server");
462 test(info.descriptor);
463 object = ObjectDescriptor();
464 object.id = Ice::stringToIdentity("test1");
465 info.descriptor->adapters[0].allocatables.push_back(object);
466 update = empty;
467 update.nodes[0].servers.push_back(info.descriptor);
468 try
469 {
470 admin->updateApplication(update);
471 test(false);
472 }
473 catch(const DeploymentException&)
474 {
475 // Object already exists
476 }
477 catch(const Ice::Exception& ex)
478 {
479 cerr << ex << endl;
480 test(false);
481 }
482
483 info = admin->getServerInfo("Server");
484 test(info.descriptor);
485 object = ObjectDescriptor();
486 object.id = Ice::stringToIdentity("test");
487 info.descriptor->adapters[0].allocatables.push_back(object);
488 update = empty;
489 update.nodes[0].servers.push_back(info.descriptor);
490 try
491 {
492 admin->updateApplication(update);
493 test(true);
494 }
495 catch(const Ice::Exception& ex)
496 {
497 cerr << ex << endl;
498 test(false);
499 }
500
501 info = admin->getServerInfo("Server");
502 test(info.descriptor);
503 object = ObjectDescriptor();
504 object.id = Ice::stringToIdentity("test");
505 info.descriptor->adapters[0].allocatables.push_back(object);
506 update = empty;
507 update.nodes[0].servers.push_back(info.descriptor);
508 try
509 {
510 admin->updateApplication(update);
511 test(false);
512 }
513 catch(const DeploymentException&)
514 {
515 // Object already exists
516 }
517 catch(const Ice::Exception& ex)
518 {
519 cerr << ex << endl;
520 test(false);
521 }
522
523 admin->removeApplication("TestApp");
524 cout << "ok" << endl;
525 }
526
527 {
528 ApplicationDescriptor testApp;
529 testApp.name = "TestApp";
530 admin->addApplication(testApp);
531
532 ApplicationUpdateDescriptor empty;
533 empty.name = "TestApp";
534 NodeUpdateDescriptor node;
535 node.name = "localnode";
536 empty.nodes.push_back(node);
537
538 ApplicationUpdateDescriptor update = empty;
539
540 cout << "testing icebox server add... " << flush;
541
542 ServiceDescriptorPtr service = new ServiceDescriptor();
543 service->name = "Service1";
544 service->entry = "TestService:create";
545 AdapterDescriptor adapter;
546 adapter.name = "${service}";
547 adapter.id = "${server}.${service}";
548 adapter.registerProcess = false;
549 adapter.serverLifetime = false;
550 addProperty(service, "${service}.Endpoints", "default");
551 service->adapters.push_back(adapter);
552
553 IceBoxDescriptorPtr server = new IceBoxDescriptor();
554 server->id = "IceBox";
555 server->exe = properties->getProperty("IceBoxExe");
556
557 server->applicationDistrib = false;
558 server->allocatable = false;
559 addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
560 server->services.resize(3);
561 server->services[0].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone());
562 service->name = "Service2";
563 server->services[1].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone());
564 service->name = "Service3";
565 server->services[2].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone());
566
567 update.nodes[0].servers.push_back(server);
568 try
569 {
570 admin->updateApplication(update);
571 }
572 catch(const DeploymentException& ex)
573 {
574 cerr << ex.reason << endl;
575 test(false);
576 }
577 catch(const Ice::Exception& ex)
578 {
579 cerr << ex << endl;
580 test(false);
581 }
582 cout << "ok" << endl;
583
584 cout << "testing service add... " << flush;
585 service->name = "First";
586 server->services.resize(4);
587 server->services[3].descriptor = service;
588 try
589 {
590 admin->updateApplication(update);
591 }
592 catch(const DeploymentException& ex)
593 {
594 cerr << ex.reason << endl;
595 test(false);
596 }
597 catch(const Ice::Exception& ex)
598 {
599 cerr << ex << endl;
600 test(false);
601 }
602 cout << "ok" << endl;
603
604 cout << "testing service remove... " << flush;
605 server->services.resize(3);
606 try
607 {
608 admin->updateApplication(update);
609 }
610 catch(const DeploymentException& ex)
611 {
612 cerr << ex.reason << endl;
613 test(false);
614 }
615 catch(const Ice::Exception& ex)
616 {
617 cerr << ex << endl;
618 test(false);
619 }
620 cout << "ok" << endl;
621
622 admin->removeApplication("TestApp");
623 }
624
625 {
626 cout << "testing node add... " << flush;
627
628 ApplicationDescriptor testApp;
629 testApp.name = "TestApp";
630 NodeDescriptor node;
631 node.variables["nodename"] = "node1";
632 testApp.nodes["node1"] = node;
633
634 try
635 {
636 admin->addApplication(testApp);
637 }
638 catch(const DeploymentException& ex)
639 {
640 cerr << ex.reason << endl;
641 }
642 catch(const Ice::Exception& ex)
643 {
644 cerr << ex << endl;
645 test(false);
646 }
647
648 ApplicationUpdateDescriptor update;
649 update.name = "TestApp";
650 NodeUpdateDescriptor nodeUpdate;
651 nodeUpdate.name = "node2";
652 nodeUpdate.variables["nodename"] = "node2";
653 update.nodes.push_back(nodeUpdate);
654
655 try
656 {
657 admin->updateApplication(update);
658 }
659 catch(const Ice::Exception& ex)
660 {
661 cerr << ex << endl;
662 test(false);
663 }
664
665 testApp = admin->getApplicationInfo("TestApp").descriptor;
666 test(testApp.nodes.size() == 2);
667 test(testApp.nodes["node1"].variables["nodename"] == "node1");
668 test(testApp.nodes["node2"].variables["nodename"] == "node2");
669 cout << "ok" << endl;
670
671 cout << "testing node update... " << flush;
672
673 nodeUpdate.name = "node2";
674 nodeUpdate.variables["nodename"] = "node2updated";
675 update.nodes.back() = nodeUpdate;
676 try
677 {
678 admin->updateApplication(update);
679 }
680 catch(const Ice::Exception& ex)
681 {
682 cerr << ex << endl;
683 test(false);
684 }
685
686 testApp = admin->getApplicationInfo("TestApp").descriptor;
687 test(testApp.nodes.size() == 2);
688 test(testApp.nodes["node1"].variables["nodename"] == "node1");
689 test(testApp.nodes["node2"].variables["nodename"] == "node2updated");
690
691 cout << "ok" << endl;
692
693 cout << "testing node remove... " << flush;
694
695 update.nodes.clear();
696 update.removeNodes.push_back("node1");
697 try
698 {
699 admin->updateApplication(update);
700 }
701 catch(const Ice::Exception& ex)
702 {
703 cerr << ex << endl;
704 test(false);
705 }
706
707 testApp = admin->getApplicationInfo("TestApp").descriptor;
708 test(testApp.nodes.size() == 1);
709 test(testApp.nodes["node2"].variables["nodename"] == "node2updated");
710
711 admin->removeApplication("TestApp");
712
713 cout << "ok" << endl;
714 }
715
716 {
717 cout << "testing variable update... " << flush;
718
719 ServerDescriptorPtr server = new ServerDescriptor();
720 server->id = "${name}";
721 server->exe = "server";
722 server->pwd = ".";
723 server->applicationDistrib = false;
724 server->allocatable = false;
725
726 addProperty(server, "ApplicationVar", "${appvar}");
727 addProperty(server, "NodeVar", "${nodevar}");
728 addProperty(server, "ServerParamVar", "${serverparamvar}");
729
730 TemplateDescriptor templ;
731 templ.parameters.push_back("name");
732 templ.parameters.push_back("serverparamvar");
733 templ.descriptor = server;
734
735 ApplicationDescriptor testApp;
736 testApp.name = "TestApp";
737 testApp.variables["appvar"] = "AppValue";
738 testApp.serverTemplates["ServerTemplate"] = templ;
739
740 NodeDescriptor node;
741 node.variables["nodevar"] = "NodeValue";
742
743 ServerInstanceDescriptor serverInstance;
744 serverInstance._cpp_template = "ServerTemplate";
745 serverInstance.parameterValues["name"] = "Server";
746 serverInstance.parameterValues["serverparamvar"] = "ServerParamValue";
747 node.serverInstances.push_back(serverInstance);
748
749 testApp.nodes["node1"] = node;
750
751 try
752 {
753 admin->addApplication(testApp);
754 }
755 catch(const DeploymentException& ex)
756 {
757 cerr << ex.reason << endl;
758 test(false);
759 }
760 catch(const Ice::Exception& ex)
761 {
762 cerr << ex << endl;
763 test(false);
764 }
765
766 ApplicationUpdateDescriptor empty;
767 empty.name = "TestApp";
768 ApplicationUpdateDescriptor update = empty;
769 update.removeVariables.push_back("appvar");
770 try
771 {
772 admin->updateApplication(update);
773 test(false);
774 }
775 catch(const DeploymentException&)
776 {
777 // Missing app variable
778 //cerr << ex.reason << endl;
779 }
780 catch(const Ice::Exception& ex)
781 {
782 cerr << ex << endl;
783 test(false);
784 }
785
786 update = empty;
787 NodeUpdateDescriptor nodeUpdate;
788 nodeUpdate.name = "node1";
789 nodeUpdate.removeVariables.push_back("nodevar");
790 update.nodes.push_back(nodeUpdate);
791 try
792 {
793 admin->updateApplication(update);
794 test(false);
795 }
796 catch(const DeploymentException&)
797 {
798 // Missing node variable
799 //cerr << ex.reason << endl;
800 }
801 catch(const Ice::Exception& ex)
802 {
803 cerr << ex << endl;
804 test(false);
805 }
806
807 update = empty;
808 serverInstance = ServerInstanceDescriptor();
809 serverInstance._cpp_template = "ServerTemplate";
810 serverInstance.parameterValues["name"] = "Server";
811 nodeUpdate = NodeUpdateDescriptor();
812 nodeUpdate.name = "node1";
813 nodeUpdate.serverInstances.push_back(serverInstance);
814 update.nodes.push_back(nodeUpdate);
815 try
816 {
817 admin->updateApplication(update);
818 test(false);
819 }
820 catch(const DeploymentException&)
821 {
822 // Missing parameter
823 //cerr << ex.reason << endl;
824 }
825 catch(const Ice::Exception& ex)
826 {
827 cerr << ex << endl;
828 test(false);
829 }
830
831 ServerInfo serverBefore = admin->getServerInfo("Server");
832 ApplicationDescriptor origApp = admin->getApplicationInfo("TestApp").descriptor;
833
834 update = empty;
835 update.variables["nodevar"] = "appoverride";
836 nodeUpdate = NodeUpdateDescriptor();
837 nodeUpdate.name = "node1";
838 nodeUpdate.variables["serverparamvar"] = "nodeoverride";
839 update.nodes.push_back(nodeUpdate);
840 try
841 {
842 admin->updateApplication(update);
843 }
844 catch(const Ice::Exception& ex)
845 {
846 cerr << ex << endl;
847 test(false);
848 }
849
850 ServerInfo serverAfter = admin->getServerInfo("Server");
851 test(serverBefore.descriptor->propertySet == serverAfter.descriptor->propertySet);
852
853 update = empty;
854 nodeUpdate = NodeUpdateDescriptor();
855 nodeUpdate.name = "node1";
856 nodeUpdate.variables["appvar"] = "nodeoverride";
857 update.nodes.push_back(nodeUpdate);
858 try
859 {
860 admin->updateApplication(update);
861 }
862 catch(const Ice::Exception& ex)
863 {
864 cerr << ex << endl;
865 test(false);
866 }
867
868 serverAfter = admin->getServerInfo("Server");
869 PropertyDescriptorSeq newProps = serverAfter.descriptor->propertySet.properties;
870 test(getProperty(serverAfter.descriptor->propertySet.properties, "ApplicationVar") == "nodeoverride");
871 test(getProperty(serverAfter.descriptor->propertySet.properties, "NodeVar") == "NodeValue");
872 test(getProperty(serverAfter.descriptor->propertySet.properties, "ServerParamVar") == "ServerParamValue");
873 admin->removeApplication("TestApp");
874 cout << "ok" << endl;
875 }
876
877 {
878 cout << "testing property set update... " << flush;
879
880 ServiceDescriptorPtr service = new ServiceDescriptor();
881 service->name = "${name}";
882 service->entry = "dummy";
883 addProperty(service, "ServiceProp", "test");
884
885 TemplateDescriptor svcTempl;
886 svcTempl.parameters.push_back("name");
887 svcTempl.descriptor = service;
888
889 ServiceInstanceDescriptor serviceInstance;
890 serviceInstance._cpp_template = "ServiceTemplate";
891 serviceInstance.parameterValues["name"] = "Service";
892 serviceInstance.propertySet.properties.push_back(createProperty("ServiceInstanceProp", "test"));
893
894 IceBoxDescriptorPtr server = new IceBoxDescriptor();
895 server->id = "${name}";
896 server->exe = "server";
897 server->pwd = ".";
898 server->applicationDistrib = false;
899 server->allocatable = false;
900 server->propertySet.references.push_back("ApplicationPropertySet");
901 server->propertySet.references.push_back("NodePropertySet");
902 addProperty(server, "ServerProp", "test");
903 server->services.push_back(serviceInstance);
904
905 TemplateDescriptor templ;
906 templ.parameters.push_back("name");
907 templ.descriptor = server;
908
909 ApplicationDescriptor testApp;
910 testApp.name = "TestApp";
911 testApp.variables["appvar"] = "AppValue";
912 testApp.serverTemplates["ServerTemplate"] = templ;
913 testApp.serviceTemplates["ServiceTemplate"] = svcTempl;
914 testApp.propertySets["ApplicationPropertySet"].properties.push_back(createProperty("ApplicationProp","test"));
915 testApp.propertySets["ApplicationPropertySet1"].properties.push_back(createProperty("ApplicationProp", "d"));
916
917 NodeDescriptor node;
918 node.variables["nodevar"] = "NodeValue";
919 node.propertySets["NodePropertySet"].properties.push_back(createProperty("NodeProp", "test"));
920 node.propertySets["NodePropertySet1"].properties.push_back(createProperty("NodeProp", "test"));
921
922 ServerInstanceDescriptor serverInstance;
923 serverInstance._cpp_template = "ServerTemplate";
924 serverInstance.parameterValues["name"] = "Server";
925 serverInstance.propertySet.properties.push_back(createProperty("ServerInstanceProp", "test"));
926 node.serverInstances.push_back(serverInstance);
927
928 testApp.nodes["node1"] = node;
929
930 try
931 {
932 admin->addApplication(testApp);
933 }
934 catch(const DeploymentException& ex)
935 {
936 cerr << ex.reason << endl;
937 test(false);
938 }
939 catch(const Ice::Exception& ex)
940 {
941 cerr << ex << endl;
942 test(false);
943 }
944
945 ServerInfo info = admin->getServerInfo("Server");
946 test(hasProperty(info.descriptor, "ServerProp", "test"));
947 test(hasProperty(info.descriptor, "NodeProp", "test"));
948 test(hasProperty(info.descriptor, "ApplicationProp", "test"));
949 test(hasProperty(info.descriptor, "ServerInstanceProp", "test"));
950
951 ServiceDescriptorPtr svc = IceBoxDescriptorPtr::dynamicCast(info.descriptor)->services[0].descriptor;
952 test(hasProperty(svc, "ServiceProp", "test"));
953
954 ApplicationUpdateDescriptor empty;
955 empty.name = "TestApp";
956 ApplicationUpdateDescriptor update;
957
958 update = empty;
959 service->propertySet.properties.clear();
960 addProperty(service, "ServiceProp", "updated");
961 svcTempl.descriptor = service;
962 update.serviceTemplates["ServiceTemplate"] = svcTempl;
963 admin->updateApplication(update);
964 info = admin->getServerInfo("Server");
965 svc = IceBoxDescriptorPtr::dynamicCast(info.descriptor)->services[0].descriptor;
966 test(hasProperty(svc, "ServiceProp", "updated"));
967
968 update = empty;
969 serviceInstance.propertySet.properties.clear();
970 serviceInstance.propertySet.properties.push_back(createProperty("ServiceInstanceProp", "updated"));
971 server->services.clear();
972 server->services.push_back(serviceInstance);
973 templ.descriptor = server;
974 update.serverTemplates["ServerTemplate"] = templ;
975 admin->updateApplication(update);
976 info = admin->getServerInfo("Server");
977 svc = IceBoxDescriptorPtr::dynamicCast(info.descriptor)->services[0].descriptor;
978 test(hasProperty(svc, "ServiceInstanceProp", "updated"));
979
980 update = empty;
981 server->propertySet.properties.clear();
982 addProperty(server, "ServerProp", "updated");
983 templ.descriptor = server;
984 update.serverTemplates["ServerTemplate"] = templ;
985 admin->updateApplication(update);
986 info = admin->getServerInfo("Server");
987 test(hasProperty(info.descriptor, "ServerProp", "updated"));
988
989 update = empty;
990 serverInstance.propertySet.properties.clear();
991 serverInstance.propertySet.properties.push_back(createProperty("ServerInstanceProp", "updated"));
992 NodeUpdateDescriptor nodeUpdate;
993 nodeUpdate.name = "node1";
994 nodeUpdate.serverInstances.push_back(serverInstance);
995 update.nodes.push_back(nodeUpdate);
996 admin->updateApplication(update);
997 info = admin->getServerInfo("Server");
998 test(hasProperty(info.descriptor, "ServerInstanceProp", "updated"));
999
1000 update = empty;
1001 nodeUpdate.name = "node1";
1002 nodeUpdate.serverInstances.clear();
1003 nodeUpdate.propertySets["NodePropertySet"].properties.clear();
1004 nodeUpdate.propertySets["NodePropertySet"].properties.push_back(
1005 createProperty("NodeProp", "updated"));
1006 nodeUpdate.removePropertySets.push_back("NodePropertySet1");
1007 update.nodes.push_back(nodeUpdate);
1008 admin->updateApplication(update);
1009 info = admin->getServerInfo("Server");
1010 test(hasProperty(info.descriptor, "NodeProp", "updated"));
1011 ApplicationDescriptor updatedApplication = admin->getApplicationInfo("TestApp").descriptor;
1012 test(updatedApplication.nodes["node1"].propertySets.find("NodePropertySet1") ==
1013 updatedApplication.nodes["node1"].propertySets.end());
1014
1015 update = empty;
1016 update.propertySets["ApplicationPropertySet"].properties.clear();
1017 update.propertySets["ApplicationPropertySet"].properties.push_back(
1018 createProperty("ApplicationProp", "updated"));
1019 update.removePropertySets.push_back("ApplicationPropertySet1");
1020 admin->updateApplication(update);
1021 info = admin->getServerInfo("Server");
1022 test(hasProperty(info.descriptor, "ApplicationProp", "updated"));
1023 updatedApplication = admin->getApplicationInfo("TestApp").descriptor;
1024 test(updatedApplication.propertySets.find("ApplicationPropertySet1") ==
1025 updatedApplication.propertySets.end());
1026
1027 admin->removeApplication("TestApp");
1028 cout << "ok" << endl;
1029 }
1030
1031 {
1032 cout << "testing description update... " << flush;
1033
1034 ApplicationDescriptor testApp;
1035 testApp.name = "TestApp";
1036 testApp.description = "Description";
1037 try
1038 {
1039 admin->addApplication(testApp);
1040 }
1041 catch(const Ice::Exception& ex)
1042 {
1043 cerr << ex << endl;
1044 test(false);
1045 }
1046 testApp = admin->getApplicationInfo("TestApp").descriptor;
1047 test(testApp.description == "Description");
1048
1049 ApplicationUpdateDescriptor update;
1050 update.name = "TestApp";
1051 try
1052 {
1053 admin->updateApplication(update);
1054 }
1055 catch(const Ice::Exception& ex)
1056 {
1057 cerr << ex << endl;
1058 test(false);
1059 }
1060 testApp = admin->getApplicationInfo("TestApp").descriptor;
1061 test(testApp.description == "Description");
1062
1063 update.description = new BoxedString("updatedDescription");
1064 try
1065 {
1066 admin->updateApplication(update);
1067 }
1068 catch(const Ice::Exception& ex)
1069 {
1070 cerr << ex << endl;
1071 test(false);
1072 }
1073 testApp = admin->getApplicationInfo("TestApp").descriptor;
1074 test(testApp.description == "updatedDescription");
1075
1076 update.description = new BoxedString("");
1077 try
1078 {
1079 admin->updateApplication(update);
1080 }
1081 catch(const Ice::Exception& ex)
1082 {
1083 cerr << ex << endl;
1084 test(false);
1085 }
1086 testApp = admin->getApplicationInfo("TestApp").descriptor;
1087 test(testApp.description == "");
1088
1089 admin->removeApplication("TestApp");
1090
1091 cout << "ok" << endl;
1092 }
1093
1094 {
1095 cout << "testing server node move... " << flush;
1096
1097 ApplicationDescriptor nodeApp;
1098 nodeApp.name = "NodeApp";
1099
1100 ServerDescriptorPtr server = new ServerDescriptor();
1101 server->id = "node-${index}";
1102 server->exe = properties->getProperty("IceGridNodeExe");
1103 server->pwd = ".";
1104 server->applicationDistrib = false;
1105 server->allocatable = false;
1106 server->options.push_back("--nowarn");
1107
1108 addProperty(server, "IceGrid.Node.Name", "node-${index}");
1109 addProperty(server, "IceGrid.Node.Data", properties->getProperty("TestDir") + "/db/node-${index}");
1110 addProperty(server, "IceGrid.Node.Endpoints", "default");
1111 addProperty(server, "IceGrid.Node.PropertiesOverride", properties->getProperty("NodePropertiesOverride"));
1112 addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
1113
1114 nodeApp.serverTemplates["nodeTemplate"].descriptor = server;
1115 nodeApp.serverTemplates["nodeTemplate"].parameters.push_back("index");
1116
1117 ServerInstanceDescriptor instance;
1118 instance._cpp_template = "nodeTemplate";
1119 instance.parameterValues["index"] = "1";
1120 nodeApp.nodes["localnode"].serverInstances.push_back(instance);
1121 instance.parameterValues["index"] = "2";
1122 nodeApp.nodes["localnode"].serverInstances.push_back(instance);
1123
1124 try
1125 {
1126 admin->addApplication(nodeApp);
1127 }
1128 catch(const Ice::Exception& ex)
1129 {
1130 cerr << ex << endl;
1131 test(false);
1132 }
1133
1134 admin->startServer("node-1");
1135 admin->startServer("node-2");
1136
1137 //
1138 // We need to wait because the node might not be fully started
1139 // here (the node adapter isn't indirect, so we can't use the
1140 // wait-for-activation feature here.)
1141 //
1142 int retry = 0;
1143 while(retry < 20)
1144 {
1145 try
1146 {
1147 if(admin->pingNode("node-1") && admin->pingNode("node-2"))
1148 {
1149 break;
1150 }
1151 }
1152 catch(const NodeNotExistException&)
1153 {
1154 }
1155 IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500));
1156 ++retry;
1157 }
1158 test(admin->pingNode("node-1"));
1159 test(admin->pingNode("node-2"));
1160
1161 ApplicationDescriptor testApp;
1162 testApp.name = "TestApp";
1163 server = new ServerDescriptor();
1164 server->id = "Server";
1165 server->exe = properties->getProperty("ServerDir") + "/server";
1166 server->pwd = ".";
1167 server->applicationDistrib = false;
1168 server->allocatable = false;
1169 addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
1170 AdapterDescriptor adapter;
1171 adapter.name = "Server";
1172 adapter.id = "ServerAdapter";
1173 adapter.registerProcess = false;
1174 adapter.serverLifetime = true;
1175 server->adapters.push_back(adapter);
1176 addProperty(server, "Server.Endpoints", "default");
1177 testApp.nodes["node-1"].servers.push_back(server);
1178
1179 try
1180 {
1181 admin->addApplication(testApp);
1182 }
1183 catch(const DeploymentException& ex)
1184 {
1185 cerr << ex.reason << endl;
1186 test(false);
1187 }
1188
1189 try
1190 {
1191 admin->startServer("Server");
1192 test(admin->getServerState("Server") == Active);
1193 }
1194 catch(const ServerStartException& ex)
1195 {
1196 cerr << ex << "\nreason = " << ex.reason << endl;
1197 test(false);
1198 }
1199 catch(const Ice::Exception& ex)
1200 {
1201 cerr << ex << endl;
1202 test(false);
1203 }
1204
1205 ApplicationUpdateDescriptor update;
1206 update.name = "TestApp";
1207
1208 NodeUpdateDescriptor nodeUpdate;
1209 nodeUpdate.name = "node-1";
1210 nodeUpdate.removeServers.push_back("Server");
1211 update.nodes.push_back(nodeUpdate);
1212 nodeUpdate.name = "node-2";
1213 nodeUpdate.servers.push_back(server);
1214 nodeUpdate.removeServers.clear();
1215 update.nodes.push_back(nodeUpdate);
1216
1217 try
1218 {
1219 admin->updateApplication(update);
1220 }
1221 catch(const DeploymentException& ex)
1222 {
1223 cerr << ex.reason << endl;
1224 test(false);
1225 }
1226 while(true)
1227 {
1228 try
1229 {
1230 test(admin->getServerInfo("Server").node == "node-2" && admin->getServerState("Server") == Inactive);
1231
1232 admin->startServer("Server");
1233 test(admin->getServerState("Server") == Active);
1234 break;
1235 }
1236 catch(const DeploymentException&)
1237 {
1238 IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200));
1239 }
1240 }
1241
1242 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1));
1243
1244 update = ApplicationUpdateDescriptor();
1245 update.name = "TestApp";
1246 nodeUpdate = NodeUpdateDescriptor();
1247 nodeUpdate.name = "node-2";
1248 nodeUpdate.removeServers.push_back("Server");
1249 update.nodes.push_back(nodeUpdate);
1250 nodeUpdate = NodeUpdateDescriptor();
1251 nodeUpdate.name = "unknownNode";
1252 nodeUpdate.servers.push_back(server);
1253 update.nodes.push_back(nodeUpdate);
1254
1255 try
1256 {
1257 admin->updateApplication(update);
1258 }
1259 catch(const DeploymentException& ex)
1260 {
1261 cerr << ex.reason << endl;
1262 test(false);
1263 }
1264
1265 try
1266 {
1267 admin->getServerState("Server");
1268 test(false);
1269 }
1270 catch(const NodeUnreachableException&)
1271 {
1272 }
1273
1274 try
1275 {
1276 admin->removeApplication("TestApp");
1277 }
1278 catch(const DeploymentException& ex)
1279 {
1280 cerr << ex.reason << endl;
1281 test(false);
1282 }
1283
1284 admin->stopServer("node-1");
1285 admin->stopServer("node-2");
1286
1287 try
1288 {
1289 admin->removeApplication("NodeApp");
1290 }
1291 catch(const Ice::Exception& ex)
1292 {
1293 cerr << ex << endl;
1294 test(false);
1295 }
1296
1297 cout << "ok" << endl;
1298 }
1299
1300 session->destroy();
1301 }
1302