1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
|
// **********************************************************************
//
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#include <IceUtil/Functional.h>
#include <Ice/Communicator.h>
#include <Ice/Properties.h>
#include <Ice/LoggerUtil.h>
#include <IceGrid/NodeCache.h>
#include <IceGrid/SessionI.h>
#include <IceGrid/NodeSessionI.h>
#include <IceGrid/ServerCache.h>
#include <IceGrid/ReplicaCache.h>
#include <IceGrid/DescriptorHelper.h>
#include <IcePatch2/Util.h>
using namespace std;
using namespace IceGrid;
namespace IceGrid
{
struct ToInternalServerDescriptor : std::unary_function<CommunicatorDescriptorPtr&, void>
{
ToInternalServerDescriptor(const InternalServerDescriptorPtr& descriptor, const InternalNodeInfoPtr& node,
int iceVersion) :
_desc(descriptor),
_node(node),
_iceVersion(iceVersion)
{
}
void
operator()(const CommunicatorDescriptorPtr& desc)
{
//
// Figure out the configuration file name for the communicator
// (if it's a service, it's "config_<service name>", if it's
// the server, it's just "config").
//
string filename = "config";
ServiceDescriptorPtr svc = ServiceDescriptorPtr::dynamicCast(desc);
if(svc)
{
filename += "_" + svc->name;
}
PropertyDescriptorSeq& props = _desc->properties[filename];
PropertyDescriptorSeq communicatorProps = desc->propertySet.properties;
//
// If this is a service communicator and the IceBox server has admin
// endpoints configured, we ignore the server-lifetime attributes of
// the service object adapters and assume it's set to false.
//
bool ignoreServerLifetime = false;
if(svc)
{
if(_iceVersion == 0 || _iceVersion >= 30300)
{
if(getProperty(_desc->properties["config"], "Ice.Admin.Endpoints") != "")
{
ignoreServerLifetime = true;
}
}
}
//
// Add the adapters and their configuration.
//
for(AdapterDescriptorSeq::const_iterator q = desc->adapters.begin(); q != desc->adapters.end(); ++q)
{
_desc->adapters.push_back(new InternalAdapterDescriptor(q->id,
ignoreServerLifetime ? false : q->serverLifetime));
props.push_back(createProperty("# Object adapter " + q->name));
PropertyDescriptor prop = removeProperty(communicatorProps, q->name + ".Endpoints");
prop.name = q->name + ".Endpoints";
props.push_back(prop);
props.push_back(createProperty(q->name + ".AdapterId", q->id));
if(!q->replicaGroupId.empty())
{
props.push_back(createProperty(q->name + ".ReplicaGroupId", q->replicaGroupId));
}
//
// Ignore the register process attribute if the server is using Ice >= 3.3.0
//
if(_iceVersion != 0 && _iceVersion < 30300)
{
if(q->registerProcess)
{
props.push_back(createProperty(q->name + ".RegisterProcess", "1"));
_desc->processRegistered = true;
}
}
}
_desc->logs.insert(_desc->logs.end(), desc->logs.begin(), desc->logs.end());
const string dbsPath = _node->dataDir + "/servers/" + _desc->id + "/dbs/";
for(DbEnvDescriptorSeq::const_iterator p = desc->dbEnvs.begin(); p != desc->dbEnvs.end(); ++p)
{
props.push_back(createProperty("# Database environment " + p->name));
if(p->dbHome.empty())
{
_desc->dbEnvs.push_back(new InternalDbEnvDescriptor(p->name, p->properties));
props.push_back(createProperty("Freeze.DbEnv." + p->name + ".DbHome", dbsPath + p->name));
}
else
{
props.push_back(createProperty("Freeze.DbEnv." + p->name + ".DbHome", p->dbHome));
}
}
//
// Copy the communicator descriptor properties.
//
if(!communicatorProps.empty())
{
if(svc)
{
props.push_back(createProperty("# Service descriptor properties"));
}
else
{
props.push_back(createProperty("# Server descriptor properties"));
}
copy(communicatorProps.begin(), communicatorProps.end(), back_inserter(props));
}
//
// For Ice servers > 3.3.0 escape the properties.
//
if(_iceVersion == 0 || _iceVersion >= 30300)
{
for(PropertyDescriptorSeq::iterator p = props.begin(); p != props.end(); ++p)
{
if(p->name.find('#') != 0 || !p->value.empty())
{
p->name = escapeProperty(p->name);
p->value = escapeProperty(p->value);
}
}
}
}
PropertyDescriptor
removeProperty(PropertyDescriptorSeq& properties, const string& name)
{
string value;
PropertyDescriptorSeq::iterator p = properties.begin();
while(p != properties.end())
{
if(p->name == name)
{
value = p->value;
p = properties.erase(p);
}
else
{
++p;
}
}
PropertyDescriptor desc;
desc.name = name;
desc.value = value;
return desc;
}
InternalServerDescriptorPtr _desc;
InternalNodeInfoPtr _node;
int _iceVersion;
};
class LoadCB : public AMI_Node_loadServer
{
public:
LoadCB(const TraceLevelsPtr& traceLevels,
const ServerEntryPtr& server,
const string& node,
int timeout) :
_traceLevels(traceLevels), _server(server), _id(server->getId()), _node(node), _timeout(timeout)
{
}
void
ice_response(const ServerPrx& server, const AdapterPrxDict& adapters, int at, int dt)
{
if(_traceLevels && _traceLevels->server > 1)
{
Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
out << "loaded `" << _id << "' on node `" << _node << "'";
}
//
// Add the node session timeout on the proxies to ensure the
// timeout is large enough.
//
_server->loadCallback(server, adapters, at + _timeout, dt + _timeout);
}
void
ice_exception(const Ice::Exception& ex)
{
try
{
ex.ice_throw();
}
catch(const DeploymentException& ex)
{
if(_traceLevels && _traceLevels->server > 1)
{
Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
out << "couldn't load `" << _id << "' on node `" << _node << "':\n" << ex.reason;
}
ostringstream os;
os << "couldn't load `" << _id << "' on node `" << _node << "':\n" << ex.reason;
_server->exception(DeploymentException(os.str()));
}
catch(const Ice::Exception& ex)
{
if(_traceLevels && _traceLevels->server > 1)
{
Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
out << "couldn't load `" << _id << "' on node `" << _node << "':\n" << ex;
}
ostringstream os;
os << ex;
_server->exception(NodeUnreachableException(_node, os.str()));
}
}
private:
const TraceLevelsPtr _traceLevels;
const ServerEntryPtr _server;
const string _id;
const string _node;
const int _timeout;
};
class DestroyCB : public AMI_Node_destroyServer
{
public:
DestroyCB(const TraceLevelsPtr& traceLevels, const ServerEntryPtr& server, const string& node) :
_traceLevels(traceLevels), _server(server), _id(server->getId()), _node(node)
{
}
void
ice_response()
{
if(_traceLevels && _traceLevels->server > 1)
{
Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
out << "unloaded `" << _id << "' on node `" << _node << "'";
}
_server->destroyCallback();
}
void
ice_exception(const Ice::Exception& ex)
{
try
{
ex.ice_throw();
}
catch(const DeploymentException& ex)
{
if(_traceLevels && _traceLevels->server > 1)
{
Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
out << "couldn't unload `" << _id << "' on node `" << _node << "':\n" << ex.reason;
}
ostringstream os;
os << "couldn't unload `" << _id << "' on node `" << _node << "':\n" << ex.reason;
_server->exception(DeploymentException(os.str()));
}
catch(const Ice::Exception& ex)
{
if(_traceLevels && _traceLevels->server > 1)
{
Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
out << "couldn't unload `" << _id << "' on node `" << _node << "':\n" << ex;
}
ostringstream os;
os << ex;
_server->exception(NodeUnreachableException(_node, os.str()));
}
}
private:
const TraceLevelsPtr _traceLevels;
const ServerEntryPtr _server;
const string _id;
const string _node;
};
class RegisterCB : public AMI_Node_registerWithReplica
{
public:
RegisterCB(const NodeEntryPtr& node) : _node(node)
{
}
void
ice_response()
{
_node->finishedRegistration();
}
void
ice_exception(const Ice::Exception& ex)
{
_node->finishedRegistration(ex);
}
private:
const NodeEntryPtr _node;
};
};
NodeCache::NodeCache(const Ice::CommunicatorPtr& communicator, ReplicaCache& replicaCache, const string& replicaName) :
_communicator(communicator),
_replicaName(replicaName),
_replicaCache(replicaCache)
{
}
NodeEntryPtr
NodeCache::get(const string& name, bool create) const
{
Lock sync(*this);
NodeEntryPtr entry = getImpl(name);
if(!entry && create)
{
NodeCache& self = const_cast<NodeCache&>(*this);
entry = new NodeEntry(self, name);
self.addImpl(name, entry);
}
if(!entry)
{
NodeNotExistException ex;
ex.name = name;
throw ex;
}
return entry;
}
NodeEntry::NodeEntry(NodeCache& cache, const std::string& name) :
_cache(cache),
_ref(0),
_name(name),
_registering(false)
{
}
NodeEntry::~NodeEntry()
{
}
void
NodeEntry::addDescriptor(const string& application, const NodeDescriptor& descriptor)
{
Lock sync(*this);
_descriptors.insert(make_pair(application, descriptor));
}
void
NodeEntry::removeDescriptor(const string& application)
{
Lock sync(*this);
_descriptors.erase(application);
}
void
NodeEntry::addServer(const ServerEntryPtr& entry)
{
Lock sync(*this);
_servers.insert(make_pair(entry->getId(), entry));
}
void
NodeEntry::removeServer(const ServerEntryPtr& entry)
{
Lock sync(*this);
_servers.erase(entry->getId());
}
void
NodeEntry::setSession(const NodeSessionIPtr& session)
{
Lock sync(*this);
if(session)
{
while(_session)
{
if(_session->isDestroyed())
{
// If the current session has just been destroyed, wait for the setSession(0) call.
assert(session != _session);
wait();
}
else
{
NodeSessionIPtr session = _session;
sync.release();
try
{
session->getNode()->ice_ping();
throw NodeActiveException();
}
catch(const Ice::LocalException&)
{
try
{
session->destroy();
}
catch(const Ice::ObjectNotExistException&)
{
}
}
sync.acquire();
}
}
//
// Clear the saved proxy, the node has established a session
// so we won't need anymore to try to register it with this
// registry.
//
_proxy = 0;
}
else
{
if(!_session)
{
return;
}
}
_session = session;
notifyAll();
if(_registering)
{
_registering = false;
notifyAll();
}
if(session)
{
if(_cache.getTraceLevels() && _cache.getTraceLevels()->node > 0)
{
Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->nodeCat);
out << "node `" << _name << "' up";
}
}
else
{
if(_cache.getTraceLevels() && _cache.getTraceLevels()->node > 0)
{
Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->nodeCat);
out << "node `" << _name << "' down";
}
}
}
NodePrx
NodeEntry::getProxy() const
{
Lock sync(*this);
checkSession();
return _session->getNode();
}
InternalNodeInfoPtr
NodeEntry::getInfo() const
{
Lock sync(*this);
checkSession();
return _session->getInfo();
}
ServerEntrySeq
NodeEntry::getServers() const
{
Lock sync(*this);
ServerEntrySeq entries;
for(map<string, ServerEntryPtr>::const_iterator p = _servers.begin(); p != _servers.end(); ++p)
{
entries.push_back(p->second);
}
return entries;
}
LoadInfo
NodeEntry::getLoadInfoAndLoadFactor(const string& application, float& loadFactor) const
{
Lock sync(*this);
checkSession();
map<string, NodeDescriptor>::const_iterator p = _descriptors.find(application);
if(p == _descriptors.end())
{
throw NodeNotExistException(); // The node doesn't exist in the given application.
}
//
// TODO: Cache the load factors? Parsing the load factor for each
// call could be costly.
//
loadFactor = -1.0f;
if(!p->second.loadFactor.empty())
{
istringstream is(p->second.loadFactor);
is >> loadFactor;
}
if(loadFactor < 0.0f)
{
if(_session->getInfo()->os != "Windows")
{
//
// On Unix platforms, we divide the load averages by the
// number of processors. A load of 2 on a dual processor
// machine is the same as a load of 1 on a single process
// machine.
//
loadFactor = 1.0f / _session->getInfo()->nProcessors;
}
else
{
//
// On Windows, load1, load5 and load15 are the average of
// the CPU utilization (all CPUs). We don't need to divide
// by the number of CPU.
//
loadFactor = 1.0f;
}
}
return _session->getLoadInfo();
}
NodeSessionIPtr
NodeEntry::getSession() const
{
Lock sync(*this);
checkSession();
return _session;
}
bool
NodeEntry::canRemove()
{
Lock sync(*this);
return _servers.empty() && !_session && _descriptors.empty();
}
void
NodeEntry::loadServer(const ServerEntryPtr& entry, const ServerInfo& server, const SessionIPtr& session, int timeout)
{
try
{
NodePrx node;
int sessionTimeout;
InternalServerDescriptorPtr desc;
{
Lock sync(*this);
checkSession();
node = _session->getNode();
sessionTimeout = _session->getTimeout();
//
// Check if we should use a specific timeout (the load
// call can deactivate the server and it can take some
// time to deactivate, up to "deactivation-timeout"
// seconds).
//
if(timeout > 0)
{
node = NodePrx::uncheckedCast(node->ice_timeout(timeout * 1000));
}
ServerInfo info = server;
try
{
info.descriptor = getServerDescriptor(server, session);
}
catch(const DeploymentException&)
{
//
// We ignore the deployment error for now (which can
// only be caused in theory by session variables not
// being defined because the server isn't
// allocated...)
//
}
desc = getInternalServerDescriptor(info);
}
assert(desc);
if(_cache.getTraceLevels() && _cache.getTraceLevels()->server > 2)
{
Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->serverCat);
out << "loading `" << desc->id << "' on node `" << _name << "'";
if(session)
{
out << " for session `" << session->getId() << "'";
}
}
AMI_Node_loadServerPtr amiCB = new LoadCB(_cache.getTraceLevels(), entry, _name, sessionTimeout);
node->loadServer_async(amiCB, desc, _cache.getReplicaName());
}
catch(const NodeUnreachableException& ex)
{
entry->exception(ex);
}
}
void
NodeEntry::destroyServer(const ServerEntryPtr& entry, const ServerInfo& info, int timeout)
{
try
{
NodePrx node;
{
Lock sync(*this);
checkSession();
node = _session->getNode();
//
// Check if we should use a specific timeout (the load
// call can deactivate the server and it can take some
// time to deactivate, up to "deactivation-timeout"
// seconds).
//
if(timeout > 0)
{
node = NodePrx::uncheckedCast(node->ice_timeout(timeout * 1000));
}
}
if(_cache.getTraceLevels() && _cache.getTraceLevels()->server > 2)
{
Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->serverCat);
out << "unloading `" << info.descriptor->id << "' on node `" << _name << "'";
}
AMI_Node_destroyServerPtr amiCB = new DestroyCB(_cache.getTraceLevels(), entry, _name);
node->destroyServer_async(amiCB, info.descriptor->id, info.uuid, info.revision, _cache.getReplicaName());
}
catch(const NodeUnreachableException& ex)
{
entry->exception(ex);
}
}
ServerInfo
NodeEntry::getServerInfo(const ServerInfo& server, const SessionIPtr& session)
{
Lock sync(*this);
checkSession();
ServerInfo info = server;
info.descriptor = getServerDescriptor(server, session);
assert(info.descriptor);
return info;
}
ServerDescriptorPtr
NodeEntry::getServerDescriptor(const ServerInfo& server, const SessionIPtr& session)
{
assert(_session);
Resolver resolve(_session->getInfo(), _cache.getCommunicator());
resolve.setReserved("application", server.application);
resolve.setReserved("server", server.descriptor->id);
resolve.setContext("server `${server}'");
if(session)
{
resolve.setReserved("session.id", session->getId());
}
IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(server.descriptor);
if(iceBox)
{
return IceBoxHelper(iceBox).instantiate(resolve, PropertyDescriptorSeq(), PropertySetDescriptorDict());
}
else
{
return ServerHelper(server.descriptor).instantiate(resolve, PropertyDescriptorSeq(),
PropertySetDescriptorDict());
}
}
void
NodeEntry::__incRef()
{
Lock sync(*this);
assert(_ref >= 0);
++_ref;
}
void
NodeEntry::__decRef()
{
//
// The node entry implements its own reference counting. If the
// reference count drops to 1, this means that only the cache
// holds a reference on the node entry. If that's the case, we
// check if the node entry can be removed or not and if it can be
// removed we remove it from the cache map.
//
bool doRemove = false;
bool doDelete = false;
{
Lock sync(*this); // We use a recursive mutex so it's fine to
// create Ptr with the mutex locked.
assert(_ref > 0);
--_ref;
if(_ref == 1)
{
doRemove = canRemove();
}
else if(_ref == 0)
{
doDelete = true;
}
}
if(doRemove)
{
_cache.remove(_name);
}
else if(doDelete)
{
delete this;
}
}
void
NodeEntry::checkSession() const
{
if(_session)
{
if(_session->isDestroyed())
{
throw NodeUnreachableException(_name, "the node is not active");
}
return;
}
else if(!_proxy && !_registering)
{
throw NodeUnreachableException(_name, "the node is not active");
}
else if(_proxy)
{
//
// If the node proxy is set, we attempt to get the node to
// register with this registry.
//
assert(!_registering);
if(_cache.getTraceLevels() && _cache.getTraceLevels()->node > 0)
{
Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->nodeCat);
out << "creating node `" << _name << "' session";
}
//
// NOTE: setting _registering to true must be done before the
// call otherwise if the callback is call immediately we'll
// hang in the while loop.
//
_registering = true;
NodeEntry* self = const_cast<NodeEntry*>(this);
_proxy->registerWithReplica_async(new RegisterCB(self), _cache.getReplicaCache().getInternalRegistry());
_proxy = 0; // Registration with the proxy is only attempted once.
}
while(_registering)
{
if(!timedWait(IceUtil::Time::seconds(5)))
{
break; // Consider the node down if it doesn't respond promptly.
}
}
if(!_session || _session->isDestroyed())
{
throw NodeUnreachableException(_name, "the node is not active");
}
}
void
NodeEntry::setProxy(const NodePrx& node)
{
Lock sync(*this);
//
// If the node has already established a session with the
// registry, no need to remember its proxy, we don't need to get
// it to register with this registry since it's already
// registered.
//
if(!_session)
{
_proxy = node;
}
}
void
NodeEntry::finishedRegistration()
{
Lock sync(*this);
if(_cache.getTraceLevels() && _cache.getTraceLevels()->node > 0)
{
Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->nodeCat);
if(_session)
{
out << "node `" << _name << "' session created";
}
else
{
out << "node `" << _name << "' session creation failed";
}
}
if(_registering)
{
_registering = false;
notifyAll();
}
}
void
NodeEntry::finishedRegistration(const Ice::Exception& ex)
{
Lock sync(*this);
if(_cache.getTraceLevels() && _cache.getTraceLevels()->node > 0)
{
Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->nodeCat);
out << "node `" << _name << "' session creation failed:\n" << ex;
}
if(_registering)
{
_registering = false;
notifyAll();
}
}
InternalServerDescriptorPtr
NodeEntry::getInternalServerDescriptor(const ServerInfo& info) const
{
//
// Note that at this point all variables in info have been resolved
//
assert(_session);
InternalServerDescriptorPtr server = new InternalServerDescriptor();
server->id = info.descriptor->id;
server->application = info.application;
server->uuid = info.uuid;
server->revision = info.revision;
server->sessionId = info.sessionId;
server->exe = info.descriptor->exe;
server->pwd = info.descriptor->pwd;
server->user = info.descriptor->user;
server->activation = info.descriptor->activation;
server->activationTimeout = info.descriptor->activationTimeout;
server->deactivationTimeout = info.descriptor->deactivationTimeout;
server->applicationDistrib = info.descriptor->applicationDistrib;
if(!info.descriptor->distrib.icepatch.empty())
{
server->distrib = new InternalDistributionDescriptor(info.descriptor->distrib.icepatch,
info.descriptor->distrib.directories);
}
server->options = info.descriptor->options;
server->envs = info.descriptor->envs;
// server->logs: assigned for each communicator (see below)
// server->adapters: assigned for each communicator (see below)
// server->dbEnvs: assigned for each communicator (see below)
// server->properties: assigned for each communicator (see below)
//
// Add server properties.
//
PropertyDescriptorSeq& props = server->properties["config"];
props.push_back(createProperty("# Server configuration"));
//
// For newer versions of Ice, we generate Ice.Admin properties:
//
int iceVersion = 0;
if(info.descriptor->iceVersion != "")
{
iceVersion = getMMVersion(info.descriptor->iceVersion);
}
server->processRegistered = false;
if(iceVersion == 0 || iceVersion >= 30300)
{
props.push_back(createProperty("Ice.Admin.ServerId", info.descriptor->id));
if(hasProperty(info.descriptor->propertySet.properties, "Ice.Admin.Endpoints"))
{
if(getProperty(info.descriptor->propertySet.properties, "Ice.Admin.Endpoints") != "")
{
server->processRegistered = true;
}
}
else
{
props.push_back(createProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"));
server->processRegistered = true;
}
}
else
{
props.push_back(createProperty("Ice.ServerId", info.descriptor->id));
}
props.push_back(createProperty("Ice.ProgramName", info.descriptor->id));
//
// Add IceBox properties.
//
string servicesStr;
IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(info.descriptor);
if(iceBox)
{
for(ServiceInstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end();++p)
{
ServiceDescriptorPtr s = p->descriptor;
const string path = _session->getInfo()->dataDir + "/servers/" + server->id + "/config/config_" + s->name;
props.push_back(createProperty("IceBox.Service." + s->name, s->entry + " --Ice.Config='" +
escapeProperty(path) + "'"));
servicesStr += s->name + " ";
}
if(!hasProperty(info.descriptor->propertySet.properties, "IceBox.InstanceName"))
{
props.push_back(createProperty("IceBox.InstanceName", server->id));
}
props.push_back(createProperty("IceBox.LoadOrder", servicesStr));
if(iceVersion != 0 && iceVersion < 30300)
{
if(hasProperty(iceBox->propertySet.properties, "IceBox.ServiceManager.RegisterProcess"))
{
if(getProperty(iceBox->propertySet.properties, "IceBox.ServiceManager.RegisterProcess") != "0")
{
server->processRegistered = true;
}
}
else
{
props.push_back(createProperty("IceBox.ServiceManager.RegisterProcess", "1"));
server->processRegistered = true;
}
if(!hasProperty(iceBox->propertySet.properties, "IceBox.ServiceManager.Endpoints"))
{
props.push_back(createProperty("IceBox.ServiceManager.Endpoints", "tcp -h 127.0.0.1"));
}
}
}
//
// Now, for each communicator of the descriptor, add the necessary
// logs, adapters, db envs and properties to the internal server
// descriptor.
//
forEachCommunicator(ToInternalServerDescriptor(server, _session->getInfo(), iceVersion))(info.descriptor);
return server;
}
|