1
// **********************************************************************
3
// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5
// This copy of Ice is licensed to you under the terms described in the
6
// ICE_LICENSE file included in this distribution.
8
// **********************************************************************
11
#include <IceGrid/DescriptorHelper.h>
12
#include <IceGrid/Util.h>
17
using namespace IceUtil;
18
using namespace IceUtilInternal;
19
using namespace IceGrid;
24
struct GetReplicaGroupId : unary_function<ReplicaGroupDescriptor&, const string&>
27
operator()(const ReplicaGroupDescriptor& desc)
33
struct TemplateDescriptorEqual : std::binary_function<TemplateDescriptor&, TemplateDescriptor&, bool>
36
operator()(const TemplateDescriptor& lhs, const TemplateDescriptor& rhs)
38
if(lhs.parameters != rhs.parameters)
43
if(lhs.parameterDefaults != rhs.parameterDefaults)
49
IceBoxDescriptorPtr slhs = IceBoxDescriptorPtr::dynamicCast(lhs.descriptor);
50
IceBoxDescriptorPtr srhs = IceBoxDescriptorPtr::dynamicCast(rhs.descriptor);
53
return IceBoxHelper(slhs) == IceBoxHelper(srhs);
57
ServerDescriptorPtr slhs = ServerDescriptorPtr::dynamicCast(lhs.descriptor);
58
ServerDescriptorPtr srhs = ServerDescriptorPtr::dynamicCast(rhs.descriptor);
61
return ServerHelper(slhs) == ServerHelper(srhs);
65
ServiceDescriptorPtr slhs = ServiceDescriptorPtr::dynamicCast(lhs.descriptor);
66
ServiceDescriptorPtr srhs = ServiceDescriptorPtr::dynamicCast(rhs.descriptor);
69
return ServiceHelper(slhs) == ServiceHelper(srhs);
77
struct ReplicaGroupEq : std::binary_function<ReplicaGroupDescriptor&, ReplicaGroupDescriptor&, bool>
80
operator()(const ReplicaGroupDescriptor& lhs, const ReplicaGroupDescriptor& rhs)
86
if(set<ObjectDescriptor>(lhs.objects.begin(), lhs.objects.end()) !=
87
set<ObjectDescriptor>(rhs.objects.begin(), rhs.objects.end()))
91
if(lhs.loadBalancing && rhs.loadBalancing)
93
if(lhs.loadBalancing->ice_id() != rhs.loadBalancing->ice_id())
97
if(lhs.loadBalancing->nReplicas != rhs.loadBalancing->nReplicas)
101
AdaptiveLoadBalancingPolicyPtr alhs = AdaptiveLoadBalancingPolicyPtr::dynamicCast(lhs.loadBalancing);
102
AdaptiveLoadBalancingPolicyPtr arhs = AdaptiveLoadBalancingPolicyPtr::dynamicCast(rhs.loadBalancing);
103
if(alhs && arhs && alhs->loadSample != arhs->loadSample)
108
else if(lhs.loadBalancing || rhs.loadBalancing)
117
template <typename GetKeyFunc, typename Seq> Seq
118
getSeqUpdatedElts(const Seq& lseq, const Seq& rseq, GetKeyFunc func)
120
#if defined(_MSC_VER) && (_MSC_VER < 1300)
121
return getSeqUpdatedEltsWithEq(lseq, rseq, func, equal_to<Seq::value_type>());
123
return getSeqUpdatedEltsWithEq(lseq, rseq, func, equal_to<typename Seq::value_type>());
127
template <typename GetKeyFunc, typename EqFunc, typename Seq> Seq
128
#if defined(_MSC_VER) && (_MSC_VER < 1300)
129
getSeqUpdatedEltsWithEq(const Seq& lseq, const Seq& rseq, GetKeyFunc func, EqFunc eq)
131
getSeqUpdatedEltsWithEq(const Seq& lseq, const Seq& rseq, GetKeyFunc func, EqFunc eq)
135
for(typename Seq::const_iterator p = rseq.begin(); p != rseq.end(); ++p)
137
typename Seq::const_iterator q = lseq.begin();
138
for(; q != lseq.end(); ++q)
140
if(func(*p) == func(*q))
145
if(q == lseq.end() || !eq(*p, *q))
147
result.push_back(*p);
153
template <typename GetKeyFunc, typename Seq> Ice::StringSeq
154
getSeqRemovedElts(const Seq& lseq, const Seq& rseq, GetKeyFunc func)
156
Ice::StringSeq removed;
157
for(typename Seq::const_iterator p = lseq.begin(); p != lseq.end(); ++p)
159
typename Seq::const_iterator q;
160
for(q = rseq.begin(); q != rseq.end(); ++q)
162
if(func(*p) == func(*q))
169
removed.push_back(func(*p));
175
template <typename GetKeyFunc, typename Seq> Seq
176
updateSeqElts(const Seq& seq, const Seq& update, const Ice::StringSeq& remove, GetKeyFunc func)
179
set<string> removed(remove.begin(), remove.end());
180
for(typename Seq::const_iterator p = seq.begin(); p != seq.end(); ++p)
182
if(removed.find(func(*p)) == removed.end())
184
typename Seq::const_iterator q = update.begin();
185
for(; q != update.end(); ++q)
187
if(func(*p) == func(*q))
192
if(q == update.end())
194
result.push_back(*p);
201
template<typename Dict> Dict
202
getDictUpdatedElts(const Dict& ldict, const Dict& rdict)
204
#if defined(_MSC_VER) && (_MSC_VER < 1300)
205
return getDictUpdatedEltsWithEq(ldict, rdict, equal_to<Dict::mapped_type>());
207
return getDictUpdatedEltsWithEq(ldict, rdict, equal_to<typename Dict::mapped_type>());
211
template<typename EqFunc, typename Dict> Dict
212
getDictUpdatedEltsWithEq(const Dict& ldict, const Dict& rdict, EqFunc eq)
215
for(typename Dict::const_iterator p = rdict.begin(); p != rdict.end(); ++p)
217
typename Dict::const_iterator q = ldict.find(p->first);
218
if(q == ldict.end() || !eq(p->second, q->second))
226
template <typename Dict> Ice::StringSeq
227
getDictRemovedElts(const Dict& ldict, const Dict& rdict)
229
Ice::StringSeq removed;
230
for(typename Dict::const_iterator p = ldict.begin(); p != ldict.end(); ++p)
232
if(rdict.find(p->first) == rdict.end())
234
removed.push_back(p->first);
240
template <typename Dict> Dict
241
updateDictElts(const Dict& dict, const Dict& update, const Ice::StringSeq& remove)
244
for(Ice::StringSeq::const_iterator p = remove.begin(); p != remove.end(); ++p)
248
for(typename Dict::const_iterator q = update.begin(); q != update.end(); ++q)
250
result[q->first] = q->second;
257
Resolver::Resolver(const ApplicationDescriptor& app, const Ice::CommunicatorPtr& communicator, bool enableWarning) :
259
_communicator(communicator),
261
_enableWarning(enableWarning),
262
_context("application `" + app.name + "'"),
263
_variables(app.variables),
264
_reserved(getReserved()),
268
// Make sure the variables don't override reserved variables.
270
checkReserved("variable", _variables);
271
setReserved("application", app.name);
274
// Some reserved variables which are ignored for now and will be
275
// substituted later.
277
_ignore.insert("node.os");
278
_ignore.insert("node.hostname");
279
_ignore.insert("node.release");
280
_ignore.insert("node.version");
281
_ignore.insert("node.machine");
282
_ignore.insert("node.datadir");
284
for(StringStringDict::const_iterator v = _variables.begin(); v != _variables.end(); ++v)
288
exception("empty variable name");
292
TemplateDescriptorDict::const_iterator t;
293
for(t = _application->serverTemplates.begin(); t != _application->serverTemplates.end(); ++t)
297
exception("empty server template id");
299
if(!t->second.descriptor)
301
exception("invalid server template `" + t->first + "': server definition is empty");
304
Ice::StringSeq params = t->second.parameters;
305
sort(params.begin(), params.end());
306
Ice::StringSeq wdups = params;
308
set_difference(wdups.begin(), wdups.end(), params.begin(), unique(params.begin(), params.end()),
309
back_inserter(dups));
312
dups.erase(unique(dups.begin(), dups.end()), dups.end());
313
exception("invalid server template `" + t->first + "': duplicate parameters " + toString(dups));
316
for(t = _application->serviceTemplates.begin(); t != _application->serviceTemplates.end(); ++t)
320
exception("empty service template id");
322
if(!t->second.descriptor)
324
exception("invalid service template `" + t->first + "': service definition is empty");
326
Ice::StringSeq params = t->second.parameters;
327
sort(params.begin(), params.end());
328
Ice::StringSeq wdups = params;
330
set_difference(wdups.begin(), wdups.end(), params.begin(), unique(params.begin(), params.end()),
331
back_inserter(dups));
334
dups.erase(unique(dups.begin(), dups.end()), dups.end());
335
exception("invalid server template `" + t->first + "': duplicate parameters " + toString(dups));
340
Resolver::Resolver(const Resolver& resolve,
341
const map<string, string>& values,
343
_application(resolve._application),
344
_communicator(resolve._communicator),
345
_escape(resolve._escape),
346
_enableWarning(resolve._enableWarning),
347
_context(resolve._context),
348
_variables(params ? resolve._variables : values),
349
_parameters(!params ? resolve._parameters : values),
350
_propertySets(resolve._propertySets),
351
_reserved(resolve._reserved),
352
_ignore(resolve._ignore),
353
_version(resolve._version)
357
checkReserved("parameter", values);
361
_variables.insert(resolve._variables.begin(), resolve._variables.end());
362
checkReserved("variable", values);
365
for(StringStringDict::const_iterator v = _variables.begin(); v != _variables.end(); ++v)
369
exception("empty variable name");
374
Resolver::Resolver(const InternalNodeInfoPtr& info, const Ice::CommunicatorPtr& com) :
378
_enableWarning(false),
379
_context("node `" + info->name + "'"),
380
_reserved(getReserved()),
383
setReserved("node", info->name);
384
setReserved("node.os", info->os);
385
setReserved("node.hostname", info->hostname);
386
setReserved("node.release", info->release);
387
setReserved("node.version", info->version);
388
setReserved("node.machine", info->machine);
389
setReserved("node.datadir", info->dataDir);
393
Resolver::operator()(const string& value, const string& name, bool allowEmpty) const
400
val = substitute(value, true, true);
402
catch(const string& reason)
404
throw "invalid variable `" + value + "':\n " + reason;
406
catch(const char* reason)
408
throw "invalid variable `" + value + "':\n " + reason;
415
throw "empty string";
419
throw "the value of `" + value + "' is an empty string";
424
catch(const string& reason)
426
exception("invalid value for attribute `" + name + "':\n" + reason);
428
catch(const char* reason)
430
exception("invalid value for attribute `" + name + "':\n" + reason);
432
return ""; // To prevent compiler warning.
436
Resolver::operator()(const Ice::StringSeq& values, const string& name) const
438
Ice::StringSeq result;
439
for(Ice::StringSeq::const_iterator p = values.begin(); p != values.end(); ++p)
441
result.push_back(operator()(*p, name));
446
DistributionDescriptor
447
Resolver::operator()(const DistributionDescriptor& desc) const
449
DistributionDescriptor result;
450
result.icepatch = operator()(desc.icepatch, "IcePatch2 server proxy");
451
result.directories = operator()(desc.directories, "distribution source directory");
455
PropertyDescriptorSeq
456
Resolver::operator()(const PropertyDescriptorSeq& properties, const string& name) const
458
PropertyDescriptorSeq result;
459
for(PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q)
461
PropertyDescriptor prop;
462
prop.name = operator()(q->name, name + " name");
463
prop.value = operator()(q->value, name + " value");
464
result.push_back(prop);
469
PropertySetDescriptorDict
470
Resolver::operator()(const PropertySetDescriptorDict& propertySets) const
472
PropertySetDescriptorDict result;
473
PropertySetDescriptorDict::const_iterator ps;
474
for(ps = propertySets.begin(); ps != propertySets.end(); ++ps)
476
PropertySetDescriptor desc;
477
desc.references = operator()(ps->second.references, "property set `" + ps->first + "' reference");
478
desc.properties = operator()(ps->second.properties, "property set `" + ps->first + "' property");
479
result.insert(make_pair(ps->first, desc));
485
Resolver::operator()(const ObjectDescriptorSeq& objects, const string& type) const
487
ObjectDescriptorSeq result;
488
for(ObjectDescriptorSeq::const_iterator q = objects.begin(); q != objects.end(); ++q)
490
ObjectDescriptor obj;
491
obj.type = operator()(q->type, type + " object type");
492
obj.id = operator()(q->id, type + " object identity");
493
result.push_back(obj);
499
Resolver::operator()(const Ice::Identity& value, const string& name) const
501
assert(_communicator);
502
string str = asId(_communicator->identityToString(value), name, false);
503
Ice::Identity id = _communicator->stringToIdentity(str);
506
exception("invalid object identity `" + _communicator->identityToString(value) + "': name empty");
511
PropertySetDescriptor
512
Resolver::operator()(const PropertySetDescriptor& desc) const
514
PropertySetDescriptor result;
515
result.properties = getProperties(desc.references);
516
PropertyDescriptorSeq props = operator()(desc.properties);
517
result.properties.insert(result.properties.end(), props.begin(), props.end());
522
Resolver::asInt(const string& value, const string& name) const
524
string v = operator()(value, name);
527
string::size_type beg = v.find_first_not_of(' ');
528
string::size_type end = v.find_last_not_of(' ');
529
v = v.substr(beg == string::npos ? 0 : beg, end == string::npos ? v.length() - 1 : end - beg + 1);
533
if(!(is >> val) || !is.eof())
535
exception("invalid value `" + value + "' for `" + name + "':\nnot an integer");
546
Resolver::asFloat(const string& value, const string& name) const
548
string v = operator()(value, name);
551
string::size_type beg = v.find_first_not_of(' ');
552
string::size_type end = v.find_last_not_of(' ');
553
v = v.substr(beg == string::npos ? 0 : beg, end == string::npos ? v.length() - 1 : end - beg + 1);
557
if(!(is >> val) || !is.eof())
559
exception("invalid value `" + value + "' for `" + name + "':\nnot a float");
566
Resolver::asId(const string& value, const string& name, bool allowEmpty) const
570
if(!allowEmpty && value.empty())
572
throw "empty string";
578
val = substitute(value, true, false);
580
catch(const string& reason)
582
throw "invalid variable `" + value + "':\n" + reason;
584
catch(const char* reason)
586
throw "invalid variable `" + value + "':\n" + reason;
589
if(!allowEmpty && val.empty())
591
throw "the value of `" + value + "' is an empty string";
595
catch(const string& reason)
597
exception("invalid value for attribute `" + name + "':\n" + reason);
599
catch(const char* reason)
601
exception("invalid value for attribute `" + name + "':\n" + reason);
603
return ""; // To prevent compiler warning.
607
Resolver::setReserved(const string& name, const string& value)
609
assert(_reserved.find(name) != _reserved.end());
610
_reserved[name] = value;
614
Resolver::setContext(const string& context)
618
_context = substitute(context, true, true);
620
catch(const string& reason)
624
catch(const char* reason)
631
Resolver::addPropertySets(const PropertySetDescriptorDict& propertySets)
633
PropertySetDescriptorDict oldPropertySets;
634
oldPropertySets.swap(_propertySets);
635
PropertySetDescriptorDict::const_iterator p;
636
for(p = propertySets.begin(); p != propertySets.end(); ++p)
638
if(!_propertySets.insert(*p).second)
640
exception("property set with id `" + p->first + "' is already defined at this scope");
643
_propertySets.insert(oldPropertySets.begin(), oldPropertySets.end());
646
// Validate the new property set references.
648
for(p = propertySets.begin(); p != propertySets.end(); ++p)
650
getProperties(p->second.references);
654
const PropertySetDescriptor&
655
Resolver::getPropertySet(const string& id) const
657
PropertySetDescriptorDict::const_iterator p = _propertySets.find(id);
658
if(p == _propertySets.end())
660
exception("invalid reference to property set, property set `" + id + "' doesn't exist");
665
PropertyDescriptorSeq
666
Resolver::getProperties(const Ice::StringSeq& references) const
668
set<string> resolved;
669
return getProperties(references, resolved);
673
Resolver::addIgnored(const string& name)
675
_ignore.insert(name);
679
Resolver::setVersion(const string& version)
681
string v = operator()(version, "ice version");
684
_version = getMMVersion(v);
687
exception("invalid ice version: " + v);
689
else if(_version > ICE_INT_VERSION && warningEnabled())
691
Ice::Warning out(_communicator->getLogger());
692
out << "invalid ice version: " << _version << " is superior to the IceGrid ";
693
out << "registry version (" << ICE_STRING_VERSION << ")";
699
Resolver::getVersion() const
705
Resolver::exception(const string& reason) const
707
throw DeploymentException(_context + ":\n" + reason);
711
Resolver::getServerTemplate(const string& tmpl) const
713
assert(_application);
714
TemplateDescriptorDict::const_iterator p = _application->serverTemplates.find(tmpl);
715
if(p == _application->serverTemplates.end())
717
throw DeploymentException("unknown server template `" + tmpl + "'");
723
Resolver::getServiceTemplate(const string& tmpl) const
725
assert(_application);
726
TemplateDescriptorDict::const_iterator p = _application->serviceTemplates.find(tmpl);
727
if(p == _application->serviceTemplates.end())
729
throw DeploymentException("unknown service template `" + tmpl + "'");
735
Resolver::hasReplicaGroup(const string& id) const
740
// If we don't know the application descrpitor we assume that
741
// the replica group exists (this is possible if the resolver
742
// wasn't built from an application helper, that's the case if
743
// it's built from NodeCache just to resolve ${node.*} and
744
// ${session.*} variables.
748
ReplicaGroupDescriptorSeq::const_iterator p;
749
for(p = _application->replicaGroups.begin(); p != _application->replicaGroups.end(); ++p)
760
Resolver::substitute(const string& v, bool useParams, bool useIgnored) const
763
string::size_type beg = 0;
764
string::size_type end = 0;
766
while((beg = value.find("${", beg)) != string::npos)
768
if(beg > 0 && value[beg - 1] == '$')
770
string::size_type escape = beg - 1;
771
while(escape > 0 && value[escape - 1] == '$')
776
if((beg - escape) % 2)
780
value.replace(escape, beg - escape, (beg - escape) / 2, '$');
787
value.replace(escape, beg - escape, (beg - escape) / 2, '$');
788
beg -= (beg - escape) / 2;
792
end = value.find("}", beg);
793
if(end == string::npos)
795
throw "malformed variable name `" + value + "'";
799
// Get the name of the variable and get its value if the
800
// variable is not currently ignored (in which case we do
801
// nothing, the variable will be substituted later). If the
802
// name refered to a parameter we don't do any recursive
803
// substitution: the parameter value is computed at the point
806
string name = value.substr(beg + 2, end - beg - 2);
807
if(_ignore.find(name) != _ignore.end())
816
throw "use of the `" + name + "' variable is now allowed here";
821
string val = getVariable(name, useParams, param);
824
val = substitute(val, false, useIgnored); // Recursive resolution
826
value.replace(beg, end - beg + 1, val);
833
Resolver::getVariable(const string& name, bool checkParams, bool& param) const
836
// We first check the reserved variables, then the parameters if
837
// necessary and finally the variables.
840
map<string, string>::const_iterator p = _reserved.find(name);
841
if(p != _reserved.end())
843
if(p->second.empty())
845
throw "undefined variable `" + name + "'";
851
p = _parameters.find(name);
852
if(p != _parameters.end())
858
p = _variables.find(name);
859
if(p != _variables.end())
864
throw "undefined variable `" + name + "'";
865
return ""; // To keep the compiler happy.
868
PropertyDescriptorSeq
869
Resolver::getProperties(const Ice::StringSeq& references, set<string>& resolved) const
871
PropertyDescriptorSeq properties;
872
for(Ice::StringSeq::const_iterator p = references.begin(); p != references.end(); ++p)
874
if(resolved.find(*p) != resolved.end())
876
exception("detected circular dependency with property reference `" + *p + "'");
879
PropertySetDescriptor desc = getPropertySet(*p);
880
if(!desc.references.empty())
883
PropertyDescriptorSeq p = getProperties(desc.references, resolved);
884
properties.insert(properties.end(), p.begin(), p.end());
887
PropertyDescriptorSeq pds = operator()(desc.properties);
888
properties.insert(properties.end(), pds.begin(), pds.end());
894
Resolver::getReserved()
897
// Allowed reserved variables (reserved variables can't be
898
// overrided, in this implementation an empty reserved variable is
899
// considered to be undefined (see getVariable))
901
map<string, string> reserved;
902
reserved["application"] = "";
903
reserved["node"] = "";
904
reserved["node.os"] = "";
905
reserved["node.hostname"] = "";
906
reserved["node.release"] = "";
907
reserved["node.version"] = "";
908
reserved["node.machine"] = "";
909
reserved["node.datadir"] = "";
910
reserved["session.id"] = "";
911
reserved["application.distrib"] = "${node.datadir}/distrib/${application}";
912
reserved["server.distrib"] = "${node.datadir}/servers/${server}/distrib";
913
reserved["server"] = "";
914
reserved["service"] = "";
919
Resolver::checkReserved(const string& type, const map<string, string>& values) const
921
for(map<string, string>::const_iterator p = values.begin(); p != values.end(); ++p)
923
if(_reserved.find(p->first) != _reserved.end())
925
exception("invalid " + type + " `" + p->first + "': reserved variable name");
930
CommunicatorHelper::CommunicatorHelper(const CommunicatorDescriptorPtr& desc) :
936
CommunicatorHelper::operator==(const CommunicatorHelper& helper) const
938
if(_desc->ice_id() != helper._desc->ice_id())
943
if(_desc->description != helper._desc->description)
948
if(set<AdapterDescriptor>(_desc->adapters.begin(), _desc->adapters.end()) !=
949
set<AdapterDescriptor>(helper._desc->adapters.begin(), helper._desc->adapters.end()))
954
if(_desc->propertySet != helper._desc->propertySet)
959
if(set<DbEnvDescriptor>(_desc->dbEnvs.begin(), _desc->dbEnvs.end()) !=
960
set<DbEnvDescriptor>(helper._desc->dbEnvs.begin(), helper._desc->dbEnvs.end()))
965
if(_desc->logs != helper._desc->logs)
974
CommunicatorHelper::operator!=(const CommunicatorHelper& helper) const
976
return !operator==(helper);
980
CommunicatorHelper::getIds(multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
982
for(AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p)
986
adapterIds.insert(p->id);
989
set<Ice::Identity> ids;
990
ObjectDescriptorSeq::const_iterator q;
991
for(q = p->objects.begin(); q != p->objects.end(); ++q)
994
objectIds.insert(q->id);
996
for(q = p->allocatables.begin(); q != p->allocatables.end(); ++q)
998
if(ids.find(q->id) == ids.end())
1000
objectIds.insert(q->id);
1011
CommunicatorHelper::getReplicaGroups(set<string>& replicaGroups) const
1013
for(AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p)
1015
if(!p->replicaGroupId.empty())
1017
replicaGroups.insert(p->replicaGroupId);
1023
CommunicatorHelper::instantiateImpl(const CommunicatorDescriptorPtr& instance, const Resolver& resolve) const
1025
instance->description = resolve(_desc->description, "description");
1026
instance->propertySet = resolve(_desc->propertySet);
1028
for(AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p)
1030
AdapterDescriptor adapter;
1031
adapter.name = resolve(p->name, "object adapter name", false);
1032
adapter.description = resolve(p->description, "object adapter description");
1033
adapter.id = resolve.asId(p->id, "object adapter id");
1034
adapter.registerProcess = p->registerProcess;
1035
adapter.serverLifetime = p->serverLifetime;
1036
adapter.replicaGroupId = resolve.asId(p->replicaGroupId, "object adapter replica group id", true);
1039
// Don't check for unknown replica groups here. This check is
1040
// instead done by the database before the application is
1041
// added. It's legal for an OA to refer to a replica group
1042
// from another application.
1044
//if(!adapter.replicaGroupId.empty() && !resolve.hasReplicaGroup(adapter.replicaGroupId))
1046
//resolve.exception("unknown replica group `" + adapter.replicaGroupId + "'");
1049
adapter.priority = resolve.asInt(p->priority, "object adapter priority");
1050
adapter.objects = resolve(p->objects, "well-known");
1051
adapter.allocatables = resolve(p->allocatables, "allocatable");
1052
instance->adapters.push_back(adapter);
1055
// Make sure the endpoints are defined.
1057
if(IceGrid::getProperty(instance->propertySet.properties, adapter.name + ".Endpoints").empty())
1059
resolve.exception("invalid endpoints for adapter `" + adapter.name + "': empty string");
1063
for(DbEnvDescriptorSeq::const_iterator s = _desc->dbEnvs.begin(); s != _desc->dbEnvs.end(); ++s)
1065
DbEnvDescriptor dbEnv;
1066
dbEnv.name = resolve(s->name, "database environment name", false);
1067
dbEnv.description = resolve(s->description, "database environment description");
1068
dbEnv.dbHome = resolve(s->dbHome, "database environment home directory");
1069
dbEnv.properties = resolve(s->properties, "database environment property");
1070
instance->dbEnvs.push_back(dbEnv);
1073
for(Ice::StringSeq::const_iterator l = _desc->logs.begin(); l != _desc->logs.end(); ++l)
1075
instance->logs.push_back(resolve(*l, "log path", false));
1080
CommunicatorHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1082
if(!_desc->description.empty())
1084
out << nl << "description";
1086
out << nl << _desc->description;
1089
set<string> hiddenProperties;
1091
for(DbEnvDescriptorSeq::const_iterator p = _desc->dbEnvs.begin(); p != _desc->dbEnvs.end(); ++p)
1093
printDbEnv(out, *p);
1097
for(AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p)
1099
hiddenProperties.insert(p->name + ".Endpoints");
1100
printObjectAdapter(communicator, out, *p);
1104
for(Ice::StringSeq::const_iterator p = _desc->logs.begin(); p != _desc->logs.end(); ++p)
1106
out << nl << "log `" << *p << "'";
1109
if(!_desc->propertySet.properties.empty() || !_desc->propertySet.references.empty())
1111
out << nl << "properties";
1113
if(!_desc->propertySet.references.empty())
1115
out << nl << "references = " << toString(_desc->propertySet.references);
1117
PropertyDescriptorSeq::const_iterator q;
1118
for(q = _desc->propertySet.properties.begin(); q != _desc->propertySet.properties.end(); ++q)
1120
if(hiddenProperties.find(q->name) == hiddenProperties.end())
1122
out << nl << q->name << " = `" << q->value << "'";
1130
CommunicatorHelper::printDbEnv(Output& out, const DbEnvDescriptor& dbEnv) const
1132
out << nl << "database environment `" << dbEnv.name << "'";
1133
if(!dbEnv.dbHome.empty() || !dbEnv.properties.empty() || !dbEnv.description.empty())
1136
if(!dbEnv.dbHome.empty())
1138
out << nl << "home = `" << dbEnv.dbHome << "'";
1140
if(!dbEnv.description.empty())
1142
out << nl << "description = `" << dbEnv.description << "'";
1144
if(!dbEnv.properties.empty())
1146
out << nl << "properties";
1148
for(PropertyDescriptorSeq::const_iterator p = dbEnv.properties.begin(); p != dbEnv.properties.end(); ++p)
1150
out << nl << p->name << " = `" << p->value << "'";
1159
CommunicatorHelper::printObjectAdapter(const Ice::CommunicatorPtr& communicator,
1161
const AdapterDescriptor& adapter) const
1163
out << nl << "adapter `" << adapter.name << "'";
1165
if(!adapter.id.empty())
1167
out << nl << "id = `" << adapter.id << "'";
1169
if(!adapter.replicaGroupId.empty())
1171
out << nl << "replica group id = `" << adapter.replicaGroupId << "'";
1173
if(!adapter.priority.empty())
1175
out << nl << "priority = `" << adapter.priority << "'";
1178
string endpoints = getProperty(adapter.name + ".Endpoints");
1179
if(!endpoints.empty())
1181
out << nl << "endpoints = `" << endpoints << "'";
1183
out << nl << "register process = `" << (adapter.registerProcess ? "true" : "false") << "'";
1184
out << nl << "server lifetime = `" << (adapter.serverLifetime ? "true" : "false") << "'";
1185
ObjectDescriptorSeq::const_iterator p;
1186
for(p = adapter.objects.begin(); p != adapter.objects.end(); ++p)
1188
out << nl << "well-known object";
1190
out << nl << "identity = `" << communicator->identityToString(p->id) << "' ";
1191
if(!p->type.empty())
1193
out << nl << "type = `" << p->type << "'";
1197
for(p = adapter.allocatables.begin(); p != adapter.allocatables.end(); ++p)
1199
out << nl << "allocatable";
1201
out << nl << "identity = `" << communicator->identityToString(p->id) << "' ";
1202
if(!p->type.empty())
1204
out << nl << "type = `" << p->type << "'";
1208
if(!adapter.description.empty())
1210
out << nl << "description = `" << adapter.description << "'";
1216
CommunicatorHelper::getProperty(const string& name) const
1218
return IceGrid::getProperty(_desc->propertySet.properties, name);
1221
ServiceHelper::ServiceHelper(const ServiceDescriptorPtr& descriptor) :
1222
CommunicatorHelper(descriptor),
1228
ServiceHelper::operator==(const CommunicatorHelper& h) const
1230
const ServiceHelper* helper = dynamic_cast<const ServiceHelper*>(&h);
1231
if(!helper || !CommunicatorHelper::operator==(h))
1236
if(_desc->name != helper->_desc->name)
1241
if(_desc->entry != helper->_desc->entry)
1250
ServiceHelper::operator!=(const CommunicatorHelper& helper) const
1252
return !operator==(helper);
1255
ServiceDescriptorPtr
1256
ServiceHelper::getDescriptor() const
1261
ServiceDescriptorPtr
1262
ServiceHelper::instantiate(const Resolver& resolver, const PropertyDescriptorSeq& props,
1263
const PropertySetDescriptorDict& serviceProps) const
1265
ServiceDescriptorPtr service = new ServiceDescriptor();
1266
instantiateImpl(service, resolver, props, serviceProps);
1271
ServiceHelper::instantiateImpl(const ServiceDescriptorPtr& instance,
1272
const Resolver& resolve,
1273
const PropertyDescriptorSeq& props,
1274
const PropertySetDescriptorDict& serviceProps) const
1276
CommunicatorHelper::instantiateImpl(instance, resolve);
1277
instance->name = resolve(_desc->name, "name", false);
1278
instance->entry = resolve(_desc->entry, "entry", false);
1279
instance->propertySet.properties.insert(instance->propertySet.properties.end(), props.begin(), props.end());
1280
PropertySetDescriptorDict::const_iterator p = serviceProps.find(instance->name);
1281
if(p != serviceProps.end())
1283
instance->propertySet.properties.insert(instance->propertySet.properties.end(),
1284
p->second.properties.begin(),
1285
p->second.properties.end());
1290
ServiceHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1292
out << "service `" + _desc->name + "'";
1294
out << nl << "entry = `" << _desc->entry << "'";
1295
CommunicatorHelper::print(communicator, out);
1299
ServerHelper::ServerHelper(const ServerDescriptorPtr& descriptor) :
1300
CommunicatorHelper(descriptor),
1306
ServerHelper::operator==(const CommunicatorHelper& h) const
1308
const ServerHelper* helper = dynamic_cast<const ServerHelper*>(&h);
1309
if(!helper || !CommunicatorHelper::operator==(h))
1314
if(_desc->id != helper->_desc->id)
1319
if(_desc->exe != helper->_desc->exe)
1324
if(_desc->iceVersion != helper->_desc->iceVersion)
1329
if(_desc->pwd != helper->_desc->pwd)
1334
if(set<string>(_desc->options.begin(), _desc->options.end()) !=
1335
set<string>(helper->_desc->options.begin(), helper->_desc->options.end()))
1340
if(set<string>(_desc->envs.begin(), _desc->envs.end()) !=
1341
set<string>(helper->_desc->envs.begin(), helper->_desc->envs.end()))
1346
if(_desc->activation != helper->_desc->activation)
1351
if(_desc->activationTimeout != helper->_desc->activationTimeout)
1356
if(_desc->deactivationTimeout != helper->_desc->deactivationTimeout)
1361
if(_desc->distrib != helper->_desc->distrib)
1366
if(_desc->allocatable != helper->_desc->allocatable)
1371
if(_desc->user != helper->_desc->user)
1380
ServerHelper::operator!=(const CommunicatorHelper& helper) const
1382
return !operator==(helper);
1386
ServerHelper::getDescriptor() const
1392
ServerHelper::instantiate(const Resolver& resolver,
1393
const PropertyDescriptorSeq& props,
1394
const PropertySetDescriptorDict& serviceProps) const
1396
if(!serviceProps.empty())
1398
resolver.exception("service property sets are only allowed in IceBox server instances");
1401
ServerDescriptorPtr server = new ServerDescriptor();
1402
instantiateImpl(server, resolver, props);
1407
ServerHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1409
print(communicator, out, ServerInfo());
1413
ServerHelper::print(const Ice::CommunicatorPtr& communicator, Output& out, const ServerInfo& info) const
1415
out << "server `" + _desc->id + "'";
1417
printImpl(communicator, out, info);
1422
ServerHelper::printImpl(const Ice::CommunicatorPtr& communicator, Output& out, const ServerInfo& info) const
1424
if(!info.application.empty())
1426
out << nl << "application = `" << info.application << "'";
1427
out << nl << "application uuid = `" << info.uuid << "'";
1428
out << nl << "application revision = `" << info.revision << "'";
1430
if(!info.node.empty())
1432
out << nl << "node = `" << info.node << "'";
1434
if(!info.sessionId.empty())
1436
out << nl << "session id = `" << info.sessionId << "'";
1438
out << nl << "exe = `" << _desc->exe << "'";
1440
if(!_desc->iceVersion.empty())
1442
out << nl << "ice version = `" << _desc->iceVersion << "'";
1445
if(!_desc->pwd.empty())
1447
out << nl << "pwd = `" << _desc->pwd << "'";
1449
out << nl << "activation = `" << _desc->activation << "'";
1450
if(!_desc->activationTimeout.empty() && _desc->activationTimeout != "0")
1452
out << nl << "activationTimeout = `" << _desc->activationTimeout << "'";
1454
if(!_desc->deactivationTimeout.empty() && _desc->deactivationTimeout != "0")
1456
out << nl << "deactivationTimeout = `" << _desc->deactivationTimeout << "'";
1458
if(!_desc->user.empty())
1460
out << nl << "user = `" << _desc->user << "'";
1462
if(!_desc->applicationDistrib)
1464
out << nl << "application distribution = `false'";
1466
if(!_desc->options.empty())
1468
out << nl << "options = `" << toString(_desc->options) << "'";
1470
if(!_desc->envs.empty())
1472
out << nl << "envs = `" << toString(_desc->envs) << "'";
1474
if(!_desc->distrib.icepatch.empty())
1476
out << nl << "distribution";
1478
out << nl << "proxy = `" << _desc->distrib.icepatch << "'";
1479
if(!_desc->distrib.directories.empty())
1481
out << nl << "directories = `" << toString(_desc->distrib.directories) << "'";
1485
CommunicatorHelper::print(communicator, out);
1489
ServerHelper::instantiateImpl(const ServerDescriptorPtr& instance,
1490
const Resolver& resolve,
1491
const PropertyDescriptorSeq& props) const
1493
CommunicatorHelper::instantiateImpl(instance, resolve);
1495
instance->id = resolve.asId(_desc->id, "id", false);
1496
instance->exe = resolve(_desc->exe, "executable", false);
1497
instance->iceVersion = resolve(_desc->iceVersion, "ice version");
1498
instance->pwd = resolve(_desc->pwd, "working directory path");
1499
instance->activation = resolve(_desc->activation, "activation");
1500
instance->applicationDistrib = _desc->applicationDistrib;
1501
instance->allocatable = _desc->allocatable;
1502
instance->user = resolve(_desc->user, "user");
1503
if(!instance->activation.empty() &&
1504
instance->activation != "manual" &&
1505
instance->activation != "on-demand" &&
1506
instance->activation != "always" &&
1507
instance->activation != "session")
1509
resolve.exception("unknown activation `" + instance->activation + "'");
1511
instance->activationTimeout = resolve.asInt(_desc->activationTimeout, "activation timeout");
1512
instance->deactivationTimeout = resolve.asInt(_desc->deactivationTimeout, "deactivation timeout");
1513
instance->options = resolve(_desc->options, "option");
1514
instance->envs = resolve(_desc->envs, "environment variable");
1515
instance->distrib = resolve(_desc->distrib);
1516
instance->propertySet.properties.insert(instance->propertySet.properties.end(), props.begin(), props.end());
1519
IceBoxHelper::IceBoxHelper(const IceBoxDescriptorPtr& descriptor) :
1520
ServerHelper(descriptor),
1523
for(ServiceInstanceDescriptorSeq::const_iterator p = _desc->services.begin(); p != _desc->services.end(); ++p)
1525
_services.push_back(ServiceInstanceHelper(*p));
1530
IceBoxHelper::operator==(const CommunicatorHelper& h) const
1532
const IceBoxHelper* helper = dynamic_cast<const IceBoxHelper*>(&h);
1533
if(!helper || !ServerHelper::operator==(h))
1538
if(_services != helper->_services)
1547
IceBoxHelper::operator!=(const CommunicatorHelper& helper) const
1549
return !operator==(helper);
1553
IceBoxHelper::instantiate(const Resolver& resolver,
1554
const PropertyDescriptorSeq& props,
1555
const PropertySetDescriptorDict& serviceProps) const
1557
IceBoxDescriptorPtr iceBox = new IceBoxDescriptor();
1558
instantiateImpl(iceBox, resolver, props, serviceProps);
1563
IceBoxHelper::getIds(multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
1565
CommunicatorHelper::getIds(adapterIds, objectIds);
1566
for(vector<ServiceInstanceHelper>::const_iterator p = _services.begin(); p != _services.end(); ++p)
1568
p->getIds(adapterIds, objectIds);
1573
IceBoxHelper::getReplicaGroups(set<string>& replicaGroups) const
1575
CommunicatorHelper::getReplicaGroups(replicaGroups);
1576
for(vector<ServiceInstanceHelper>::const_iterator p = _services.begin(); p != _services.end(); ++p)
1578
p->getReplicaGroups(replicaGroups);
1583
IceBoxHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1585
print(communicator, out, ServerInfo());
1589
IceBoxHelper::print(const Ice::CommunicatorPtr& communicator, Output& out, const ServerInfo& info) const
1591
out << "icebox `" + _desc->id + "'";
1594
string endpoints = getProperty("IceBox.ServiceManager.Endpoints");
1595
out << nl << "service manager endpoints = `" << endpoints << "'";
1596
printImpl(communicator, out, info);
1597
out << nl << "services";
1599
for(ServiceInstanceDescriptorSeq::const_iterator p = _desc->services.begin(); p != _desc->services.end(); ++p)
1601
assert(p->descriptor);
1602
out << nl << p->descriptor->name;
1609
IceBoxHelper::instantiateImpl(const IceBoxDescriptorPtr& instance,
1610
const Resolver& resolver,
1611
const PropertyDescriptorSeq& props,
1612
const PropertySetDescriptorDict& serviceProps) const
1614
ServerHelper::instantiateImpl(instance, resolver, props);
1615
set<string> serviceNames;
1616
for(vector<ServiceInstanceHelper>::const_iterator p = _services.begin(); p != _services.end(); ++p)
1618
ServiceInstanceDescriptor desc = p->instantiate(resolver, serviceProps);
1619
assert(desc.descriptor);
1620
serviceNames.insert(desc.descriptor->name);
1621
instance->services.push_back(desc);
1623
for(PropertySetDescriptorDict::const_iterator q = serviceProps.begin(); q != serviceProps.end(); ++q)
1625
if(serviceNames.find(q->first) == serviceNames.end())
1627
resolver.exception("invalid service property set: service `" + q->first + "' doesn't exist");
1633
InstanceHelper::instantiateParams(const Resolver& resolve,
1635
const map<string, string>& parameters,
1636
const vector<string>& requiredParameters,
1637
const map<string, string>& defaults) const
1639
map<string, string> params;
1641
set<string> required(requiredParameters.begin(), requiredParameters.end());
1642
set<string> unknown;
1643
for(map<string, string>::const_iterator p = parameters.begin(); p != parameters.end(); ++p)
1645
if(required.find(p->first) == required.end())
1647
unknown.insert(p->first);
1649
params.insert(make_pair(p->first, resolve(p->second, "parameter `" + p->first + "'")));
1651
if(!unknown.empty())
1654
os << "unknown parameters when instantiating `" + tmpl + "' template: ";
1655
copy(unknown.begin(), unknown.end(), ostream_iterator<string>(os, " "));
1656
resolve.exception(os.str());
1659
set<string> missingParams;
1660
for(set<string>::const_iterator q = required.begin(); q != required.end(); ++q)
1662
if(params.find(*q) == params.end())
1664
map<string, string>::const_iterator r = defaults.find(*q);
1665
if(r == defaults.end())
1667
missingParams.insert(*q);
1671
params.insert(make_pair(r->first, resolve(r->second, "default parameter `" + r->first + "'")));
1675
if(!missingParams.empty())
1678
os << "undefined parameters when instantiating `" + tmpl + "' template: ";
1679
copy(missingParams.begin(), missingParams.end(), ostream_iterator<string>(os, " "));
1680
resolve.exception(os.str());
1686
ServiceInstanceHelper::ServiceInstanceHelper(const ServiceInstanceDescriptor& desc) :
1690
// If the service instance is not a template instance, its
1691
// descriptor must be set and contain the definition of the
1694
if(_def._cpp_template.empty() && !_def.descriptor)
1696
throw DeploymentException("invalid service instance: no template defined");
1701
_service = ServiceHelper(_def.descriptor);
1706
ServiceInstanceHelper::operator==(const ServiceInstanceHelper& helper) const
1708
if(_def._cpp_template.empty())
1710
return _service == helper._service;
1714
return _def._cpp_template == helper._def._cpp_template &&
1715
_def.parameterValues == helper._def.parameterValues &&
1716
_def.propertySet == helper._def.propertySet;
1721
ServiceInstanceHelper::operator!=(const ServiceInstanceHelper& helper) const
1723
return !operator==(helper);
1726
ServiceInstanceDescriptor
1727
ServiceInstanceHelper::instantiate(const Resolver& resolve, const PropertySetDescriptorDict& serviceProps) const
1729
ServiceHelper def = _service;
1730
std::map<std::string, std::string> parameterValues;
1731
if(!def.getDescriptor())
1733
assert(!_def._cpp_template.empty());
1734
TemplateDescriptor tmpl = resolve.getServiceTemplate(_def._cpp_template);
1735
def = ServiceHelper(ServiceDescriptorPtr::dynamicCast(tmpl.descriptor));
1736
parameterValues = instantiateParams(resolve,
1738
_def.parameterValues,
1740
tmpl.parameterDefaults);
1744
// Setup the resolver.
1746
Resolver svcResolve(resolve, parameterValues, !_service.getDescriptor());
1747
svcResolve.setReserved("service", svcResolve(def.getDescriptor()->name, "service name", false));
1748
svcResolve.setContext("service `${service}' from server `${server}'");
1751
// Instantiate the service instance.
1753
ServiceInstanceDescriptor desc;
1754
desc.descriptor = def.instantiate(svcResolve, svcResolve(_def.propertySet).properties, serviceProps);
1757
// NOTE: We can't keep the following attributes in the service
1758
// instance otherwise the instance comparison would be based on
1759
// the template + parameters which would be wrong (if the template
1760
// changed the instance also changed.)
1762
//desc._cpp_template = _template;
1763
//desc.parameterValues = _parameters;
1768
ServiceInstanceHelper::getIds(multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
1770
assert(_service.getDescriptor());
1771
_service.getIds(adapterIds, objectIds);
1775
ServiceInstanceHelper::getReplicaGroups(set<string>& replicaGroups) const
1777
assert(_service.getDescriptor());
1778
_service.getReplicaGroups(replicaGroups);
1782
ServiceInstanceHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1784
if(_service.getDescriptor())
1786
_service.print(communicator, out);
1790
assert(!_def._cpp_template.empty());
1791
out << "service instance";
1793
out << nl << "template = `" << _def._cpp_template << "'";
1794
out << nl << "parameters";
1796
for(StringStringDict::const_iterator p = _def.parameterValues.begin(); p != _def.parameterValues.end(); ++p)
1798
out << nl << p->first << " = `" << p->second << "'";
1805
ServerInstanceHelper::ServerInstanceHelper(const ServerInstanceDescriptor& desc,
1806
const Resolver& resolve,
1810
init(0, resolve, instantiate);
1813
ServerInstanceHelper::ServerInstanceHelper(const ServerDescriptorPtr& definition,
1814
const Resolver& resolve,
1816
_def(ServerInstanceDescriptor())
1818
init(definition, resolve, instantiate);
1822
ServerInstanceHelper::init(const ServerDescriptorPtr& definition, const Resolver& resolve, bool instantiate)
1825
// Get the server definition if it's not provided.
1827
ServerDescriptorPtr def = definition;
1828
std::map<std::string, std::string> parameterValues;
1831
if(_def._cpp_template.empty())
1833
resolve.exception("invalid server instance: template is not defined");
1837
// Get the server definition and the template property sets.
1839
TemplateDescriptor tmpl = resolve.getServerTemplate(_def._cpp_template);
1840
def = ServerDescriptorPtr::dynamicCast(tmpl.descriptor);
1841
parameterValues = instantiateParams(resolve,
1843
_def.parameterValues,
1845
tmpl.parameterDefaults);
1850
// Setup the resolver.
1852
Resolver svrResolve(resolve, parameterValues, true);
1853
svrResolve.setReserved("server", svrResolve.asId(def->id, "server id", false));
1854
svrResolve.setContext("server `${server}'");
1855
svrResolve.setVersion(def->iceVersion);
1856
_id = svrResolve("${server}");
1859
// Set the server definition.
1861
_serverDefinition = createHelper(def);
1865
return; // We're done.
1869
// Ignore undefined session.id variable if the activation mode is
1870
// 'session', it will get defined when the server is allocated.
1872
if(svrResolve(def->activation, "server activation", true) == "session")
1874
svrResolve.addIgnored("session.id");
1878
// Instantiate the server instance definition (we use the server
1879
// resolver above, so using parameters in properties is possible).
1881
if(!_def._cpp_template.empty())
1883
_instance._cpp_template = _def._cpp_template;
1884
_instance.parameterValues = parameterValues;
1885
_instance.propertySet = svrResolve(_def.propertySet);
1886
for(PropertySetDescriptorDict::const_iterator p = _def.servicePropertySets.begin();
1887
p != _def.servicePropertySets.end(); ++p)
1889
_instance.servicePropertySets.insert(make_pair(svrResolve(p->first), svrResolve(p->second)));
1894
// Instantiate the server definition.
1896
ServerDescriptorPtr inst = _serverDefinition->instantiate(svrResolve, _instance.propertySet.properties,
1897
_instance.servicePropertySets);
1898
_serverInstance = createHelper(inst);
1902
ServerInstanceHelper::operator==(const ServerInstanceHelper& helper) const
1904
if(_def._cpp_template.empty())
1906
return *_serverDefinition == *helper._serverDefinition;
1910
return _def._cpp_template == helper._def._cpp_template &&
1911
_def.parameterValues == helper._def.parameterValues &&
1912
_def.propertySet == helper._def.propertySet &&
1913
_def.servicePropertySets == helper._def.servicePropertySets;
1918
ServerInstanceHelper::operator!=(const ServerInstanceHelper& helper) const
1920
return !operator==(helper);
1924
ServerInstanceHelper::getId() const
1929
ServerInstanceDescriptor
1930
ServerInstanceHelper::getDefinition() const
1932
assert(!_def._cpp_template.empty());
1936
ServerInstanceDescriptor
1937
ServerInstanceHelper::getInstance() const
1939
assert(!_def._cpp_template.empty() && !_instance._cpp_template.empty());
1944
ServerInstanceHelper::getServerDefinition() const
1946
assert(_def._cpp_template.empty());
1947
return _serverDefinition->getDescriptor();
1951
ServerInstanceHelper::getServerInstance() const
1953
assert(_serverInstance);
1954
return _serverInstance->getDescriptor();
1958
ServerInstanceHelper::getIds(multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
1960
assert(_serverInstance);
1961
_serverInstance->getIds(adapterIds, objectIds);
1965
ServerInstanceHelper::getReplicaGroups(set<string>& replicaGroups) const
1967
assert(_serverInstance);
1968
_serverInstance->getReplicaGroups(replicaGroups);
1971
NodeHelper::NodeHelper(const string& name,
1972
const NodeDescriptor& descriptor,
1973
const Resolver& appResolve,
1977
_instantiated(instantiate)
1981
appResolve.exception("invalid node: empty name");
1984
Resolver resolve(appResolve, _def.variables, false);
1985
resolve.setReserved("node", _name);
1986
resolve.setContext("node `" + _name + "'");
1991
// Instantiate the node definition.
1993
_instance.variables = _def.variables;
1994
_instance.loadFactor = resolve.asFloat(_def.loadFactor, "load factor");
1995
_instance.description = resolve(_def.description, "description");
1996
_instance.propertySets = resolve(_def.propertySets);
1999
// Set the named property sets on the resolver. We use the
2000
// instantiated named property sets here -- named property sets
2001
// must be fully definied at the node level.
2003
resolve.addPropertySets(_instance.propertySets);
2006
ServerInstanceDescriptorSeq::const_iterator p;
2007
for(p = _def.serverInstances.begin(); p != _def.serverInstances.end(); ++p)
2009
ServerInstanceHelper helper(*p, resolve, instantiate);
2010
if(!_serverInstances.insert(make_pair(helper.getId(), helper)).second)
2012
resolve.exception("duplicate server `" + helper.getId() + "' in node `" + _name + "'");
2016
_instance.serverInstances.push_back(helper.getInstance());
2020
ServerDescriptorSeq::const_iterator q;
2021
for(q = _def.servers.begin(); q != _def.servers.end(); ++q)
2023
ServerInstanceHelper helper(*q, resolve, instantiate);
2024
if(!_servers.insert(make_pair(helper.getId(), helper)).second)
2026
resolve.exception("duplicate server `" + helper.getId() + "' in node `" + _name + "'");
2030
_instance.servers.push_back(helper.getServerInstance());
2036
NodeHelper::operator==(const NodeHelper& helper) const
2038
if(_def.variables != helper._def.variables)
2043
if(_serverInstances != helper._serverInstances)
2048
if(_servers != helper._servers)
2053
if(_def.loadFactor != helper._def.loadFactor)
2058
if(_def.description != helper._def.description)
2063
if(_def.propertySets != helper._def.propertySets)
2072
NodeHelper::operator!=(const NodeHelper& helper) const
2074
return !operator==(helper);
2077
NodeUpdateDescriptor
2078
NodeHelper::diff(const NodeHelper& helper) const
2080
assert(_name == helper._name);
2082
NodeUpdateDescriptor update;
2084
update.name = _name;
2085
if(_def.loadFactor != helper._def.loadFactor)
2087
update.loadFactor = new BoxedString(_def.loadFactor);
2090
if(_def.description != helper._def.description)
2092
update.description = new BoxedString(_def.description);
2095
update.variables = getDictUpdatedElts(helper._def.variables, _def.variables);
2096
update.removeVariables = getDictRemovedElts(helper._def.variables, _def.variables);
2098
update.propertySets = getDictUpdatedElts(helper._def.propertySets, _def.propertySets);
2099
update.removePropertySets = getDictRemovedElts(helper._def.propertySets, _def.propertySets);
2101
ServerInstanceHelperDict updated = getDictUpdatedElts(helper._serverInstances, _serverInstances);
2102
for(ServerInstanceHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
2104
update.serverInstances.push_back(p->second.getDefinition());
2106
update.removeServers = getDictRemovedElts(helper._serverInstances, _serverInstances);
2108
updated = getDictUpdatedElts(helper._servers, _servers);
2109
for(ServerInstanceHelperDict::const_iterator q = updated.begin(); q != updated.end(); ++q)
2111
update.servers.push_back(q->second.getServerDefinition());
2113
Ice::StringSeq removed = getDictRemovedElts(helper._servers, _servers);
2114
update.removeServers.insert(update.removeServers.end(), removed.begin(), removed.end());
2119
NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolve) const
2122
assert(update.name == _name);
2125
// Update the variables, property sets, load factor, description.
2127
def.variables = updateDictElts(_def.variables, update.variables, update.removeVariables);
2128
def.propertySets = updateDictElts(_def.propertySets, update.propertySets, update.removePropertySets);
2129
def.loadFactor = update.loadFactor ? update.loadFactor->value : _def.loadFactor;
2130
def.description = update.description ? update.description->value : _def.description;
2133
// NOTE: It's important to create the resolver *after* updating
2134
// the node variables!
2136
Resolver resolve(appResolve, def.variables, false);
2137
resolve.setReserved("node", _name);
2138
resolve.setContext("node `" + _name + "'");
2141
// Update the node servers and server instances. The update is in 2 steps:
2143
// * first we instantiate the servers from the update descriptor.
2144
// * then we add the servers from the node which were not updated or removed.
2147
ServerInstanceHelperDict::const_iterator r;
2150
set<string> removed(update.removeServers.begin(), update.removeServers.end());
2152
ServerInstanceDescriptorSeq::const_iterator q;
2153
for(q = update.serverInstances.begin(); q != update.serverInstances.end(); ++q)
2155
ServerInstanceHelper helper(*q, resolve, false);
2156
if(!added.insert(helper.getId()).second)
2158
resolve.exception("duplicate server `" + helper.getId() + "' in node `" + _name + "'");
2160
def.serverInstances.push_back(helper.getDefinition());
2162
for(r = _serverInstances.begin(); r != _serverInstances.end(); ++r)
2164
if(removed.find(r->first) != removed.end() || added.find(r->first) != added.end())
2170
// Re-instantiate the server. Make sure the server ID didn't
2171
// change, if the ID of a server changes the update descriptor
2172
// has to remove the server and add an update entry for it.
2174
ServerInstanceHelper helper(r->second.getDefinition(), resolve, false);
2175
if(helper.getId() != r->first)
2177
resolve.exception("invalid update in node `" + _name + "':\n" + "server instance id `" + r->first +
2178
"' changed to `" + helper.getId() + "'");
2180
def.serverInstances.push_back(helper.getDefinition());
2184
for(ServerDescriptorSeq::const_iterator s = update.servers.begin(); s != update.servers.end(); ++s)
2186
ServerInstanceHelper helper(*s, resolve, false);
2187
if(!added.insert(helper.getId()).second)
2189
resolve.exception("duplicate server `" + helper.getId() + "' in node `" + _name + "'");
2191
def.servers.push_back(helper.getServerDefinition());
2193
for(r = _servers.begin(); r != _servers.end(); ++r)
2195
if(removed.find(r->first) != removed.end() || added.find(r->first) != added.end())
2201
// Re-instantiate the server. Make sure the server ID didn't
2202
// change, if the ID of a server changes the update descriptor
2203
// has to remove the server and add an update entry for it.
2205
ServerInstanceHelper helper(r->second.getServerDefinition(), resolve, false);
2206
if(helper.getId() != r->first)
2208
resolve.exception("invalid update in node `" + _name + "':\nserver instance id `" + r->first +
2209
"' changed to `" + helper.getId() + "'");
2211
def.servers.push_back(helper.getServerDefinition());
2217
NodeHelper::getIds(multiset<string>& serverIds, multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
2219
assert(_instantiated);
2220
ServerInstanceHelperDict::const_iterator p;
2221
for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2223
serverIds.insert(p->first);
2224
p->second.getIds(adapterIds, objectIds);
2226
for(p = _servers.begin(); p != _servers.end(); ++p)
2228
serverIds.insert(p->first);
2229
p->second.getIds(adapterIds, objectIds);
2234
NodeHelper::getReplicaGroups(set<string>& replicaGroups) const
2236
assert(_instantiated);
2237
ServerInstanceHelperDict::const_iterator p;
2238
for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2240
p->second.getReplicaGroups(replicaGroups);
2242
for(p = _servers.begin(); p != _servers.end(); ++p)
2244
p->second.getReplicaGroups(replicaGroups);
2248
const NodeDescriptor&
2249
NodeHelper::getDefinition() const
2254
const NodeDescriptor&
2255
NodeHelper::getInstance() const
2257
assert(_instantiated);
2262
NodeHelper::getServerInfos(const string& app, const string& uuid, int revision, map<string, ServerInfo>& servers) const
2264
assert(_instantiated);
2266
ServerInstanceHelperDict::const_iterator p;
2267
for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2271
info.application = app;
2273
info.revision = revision;
2274
info.descriptor = p->second.getServerInstance();
2275
servers.insert(make_pair(p->second.getId(), info));
2277
for(p = _servers.begin(); p != _servers.end(); ++p)
2281
info.application = app;
2283
info.revision = revision;
2284
info.descriptor = p->second.getServerInstance();
2285
servers.insert(make_pair(p->second.getId(), info));
2290
NodeHelper::hasDistributions(const string& server) const
2292
assert(_instantiated);
2295
// Get the server distributions to patch.
2299
ServerInstanceHelperDict::const_iterator p;
2300
for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2302
if(!p->second.getServerInstance()->distrib.icepatch.empty())
2307
for(p = _servers.begin(); p != _servers.end(); ++p)
2309
if(!p->second.getServerInstance()->distrib.icepatch.empty())
2317
ServerInstanceHelperDict::const_iterator p = _serverInstances.find(server);
2318
if(p == _serverInstances.end())
2320
p = _servers.find(server);
2321
if(p == _servers.end())
2327
if(!p->second.getServerInstance()->distrib.icepatch.empty())
2337
NodeHelper::hasServers() const
2339
return !_serverInstances.empty() || !_servers.empty();
2343
NodeHelper::hasServer(const string& name) const
2345
return _serverInstances.find(name) != _serverInstances.end() || _servers.find(name) != _servers.end();
2349
NodeHelper::print(Output& out) const
2351
assert(_instantiated);
2353
out << nl << "node `" << _name << "'";
2355
if(!_instance.loadFactor.empty())
2357
out << nl << "load factor = `" << _instance.loadFactor << "'";
2359
if(!_instance.description.empty())
2361
out << nl << "description = `" << _instance.description << "'";
2363
if(!_instance.variables.empty())
2365
out << nl << "variables";
2367
for(StringStringDict::const_iterator q = _instance.variables.begin(); q != _instance.variables.end(); ++q)
2369
out << nl << q->first << " = `" << q->second << "'";
2373
if(!_instance.propertySets.empty())
2375
PropertySetDescriptorDict::const_iterator q;
2376
for(q = _instance.propertySets.begin(); q != _instance.propertySets.end(); ++q)
2378
out << nl << "properties `" << q->first << "'";
2380
if(!q->second.references.empty())
2382
out << nl << "references = " << toString(q->second.references);
2384
PropertyDescriptorSeq::const_iterator r;
2385
for(r = q->second.properties.begin(); r != q->second.properties.end(); ++r)
2387
out << nl << r->name << " = `" << r->value << "'";
2393
if(_serverInstances.empty() && _servers.empty())
2398
out << nl << "servers";
2400
ServerInstanceHelperDict::const_iterator p;
2401
for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2403
out << nl << p->first;
2405
for(p = _servers.begin(); p != _servers.end(); ++p)
2407
out << nl << p->first;
2414
NodeHelper::printDiff(Output& out, const NodeHelper& helper) const
2416
assert(_instantiated);
2418
ServerInstanceHelperDict updated1 = getDictUpdatedElts(helper._serverInstances, _serverInstances);
2419
Ice::StringSeq removed1 = getDictRemovedElts(helper._serverInstances, _serverInstances);
2420
ServerInstanceHelperDict updated2 = getDictUpdatedElts(helper._servers, _servers);
2421
Ice::StringSeq removed2 = getDictRemovedElts(helper._servers, _servers);
2423
ServerInstanceHelperDict updated;
2424
Ice::StringSeq removed;
2425
updated.insert(updated1.begin(), updated1.end());
2426
removed.insert(removed.end(), removed1.begin(), removed1.end());
2427
updated.insert(updated2.begin(), updated2.end());
2428
removed.insert(removed.end(), removed2.begin(), removed2.end());
2430
map<string, string> variables = getDictUpdatedElts(helper._def.variables, _def.variables);
2431
Ice::StringSeq removeVariables = getDictRemovedElts(helper._def.variables, _def.variables);
2433
PropertySetDescriptorDict updatedPs = getDictUpdatedElts(helper._def.propertySets, _def.propertySets);
2434
Ice::StringSeq removedPs = getDictRemovedElts(helper._def.propertySets, _def.propertySets);
2436
if(updated.empty() && removed.empty() &&
2437
variables.empty() && removeVariables.empty() &&
2438
updatedPs.empty() && removedPs.empty() &&
2439
_def.loadFactor == helper._def.loadFactor &&
2440
_def.description == helper._def.description)
2446
// TODO: Show updated variables?
2449
out << nl << "node `" + _name + "' updated";
2452
if(_def.loadFactor != helper._def.loadFactor)
2454
out << nl << "load factor udpated";
2456
if(_def.description != helper._def.description)
2458
out << nl << "description udpated";
2460
if(!updatedPs.empty() || !removedPs.empty())
2462
out << nl << "property sets udpated";
2464
if(!variables.empty() || !removeVariables.empty())
2466
out << nl << "variables udpated";
2468
if(!updated.empty() || !removed.empty())
2470
out << nl << "servers";
2472
ServerInstanceHelperDict::const_iterator p;
2473
for(p = updated.begin(); p != updated.end(); ++p)
2475
if(helper._serverInstances.find(p->first) == helper._serverInstances.end() &&
2476
helper._servers.find(p->first) == helper._servers.end())
2478
out << nl << "server `" << p->first << "' added";
2481
for(p = updated.begin(); p != updated.end(); ++p)
2483
if(helper._serverInstances.find(p->first) != helper._serverInstances.end() ||
2484
helper._servers.find(p->first) != helper._servers.end())
2486
out << nl << "server `" << p->first << "' updated";
2489
for(Ice::StringSeq::const_iterator q = removed.begin(); q != removed.end(); ++q)
2491
out << nl << "server `" << *q << "' removed";
2498
ApplicationHelper::ApplicationHelper(const Ice::CommunicatorPtr& communicator,
2499
const ApplicationDescriptor& desc,
2502
_communicator(communicator),
2505
if(_def.name.empty())
2507
throw DeploymentException("invalid application: empty name");
2510
Resolver resolve(_def, communicator, enableWarning);
2515
// Instantiate the application definition.
2517
_instance.name = _def.name;
2518
_instance.variables = _def.variables;
2519
_instance.serverTemplates = _def.serverTemplates;
2520
_instance.serviceTemplates = _def.serviceTemplates;
2521
_instance.description = resolve(_def.description, "description");
2522
_instance.distrib = resolve(_def.distrib);
2523
_instance.propertySets = resolve(_def.propertySets);
2525
for(ReplicaGroupDescriptorSeq::iterator r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r)
2527
ReplicaGroupDescriptor desc;
2528
desc.id = resolve.asId(r->id, "replica group id", false);
2529
desc.description = resolve(r->description, "replica group description");
2530
desc.objects = resolve(r->objects, "replica group well-known");
2531
if(!r->loadBalancing)
2533
resolve.exception("replica group load balancing is not set");
2535
desc.loadBalancing = LoadBalancingPolicyPtr::dynamicCast(r->loadBalancing->ice_clone());
2536
desc.loadBalancing->nReplicas =
2537
resolve.asInt(r->loadBalancing->nReplicas, "replica group number of replicas");
2538
if(desc.loadBalancing->nReplicas.empty())
2540
resolve.exception("invalid replica group load balancing number of replicas value: empty value");
2542
else if(desc.loadBalancing->nReplicas[0] == '-')
2544
resolve.exception("invalid replica group load balancing number of replicas value: inferior to 0");
2546
AdaptiveLoadBalancingPolicyPtr al = AdaptiveLoadBalancingPolicyPtr::dynamicCast(desc.loadBalancing);
2549
al->loadSample = resolve(al->loadSample, "replica group load sample");
2550
if(al->loadSample != "" && al->loadSample != "1" && al->loadSample != "5" && al->loadSample != "15")
2552
resolve.exception("invalid load sample value (allowed values are 1, 5 or 15)");
2555
_instance.replicaGroups.push_back(desc);
2559
// Set the named property sets on the resolver. We use the
2560
// instantiated named property sets here -- named property sets
2561
// must be fully definied at the application level.
2563
resolve.addPropertySets(_instance.propertySets);
2567
// Create the node helpers.
2569
NodeHelperDict::const_iterator n;
2570
for(NodeDescriptorDict::const_iterator p = _def.nodes.begin(); p != _def.nodes.end(); ++p)
2572
n = _nodes.insert(make_pair(p->first, NodeHelper(p->first, p->second, resolve, instantiate))).first;
2575
_instance.nodes.insert(make_pair(n->first, n->second.getInstance()));
2580
// If the application is instantiated, ensure the unicity of
2581
// object ids, adapter ids and server ids.
2585
multiset<string> serverIds;
2586
multiset<string> adapterIds;
2587
multiset<Ice::Identity> objectIds;
2588
for(n = _nodes.begin(); n != _nodes.end(); ++n)
2590
n->second.getIds(serverIds, adapterIds, objectIds);
2593
for(ReplicaGroupDescriptorSeq::iterator r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r)
2597
throw DeploymentException("replica group id is empty");
2599
if(adapterIds.find(r->id) != adapterIds.end())
2601
throw DeploymentException("duplicate replica group `" + r->id + "'");
2603
adapterIds.insert(r->id);
2604
for(ObjectDescriptorSeq::const_iterator o = r->objects.begin(); o != r->objects.end(); ++o)
2606
objectIds.insert(o->id);
2610
for(multiset<string>::const_iterator s = serverIds.begin(); s != serverIds.end(); ++s)
2612
if(serverIds.count(*s) > 1)
2614
resolve.exception("duplicate server `" + *s + "'");
2617
for(multiset<string>::const_iterator a = adapterIds.begin(); a != adapterIds.end(); ++a)
2619
if(adapterIds.count(*a) > 1)
2621
resolve.exception("duplicate adapter `" + *a + "'");
2624
for(multiset<Ice::Identity>::const_iterator o = objectIds.begin(); o != objectIds.end(); ++o)
2626
if(objectIds.count(*o) > 1)
2628
resolve.exception("duplicate object `" + _communicator->identityToString(*o) + "'");
2634
ApplicationUpdateDescriptor
2635
ApplicationHelper::diff(const ApplicationHelper& helper) const
2637
ApplicationUpdateDescriptor updt;
2638
assert(helper._def.name == _def.name);
2640
updt.name = _def.name;
2641
if(_def.description != helper._def.description)
2643
updt.description = new BoxedString(_def.description);
2646
updt.variables = getDictUpdatedElts(helper._def.variables, _def.variables);
2647
updt.removeVariables = getDictRemovedElts(helper._def.variables, _def.variables);
2649
updt.propertySets = getDictUpdatedElts(helper._def.propertySets, _def.propertySets);
2650
updt.removePropertySets = getDictRemovedElts(helper._def.propertySets, _def.propertySets);
2652
if(_def.distrib != helper._def.distrib)
2654
updt.distrib = new BoxedDistributionDescriptor(_def.distrib);
2657
GetReplicaGroupId rk;
2659
updt.replicaGroups = getSeqUpdatedEltsWithEq(helper._def.replicaGroups, _def.replicaGroups, rk, req);
2660
updt.removeReplicaGroups = getSeqRemovedElts(helper._def.replicaGroups, _def.replicaGroups, rk);
2662
TemplateDescriptorEqual eq;
2663
updt.serverTemplates = getDictUpdatedEltsWithEq(helper._def.serverTemplates, _def.serverTemplates, eq);
2664
updt.removeServerTemplates = getDictRemovedElts(helper._def.serverTemplates, _def.serverTemplates);
2665
updt.serviceTemplates = getDictUpdatedEltsWithEq(helper._def.serviceTemplates, _def.serviceTemplates, eq);
2666
updt.removeServiceTemplates = getDictRemovedElts(helper._def.serviceTemplates, _def.serviceTemplates);
2668
NodeHelperDict updated = getDictUpdatedElts(helper._nodes, _nodes);
2669
for(NodeHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
2671
NodeHelperDict::const_iterator q = helper._nodes.find(p->first);
2672
if(q == helper._nodes.end())
2674
NodeUpdateDescriptor nodeUpdate;
2675
const NodeDescriptor& node = p->second.getDefinition();
2676
nodeUpdate.name = p->first;
2677
nodeUpdate.variables = node.variables;
2678
nodeUpdate.servers = node.servers;
2679
nodeUpdate.serverInstances = node.serverInstances;
2680
nodeUpdate.loadFactor = new BoxedString(node.loadFactor);
2681
nodeUpdate.description = new BoxedString(node.description);
2682
updt.nodes.push_back(nodeUpdate);
2686
updt.nodes.push_back(p->second.diff(q->second));
2689
updt.removeNodes = getDictRemovedElts(helper._nodes, _nodes);
2694
ApplicationDescriptor
2695
ApplicationHelper::update(const ApplicationUpdateDescriptor& updt) const
2697
ApplicationDescriptor def;
2698
GetReplicaGroupId rg;
2700
def.name = _def.name;
2701
def.description = updt.description ? updt.description->value : _def.description;
2702
def.distrib = updt.distrib ? updt.distrib->value : _def.distrib;
2703
def.replicaGroups = updateSeqElts(_def.replicaGroups, updt.replicaGroups, updt.removeReplicaGroups, rg);
2704
def.variables = updateDictElts(_def.variables, updt.variables, updt.removeVariables);
2705
def.propertySets = updateDictElts(_def.propertySets, updt.propertySets, updt.removePropertySets);
2706
def.serverTemplates = updateDictElts(_def.serverTemplates, updt.serverTemplates, updt.removeServerTemplates);
2707
def.serviceTemplates = updateDictElts(_def.serviceTemplates, updt.serviceTemplates, updt.removeServiceTemplates);
2709
Resolver resolve(def, _communicator, false); // A resolver based on the *updated* application descriptor.
2710
for(NodeUpdateDescriptorSeq::const_iterator p = updt.nodes.begin(); p != updt.nodes.end(); ++p)
2712
NodeHelperDict::const_iterator q = _nodes.find(p->name);
2713
if(q != _nodes.end()) // Updated node
2715
NodeDescriptor desc = q->second.update(*p, resolve);
2716
def.nodes.insert(make_pair(p->name, q->second.update(*p, resolve)));
2720
NodeDescriptor desc;
2721
desc.variables = p->variables;
2722
if(!p->removeVariables.empty())
2724
resolve.exception("can't remove variables for node `" + p->name + "': node doesn't exist");
2726
desc.propertySets = p->propertySets;
2727
if(!p->removePropertySets.empty())
2729
resolve.exception("can't remove property sets for node `" + p->name + "': node doesn't exist");
2731
desc.servers = p->servers;
2732
desc.serverInstances = p->serverInstances;
2733
if(!p->removeServers.empty())
2735
resolve.exception("can't remove servers for node `" + p->name + "': node doesn't exist");
2737
desc.loadFactor = p->loadFactor ? p->loadFactor->value : string("");
2738
desc.description = p->description ? p->description->value : string("");
2739
def.nodes.insert(make_pair(p->name, desc));
2742
set<string> removedNodes(updt.removeNodes.begin(), updt.removeNodes.end());
2743
for(NodeHelperDict::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n)
2745
if(removedNodes.find(n->first) != removedNodes.end() || def.nodes.find(n->first) != def.nodes.end())
2747
continue; // Node was removed or updated.
2749
def.nodes.insert(make_pair(n->first, n->second.getDefinition()));
2755
ApplicationDescriptor
2756
ApplicationHelper::instantiateServer(const string& node, const ServerInstanceDescriptor& instance) const
2759
// Copy this application descriptor definition and add a server
2760
// instance to the given node. The caller should then construct
2761
// an application helper with the new application definition to
2762
// ensure it's valid.
2764
ApplicationDescriptor def = _def;
2765
NodeDescriptorDict::iterator q = def.nodes.find(node);
2766
if(q == def.nodes.end())
2768
NodeDescriptor desc;
2769
desc.serverInstances.push_back(instance);
2770
def.nodes.insert(make_pair(node, desc));
2774
q->second.serverInstances.push_back(instance);
2780
ApplicationHelper::getIds(set<string>& serverIds, set<string>& adapterIds, set<Ice::Identity>& objectIds) const
2782
multiset<string> sIds;
2783
multiset<string> aIds;
2784
multiset<Ice::Identity> oIds;
2786
for(NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p)
2788
p->second.getIds(sIds, aIds, oIds);
2790
ReplicaGroupDescriptorSeq::const_iterator r;
2791
for(r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r)
2794
for(ObjectDescriptorSeq::const_iterator o = r->objects.begin(); o != r->objects.end(); ++o)
2800
copy(sIds.begin(), sIds.end(), inserter(serverIds, serverIds.begin()));
2801
copy(aIds.begin(), aIds.end(), inserter(adapterIds, adapterIds.begin()));
2802
copy(oIds.begin(), oIds.end(), inserter(objectIds, objectIds.begin()));
2806
ApplicationHelper::getReplicaGroups(set<string>& replicaGroups, set<string>& adapterReplicaGroups) const
2808
ReplicaGroupDescriptorSeq::const_iterator r;
2809
for(r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r)
2811
replicaGroups.insert(r->id);
2814
set<string> allAdapterReplicaGroups;
2815
for(NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p)
2817
p->second.getReplicaGroups(allAdapterReplicaGroups);
2821
// Only return references to replica groups which don't belong to
2822
// this application.
2824
set_difference(allAdapterReplicaGroups.begin(), allAdapterReplicaGroups.end(),
2825
replicaGroups.begin(), replicaGroups.end(), set_inserter(adapterReplicaGroups));
2828
const ApplicationDescriptor&
2829
ApplicationHelper::getDefinition() const
2834
const ApplicationDescriptor&
2835
ApplicationHelper::getInstance() const
2837
assert(!_instance.name.empty());
2841
map<string, ServerInfo>
2842
ApplicationHelper::getServerInfos(const string& uuid, int revision) const
2844
assert(!_instance.name.empty());
2846
map<string, ServerInfo> servers;
2847
for(NodeHelperDict::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n)
2849
n->second.getServerInfos(_def.name, uuid, revision, servers);
2855
ApplicationHelper::getDistributions(DistributionDescriptor& distribution,
2856
vector<string>& nodes,
2857
const string& server) const
2859
assert(!_instance.name.empty());
2861
distribution = _instance.distrib;
2862
for(NodeHelperDict::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n)
2864
if(n->second.hasDistributions(server))
2866
nodes.push_back(n->first);
2872
else if(!_instance.distrib.icepatch.empty() &&
2873
((server.empty() && n->second.hasServers()) || n->second.hasServer(server)))
2875
nodes.push_back(n->first);
2881
ApplicationHelper::print(Output& out, const ApplicationInfo& info) const
2883
assert(!_instance.name.empty());
2885
out << "application `" << _instance.name << "'";
2887
out << nl << "uuid = `" << info.uuid << "'";
2888
out << nl << "revision = `" << info.revision << "'";
2889
out << nl << "creation time = `" << IceUtil::Time::milliSeconds(info.createTime).toDateTime() << "'";
2890
out << nl << "created by = `" << info.createUser << "'";
2891
out << nl << "update time = `" << IceUtil::Time::milliSeconds(info.updateTime).toDateTime() << "'";
2892
out << nl << "updated by = `" << info.updateUser << "'";
2894
if(!_instance.description.empty())
2896
out << nl << "description = `" << _instance.description << "'";
2898
if(!_instance.variables.empty())
2900
out << nl << "variables";
2902
for(StringStringDict::const_iterator p = _instance.variables.begin(); p != _instance.variables.end();
2905
out << nl << p->first << " = `" << p->second << "'";
2909
if(!_instance.propertySets.empty())
2911
PropertySetDescriptorDict::const_iterator q;
2912
for(q = _instance.propertySets.begin(); q != _instance.propertySets.end(); ++q)
2914
out << nl << "properties `" << q->first << "'";
2916
if(!q->second.references.empty())
2918
out << nl << "references = " << toString(q->second.references);
2920
PropertyDescriptorSeq::const_iterator r;
2921
for(r = q->second.properties.begin(); r != q->second.properties.end(); ++r)
2923
out << nl << r->name << " = `" << r->value << "'";
2928
if(!_instance.distrib.icepatch.empty())
2930
out << nl << "distribution";
2932
out << nl << "proxy = `" << _instance.distrib.icepatch << "'";
2933
if(!_instance.distrib.directories.empty())
2935
out << nl << "directories = `" << toString(_instance.distrib.directories) << "'";
2939
if(!_instance.replicaGroups.empty())
2941
out << nl << "replica groups";
2943
ReplicaGroupDescriptorSeq::const_iterator p;
2944
for(p = _instance.replicaGroups.begin(); p != _instance.replicaGroups.end(); ++p)
2946
out << nl << "id = `" << p->id << "' load balancing = `";
2947
if(!p->loadBalancing)
2949
out << "default (return all endpoints)";
2951
else if(RandomLoadBalancingPolicyPtr::dynamicCast(p->loadBalancing))
2955
else if(RoundRobinLoadBalancingPolicyPtr::dynamicCast(p->loadBalancing))
2957
out << "round-robin";
2959
else if(AdaptiveLoadBalancingPolicyPtr::dynamicCast(p->loadBalancing))
2965
out << "<unknown load balancing policy>";
2971
if(!_instance.serverTemplates.empty())
2973
out << nl << "server templates";
2975
TemplateDescriptorDict::const_iterator p;
2976
for(p = _instance.serverTemplates.begin(); p != _instance.serverTemplates.end(); ++p)
2978
out << nl << p->first;
2982
if(!_instance.serviceTemplates.empty())
2984
out << nl << "service templates";
2986
TemplateDescriptorDict::const_iterator p;
2987
for(p = _instance.serviceTemplates.begin(); p != _instance.serviceTemplates.end(); ++p)
2989
out << nl << p->first;
2995
for(NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p)
2997
p->second.print(out);
3004
ApplicationHelper::printDiff(Output& out, const ApplicationHelper& helper) const
3006
assert(!_instance.name.empty());
3008
out << "application `" << _def.name << "'";
3012
map<string, string> variables = getDictUpdatedElts(helper._def.variables, _def.variables);
3013
Ice::StringSeq removeVariables = getDictRemovedElts(helper._def.variables, _def.variables);
3014
if(!variables.empty() || !removeVariables.empty())
3016
out << nl << "variables udpated";
3020
if(_def.distrib != helper._def.distrib)
3022
out << nl << "distribution updated";
3026
PropertySetDescriptorDict updt = getDictUpdatedElts(helper._def.propertySets, _def.propertySets);
3027
Ice::StringSeq removed = getDictRemovedElts(helper._def.propertySets, _def.propertySets);
3028
if(!updt.empty() || !removed.empty())
3030
out << nl << "property sets udpated";
3034
GetReplicaGroupId rk;
3036
ReplicaGroupDescriptorSeq updated =
3037
getSeqUpdatedEltsWithEq(helper._def.replicaGroups, _def.replicaGroups, rk, req);
3038
Ice::StringSeq removed = getSeqRemovedElts(helper._def.replicaGroups, _def.replicaGroups, rk);
3039
if(!updated.empty() || !removed.empty())
3041
out << nl << "replica groups";
3043
ReplicaGroupDescriptorSeq::iterator p = updated.begin();
3044
while(p != updated.end())
3046
ReplicaGroupDescriptorSeq::const_iterator r;
3047
for(r = helper._def.replicaGroups.begin(); r != helper._def.replicaGroups.end();
3052
out << nl << "replica group `" << r->id << "' updated";
3053
p = updated.erase(p);
3057
if(r == helper._def.replicaGroups.end())
3062
for(p = updated.begin(); p != updated.end(); ++p)
3064
out << nl << "replica group `" << p->id << "' added";
3066
for(Ice::StringSeq::const_iterator q = removed.begin(); q != removed.end(); ++q)
3068
out << nl << "replica group `" << *q << "' removed";
3075
TemplateDescriptorEqual eq;
3076
TemplateDescriptorDict updated;
3077
updated = getDictUpdatedEltsWithEq(helper._def.serverTemplates, _def.serverTemplates, eq);
3078
Ice::StringSeq removed = getDictRemovedElts(helper._def.serverTemplates, _def.serverTemplates);
3079
if(!updated.empty() || !removed.empty())
3081
out << nl << "server templates";
3083
for(TemplateDescriptorDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
3085
if(helper._def.serverTemplates.find(p->first) == helper._def.serverTemplates.end())
3087
out << nl << "server template `" << p->first << "' added";
3090
for(TemplateDescriptorDict::const_iterator q = updated.begin(); q != updated.end(); ++q)
3092
if(helper._def.serverTemplates.find(q->first) != helper._def.serverTemplates.end())
3094
out << nl << "server template `" << q->first << "' updated";
3097
for(Ice::StringSeq::const_iterator r = removed.begin(); r != removed.end(); ++r)
3099
out << nl << "server template `" << *r << "' removed";
3105
TemplateDescriptorEqual eq;
3106
TemplateDescriptorDict updated;
3107
updated = getDictUpdatedEltsWithEq(helper._def.serviceTemplates, _def.serviceTemplates, eq);
3108
Ice::StringSeq removed = getDictRemovedElts(helper._def.serviceTemplates, _def.serviceTemplates);
3109
if(!updated.empty() || !removed.empty())
3111
out << nl << "service templates";
3113
for(TemplateDescriptorDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
3115
if(helper._def.serviceTemplates.find(p->first) == helper._def.serviceTemplates.end())
3117
out << nl << "service template `" << p->first << "' added";
3120
for(TemplateDescriptorDict::const_iterator q = updated.begin(); q != updated.end(); ++q)
3122
if(helper._def.serviceTemplates.find(q->first) != helper._def.serviceTemplates.end())
3124
out << nl << "service template `" << q->first << "' updated";
3127
for(Ice::StringSeq::const_iterator r = removed.begin(); r != removed.end(); ++r)
3129
out << nl << "service template `" << *r << "' removed";
3135
NodeHelperDict updated = getDictUpdatedElts(helper._nodes, _nodes);
3136
Ice::StringSeq removed = getDictRemovedElts(helper._nodes, _nodes);
3137
if(!updated.empty() || !removed.empty())
3139
out << nl << "nodes";
3141
for(NodeHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
3143
NodeHelperDict::const_iterator q = helper._nodes.find(p->first);
3144
if(q == helper._nodes.end())
3146
p->second.print(out);
3149
for(NodeHelperDict::const_iterator r = updated.begin(); r != updated.end(); ++r)
3151
NodeHelperDict::const_iterator q = helper._nodes.find(r->first);
3152
if(q != helper._nodes.end())
3154
r->second.printDiff(out, q->second);
3157
for(Ice::StringSeq::const_iterator s = removed.begin(); s != removed.end(); ++s)
3159
out << nl << "node `" << *s << "' removed";
3168
IceGrid::descriptorEqual(const ServerDescriptorPtr& lhs, const ServerDescriptorPtr& rhs)
3170
IceBoxDescriptorPtr lhsIceBox = IceBoxDescriptorPtr::dynamicCast(lhs);
3171
IceBoxDescriptorPtr rhsIceBox = IceBoxDescriptorPtr::dynamicCast(rhs);
3172
if(lhsIceBox && rhsIceBox)
3174
return IceBoxHelper(lhsIceBox) == IceBoxHelper(rhsIceBox);
3176
else if(!lhsIceBox && !rhsIceBox)
3178
return ServerHelper(lhs) == ServerHelper(rhs);
3187
IceGrid::createHelper(const ServerDescriptorPtr& desc)
3189
IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(desc);
3192
return new IceBoxHelper(iceBox);
3196
return new ServerHelper(desc);