~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to .pc/ice_for_gcc4.7.patch/cpp/src/IceGrid/DescriptorHelper.cpp

  • Committer: Package Import Robot
  • Author(s): Michael Ziegler
  • Date: 2012-07-07 15:24:30 UTC
  • mfrom: (6.1.25 sid)
  • Revision ID: package-import@ubuntu.com-20120707152430-kktx4mfmywkz382j
Tags: 3.4.2-8.1
* Non-maintainer upload.
* Revert the patch 'fixing' the FTBFS with gcc-4.7 that breaks ABI, and
  add force_gcc_4.6.patch.  We need to do this all in the upstream makefile
  because it has a silly check for the intel icpc compiler that we need to
  patch around or the build will fail with anything but c++ as the compiler,
  and we can't just override CXX in /rules because the wonderful 3.0 (quilt)
  system will revert that patch before the clean target is run ensuring that
  hilarious fail is guaranteed.
  Closes: #672066

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// **********************************************************************
2
 
//
3
 
// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4
 
//
5
 
// This copy of Ice is licensed to you under the terms described in the
6
 
// ICE_LICENSE file included in this distribution.
7
 
//
8
 
// **********************************************************************
9
 
 
10
 
#include <Ice/Ice.h>
11
 
#include <IceGrid/DescriptorHelper.h>
12
 
#include <IceGrid/Util.h>
13
 
 
14
 
#include <iterator>
15
 
 
16
 
using namespace std;
17
 
using namespace IceUtil;
18
 
using namespace IceUtilInternal;
19
 
using namespace IceGrid;
20
 
 
21
 
namespace IceGrid
22
 
{
23
 
 
24
 
struct GetReplicaGroupId : unary_function<ReplicaGroupDescriptor&, const string&>
25
 
{
26
 
    const string&
27
 
    operator()(const ReplicaGroupDescriptor& desc)
28
 
    {
29
 
        return desc.id;
30
 
    }
31
 
};
32
 
 
33
 
struct TemplateDescriptorEqual : std::binary_function<TemplateDescriptor&, TemplateDescriptor&, bool>
34
 
{
35
 
    bool
36
 
    operator()(const TemplateDescriptor& lhs, const TemplateDescriptor& rhs)
37
 
    {
38
 
        if(lhs.parameters != rhs.parameters)
39
 
        {
40
 
            return false;
41
 
        }
42
 
 
43
 
        if(lhs.parameterDefaults != rhs.parameterDefaults)
44
 
        {
45
 
            return false;
46
 
        }
47
 
 
48
 
        {
49
 
            IceBoxDescriptorPtr slhs = IceBoxDescriptorPtr::dynamicCast(lhs.descriptor);
50
 
            IceBoxDescriptorPtr srhs = IceBoxDescriptorPtr::dynamicCast(rhs.descriptor);
51
 
            if(slhs && srhs)
52
 
            {
53
 
                return IceBoxHelper(slhs) == IceBoxHelper(srhs);
54
 
            }
55
 
        }
56
 
        {
57
 
            ServerDescriptorPtr slhs = ServerDescriptorPtr::dynamicCast(lhs.descriptor);
58
 
            ServerDescriptorPtr srhs = ServerDescriptorPtr::dynamicCast(rhs.descriptor);
59
 
            if(slhs && srhs)
60
 
            {
61
 
                return ServerHelper(slhs) == ServerHelper(srhs);
62
 
            }
63
 
        }
64
 
        {
65
 
            ServiceDescriptorPtr slhs = ServiceDescriptorPtr::dynamicCast(lhs.descriptor);
66
 
            ServiceDescriptorPtr srhs = ServiceDescriptorPtr::dynamicCast(rhs.descriptor);
67
 
            if(slhs && srhs)
68
 
            {
69
 
                return ServiceHelper(slhs) == ServiceHelper(srhs);
70
 
            }   
71
 
        }
72
 
 
73
 
        return false;
74
 
    }
75
 
};
76
 
 
77
 
struct ReplicaGroupEq : std::binary_function<ReplicaGroupDescriptor&, ReplicaGroupDescriptor&, bool>
78
 
{
79
 
    bool
80
 
    operator()(const ReplicaGroupDescriptor& lhs, const ReplicaGroupDescriptor& rhs)
81
 
    {
82
 
        if(lhs.id != rhs.id)
83
 
        {
84
 
            return false;
85
 
        }
86
 
        if(set<ObjectDescriptor>(lhs.objects.begin(), lhs.objects.end()) != 
87
 
           set<ObjectDescriptor>(rhs.objects.begin(), rhs.objects.end()))
88
 
        {
89
 
            return false;
90
 
        }
91
 
        if(lhs.loadBalancing && rhs.loadBalancing)
92
 
        {
93
 
            if(lhs.loadBalancing->ice_id() != rhs.loadBalancing->ice_id())
94
 
            {
95
 
                return false;
96
 
            }
97
 
            if(lhs.loadBalancing->nReplicas != rhs.loadBalancing->nReplicas)
98
 
            {
99
 
                return false;
100
 
            }
101
 
            AdaptiveLoadBalancingPolicyPtr alhs = AdaptiveLoadBalancingPolicyPtr::dynamicCast(lhs.loadBalancing);
102
 
            AdaptiveLoadBalancingPolicyPtr arhs = AdaptiveLoadBalancingPolicyPtr::dynamicCast(rhs.loadBalancing);
103
 
            if(alhs && arhs && alhs->loadSample != arhs->loadSample)
104
 
            {
105
 
                return false;
106
 
            }
107
 
        }
108
 
        else if(lhs.loadBalancing || rhs.loadBalancing)
109
 
        {
110
 
            return false;
111
 
        }
112
 
 
113
 
        return true;
114
 
    }
115
 
};
116
 
 
117
 
template <typename GetKeyFunc, typename Seq> Seq
118
 
getSeqUpdatedElts(const Seq& lseq, const Seq& rseq, GetKeyFunc func)
119
 
{
120
 
#if defined(_MSC_VER) && (_MSC_VER < 1300)
121
 
   return getSeqUpdatedEltsWithEq(lseq, rseq, func, equal_to<Seq::value_type>());
122
 
#else
123
 
   return getSeqUpdatedEltsWithEq(lseq, rseq, func, equal_to<typename Seq::value_type>());
124
 
#endif
125
 
}
126
 
 
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)
130
 
#else
131
 
getSeqUpdatedEltsWithEq(const Seq& lseq, const Seq& rseq, GetKeyFunc func, EqFunc eq)
132
 
#endif
133
 
{
134
 
    Seq result;
135
 
    for(typename Seq::const_iterator p = rseq.begin(); p != rseq.end(); ++p)
136
 
    {
137
 
        typename Seq::const_iterator q = lseq.begin();
138
 
        for(; q != lseq.end(); ++q)
139
 
        {
140
 
            if(func(*p) == func(*q))
141
 
            {
142
 
                break;
143
 
            }
144
 
        }
145
 
        if(q == lseq.end() || !eq(*p, *q))
146
 
        {
147
 
            result.push_back(*p);
148
 
        }
149
 
    }
150
 
    return result;
151
 
}
152
 
 
153
 
template <typename GetKeyFunc, typename Seq> Ice::StringSeq 
154
 
getSeqRemovedElts(const Seq& lseq, const Seq& rseq, GetKeyFunc func)
155
 
{
156
 
    Ice::StringSeq removed;
157
 
    for(typename Seq::const_iterator p = lseq.begin(); p != lseq.end(); ++p)
158
 
    {
159
 
        typename Seq::const_iterator q;
160
 
        for(q = rseq.begin(); q != rseq.end(); ++q)
161
 
        {
162
 
            if(func(*p) == func(*q))
163
 
            {
164
 
                break;
165
 
            }
166
 
        }
167
 
        if(q == rseq.end())
168
 
        {
169
 
            removed.push_back(func(*p));
170
 
        }
171
 
    }
172
 
    return removed;
173
 
}
174
 
 
175
 
template <typename GetKeyFunc, typename Seq> Seq
176
 
updateSeqElts(const Seq& seq, const Seq& update, const Ice::StringSeq& remove, GetKeyFunc func)
177
 
{
178
 
    Seq result = update;
179
 
    set<string> removed(remove.begin(), remove.end());
180
 
    for(typename Seq::const_iterator p = seq.begin(); p != seq.end(); ++p)
181
 
    {
182
 
        if(removed.find(func(*p)) == removed.end())
183
 
        {
184
 
            typename Seq::const_iterator q = update.begin();
185
 
            for(; q != update.end(); ++q)
186
 
            {
187
 
                if(func(*p) == func(*q))
188
 
                {
189
 
                    break;
190
 
                }
191
 
            }
192
 
            if(q == update.end())
193
 
            {
194
 
                result.push_back(*p);
195
 
            }
196
 
        }
197
 
    }
198
 
    return result;
199
 
}
200
 
 
201
 
template<typename Dict> Dict
202
 
getDictUpdatedElts(const Dict& ldict, const Dict& rdict)
203
 
{
204
 
#if defined(_MSC_VER) && (_MSC_VER < 1300)
205
 
    return getDictUpdatedEltsWithEq(ldict, rdict, equal_to<Dict::mapped_type>());
206
 
#else
207
 
    return getDictUpdatedEltsWithEq(ldict, rdict, equal_to<typename Dict::mapped_type>());
208
 
#endif
209
 
}
210
 
 
211
 
template<typename EqFunc, typename Dict> Dict
212
 
getDictUpdatedEltsWithEq(const Dict& ldict, const Dict& rdict, EqFunc eq)
213
 
{
214
 
    Dict result;
215
 
    for(typename Dict::const_iterator p = rdict.begin(); p != rdict.end(); ++p)
216
 
    {
217
 
        typename Dict::const_iterator q = ldict.find(p->first);
218
 
        if(q == ldict.end() || !eq(p->second, q->second))
219
 
        {
220
 
            result.insert(*p);
221
 
        }
222
 
    }
223
 
    return result;
224
 
}
225
 
 
226
 
template <typename Dict> Ice::StringSeq
227
 
getDictRemovedElts(const Dict& ldict, const Dict& rdict)
228
 
{
229
 
    Ice::StringSeq removed;
230
 
    for(typename Dict::const_iterator p = ldict.begin(); p != ldict.end(); ++p)
231
 
    {
232
 
        if(rdict.find(p->first) == rdict.end())
233
 
        {
234
 
            removed.push_back(p->first);
235
 
        }
236
 
    }
237
 
    return removed;
238
 
}
239
 
 
240
 
template <typename Dict> Dict
241
 
updateDictElts(const Dict& dict, const Dict& update, const Ice::StringSeq& remove)
242
 
{
243
 
    Dict result = dict;
244
 
    for(Ice::StringSeq::const_iterator p = remove.begin(); p != remove.end(); ++p)
245
 
    {
246
 
        result.erase(*p);
247
 
    }
248
 
    for(typename Dict::const_iterator q = update.begin(); q != update.end(); ++q)
249
 
    {
250
 
        result[q->first] = q->second;
251
 
    }
252
 
    return result;
253
 
}
254
 
 
255
 
}
256
 
 
257
 
Resolver::Resolver(const ApplicationDescriptor& app, const Ice::CommunicatorPtr& communicator, bool enableWarning) : 
258
 
    _application(&app),
259
 
    _communicator(communicator),
260
 
    _escape(false),
261
 
    _enableWarning(enableWarning),
262
 
    _context("application `" + app.name + "'"),
263
 
    _variables(app.variables),
264
 
    _reserved(getReserved()),
265
 
    _version(0)
266
 
{
267
 
    //
268
 
    // Make sure the variables don't override reserved variables.
269
 
    //
270
 
    checkReserved("variable", _variables);
271
 
    setReserved("application", app.name);
272
 
 
273
 
    //
274
 
    // Some reserved variables which are ignored for now and will be
275
 
    // substituted later.
276
 
    //
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");
283
 
 
284
 
    for(StringStringDict::const_iterator v = _variables.begin(); v != _variables.end(); ++v)
285
 
    {
286
 
        if(v->first == "")
287
 
        {
288
 
            exception("empty variable name");
289
 
        }
290
 
    }
291
 
 
292
 
    TemplateDescriptorDict::const_iterator t;
293
 
    for(t = _application->serverTemplates.begin(); t != _application->serverTemplates.end(); ++t)
294
 
    {
295
 
        if(t->first == "")
296
 
        {
297
 
            exception("empty server template id");
298
 
        }
299
 
        if(!t->second.descriptor)
300
 
        {
301
 
            exception("invalid server template `" + t->first + "': server definition is empty");
302
 
        }
303
 
 
304
 
        Ice::StringSeq params = t->second.parameters;
305
 
        sort(params.begin(), params.end());
306
 
        Ice::StringSeq wdups = params;
307
 
        Ice::StringSeq dups;
308
 
        set_difference(wdups.begin(), wdups.end(), params.begin(), unique(params.begin(), params.end()), 
309
 
                       back_inserter(dups));
310
 
        if(!dups.empty())
311
 
        {
312
 
            dups.erase(unique(dups.begin(), dups.end()), dups.end());
313
 
            exception("invalid server template `" + t->first + "': duplicate parameters " + toString(dups));
314
 
        }
315
 
    }
316
 
    for(t = _application->serviceTemplates.begin(); t != _application->serviceTemplates.end(); ++t)
317
 
    {
318
 
        if(t->first == "")
319
 
        {
320
 
            exception("empty service template id");
321
 
        }
322
 
        if(!t->second.descriptor)
323
 
        {
324
 
            exception("invalid service template `" + t->first + "': service definition is empty");
325
 
        }
326
 
        Ice::StringSeq params = t->second.parameters;
327
 
        sort(params.begin(), params.end());
328
 
        Ice::StringSeq wdups = params;
329
 
        Ice::StringSeq dups;
330
 
        set_difference(wdups.begin(), wdups.end(), params.begin(), unique(params.begin(), params.end()), 
331
 
                       back_inserter(dups));
332
 
        if(!dups.empty())
333
 
        {
334
 
            dups.erase(unique(dups.begin(), dups.end()), dups.end());
335
 
            exception("invalid server template `" + t->first + "': duplicate parameters " + toString(dups));
336
 
        }
337
 
    }
338
 
}
339
 
 
340
 
Resolver::Resolver(const Resolver& resolve, 
341
 
                   const map<string, string>& values, 
342
 
                   bool params) :
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)
354
 
{
355
 
    if(params)
356
 
    {
357
 
        checkReserved("parameter", values);
358
 
    }
359
 
    else
360
 
    {
361
 
        _variables.insert(resolve._variables.begin(), resolve._variables.end());
362
 
        checkReserved("variable", values);
363
 
    }
364
 
 
365
 
    for(StringStringDict::const_iterator v = _variables.begin(); v != _variables.end(); ++v)
366
 
    {
367
 
        if(v->first == "")
368
 
        {
369
 
            exception("empty variable name");
370
 
        }
371
 
    }
372
 
}
373
 
 
374
 
Resolver::Resolver(const InternalNodeInfoPtr& info, const Ice::CommunicatorPtr& com) :
375
 
    _application(0),
376
 
    _communicator(com),
377
 
    _escape(true),
378
 
    _enableWarning(false),
379
 
    _context("node `" + info->name + "'"),
380
 
    _reserved(getReserved()),
381
 
    _version(0)
382
 
{
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);
390
 
}
391
 
 
392
 
string 
393
 
Resolver::operator()(const string& value, const string& name, bool allowEmpty) const
394
 
{
395
 
    try
396
 
    {
397
 
        string val;
398
 
        try
399
 
        {
400
 
            val = substitute(value, true, true);
401
 
        }
402
 
        catch(const string& reason)
403
 
        {
404
 
            throw "invalid variable `" + value + "':\n " + reason;
405
 
        }
406
 
        catch(const char* reason)
407
 
        {
408
 
            throw "invalid variable `" + value + "':\n " + reason;
409
 
        }
410
 
 
411
 
        if(!allowEmpty)
412
 
        {
413
 
            if(value.empty())
414
 
            {
415
 
                throw "empty string";
416
 
            }
417
 
            else if(val.empty())
418
 
            {
419
 
                throw "the value of `" + value + "' is an empty string";
420
 
            }
421
 
        }
422
 
        return val;
423
 
    }
424
 
    catch(const string& reason)
425
 
    {
426
 
        exception("invalid value for attribute `" + name + "':\n" + reason);
427
 
    }
428
 
    catch(const char* reason)
429
 
    {
430
 
        exception("invalid value for attribute `" + name + "':\n" + reason);
431
 
    }
432
 
    return ""; // To prevent compiler warning.
433
 
}
434
 
 
435
 
Ice::StringSeq
436
 
Resolver::operator()(const Ice::StringSeq& values, const string& name) const
437
 
{
438
 
    Ice::StringSeq result;
439
 
    for(Ice::StringSeq::const_iterator p = values.begin(); p != values.end(); ++p)
440
 
    {
441
 
        result.push_back(operator()(*p, name));
442
 
    }
443
 
    return result;
444
 
}
445
 
 
446
 
DistributionDescriptor
447
 
Resolver::operator()(const DistributionDescriptor& desc) const
448
 
{
449
 
    DistributionDescriptor result;
450
 
    result.icepatch = operator()(desc.icepatch, "IcePatch2 server proxy");
451
 
    result.directories = operator()(desc.directories, "distribution source directory");
452
 
    return result;
453
 
}
454
 
 
455
 
PropertyDescriptorSeq
456
 
Resolver::operator()(const PropertyDescriptorSeq& properties, const string& name) const 
457
 
{
458
 
    PropertyDescriptorSeq result;
459
 
    for(PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q)
460
 
    {
461
 
        PropertyDescriptor prop;
462
 
        prop.name = operator()(q->name, name + " name");
463
 
        prop.value = operator()(q->value, name + " value");
464
 
        result.push_back(prop);
465
 
    }
466
 
    return result;
467
 
}
468
 
 
469
 
PropertySetDescriptorDict
470
 
Resolver::operator()(const PropertySetDescriptorDict& propertySets) const
471
 
{
472
 
    PropertySetDescriptorDict result;
473
 
    PropertySetDescriptorDict::const_iterator ps;
474
 
    for(ps = propertySets.begin(); ps != propertySets.end(); ++ps)
475
 
    {
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));
480
 
    }
481
 
    return result;
482
 
}
483
 
 
484
 
ObjectDescriptorSeq
485
 
Resolver::operator()(const ObjectDescriptorSeq& objects, const string& type) const
486
 
{
487
 
    ObjectDescriptorSeq result;
488
 
    for(ObjectDescriptorSeq::const_iterator q = objects.begin(); q != objects.end(); ++q)
489
 
    {
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);
494
 
    }
495
 
    return result;
496
 
}
497
 
 
498
 
Ice::Identity
499
 
Resolver::operator()(const Ice::Identity& value, const string& name) const
500
 
{
501
 
    assert(_communicator);
502
 
    string str = asId(_communicator->identityToString(value), name, false);
503
 
    Ice::Identity id = _communicator->stringToIdentity(str);
504
 
    if(id.name.empty())
505
 
    {
506
 
        exception("invalid object identity `" + _communicator->identityToString(value) + "': name empty");
507
 
    }
508
 
    return id;
509
 
}
510
 
 
511
 
PropertySetDescriptor
512
 
Resolver::operator()(const PropertySetDescriptor& desc) const
513
 
{
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());
518
 
    return result;
519
 
}
520
 
 
521
 
string
522
 
Resolver::asInt(const string& value, const string& name) const
523
 
{
524
 
    string v = operator()(value, name);
525
 
    if(!v.empty())
526
 
    {
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);
530
 
 
531
 
        int val;
532
 
        istringstream is(v);
533
 
        if(!(is >> val) || !is.eof())
534
 
        {
535
 
            exception("invalid value `" + value + "' for `" + name + "':\nnot an integer");
536
 
        }
537
 
 
538
 
        ostringstream os;
539
 
        os << val;
540
 
        v = os.str();
541
 
    }
542
 
    return v;
543
 
}
544
 
 
545
 
string
546
 
Resolver::asFloat(const string& value, const string& name) const
547
 
{
548
 
    string v = operator()(value, name);
549
 
    if(!v.empty())
550
 
    {
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);
554
 
 
555
 
        float val;
556
 
        istringstream is(v);
557
 
        if(!(is >> val) || !is.eof())
558
 
        {
559
 
            exception("invalid value `" + value + "' for `" + name + "':\nnot a float");
560
 
        }
561
 
    }
562
 
    return v;
563
 
}
564
 
 
565
 
string
566
 
Resolver::asId(const string& value, const string& name, bool allowEmpty) const
567
 
{
568
 
    try
569
 
    {
570
 
        if(!allowEmpty && value.empty())
571
 
        {
572
 
            throw "empty string";
573
 
        }
574
 
 
575
 
        string val;
576
 
        try
577
 
        {
578
 
            val = substitute(value, true, false);
579
 
        }
580
 
        catch(const string& reason)
581
 
        {
582
 
            throw "invalid variable `" + value + "':\n" + reason;
583
 
        }
584
 
        catch(const char* reason)
585
 
        {
586
 
            throw "invalid variable `" + value + "':\n" + reason;
587
 
        }
588
 
 
589
 
        if(!allowEmpty && val.empty())
590
 
        {
591
 
            throw "the value of `" + value + "' is an empty string";
592
 
        }
593
 
        return val;
594
 
    }
595
 
    catch(const string& reason)
596
 
    {
597
 
        exception("invalid value for attribute `" + name + "':\n" + reason);
598
 
    }
599
 
    catch(const char* reason)
600
 
    {
601
 
        exception("invalid value for attribute `" + name + "':\n" + reason);
602
 
    }
603
 
    return ""; // To prevent compiler warning.
604
 
}
605
 
 
606
 
void
607
 
Resolver::setReserved(const string& name, const string& value)
608
 
{
609
 
    assert(_reserved.find(name) != _reserved.end());
610
 
    _reserved[name] = value;
611
 
}    
612
 
 
613
 
void
614
 
Resolver::setContext(const string& context)
615
 
{
616
 
    try
617
 
    {
618
 
        _context = substitute(context, true, true);
619
 
    }
620
 
    catch(const string& reason)
621
 
    {
622
 
        exception(reason);
623
 
    }
624
 
    catch(const char* reason)
625
 
    {
626
 
        exception(reason);
627
 
    }
628
 
}
629
 
 
630
 
void
631
 
Resolver::addPropertySets(const PropertySetDescriptorDict& propertySets)
632
 
{
633
 
    PropertySetDescriptorDict oldPropertySets;
634
 
    oldPropertySets.swap(_propertySets);
635
 
    PropertySetDescriptorDict::const_iterator p;
636
 
    for(p = propertySets.begin(); p != propertySets.end(); ++p)
637
 
    {
638
 
        if(!_propertySets.insert(*p).second)
639
 
        {
640
 
            exception("property set with id `" + p->first + "' is already defined at this scope");
641
 
        }
642
 
    }
643
 
    _propertySets.insert(oldPropertySets.begin(), oldPropertySets.end());
644
 
 
645
 
    //
646
 
    // Validate the new property set references.
647
 
    //
648
 
    for(p = propertySets.begin(); p != propertySets.end(); ++p)
649
 
    {
650
 
        getProperties(p->second.references);
651
 
    }
652
 
}
653
 
 
654
 
const PropertySetDescriptor&
655
 
Resolver::getPropertySet(const string& id) const
656
 
{
657
 
    PropertySetDescriptorDict::const_iterator p = _propertySets.find(id);
658
 
    if(p == _propertySets.end())
659
 
    {
660
 
        exception("invalid reference to property set, property set `" + id + "' doesn't exist");
661
 
    }
662
 
    return p->second;
663
 
}
664
 
 
665
 
PropertyDescriptorSeq
666
 
Resolver::getProperties(const Ice::StringSeq& references) const
667
 
{
668
 
    set<string> resolved;
669
 
    return getProperties(references, resolved);
670
 
}
671
 
 
672
 
void
673
 
Resolver::addIgnored(const string& name)
674
 
{
675
 
    _ignore.insert(name);
676
 
}
677
 
 
678
 
void
679
 
Resolver::setVersion(const string& version)
680
 
{
681
 
    string v = operator()(version, "ice version");
682
 
    if(!v.empty())
683
 
    {
684
 
        _version = getMMVersion(v);
685
 
        if(_version < 0)
686
 
        {
687
 
            exception("invalid ice version: " + v);
688
 
        }
689
 
        else if(_version > ICE_INT_VERSION && warningEnabled())
690
 
        {
691
 
            Ice::Warning out(_communicator->getLogger());
692
 
            out << "invalid ice version: " << _version << " is superior to the IceGrid ";
693
 
            out << "registry version (" << ICE_STRING_VERSION << ")";
694
 
        }
695
 
    }
696
 
}
697
 
 
698
 
int
699
 
Resolver::getVersion() const
700
 
{
701
 
    return _version;
702
 
}
703
 
 
704
 
void
705
 
Resolver::exception(const string& reason) const
706
 
{
707
 
    throw DeploymentException(_context + ":\n" + reason);
708
 
}
709
 
 
710
 
TemplateDescriptor
711
 
Resolver::getServerTemplate(const string& tmpl) const
712
 
{
713
 
    assert(_application);
714
 
    TemplateDescriptorDict::const_iterator p = _application->serverTemplates.find(tmpl);
715
 
    if(p == _application->serverTemplates.end())
716
 
    {
717
 
        throw DeploymentException("unknown server template `" + tmpl + "'");
718
 
    }
719
 
    return p->second;
720
 
}
721
 
 
722
 
TemplateDescriptor
723
 
Resolver::getServiceTemplate(const string& tmpl) const
724
 
{
725
 
    assert(_application);
726
 
    TemplateDescriptorDict::const_iterator p = _application->serviceTemplates.find(tmpl);
727
 
    if(p == _application->serviceTemplates.end())
728
 
    {
729
 
        throw DeploymentException("unknown service template `" + tmpl + "'");
730
 
    }
731
 
    return p->second;
732
 
}
733
 
 
734
 
bool
735
 
Resolver::hasReplicaGroup(const string& id) const
736
 
{
737
 
    if(!_application)
738
 
    {
739
 
        //
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.
745
 
        //
746
 
        return true;
747
 
    }
748
 
    ReplicaGroupDescriptorSeq::const_iterator p;
749
 
    for(p = _application->replicaGroups.begin(); p != _application->replicaGroups.end(); ++p)
750
 
    {
751
 
        if(p->id == id)
752
 
        {
753
 
            return true;
754
 
        }
755
 
    } 
756
 
    return false;
757
 
}
758
 
 
759
 
string
760
 
Resolver::substitute(const string& v, bool useParams, bool useIgnored) const
761
 
{
762
 
    string value(v);
763
 
    string::size_type beg = 0;
764
 
    string::size_type end = 0;
765
 
 
766
 
    while((beg = value.find("${", beg)) != string::npos)
767
 
    {
768
 
        if(beg > 0 && value[beg - 1] == '$')
769
 
        {
770
 
            string::size_type escape = beg - 1;
771
 
            while(escape > 0 && value[escape - 1] == '$')
772
 
            {
773
 
                --escape;
774
 
            }
775
 
            
776
 
            if((beg - escape) % 2)
777
 
            {
778
 
                if(_escape)
779
 
                {
780
 
                    value.replace(escape, beg - escape, (beg - escape) / 2, '$');                   
781
 
                }
782
 
                ++beg;
783
 
                continue;
784
 
            }
785
 
            else
786
 
            {
787
 
                value.replace(escape, beg - escape, (beg - escape) / 2, '$');
788
 
                beg -= (beg - escape) / 2;
789
 
            }
790
 
        }
791
 
 
792
 
        end = value.find("}", beg);
793
 
        if(end == string::npos)
794
 
        {
795
 
            throw "malformed variable name `" + value + "'";
796
 
        }
797
 
 
798
 
        //
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
804
 
        // of definition.
805
 
        //
806
 
        string name = value.substr(beg + 2, end - beg - 2);
807
 
        if(_ignore.find(name) != _ignore.end())
808
 
        {
809
 
            if(useIgnored)
810
 
            {
811
 
                ++beg;
812
 
                continue;
813
 
            }
814
 
            else
815
 
            {
816
 
                throw "use of the `" + name + "' variable is now allowed here";
817
 
            }
818
 
        }
819
 
 
820
 
        bool param;
821
 
        string val = getVariable(name, useParams, param);
822
 
        if(!param)
823
 
        {
824
 
            val = substitute(val, false, useIgnored); // Recursive resolution
825
 
        }
826
 
        value.replace(beg, end - beg + 1, val);
827
 
        beg += val.length();
828
 
    }
829
 
    return value;
830
 
}
831
 
 
832
 
string
833
 
Resolver::getVariable(const string& name, bool checkParams, bool& param) const
834
 
{
835
 
    //
836
 
    // We first check the reserved variables, then the parameters if
837
 
    // necessary and finally the variables.
838
 
    //
839
 
    param = false;
840
 
    map<string, string>::const_iterator p = _reserved.find(name);
841
 
    if(p != _reserved.end())
842
 
    {
843
 
        if(p->second.empty())
844
 
        {
845
 
            throw "undefined variable `" + name + "'";
846
 
        }
847
 
        return p->second;
848
 
    }
849
 
    if(checkParams)
850
 
    {
851
 
        p = _parameters.find(name);
852
 
        if(p != _parameters.end())
853
 
        {
854
 
            param = true;
855
 
            return p->second;
856
 
        }
857
 
    }
858
 
    p = _variables.find(name);
859
 
    if(p != _variables.end())
860
 
    {
861
 
        return p->second;
862
 
    }    
863
 
 
864
 
    throw "undefined variable `" + name + "'";
865
 
    return ""; // To keep the compiler happy.
866
 
}
867
 
 
868
 
PropertyDescriptorSeq
869
 
Resolver::getProperties(const Ice::StringSeq& references, set<string>& resolved) const
870
 
{
871
 
    PropertyDescriptorSeq properties;
872
 
    for(Ice::StringSeq::const_iterator p = references.begin(); p != references.end(); ++p)
873
 
    {
874
 
        if(resolved.find(*p) != resolved.end())
875
 
        {
876
 
            exception("detected circular dependency with property reference `" + *p + "'");
877
 
        }
878
 
 
879
 
        PropertySetDescriptor desc = getPropertySet(*p);
880
 
        if(!desc.references.empty())
881
 
        {
882
 
            resolved.insert(*p);
883
 
            PropertyDescriptorSeq p = getProperties(desc.references, resolved);
884
 
            properties.insert(properties.end(), p.begin(), p.end());
885
 
        }
886
 
        
887
 
        PropertyDescriptorSeq pds = operator()(desc.properties);
888
 
        properties.insert(properties.end(), pds.begin(), pds.end());
889
 
    }
890
 
    return properties;
891
 
}
892
 
 
893
 
map<string, string>
894
 
Resolver::getReserved()
895
 
{
896
 
    //
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))
900
 
    //
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"] = "";
915
 
    return reserved;
916
 
}
917
 
 
918
 
void
919
 
Resolver::checkReserved(const string& type, const map<string, string>& values) const
920
 
{
921
 
    for(map<string, string>::const_iterator p = values.begin(); p != values.end(); ++p)
922
 
    {
923
 
        if(_reserved.find(p->first) != _reserved.end())
924
 
        {
925
 
            exception("invalid " + type + " `" + p->first + "': reserved variable name");
926
 
        }
927
 
    }
928
 
}
929
 
 
930
 
CommunicatorHelper::CommunicatorHelper(const CommunicatorDescriptorPtr& desc) : 
931
 
    _desc(desc)
932
 
{
933
 
}
934
 
 
935
 
bool 
936
 
CommunicatorHelper::operator==(const CommunicatorHelper& helper) const
937
 
{
938
 
    if(_desc->ice_id() != helper._desc->ice_id())
939
 
    {
940
 
        return false;
941
 
    }
942
 
 
943
 
    if(_desc->description != helper._desc->description)
944
 
    {
945
 
        return false;
946
 
    }
947
 
 
948
 
    if(set<AdapterDescriptor>(_desc->adapters.begin(), _desc->adapters.end())  != 
949
 
       set<AdapterDescriptor>(helper._desc->adapters.begin(), helper._desc->adapters.end()))
950
 
    {
951
 
        return false;
952
 
    }
953
 
 
954
 
    if(_desc->propertySet != helper._desc->propertySet)
955
 
    {
956
 
        return false;
957
 
    }
958
 
 
959
 
    if(set<DbEnvDescriptor>(_desc->dbEnvs.begin(), _desc->dbEnvs.end()) != 
960
 
       set<DbEnvDescriptor>(helper._desc->dbEnvs.begin(), helper._desc->dbEnvs.end()))
961
 
    {
962
 
        return false;
963
 
    }
964
 
 
965
 
    if(_desc->logs != helper._desc->logs)
966
 
    {
967
 
        return false;
968
 
    }
969
 
 
970
 
    return true;
971
 
}
972
 
 
973
 
bool
974
 
CommunicatorHelper::operator!=(const CommunicatorHelper& helper) const
975
 
{
976
 
    return !operator==(helper);
977
 
}
978
 
 
979
 
void 
980
 
CommunicatorHelper::getIds(multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
981
 
{
982
 
    for(AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p)
983
 
    {   
984
 
        if(!p->id.empty())
985
 
        {
986
 
            adapterIds.insert(p->id);
987
 
        }
988
 
 
989
 
        set<Ice::Identity> ids;
990
 
        ObjectDescriptorSeq::const_iterator q;
991
 
        for(q = p->objects.begin(); q != p->objects.end(); ++q)
992
 
        {
993
 
            ids.insert(q->id);
994
 
            objectIds.insert(q->id);
995
 
        }
996
 
        for(q = p->allocatables.begin(); q != p->allocatables.end(); ++q)
997
 
        {
998
 
             if(ids.find(q->id) == ids.end())
999
 
             {
1000
 
                 objectIds.insert(q->id);
1001
 
             }
1002
 
             else
1003
 
             {
1004
 
                 ids.erase(q->id);
1005
 
             }
1006
 
        }
1007
 
    }
1008
 
}
1009
 
 
1010
 
void 
1011
 
CommunicatorHelper::getReplicaGroups(set<string>& replicaGroups) const
1012
 
{
1013
 
    for(AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p)
1014
 
    {
1015
 
        if(!p->replicaGroupId.empty())
1016
 
        {
1017
 
            replicaGroups.insert(p->replicaGroupId);
1018
 
        }
1019
 
    }
1020
 
}
1021
 
 
1022
 
void
1023
 
CommunicatorHelper::instantiateImpl(const CommunicatorDescriptorPtr& instance, const Resolver& resolve) const
1024
 
{
1025
 
    instance->description = resolve(_desc->description, "description");
1026
 
    instance->propertySet = resolve(_desc->propertySet);
1027
 
 
1028
 
    for(AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p)
1029
 
    {
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);
1037
 
 
1038
 
        //
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.
1043
 
        //
1044
 
        //if(!adapter.replicaGroupId.empty() && !resolve.hasReplicaGroup(adapter.replicaGroupId))
1045
 
        //{
1046
 
        //resolve.exception("unknown replica group `" + adapter.replicaGroupId + "'");
1047
 
        //}
1048
 
 
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);
1053
 
 
1054
 
        //
1055
 
        // Make sure the endpoints are defined.
1056
 
        //
1057
 
        if(IceGrid::getProperty(instance->propertySet.properties, adapter.name + ".Endpoints").empty())
1058
 
        {
1059
 
            resolve.exception("invalid endpoints for adapter `" + adapter.name + "': empty string");
1060
 
        }
1061
 
    }
1062
 
 
1063
 
    for(DbEnvDescriptorSeq::const_iterator s = _desc->dbEnvs.begin(); s != _desc->dbEnvs.end(); ++s)
1064
 
    {
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);
1071
 
    }
1072
 
 
1073
 
    for(Ice::StringSeq::const_iterator l = _desc->logs.begin(); l != _desc->logs.end(); ++l)
1074
 
    {
1075
 
        instance->logs.push_back(resolve(*l, "log path", false));
1076
 
    }
1077
 
}
1078
 
 
1079
 
void
1080
 
CommunicatorHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1081
 
{
1082
 
    if(!_desc->description.empty())
1083
 
    {
1084
 
        out << nl << "description";
1085
 
        out << sb;
1086
 
        out << nl << _desc->description;
1087
 
        out << eb;
1088
 
    }
1089
 
    set<string> hiddenProperties;
1090
 
    {
1091
 
        for(DbEnvDescriptorSeq::const_iterator p = _desc->dbEnvs.begin(); p != _desc->dbEnvs.end(); ++p)
1092
 
        {
1093
 
            printDbEnv(out, *p);
1094
 
        }
1095
 
    }
1096
 
    {
1097
 
        for(AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p)
1098
 
        {
1099
 
            hiddenProperties.insert(p->name + ".Endpoints");
1100
 
            printObjectAdapter(communicator, out, *p);
1101
 
        }
1102
 
    }
1103
 
    {
1104
 
        for(Ice::StringSeq::const_iterator p = _desc->logs.begin(); p != _desc->logs.end(); ++p)
1105
 
        {
1106
 
            out << nl << "log `" << *p << "'";
1107
 
        }
1108
 
    }
1109
 
    if(!_desc->propertySet.properties.empty() || !_desc->propertySet.references.empty())
1110
 
    {
1111
 
        out << nl << "properties";
1112
 
        out << sb;
1113
 
        if(!_desc->propertySet.references.empty())
1114
 
        {
1115
 
            out << nl << "references = " << toString(_desc->propertySet.references);
1116
 
        }
1117
 
        PropertyDescriptorSeq::const_iterator q;
1118
 
        for(q = _desc->propertySet.properties.begin(); q != _desc->propertySet.properties.end(); ++q)
1119
 
        {
1120
 
            if(hiddenProperties.find(q->name) == hiddenProperties.end())
1121
 
            {
1122
 
                out << nl << q->name << " = `" << q->value << "'";
1123
 
            }
1124
 
        }
1125
 
        out << eb;
1126
 
    }
1127
 
}
1128
 
 
1129
 
void 
1130
 
CommunicatorHelper::printDbEnv(Output& out, const DbEnvDescriptor& dbEnv) const
1131
 
{
1132
 
    out << nl << "database environment `" << dbEnv.name << "'";
1133
 
    if(!dbEnv.dbHome.empty() || !dbEnv.properties.empty() || !dbEnv.description.empty())
1134
 
    {
1135
 
        out << sb;
1136
 
        if(!dbEnv.dbHome.empty())
1137
 
        {
1138
 
            out << nl << "home = `" << dbEnv.dbHome << "'";
1139
 
        }
1140
 
        if(!dbEnv.description.empty())
1141
 
        {
1142
 
            out << nl << "description = `" << dbEnv.description << "'";
1143
 
        }
1144
 
        if(!dbEnv.properties.empty())
1145
 
        {
1146
 
            out << nl << "properties";
1147
 
            out << sb;
1148
 
            for(PropertyDescriptorSeq::const_iterator p = dbEnv.properties.begin(); p != dbEnv.properties.end(); ++p)
1149
 
            {
1150
 
                out << nl << p->name << " = `" << p->value << "'";
1151
 
            }
1152
 
            out << eb;
1153
 
        }
1154
 
        out << eb;
1155
 
    }
1156
 
}
1157
 
 
1158
 
void
1159
 
CommunicatorHelper::printObjectAdapter(const Ice::CommunicatorPtr& communicator,
1160
 
                                       Output& out, 
1161
 
                                       const AdapterDescriptor& adapter) const
1162
 
{
1163
 
    out << nl << "adapter `" << adapter.name << "'";
1164
 
    out << sb;
1165
 
    if(!adapter.id.empty())
1166
 
    {
1167
 
        out << nl << "id = `" << adapter.id << "'";
1168
 
    }
1169
 
    if(!adapter.replicaGroupId.empty())
1170
 
    {
1171
 
        out << nl << "replica group id = `" << adapter.replicaGroupId << "'";
1172
 
    }
1173
 
    if(!adapter.priority.empty())
1174
 
    {
1175
 
        out << nl << "priority = `" << adapter.priority << "'";
1176
 
    }
1177
 
 
1178
 
    string endpoints = getProperty(adapter.name + ".Endpoints");
1179
 
    if(!endpoints.empty())
1180
 
    {
1181
 
        out << nl << "endpoints = `" << endpoints << "'";
1182
 
    }
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)
1187
 
    {
1188
 
        out << nl << "well-known object";
1189
 
        out << sb;
1190
 
        out << nl << "identity = `" << communicator->identityToString(p->id) << "' ";
1191
 
        if(!p->type.empty())
1192
 
        {
1193
 
            out << nl << "type = `" << p->type << "'";
1194
 
        }
1195
 
        out << eb;
1196
 
    }
1197
 
    for(p = adapter.allocatables.begin(); p != adapter.allocatables.end(); ++p)
1198
 
    {
1199
 
        out << nl << "allocatable";
1200
 
        out << sb;
1201
 
        out << nl << "identity = `" << communicator->identityToString(p->id) << "' ";
1202
 
        if(!p->type.empty())
1203
 
        {
1204
 
            out << nl << "type = `" << p->type << "'";
1205
 
        }
1206
 
        out << eb;
1207
 
    }
1208
 
    if(!adapter.description.empty())
1209
 
    {
1210
 
        out << nl << "description = `" << adapter.description << "'";
1211
 
    }
1212
 
    out << eb;
1213
 
}
1214
 
 
1215
 
string
1216
 
CommunicatorHelper::getProperty(const string& name) const
1217
 
{
1218
 
    return IceGrid::getProperty(_desc->propertySet.properties, name);
1219
 
}
1220
 
 
1221
 
ServiceHelper::ServiceHelper(const ServiceDescriptorPtr& descriptor) :
1222
 
    CommunicatorHelper(descriptor),
1223
 
    _desc(descriptor)
1224
 
{
1225
 
}
1226
 
 
1227
 
bool 
1228
 
ServiceHelper::operator==(const CommunicatorHelper& h) const
1229
 
{
1230
 
    const ServiceHelper* helper = dynamic_cast<const ServiceHelper*>(&h);
1231
 
    if(!helper || !CommunicatorHelper::operator==(h))
1232
 
    {
1233
 
        return false;
1234
 
    }
1235
 
 
1236
 
    if(_desc->name != helper->_desc->name)
1237
 
    {
1238
 
        return false;
1239
 
    }
1240
 
 
1241
 
    if(_desc->entry != helper->_desc->entry)
1242
 
    {
1243
 
        return false;
1244
 
    }
1245
 
 
1246
 
    return true;
1247
 
}
1248
 
 
1249
 
bool
1250
 
ServiceHelper::operator!=(const CommunicatorHelper& helper) const
1251
 
{
1252
 
    return !operator==(helper);
1253
 
}
1254
 
 
1255
 
ServiceDescriptorPtr
1256
 
ServiceHelper::getDescriptor() const
1257
 
{
1258
 
    return _desc;
1259
 
}
1260
 
 
1261
 
ServiceDescriptorPtr
1262
 
ServiceHelper::instantiate(const Resolver& resolver, const PropertyDescriptorSeq& props, 
1263
 
                           const PropertySetDescriptorDict& serviceProps) const
1264
 
{
1265
 
    ServiceDescriptorPtr service = new ServiceDescriptor();
1266
 
    instantiateImpl(service, resolver, props, serviceProps);
1267
 
    return service;
1268
 
}
1269
 
 
1270
 
void
1271
 
ServiceHelper::instantiateImpl(const ServiceDescriptorPtr& instance, 
1272
 
                               const Resolver& resolve, 
1273
 
                               const PropertyDescriptorSeq& props,
1274
 
                               const PropertySetDescriptorDict& serviceProps) const
1275
 
{
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())
1282
 
    {
1283
 
        instance->propertySet.properties.insert(instance->propertySet.properties.end(), 
1284
 
                                                p->second.properties.begin(),
1285
 
                                                p->second.properties.end());
1286
 
    }
1287
 
}
1288
 
 
1289
 
void
1290
 
ServiceHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1291
 
{
1292
 
    out << "service `" + _desc->name + "'";
1293
 
    out << sb;
1294
 
    out << nl << "entry = `" << _desc->entry << "'";
1295
 
    CommunicatorHelper::print(communicator, out);
1296
 
    out << eb;
1297
 
}
1298
 
 
1299
 
ServerHelper::ServerHelper(const ServerDescriptorPtr& descriptor) :
1300
 
    CommunicatorHelper(descriptor),
1301
 
    _desc(descriptor)
1302
 
{
1303
 
}
1304
 
 
1305
 
bool 
1306
 
ServerHelper::operator==(const CommunicatorHelper& h) const
1307
 
{
1308
 
    const ServerHelper* helper = dynamic_cast<const ServerHelper*>(&h);
1309
 
    if(!helper || !CommunicatorHelper::operator==(h))
1310
 
    {
1311
 
        return false;
1312
 
    }
1313
 
 
1314
 
    if(_desc->id != helper->_desc->id)
1315
 
    {
1316
 
        return false;
1317
 
    }
1318
 
 
1319
 
    if(_desc->exe != helper->_desc->exe)
1320
 
    {
1321
 
        return false;
1322
 
    }
1323
 
 
1324
 
    if(_desc->iceVersion != helper->_desc->iceVersion)
1325
 
    {
1326
 
        return false;
1327
 
    }
1328
 
 
1329
 
    if(_desc->pwd != helper->_desc->pwd)
1330
 
    {
1331
 
        return false;
1332
 
    }
1333
 
 
1334
 
    if(set<string>(_desc->options.begin(), _desc->options.end()) != 
1335
 
       set<string>(helper->_desc->options.begin(), helper->_desc->options.end()))
1336
 
    {
1337
 
        return false;
1338
 
    }
1339
 
 
1340
 
    if(set<string>(_desc->envs.begin(), _desc->envs.end()) != 
1341
 
       set<string>(helper->_desc->envs.begin(), helper->_desc->envs.end()))
1342
 
    {
1343
 
        return false;
1344
 
    }
1345
 
 
1346
 
    if(_desc->activation != helper->_desc->activation)
1347
 
    {
1348
 
        return false;
1349
 
    }
1350
 
 
1351
 
    if(_desc->activationTimeout != helper->_desc->activationTimeout)
1352
 
    {
1353
 
        return false;
1354
 
    }
1355
 
 
1356
 
    if(_desc->deactivationTimeout != helper->_desc->deactivationTimeout)
1357
 
    {
1358
 
        return false;
1359
 
    }
1360
 
 
1361
 
    if(_desc->distrib != helper->_desc->distrib)
1362
 
    {
1363
 
        return false;
1364
 
    }
1365
 
 
1366
 
    if(_desc->allocatable != helper->_desc->allocatable)
1367
 
    {
1368
 
        return false;
1369
 
    }
1370
 
 
1371
 
    if(_desc->user != helper->_desc->user)
1372
 
    {
1373
 
        return false;
1374
 
    }
1375
 
 
1376
 
    return true;
1377
 
}
1378
 
 
1379
 
bool
1380
 
ServerHelper::operator!=(const CommunicatorHelper& helper) const
1381
 
{
1382
 
    return !operator==(helper);
1383
 
}
1384
 
 
1385
 
ServerDescriptorPtr
1386
 
ServerHelper::getDescriptor() const
1387
 
{
1388
 
    return _desc;
1389
 
}
1390
 
 
1391
 
ServerDescriptorPtr
1392
 
ServerHelper::instantiate(const Resolver& resolver,
1393
 
                          const PropertyDescriptorSeq& props, 
1394
 
                          const PropertySetDescriptorDict& serviceProps) const
1395
 
{
1396
 
    if(!serviceProps.empty())
1397
 
    {
1398
 
        resolver.exception("service property sets are only allowed in IceBox server instances");
1399
 
    }
1400
 
 
1401
 
    ServerDescriptorPtr server = new ServerDescriptor();
1402
 
    instantiateImpl(server, resolver, props);
1403
 
    return server;
1404
 
}
1405
 
 
1406
 
void
1407
 
ServerHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1408
 
{
1409
 
    print(communicator, out, ServerInfo());
1410
 
}
1411
 
 
1412
 
void
1413
 
ServerHelper::print(const Ice::CommunicatorPtr& communicator, Output& out, const ServerInfo& info) const
1414
 
{
1415
 
    out << "server `" + _desc->id + "'";
1416
 
    out << sb;
1417
 
    printImpl(communicator, out, info);
1418
 
    out << eb;
1419
 
}
1420
 
 
1421
 
void
1422
 
ServerHelper::printImpl(const Ice::CommunicatorPtr& communicator, Output& out, const ServerInfo& info) const
1423
 
{
1424
 
    if(!info.application.empty())
1425
 
    {
1426
 
        out << nl << "application = `" << info.application << "'";
1427
 
        out << nl << "application uuid = `" << info.uuid << "'";
1428
 
        out << nl << "application revision = `" << info.revision << "'";
1429
 
    }
1430
 
    if(!info.node.empty())
1431
 
    {
1432
 
        out << nl << "node = `" << info.node << "'";
1433
 
    }
1434
 
    if(!info.sessionId.empty())
1435
 
    {
1436
 
        out << nl << "session id = `" << info.sessionId << "'";
1437
 
    }
1438
 
    out << nl << "exe = `" << _desc->exe << "'";
1439
 
 
1440
 
    if(!_desc->iceVersion.empty())
1441
 
    {
1442
 
        out << nl << "ice version = `" << _desc->iceVersion << "'";
1443
 
    }
1444
 
 
1445
 
    if(!_desc->pwd.empty())
1446
 
    {
1447
 
        out << nl << "pwd = `" << _desc->pwd << "'";
1448
 
    }
1449
 
    out << nl << "activation = `" << _desc->activation << "'";
1450
 
    if(!_desc->activationTimeout.empty() && _desc->activationTimeout != "0")
1451
 
    {
1452
 
        out << nl << "activationTimeout = `" << _desc->activationTimeout << "'";
1453
 
    }
1454
 
    if(!_desc->deactivationTimeout.empty() && _desc->deactivationTimeout != "0")
1455
 
    {
1456
 
        out << nl << "deactivationTimeout = `" << _desc->deactivationTimeout << "'";
1457
 
    }
1458
 
    if(!_desc->user.empty())
1459
 
    {
1460
 
        out << nl << "user = `" << _desc->user << "'";
1461
 
    }
1462
 
    if(!_desc->applicationDistrib)
1463
 
    {
1464
 
        out << nl << "application distribution = `false'";
1465
 
    }
1466
 
    if(!_desc->options.empty())
1467
 
    {
1468
 
        out << nl << "options = `" << toString(_desc->options) << "'";
1469
 
    }
1470
 
    if(!_desc->envs.empty())
1471
 
    {
1472
 
        out << nl << "envs = `" << toString(_desc->envs) << "'";
1473
 
    }
1474
 
    if(!_desc->distrib.icepatch.empty())
1475
 
    {
1476
 
        out << nl << "distribution";
1477
 
        out << sb;
1478
 
        out << nl << "proxy = `" << _desc->distrib.icepatch << "'";
1479
 
        if(!_desc->distrib.directories.empty())
1480
 
        {
1481
 
            out << nl << "directories = `" << toString(_desc->distrib.directories) << "'";
1482
 
        }
1483
 
        out << eb;
1484
 
    }
1485
 
    CommunicatorHelper::print(communicator, out);
1486
 
}
1487
 
 
1488
 
void
1489
 
ServerHelper::instantiateImpl(const ServerDescriptorPtr& instance, 
1490
 
                              const Resolver& resolve, 
1491
 
                              const PropertyDescriptorSeq& props) const
1492
 
{
1493
 
    CommunicatorHelper::instantiateImpl(instance, resolve);
1494
 
 
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")
1508
 
    {
1509
 
        resolve.exception("unknown activation `" + instance->activation + "'");
1510
 
    }
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());
1517
 
}
1518
 
 
1519
 
IceBoxHelper::IceBoxHelper(const IceBoxDescriptorPtr& descriptor) :
1520
 
    ServerHelper(descriptor),
1521
 
    _desc(descriptor)
1522
 
{
1523
 
    for(ServiceInstanceDescriptorSeq::const_iterator p = _desc->services.begin(); p != _desc->services.end(); ++p)
1524
 
    {
1525
 
        _services.push_back(ServiceInstanceHelper(*p));
1526
 
    }
1527
 
}
1528
 
 
1529
 
bool 
1530
 
IceBoxHelper::operator==(const CommunicatorHelper& h) const
1531
 
{
1532
 
    const IceBoxHelper* helper = dynamic_cast<const IceBoxHelper*>(&h);
1533
 
    if(!helper || !ServerHelper::operator==(h))
1534
 
    {
1535
 
        return false;
1536
 
    }
1537
 
 
1538
 
    if(_services != helper->_services)
1539
 
    {
1540
 
        return false;
1541
 
    }
1542
 
    
1543
 
    return true;
1544
 
}
1545
 
 
1546
 
bool
1547
 
IceBoxHelper::operator!=(const CommunicatorHelper& helper) const
1548
 
{
1549
 
    return !operator==(helper);
1550
 
}
1551
 
 
1552
 
ServerDescriptorPtr
1553
 
IceBoxHelper::instantiate(const Resolver& resolver, 
1554
 
                          const PropertyDescriptorSeq& props,
1555
 
                          const PropertySetDescriptorDict& serviceProps) const
1556
 
{
1557
 
    IceBoxDescriptorPtr iceBox = new IceBoxDescriptor();
1558
 
    instantiateImpl(iceBox, resolver, props, serviceProps);
1559
 
    return iceBox;
1560
 
}
1561
 
 
1562
 
void
1563
 
IceBoxHelper::getIds(multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
1564
 
{
1565
 
    CommunicatorHelper::getIds(adapterIds, objectIds);
1566
 
    for(vector<ServiceInstanceHelper>::const_iterator p = _services.begin(); p != _services.end(); ++p)
1567
 
    {
1568
 
        p->getIds(adapterIds, objectIds);
1569
 
    }
1570
 
}
1571
 
 
1572
 
void
1573
 
IceBoxHelper::getReplicaGroups(set<string>& replicaGroups) const
1574
 
{
1575
 
    CommunicatorHelper::getReplicaGroups(replicaGroups);
1576
 
    for(vector<ServiceInstanceHelper>::const_iterator p = _services.begin(); p != _services.end(); ++p)
1577
 
    {
1578
 
        p->getReplicaGroups(replicaGroups);
1579
 
    }
1580
 
}
1581
 
 
1582
 
void
1583
 
IceBoxHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1584
 
{
1585
 
    print(communicator, out, ServerInfo());
1586
 
}
1587
 
 
1588
 
void
1589
 
IceBoxHelper::print(const Ice::CommunicatorPtr& communicator, Output& out, const ServerInfo& info) const
1590
 
{
1591
 
    out << "icebox `" + _desc->id + "'";
1592
 
    out << sb;
1593
 
 
1594
 
    string endpoints = getProperty("IceBox.ServiceManager.Endpoints");
1595
 
    out << nl << "service manager endpoints = `" << endpoints << "'";
1596
 
    printImpl(communicator, out, info);
1597
 
    out << nl << "services";
1598
 
    out << sb;
1599
 
    for(ServiceInstanceDescriptorSeq::const_iterator p = _desc->services.begin(); p != _desc->services.end(); ++p)
1600
 
    {
1601
 
        assert(p->descriptor);
1602
 
        out << nl << p->descriptor->name;
1603
 
    }
1604
 
    out << eb;
1605
 
    out << eb;
1606
 
}
1607
 
 
1608
 
void
1609
 
IceBoxHelper::instantiateImpl(const IceBoxDescriptorPtr& instance, 
1610
 
                              const Resolver& resolver, 
1611
 
                              const PropertyDescriptorSeq& props,
1612
 
                              const PropertySetDescriptorDict& serviceProps) const
1613
 
{
1614
 
    ServerHelper::instantiateImpl(instance, resolver, props);
1615
 
    set<string> serviceNames;
1616
 
    for(vector<ServiceInstanceHelper>::const_iterator p = _services.begin(); p != _services.end(); ++p)
1617
 
    {
1618
 
        ServiceInstanceDescriptor desc = p->instantiate(resolver, serviceProps);
1619
 
        assert(desc.descriptor);
1620
 
        serviceNames.insert(desc.descriptor->name);
1621
 
        instance->services.push_back(desc);
1622
 
    }
1623
 
    for(PropertySetDescriptorDict::const_iterator q = serviceProps.begin(); q != serviceProps.end(); ++q)
1624
 
    {
1625
 
        if(serviceNames.find(q->first) == serviceNames.end())
1626
 
        {
1627
 
            resolver.exception("invalid service property set: service `" + q->first + "' doesn't exist");
1628
 
        }
1629
 
    }
1630
 
}
1631
 
 
1632
 
map<string, string>
1633
 
InstanceHelper::instantiateParams(const Resolver& resolve, 
1634
 
                                  const string& tmpl, 
1635
 
                                  const map<string, string>& parameters,
1636
 
                                  const vector<string>& requiredParameters,
1637
 
                                  const map<string, string>& defaults) const
1638
 
{
1639
 
    map<string, string> params;
1640
 
 
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)
1644
 
    {
1645
 
        if(required.find(p->first) == required.end())
1646
 
        {
1647
 
            unknown.insert(p->first);
1648
 
        }
1649
 
        params.insert(make_pair(p->first, resolve(p->second, "parameter `" + p->first + "'")));
1650
 
    }
1651
 
    if(!unknown.empty())
1652
 
    {
1653
 
        ostringstream os;
1654
 
        os << "unknown parameters when instantiating `" + tmpl + "' template: ";
1655
 
        copy(unknown.begin(), unknown.end(), ostream_iterator<string>(os, " "));
1656
 
        resolve.exception(os.str());
1657
 
    }
1658
 
    
1659
 
    set<string> missingParams;
1660
 
    for(set<string>::const_iterator q = required.begin(); q != required.end(); ++q)
1661
 
    {
1662
 
        if(params.find(*q) == params.end())
1663
 
        {
1664
 
            map<string, string>::const_iterator r = defaults.find(*q);
1665
 
            if(r == defaults.end())
1666
 
            {
1667
 
                missingParams.insert(*q);
1668
 
            }
1669
 
            else
1670
 
            {
1671
 
                params.insert(make_pair(r->first, resolve(r->second, "default parameter `" + r->first + "'")));
1672
 
            }
1673
 
        }
1674
 
    }
1675
 
    if(!missingParams.empty())
1676
 
    {
1677
 
        ostringstream os;
1678
 
        os << "undefined parameters when instantiating `" + tmpl + "' template: ";
1679
 
        copy(missingParams.begin(), missingParams.end(), ostream_iterator<string>(os, " "));
1680
 
        resolve.exception(os.str());
1681
 
    }
1682
 
 
1683
 
    return params;
1684
 
}
1685
 
 
1686
 
ServiceInstanceHelper::ServiceInstanceHelper(const ServiceInstanceDescriptor& desc) :
1687
 
    _def(desc)
1688
 
{
1689
 
    //
1690
 
    // If the service instance is not a template instance, its
1691
 
    // descriptor must be set and contain the definition of the
1692
 
    // service.
1693
 
    //
1694
 
    if(_def._cpp_template.empty() && !_def.descriptor)
1695
 
    {
1696
 
        throw DeploymentException("invalid service instance: no template defined");
1697
 
    }
1698
 
 
1699
 
    if(_def.descriptor)
1700
 
    {
1701
 
        _service = ServiceHelper(_def.descriptor);
1702
 
    }
1703
 
}
1704
 
 
1705
 
bool
1706
 
ServiceInstanceHelper::operator==(const ServiceInstanceHelper& helper) const
1707
 
{
1708
 
    if(_def._cpp_template.empty())
1709
 
    {
1710
 
        return _service == helper._service;
1711
 
    }
1712
 
    else
1713
 
    {
1714
 
        return _def._cpp_template == helper._def._cpp_template && 
1715
 
            _def.parameterValues == helper._def.parameterValues &&
1716
 
            _def.propertySet == helper._def.propertySet;
1717
 
    }
1718
 
}
1719
 
 
1720
 
bool
1721
 
ServiceInstanceHelper::operator!=(const ServiceInstanceHelper& helper) const
1722
 
{
1723
 
    return !operator==(helper);
1724
 
}
1725
 
 
1726
 
ServiceInstanceDescriptor
1727
 
ServiceInstanceHelper::instantiate(const Resolver& resolve, const PropertySetDescriptorDict& serviceProps) const
1728
 
1729
 
    ServiceHelper def = _service;
1730
 
    std::map<std::string, std::string> parameterValues;
1731
 
    if(!def.getDescriptor())
1732
 
    {
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, 
1737
 
                                            _def._cpp_template, 
1738
 
                                            _def.parameterValues,
1739
 
                                            tmpl.parameters, 
1740
 
                                            tmpl.parameterDefaults);
1741
 
    }
1742
 
 
1743
 
    //
1744
 
    // Setup the resolver.
1745
 
    //
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}'");
1749
 
 
1750
 
    //
1751
 
    // Instantiate the service instance.
1752
 
    //
1753
 
    ServiceInstanceDescriptor desc;
1754
 
    desc.descriptor = def.instantiate(svcResolve, svcResolve(_def.propertySet).properties, serviceProps);
1755
 
 
1756
 
    //
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.)
1761
 
    //
1762
 
    //desc._cpp_template = _template;
1763
 
    //desc.parameterValues = _parameters;
1764
 
    return desc;
1765
 
}
1766
 
 
1767
 
void
1768
 
ServiceInstanceHelper::getIds(multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
1769
 
{
1770
 
    assert(_service.getDescriptor());
1771
 
    _service.getIds(adapterIds, objectIds);
1772
 
}
1773
 
 
1774
 
void
1775
 
ServiceInstanceHelper::getReplicaGroups(set<string>& replicaGroups) const
1776
 
{
1777
 
    assert(_service.getDescriptor());
1778
 
    _service.getReplicaGroups(replicaGroups);
1779
 
}
1780
 
 
1781
 
void
1782
 
ServiceInstanceHelper::print(const Ice::CommunicatorPtr& communicator, Output& out) const
1783
 
{
1784
 
    if(_service.getDescriptor())
1785
 
    {
1786
 
        _service.print(communicator, out);
1787
 
    }
1788
 
    else
1789
 
    {
1790
 
        assert(!_def._cpp_template.empty());
1791
 
        out << "service instance";
1792
 
        out << sb;
1793
 
        out << nl << "template = `" << _def._cpp_template << "'";
1794
 
        out << nl << "parameters";
1795
 
        out << sb;
1796
 
        for(StringStringDict::const_iterator p = _def.parameterValues.begin(); p != _def.parameterValues.end(); ++p)
1797
 
        {
1798
 
            out << nl << p->first << " = `" << p->second << "'";
1799
 
        }
1800
 
        out << eb;
1801
 
        out << eb;
1802
 
    }
1803
 
}
1804
 
 
1805
 
ServerInstanceHelper::ServerInstanceHelper(const ServerInstanceDescriptor& desc,
1806
 
                                           const Resolver& resolve,
1807
 
                                           bool instantiate) :
1808
 
    _def(desc)
1809
 
{
1810
 
    init(0, resolve, instantiate);
1811
 
}
1812
 
 
1813
 
ServerInstanceHelper::ServerInstanceHelper(const ServerDescriptorPtr& definition, 
1814
 
                                           const Resolver& resolve,
1815
 
                                           bool instantiate) :
1816
 
    _def(ServerInstanceDescriptor())
1817
 
{
1818
 
    init(definition, resolve, instantiate);
1819
 
}
1820
 
 
1821
 
void
1822
 
ServerInstanceHelper::init(const ServerDescriptorPtr& definition, const Resolver& resolve, bool instantiate)
1823
 
{
1824
 
    //
1825
 
    // Get the server definition if it's not provided.
1826
 
    //
1827
 
    ServerDescriptorPtr def = definition;
1828
 
    std::map<std::string, std::string> parameterValues;
1829
 
    if(!def)
1830
 
    {
1831
 
        if(_def._cpp_template.empty())
1832
 
        {
1833
 
            resolve.exception("invalid server instance: template is not defined");
1834
 
        }
1835
 
        
1836
 
        //
1837
 
        // Get the server definition and the template property sets.
1838
 
        //
1839
 
        TemplateDescriptor tmpl = resolve.getServerTemplate(_def._cpp_template);
1840
 
        def = ServerDescriptorPtr::dynamicCast(tmpl.descriptor);
1841
 
        parameterValues = instantiateParams(resolve, 
1842
 
                                            _def._cpp_template, 
1843
 
                                            _def.parameterValues, 
1844
 
                                            tmpl.parameters, 
1845
 
                                            tmpl.parameterDefaults);
1846
 
    }
1847
 
    assert(def);
1848
 
 
1849
 
    //
1850
 
    // Setup the resolver.
1851
 
    //
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}");
1857
 
 
1858
 
    //
1859
 
    // Set the server definition.
1860
 
    //
1861
 
    _serverDefinition = createHelper(def);
1862
 
 
1863
 
    if(!instantiate)
1864
 
    {
1865
 
        return; // We're done.
1866
 
    }
1867
 
 
1868
 
    //
1869
 
    // Ignore undefined session.id variable if the activation mode is
1870
 
    // 'session', it will get defined when the server is allocated.
1871
 
    //
1872
 
    if(svrResolve(def->activation, "server activation", true) == "session")
1873
 
    {
1874
 
        svrResolve.addIgnored("session.id"); 
1875
 
    }
1876
 
        
1877
 
    //
1878
 
    // Instantiate the server instance definition (we use the server
1879
 
    // resolver above, so using parameters in properties is possible).
1880
 
    //
1881
 
    if(!_def._cpp_template.empty())
1882
 
    {
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)
1888
 
        {
1889
 
            _instance.servicePropertySets.insert(make_pair(svrResolve(p->first), svrResolve(p->second)));
1890
 
        }
1891
 
    }
1892
 
    
1893
 
    //
1894
 
    // Instantiate the server definition.
1895
 
    //
1896
 
    ServerDescriptorPtr inst = _serverDefinition->instantiate(svrResolve, _instance.propertySet.properties,
1897
 
                                                              _instance.servicePropertySets);
1898
 
    _serverInstance = createHelper(inst);
1899
 
}
1900
 
 
1901
 
bool
1902
 
ServerInstanceHelper::operator==(const ServerInstanceHelper& helper) const
1903
 
{
1904
 
    if(_def._cpp_template.empty())
1905
 
    {
1906
 
        return *_serverDefinition == *helper._serverDefinition;
1907
 
    }
1908
 
    else
1909
 
    {
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;
1914
 
    }
1915
 
}
1916
 
 
1917
 
bool
1918
 
ServerInstanceHelper::operator!=(const ServerInstanceHelper& helper) const
1919
 
{
1920
 
    return !operator==(helper);
1921
 
}
1922
 
 
1923
 
string
1924
 
ServerInstanceHelper::getId() const
1925
 
{
1926
 
    return _id;
1927
 
}
1928
 
 
1929
 
ServerInstanceDescriptor
1930
 
ServerInstanceHelper::getDefinition() const
1931
 
{
1932
 
    assert(!_def._cpp_template.empty());
1933
 
    return _def;
1934
 
}
1935
 
 
1936
 
ServerInstanceDescriptor
1937
 
ServerInstanceHelper::getInstance() const
1938
 
{
1939
 
    assert(!_def._cpp_template.empty() && !_instance._cpp_template.empty());
1940
 
    return _instance;
1941
 
}
1942
 
 
1943
 
ServerDescriptorPtr
1944
 
ServerInstanceHelper::getServerDefinition() const
1945
 
{
1946
 
    assert(_def._cpp_template.empty());
1947
 
    return _serverDefinition->getDescriptor();
1948
 
}
1949
 
 
1950
 
ServerDescriptorPtr
1951
 
ServerInstanceHelper::getServerInstance() const
1952
 
{
1953
 
    assert(_serverInstance);
1954
 
    return _serverInstance->getDescriptor();
1955
 
}
1956
 
 
1957
 
void
1958
 
ServerInstanceHelper::getIds(multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
1959
 
{
1960
 
    assert(_serverInstance);
1961
 
    _serverInstance->getIds(adapterIds, objectIds);
1962
 
}
1963
 
 
1964
 
void
1965
 
ServerInstanceHelper::getReplicaGroups(set<string>& replicaGroups) const
1966
 
{
1967
 
    assert(_serverInstance);
1968
 
    _serverInstance->getReplicaGroups(replicaGroups);
1969
 
}
1970
 
 
1971
 
NodeHelper::NodeHelper(const string& name, 
1972
 
                       const NodeDescriptor& descriptor, 
1973
 
                       const Resolver& appResolve,
1974
 
                       bool instantiate) : 
1975
 
    _name(name),
1976
 
    _def(descriptor),
1977
 
    _instantiated(instantiate)
1978
 
{
1979
 
    if(_name.empty())
1980
 
    {
1981
 
        appResolve.exception("invalid node: empty name");
1982
 
    }
1983
 
 
1984
 
    Resolver resolve(appResolve, _def.variables, false);
1985
 
    resolve.setReserved("node", _name);
1986
 
    resolve.setContext("node `" + _name + "'");
1987
 
 
1988
 
    if(instantiate)
1989
 
    {
1990
 
        //
1991
 
        // Instantiate the node definition.
1992
 
        //
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);
1997
 
 
1998
 
        //
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.
2002
 
        //
2003
 
        resolve.addPropertySets(_instance.propertySets);
2004
 
    }
2005
 
 
2006
 
    ServerInstanceDescriptorSeq::const_iterator p;
2007
 
    for(p = _def.serverInstances.begin(); p != _def.serverInstances.end(); ++p)
2008
 
    {
2009
 
        ServerInstanceHelper helper(*p, resolve, instantiate);
2010
 
        if(!_serverInstances.insert(make_pair(helper.getId(), helper)).second)
2011
 
        {
2012
 
            resolve.exception("duplicate server `" + helper.getId() + "' in node `" + _name + "'");
2013
 
        }
2014
 
        if(instantiate)
2015
 
        {
2016
 
            _instance.serverInstances.push_back(helper.getInstance());
2017
 
        }
2018
 
    }
2019
 
 
2020
 
    ServerDescriptorSeq::const_iterator q;
2021
 
    for(q = _def.servers.begin(); q != _def.servers.end(); ++q)
2022
 
    {
2023
 
        ServerInstanceHelper helper(*q, resolve, instantiate);
2024
 
        if(!_servers.insert(make_pair(helper.getId(), helper)).second)
2025
 
        {
2026
 
            resolve.exception("duplicate server `" + helper.getId() + "' in node `" + _name + "'");
2027
 
        }
2028
 
        if(instantiate)
2029
 
        {
2030
 
            _instance.servers.push_back(helper.getServerInstance());
2031
 
        }
2032
 
    }
2033
 
}
2034
 
 
2035
 
bool
2036
 
NodeHelper::operator==(const NodeHelper& helper) const
2037
 
{
2038
 
    if(_def.variables != helper._def.variables)
2039
 
    {
2040
 
        return false;
2041
 
    }
2042
 
 
2043
 
    if(_serverInstances != helper._serverInstances)
2044
 
    {
2045
 
        return false;
2046
 
    }
2047
 
 
2048
 
    if(_servers != helper._servers)
2049
 
    {
2050
 
        return false;
2051
 
    }
2052
 
 
2053
 
    if(_def.loadFactor != helper._def.loadFactor)
2054
 
    {
2055
 
        return false;
2056
 
    }
2057
 
 
2058
 
    if(_def.description != helper._def.description)
2059
 
    {
2060
 
        return false;
2061
 
    }
2062
 
 
2063
 
    if(_def.propertySets != helper._def.propertySets)
2064
 
    {
2065
 
        return false;
2066
 
    }
2067
 
 
2068
 
    return true;
2069
 
}
2070
 
 
2071
 
bool
2072
 
NodeHelper::operator!=(const NodeHelper& helper) const
2073
 
{
2074
 
    return !operator==(helper);
2075
 
}
2076
 
 
2077
 
NodeUpdateDescriptor
2078
 
NodeHelper::diff(const NodeHelper& helper) const
2079
 
{
2080
 
    assert(_name == helper._name);
2081
 
 
2082
 
    NodeUpdateDescriptor update;
2083
 
 
2084
 
    update.name = _name;
2085
 
    if(_def.loadFactor != helper._def.loadFactor)
2086
 
    {
2087
 
        update.loadFactor = new BoxedString(_def.loadFactor);
2088
 
    }
2089
 
 
2090
 
    if(_def.description != helper._def.description)
2091
 
    {
2092
 
        update.description = new BoxedString(_def.description);
2093
 
    }
2094
 
 
2095
 
    update.variables = getDictUpdatedElts(helper._def.variables, _def.variables);
2096
 
    update.removeVariables = getDictRemovedElts(helper._def.variables, _def.variables);
2097
 
 
2098
 
    update.propertySets = getDictUpdatedElts(helper._def.propertySets, _def.propertySets);
2099
 
    update.removePropertySets = getDictRemovedElts(helper._def.propertySets, _def.propertySets);
2100
 
    
2101
 
    ServerInstanceHelperDict updated = getDictUpdatedElts(helper._serverInstances, _serverInstances);
2102
 
    for(ServerInstanceHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
2103
 
    {
2104
 
        update.serverInstances.push_back(p->second.getDefinition());
2105
 
    }
2106
 
    update.removeServers = getDictRemovedElts(helper._serverInstances, _serverInstances);
2107
 
 
2108
 
    updated = getDictUpdatedElts(helper._servers, _servers);
2109
 
    for(ServerInstanceHelperDict::const_iterator q = updated.begin(); q != updated.end(); ++q)
2110
 
    {
2111
 
        update.servers.push_back(q->second.getServerDefinition());
2112
 
    }
2113
 
    Ice::StringSeq removed = getDictRemovedElts(helper._servers, _servers);
2114
 
    update.removeServers.insert(update.removeServers.end(), removed.begin(), removed.end());
2115
 
    return update;
2116
 
}
2117
 
 
2118
 
NodeDescriptor
2119
 
NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolve) const
2120
 
{
2121
 
    NodeDescriptor def;
2122
 
    assert(update.name == _name);
2123
 
 
2124
 
    //
2125
 
    // Update the variables, property sets, load factor, description.
2126
 
    //
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;
2131
 
    
2132
 
    //
2133
 
    // NOTE: It's important to create the resolver *after* updating
2134
 
    // the node variables!
2135
 
    //
2136
 
    Resolver resolve(appResolve, def.variables, false);
2137
 
    resolve.setReserved("node", _name);
2138
 
    resolve.setContext("node `" + _name + "'");
2139
 
 
2140
 
    //
2141
 
    // Update the node servers and server instances. The update is in 2 steps:
2142
 
    //
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.
2145
 
    //
2146
 
 
2147
 
    ServerInstanceHelperDict::const_iterator r;
2148
 
 
2149
 
    set<string> added;
2150
 
    set<string> removed(update.removeServers.begin(), update.removeServers.end());
2151
 
 
2152
 
    ServerInstanceDescriptorSeq::const_iterator q;
2153
 
    for(q = update.serverInstances.begin(); q != update.serverInstances.end(); ++q)
2154
 
    {
2155
 
        ServerInstanceHelper helper(*q, resolve, false);
2156
 
        if(!added.insert(helper.getId()).second)
2157
 
        {
2158
 
            resolve.exception("duplicate server `" + helper.getId() + "' in node `" + _name + "'");
2159
 
        }
2160
 
        def.serverInstances.push_back(helper.getDefinition());
2161
 
    }
2162
 
    for(r = _serverInstances.begin(); r != _serverInstances.end(); ++r)
2163
 
    {
2164
 
        if(removed.find(r->first) != removed.end() || added.find(r->first) != added.end())
2165
 
        {
2166
 
            continue;
2167
 
        } 
2168
 
 
2169
 
        //
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.
2173
 
        //
2174
 
        ServerInstanceHelper helper(r->second.getDefinition(), resolve, false);
2175
 
        if(helper.getId() != r->first)
2176
 
        {
2177
 
            resolve.exception("invalid update in node `" + _name + "':\n" + "server instance id `" + r->first +
2178
 
                              "' changed to `" + helper.getId() + "'");
2179
 
        }
2180
 
        def.serverInstances.push_back(helper.getDefinition());
2181
 
    }
2182
 
 
2183
 
    added.clear();
2184
 
    for(ServerDescriptorSeq::const_iterator s = update.servers.begin(); s != update.servers.end(); ++s)
2185
 
    {
2186
 
        ServerInstanceHelper helper(*s, resolve, false);
2187
 
        if(!added.insert(helper.getId()).second)
2188
 
        {
2189
 
            resolve.exception("duplicate server `" + helper.getId() + "' in node `" + _name + "'");
2190
 
        }
2191
 
        def.servers.push_back(helper.getServerDefinition());
2192
 
    }    
2193
 
    for(r = _servers.begin(); r != _servers.end(); ++r)
2194
 
    {
2195
 
        if(removed.find(r->first) != removed.end() || added.find(r->first) != added.end())
2196
 
        {
2197
 
            continue;
2198
 
        } 
2199
 
 
2200
 
        //
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.
2204
 
        //
2205
 
        ServerInstanceHelper helper(r->second.getServerDefinition(), resolve, false);
2206
 
        if(helper.getId() != r->first)
2207
 
        {
2208
 
            resolve.exception("invalid update in node `" + _name + "':\nserver instance id `" + r->first + 
2209
 
                              "' changed to `" + helper.getId() + "'");
2210
 
        }       
2211
 
        def.servers.push_back(helper.getServerDefinition());
2212
 
    }
2213
 
    return def;
2214
 
}
2215
 
 
2216
 
void
2217
 
NodeHelper::getIds(multiset<string>& serverIds, multiset<string>& adapterIds, multiset<Ice::Identity>& objectIds) const
2218
 
{
2219
 
    assert(_instantiated);
2220
 
    ServerInstanceHelperDict::const_iterator p;
2221
 
    for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2222
 
    {
2223
 
        serverIds.insert(p->first);
2224
 
        p->second.getIds(adapterIds, objectIds);
2225
 
    }
2226
 
    for(p = _servers.begin(); p != _servers.end(); ++p)
2227
 
    {
2228
 
        serverIds.insert(p->first);
2229
 
        p->second.getIds(adapterIds, objectIds);
2230
 
    }    
2231
 
}
2232
 
 
2233
 
void
2234
 
NodeHelper::getReplicaGroups(set<string>& replicaGroups) const
2235
 
{
2236
 
    assert(_instantiated);
2237
 
    ServerInstanceHelperDict::const_iterator p;
2238
 
    for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2239
 
    {
2240
 
        p->second.getReplicaGroups(replicaGroups);
2241
 
    }
2242
 
    for(p = _servers.begin(); p != _servers.end(); ++p)
2243
 
    {
2244
 
        p->second.getReplicaGroups(replicaGroups);
2245
 
    }    
2246
 
}
2247
 
 
2248
 
const NodeDescriptor&
2249
 
NodeHelper::getDefinition() const
2250
 
{
2251
 
    return _def;
2252
 
}
2253
 
 
2254
 
const NodeDescriptor&
2255
 
NodeHelper::getInstance() const
2256
 
{
2257
 
    assert(_instantiated);
2258
 
    return _instance;
2259
 
}
2260
 
 
2261
 
void
2262
 
NodeHelper::getServerInfos(const string& app, const string& uuid, int revision, map<string, ServerInfo>& servers) const
2263
 
{
2264
 
    assert(_instantiated);
2265
 
 
2266
 
    ServerInstanceHelperDict::const_iterator p;
2267
 
    for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2268
 
    {
2269
 
        ServerInfo info;
2270
 
        info.node = _name;
2271
 
        info.application = app;
2272
 
        info.uuid = uuid;
2273
 
        info.revision = revision;
2274
 
        info.descriptor = p->second.getServerInstance();
2275
 
        servers.insert(make_pair(p->second.getId(), info));
2276
 
    }
2277
 
    for(p = _servers.begin(); p != _servers.end(); ++p)
2278
 
    {
2279
 
        ServerInfo info;
2280
 
        info.node = _name;
2281
 
        info.application = app;
2282
 
        info.uuid = uuid;
2283
 
        info.revision = revision;
2284
 
        info.descriptor = p->second.getServerInstance();
2285
 
        servers.insert(make_pair(p->second.getId(), info));
2286
 
    }
2287
 
}
2288
 
 
2289
 
bool
2290
 
NodeHelper::hasDistributions(const string& server) const
2291
 
{
2292
 
    assert(_instantiated);
2293
 
 
2294
 
    //
2295
 
    // Get the server distributions to patch.
2296
 
    //
2297
 
    if(server.empty())
2298
 
    {
2299
 
        ServerInstanceHelperDict::const_iterator p;
2300
 
        for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2301
 
        {
2302
 
            if(!p->second.getServerInstance()->distrib.icepatch.empty())
2303
 
            {
2304
 
                return true;
2305
 
            }
2306
 
        }
2307
 
        for(p = _servers.begin(); p != _servers.end(); ++p)
2308
 
        {
2309
 
            if(!p->second.getServerInstance()->distrib.icepatch.empty())
2310
 
            {
2311
 
                return true;
2312
 
            }
2313
 
        }
2314
 
    }
2315
 
    else
2316
 
    {
2317
 
        ServerInstanceHelperDict::const_iterator p = _serverInstances.find(server);
2318
 
        if(p == _serverInstances.end())
2319
 
        {
2320
 
            p = _servers.find(server);
2321
 
            if(p == _servers.end())
2322
 
            {
2323
 
                return false;
2324
 
            }
2325
 
        }
2326
 
 
2327
 
        if(!p->second.getServerInstance()->distrib.icepatch.empty())
2328
 
        {
2329
 
            return true;
2330
 
        }
2331
 
    }
2332
 
 
2333
 
    return false;
2334
 
}
2335
 
 
2336
 
bool
2337
 
NodeHelper::hasServers() const
2338
 
{
2339
 
    return !_serverInstances.empty() || !_servers.empty();
2340
 
}
2341
 
 
2342
 
bool
2343
 
NodeHelper::hasServer(const string& name) const
2344
 
{
2345
 
    return _serverInstances.find(name) != _serverInstances.end() || _servers.find(name) != _servers.end();
2346
 
}
2347
 
 
2348
 
void
2349
 
NodeHelper::print(Output& out) const
2350
 
{
2351
 
    assert(_instantiated);
2352
 
 
2353
 
    out << nl << "node `" << _name << "'";
2354
 
    out << sb;
2355
 
    if(!_instance.loadFactor.empty())
2356
 
    {
2357
 
        out << nl << "load factor = `" << _instance.loadFactor << "'";
2358
 
    }
2359
 
    if(!_instance.description.empty())
2360
 
    {
2361
 
        out << nl << "description = `" << _instance.description << "'";
2362
 
    }
2363
 
    if(!_instance.variables.empty())
2364
 
    {
2365
 
        out << nl << "variables";
2366
 
        out << sb;
2367
 
        for(StringStringDict::const_iterator q = _instance.variables.begin(); q != _instance.variables.end(); ++q)
2368
 
        {
2369
 
            out << nl << q->first << " = `" << q->second << "'";
2370
 
        }
2371
 
        out << eb;
2372
 
    }
2373
 
    if(!_instance.propertySets.empty())
2374
 
    {
2375
 
        PropertySetDescriptorDict::const_iterator q;
2376
 
        for(q = _instance.propertySets.begin(); q != _instance.propertySets.end(); ++q)
2377
 
        {
2378
 
            out << nl << "properties `" << q->first << "'";
2379
 
            out << sb;
2380
 
            if(!q->second.references.empty())
2381
 
            {
2382
 
                out << nl << "references = " << toString(q->second.references);
2383
 
            }
2384
 
            PropertyDescriptorSeq::const_iterator r;
2385
 
            for(r = q->second.properties.begin(); r != q->second.properties.end(); ++r)
2386
 
            {
2387
 
                out << nl << r->name << " = `" << r->value << "'";
2388
 
            }
2389
 
            out << eb;
2390
 
        }
2391
 
    }
2392
 
 
2393
 
    if(_serverInstances.empty() && _servers.empty())
2394
 
    {
2395
 
        return;
2396
 
    }
2397
 
    
2398
 
    out << nl << "servers";
2399
 
    out << sb;
2400
 
    ServerInstanceHelperDict::const_iterator p;
2401
 
    for(p = _serverInstances.begin(); p != _serverInstances.end(); ++p)
2402
 
    {
2403
 
        out << nl << p->first;
2404
 
    }
2405
 
    for(p = _servers.begin(); p != _servers.end(); ++p)
2406
 
    {
2407
 
        out << nl << p->first;
2408
 
    }
2409
 
    out << eb;
2410
 
    out << eb;
2411
 
}
2412
 
 
2413
 
void
2414
 
NodeHelper::printDiff(Output& out, const NodeHelper& helper) const
2415
 
{
2416
 
    assert(_instantiated);
2417
 
 
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);
2422
 
    
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());
2429
 
 
2430
 
    map<string, string> variables = getDictUpdatedElts(helper._def.variables, _def.variables);
2431
 
    Ice::StringSeq removeVariables = getDictRemovedElts(helper._def.variables, _def.variables);
2432
 
 
2433
 
    PropertySetDescriptorDict updatedPs = getDictUpdatedElts(helper._def.propertySets, _def.propertySets);
2434
 
    Ice::StringSeq removedPs = getDictRemovedElts(helper._def.propertySets, _def.propertySets);
2435
 
 
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)
2441
 
    {
2442
 
        return;
2443
 
    }
2444
 
 
2445
 
    //
2446
 
    // TODO: Show updated variables?
2447
 
    //
2448
 
 
2449
 
    out << nl << "node `" + _name + "' updated";
2450
 
    out << sb;
2451
 
 
2452
 
    if(_def.loadFactor != helper._def.loadFactor)
2453
 
    {
2454
 
        out << nl << "load factor udpated";
2455
 
    }
2456
 
    if(_def.description != helper._def.description)
2457
 
    {
2458
 
        out << nl << "description udpated";
2459
 
    }
2460
 
    if(!updatedPs.empty() || !removedPs.empty())
2461
 
    {
2462
 
        out << nl << "property sets udpated";
2463
 
    }
2464
 
    if(!variables.empty() || !removeVariables.empty())
2465
 
    {
2466
 
        out << nl << "variables udpated";
2467
 
    }
2468
 
    if(!updated.empty() || !removed.empty())
2469
 
    {
2470
 
        out << nl << "servers";
2471
 
        out << sb;
2472
 
        ServerInstanceHelperDict::const_iterator p;
2473
 
        for(p = updated.begin(); p != updated.end(); ++p)
2474
 
        {
2475
 
            if(helper._serverInstances.find(p->first) == helper._serverInstances.end() &&
2476
 
               helper._servers.find(p->first) == helper._servers.end())
2477
 
            {
2478
 
                out << nl << "server `" << p->first << "' added";
2479
 
            }
2480
 
        }
2481
 
        for(p = updated.begin(); p != updated.end(); ++p)
2482
 
        {
2483
 
            if(helper._serverInstances.find(p->first) != helper._serverInstances.end() ||
2484
 
               helper._servers.find(p->first) != helper._servers.end())
2485
 
            {
2486
 
                out << nl << "server `" << p->first << "' updated";
2487
 
            }
2488
 
        }
2489
 
        for(Ice::StringSeq::const_iterator q = removed.begin(); q != removed.end(); ++q)
2490
 
        {
2491
 
            out << nl << "server `" << *q << "' removed";
2492
 
        }    
2493
 
        out << eb;
2494
 
    }
2495
 
    out << eb;
2496
 
}
2497
 
 
2498
 
ApplicationHelper::ApplicationHelper(const Ice::CommunicatorPtr& communicator, 
2499
 
                                     const ApplicationDescriptor& desc,
2500
 
                                     bool enableWarning,
2501
 
                                     bool instantiate) :
2502
 
    _communicator(communicator),
2503
 
    _def(desc)
2504
 
{
2505
 
    if(_def.name.empty())
2506
 
    {
2507
 
        throw DeploymentException("invalid application: empty name");
2508
 
    }
2509
 
 
2510
 
    Resolver resolve(_def, communicator, enableWarning);
2511
 
 
2512
 
    if(instantiate)
2513
 
    {
2514
 
        //
2515
 
        // Instantiate the application definition.
2516
 
        //
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);
2524
 
        
2525
 
        for(ReplicaGroupDescriptorSeq::iterator r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r)
2526
 
        {
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)
2532
 
            {
2533
 
                resolve.exception("replica group load balancing is not set");
2534
 
            }
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())
2539
 
            {
2540
 
                resolve.exception("invalid replica group load balancing number of replicas value: empty value");
2541
 
            }
2542
 
            else if(desc.loadBalancing->nReplicas[0] == '-')
2543
 
            {
2544
 
                resolve.exception("invalid replica group load balancing number of replicas value: inferior to 0");
2545
 
            }
2546
 
            AdaptiveLoadBalancingPolicyPtr al = AdaptiveLoadBalancingPolicyPtr::dynamicCast(desc.loadBalancing);
2547
 
            if(al)
2548
 
            {
2549
 
                al->loadSample = resolve(al->loadSample, "replica group load sample");
2550
 
                if(al->loadSample != "" && al->loadSample != "1" && al->loadSample != "5" && al->loadSample != "15")
2551
 
                {
2552
 
                    resolve.exception("invalid load sample value (allowed values are 1, 5 or 15)");
2553
 
                }
2554
 
            }
2555
 
            _instance.replicaGroups.push_back(desc);
2556
 
        }
2557
 
        
2558
 
        //
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.
2562
 
        //
2563
 
        resolve.addPropertySets(_instance.propertySets);
2564
 
    }
2565
 
 
2566
 
    //
2567
 
    // Create the node helpers.
2568
 
    //
2569
 
    NodeHelperDict::const_iterator n;
2570
 
    for(NodeDescriptorDict::const_iterator p = _def.nodes.begin(); p != _def.nodes.end(); ++p)
2571
 
    {
2572
 
        n = _nodes.insert(make_pair(p->first, NodeHelper(p->first, p->second, resolve, instantiate))).first;
2573
 
        if(instantiate)
2574
 
        {
2575
 
            _instance.nodes.insert(make_pair(n->first, n->second.getInstance()));
2576
 
        }
2577
 
    }
2578
 
 
2579
 
    //
2580
 
    // If the application is instantiated, ensure the unicity of
2581
 
    // object ids, adapter ids and server ids.
2582
 
    //    
2583
 
    if(instantiate)
2584
 
    {
2585
 
        multiset<string> serverIds;
2586
 
        multiset<string> adapterIds;
2587
 
        multiset<Ice::Identity> objectIds;
2588
 
        for(n = _nodes.begin(); n != _nodes.end(); ++n)
2589
 
        {
2590
 
            n->second.getIds(serverIds, adapterIds, objectIds);
2591
 
        }
2592
 
 
2593
 
        for(ReplicaGroupDescriptorSeq::iterator r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r)
2594
 
        {
2595
 
            if(r->id.empty())
2596
 
            {
2597
 
                throw DeploymentException("replica group id is empty");
2598
 
            }
2599
 
            if(adapterIds.find(r->id) != adapterIds.end())
2600
 
            {
2601
 
                throw DeploymentException("duplicate replica group `" +  r->id + "'");
2602
 
            }
2603
 
            adapterIds.insert(r->id);
2604
 
            for(ObjectDescriptorSeq::const_iterator o = r->objects.begin(); o != r->objects.end(); ++o)
2605
 
            {
2606
 
                objectIds.insert(o->id);
2607
 
            }
2608
 
        }
2609
 
 
2610
 
        for(multiset<string>::const_iterator s = serverIds.begin(); s != serverIds.end(); ++s)
2611
 
        {
2612
 
            if(serverIds.count(*s) > 1)
2613
 
            {
2614
 
                resolve.exception("duplicate server `" + *s + "'");
2615
 
            }
2616
 
        }
2617
 
        for(multiset<string>::const_iterator a = adapterIds.begin(); a != adapterIds.end(); ++a)
2618
 
        {
2619
 
            if(adapterIds.count(*a) > 1)
2620
 
            {
2621
 
                resolve.exception("duplicate adapter `" + *a + "'");
2622
 
            }
2623
 
        }
2624
 
        for(multiset<Ice::Identity>::const_iterator o = objectIds.begin(); o != objectIds.end(); ++o)
2625
 
        {
2626
 
            if(objectIds.count(*o) > 1)
2627
 
            {
2628
 
                resolve.exception("duplicate object `" + _communicator->identityToString(*o) + "'");
2629
 
            }
2630
 
        }
2631
 
    }
2632
 
}
2633
 
 
2634
 
ApplicationUpdateDescriptor
2635
 
ApplicationHelper::diff(const ApplicationHelper& helper) const
2636
 
{
2637
 
    ApplicationUpdateDescriptor updt;
2638
 
    assert(helper._def.name == _def.name);
2639
 
 
2640
 
    updt.name = _def.name;
2641
 
    if(_def.description != helper._def.description)
2642
 
    {
2643
 
        updt.description = new BoxedString(_def.description);
2644
 
    }
2645
 
 
2646
 
    updt.variables = getDictUpdatedElts(helper._def.variables, _def.variables);
2647
 
    updt.removeVariables = getDictRemovedElts(helper._def.variables, _def.variables);
2648
 
 
2649
 
    updt.propertySets = getDictUpdatedElts(helper._def.propertySets, _def.propertySets);
2650
 
    updt.removePropertySets = getDictRemovedElts(helper._def.propertySets, _def.propertySets);
2651
 
 
2652
 
    if(_def.distrib != helper._def.distrib)
2653
 
    {
2654
 
        updt.distrib = new BoxedDistributionDescriptor(_def.distrib);
2655
 
    }
2656
 
 
2657
 
    GetReplicaGroupId rk;
2658
 
    ReplicaGroupEq req;
2659
 
    updt.replicaGroups = getSeqUpdatedEltsWithEq(helper._def.replicaGroups, _def.replicaGroups, rk, req);
2660
 
    updt.removeReplicaGroups = getSeqRemovedElts(helper._def.replicaGroups, _def.replicaGroups, rk);
2661
 
 
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);
2667
 
 
2668
 
    NodeHelperDict updated = getDictUpdatedElts(helper._nodes, _nodes);
2669
 
    for(NodeHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
2670
 
    {
2671
 
        NodeHelperDict::const_iterator q = helper._nodes.find(p->first);
2672
 
        if(q == helper._nodes.end())
2673
 
        {
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);
2683
 
        }
2684
 
        else
2685
 
        {
2686
 
            updt.nodes.push_back(p->second.diff(q->second));
2687
 
        }
2688
 
    }
2689
 
    updt.removeNodes = getDictRemovedElts(helper._nodes, _nodes);
2690
 
 
2691
 
    return updt;
2692
 
}
2693
 
 
2694
 
ApplicationDescriptor
2695
 
ApplicationHelper::update(const ApplicationUpdateDescriptor& updt) const
2696
 
{
2697
 
    ApplicationDescriptor def;
2698
 
    GetReplicaGroupId rg;
2699
 
 
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);
2708
 
 
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)
2711
 
    {
2712
 
        NodeHelperDict::const_iterator q = _nodes.find(p->name);
2713
 
        if(q != _nodes.end()) // Updated node
2714
 
        {
2715
 
            NodeDescriptor desc = q->second.update(*p, resolve);
2716
 
            def.nodes.insert(make_pair(p->name, q->second.update(*p, resolve)));
2717
 
        }
2718
 
        else // New node
2719
 
        {
2720
 
            NodeDescriptor desc;
2721
 
            desc.variables = p->variables;
2722
 
            if(!p->removeVariables.empty())
2723
 
            {
2724
 
                resolve.exception("can't remove variables for node `" + p->name + "': node doesn't exist");
2725
 
            }
2726
 
            desc.propertySets = p->propertySets;
2727
 
            if(!p->removePropertySets.empty())
2728
 
            {
2729
 
                resolve.exception("can't remove property sets for node `" + p->name + "': node doesn't exist");
2730
 
            }
2731
 
            desc.servers = p->servers;
2732
 
            desc.serverInstances = p->serverInstances;
2733
 
            if(!p->removeServers.empty())
2734
 
            {
2735
 
                resolve.exception("can't remove servers for node `" + p->name + "': node doesn't exist");
2736
 
            }
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));
2740
 
        }
2741
 
    }
2742
 
    set<string> removedNodes(updt.removeNodes.begin(), updt.removeNodes.end());
2743
 
    for(NodeHelperDict::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n)
2744
 
    {
2745
 
        if(removedNodes.find(n->first) != removedNodes.end() || def.nodes.find(n->first) != def.nodes.end())
2746
 
        {
2747
 
            continue; // Node was removed or updated.
2748
 
        }
2749
 
        def.nodes.insert(make_pair(n->first, n->second.getDefinition()));
2750
 
    }
2751
 
 
2752
 
    return def;
2753
 
}
2754
 
 
2755
 
ApplicationDescriptor
2756
 
ApplicationHelper::instantiateServer(const string& node, const ServerInstanceDescriptor& instance) const
2757
 
{
2758
 
    //
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.
2763
 
    //
2764
 
    ApplicationDescriptor def = _def;
2765
 
    NodeDescriptorDict::iterator q = def.nodes.find(node);
2766
 
    if(q == def.nodes.end())
2767
 
    {
2768
 
        NodeDescriptor desc;
2769
 
        desc.serverInstances.push_back(instance);
2770
 
        def.nodes.insert(make_pair(node, desc));
2771
 
    }
2772
 
    else
2773
 
    {
2774
 
        q->second.serverInstances.push_back(instance);
2775
 
    }
2776
 
    return def;
2777
 
}
2778
 
 
2779
 
void
2780
 
ApplicationHelper::getIds(set<string>& serverIds, set<string>& adapterIds, set<Ice::Identity>& objectIds) const
2781
 
{
2782
 
    multiset<string> sIds;
2783
 
    multiset<string> aIds;
2784
 
    multiset<Ice::Identity> oIds;
2785
 
    
2786
 
    for(NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p)
2787
 
    {
2788
 
        p->second.getIds(sIds, aIds, oIds);
2789
 
    }
2790
 
    ReplicaGroupDescriptorSeq::const_iterator r;
2791
 
    for(r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r)
2792
 
    {
2793
 
        aIds.insert(r->id);
2794
 
        for(ObjectDescriptorSeq::const_iterator o = r->objects.begin(); o != r->objects.end(); ++o)
2795
 
        {
2796
 
            oIds.insert(o->id);
2797
 
        }
2798
 
    }
2799
 
 
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()));
2803
 
}
2804
 
 
2805
 
void
2806
 
ApplicationHelper::getReplicaGroups(set<string>& replicaGroups, set<string>& adapterReplicaGroups) const
2807
 
{
2808
 
    ReplicaGroupDescriptorSeq::const_iterator r;
2809
 
    for(r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r)
2810
 
    {
2811
 
        replicaGroups.insert(r->id);
2812
 
    }
2813
 
 
2814
 
    set<string> allAdapterReplicaGroups;
2815
 
    for(NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p)
2816
 
    {
2817
 
        p->second.getReplicaGroups(allAdapterReplicaGroups);
2818
 
    }
2819
 
    
2820
 
    //
2821
 
    // Only return references to replica groups which don't belong to
2822
 
    // this application.
2823
 
    //
2824
 
    set_difference(allAdapterReplicaGroups.begin(), allAdapterReplicaGroups.end(),
2825
 
                   replicaGroups.begin(), replicaGroups.end(), set_inserter(adapterReplicaGroups));
2826
 
}
2827
 
 
2828
 
const ApplicationDescriptor&
2829
 
ApplicationHelper::getDefinition() const
2830
 
{
2831
 
    return _def;
2832
 
}
2833
 
 
2834
 
const ApplicationDescriptor&
2835
 
ApplicationHelper::getInstance() const
2836
 
{
2837
 
    assert(!_instance.name.empty());
2838
 
    return _instance;
2839
 
}
2840
 
 
2841
 
map<string, ServerInfo>
2842
 
ApplicationHelper::getServerInfos(const string& uuid, int revision) const
2843
 
{
2844
 
    assert(!_instance.name.empty());
2845
 
 
2846
 
    map<string, ServerInfo> servers;
2847
 
    for(NodeHelperDict::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n)
2848
 
    {
2849
 
        n->second.getServerInfos(_def.name, uuid, revision, servers);
2850
 
    }
2851
 
    return servers;
2852
 
}
2853
 
 
2854
 
void
2855
 
ApplicationHelper::getDistributions(DistributionDescriptor& distribution, 
2856
 
                                    vector<string>& nodes,
2857
 
                                    const string& server) const
2858
 
{
2859
 
    assert(!_instance.name.empty());
2860
 
 
2861
 
    distribution = _instance.distrib;
2862
 
    for(NodeHelperDict::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n)
2863
 
    {
2864
 
        if(n->second.hasDistributions(server))
2865
 
        {
2866
 
            nodes.push_back(n->first);
2867
 
            if(!server.empty())
2868
 
            {
2869
 
                break;
2870
 
            }
2871
 
        }
2872
 
        else if(!_instance.distrib.icepatch.empty() && 
2873
 
                ((server.empty() && n->second.hasServers()) || n->second.hasServer(server)))
2874
 
        {
2875
 
            nodes.push_back(n->first);
2876
 
        }
2877
 
    }
2878
 
}
2879
 
 
2880
 
void
2881
 
ApplicationHelper::print(Output& out, const ApplicationInfo& info) const
2882
 
{
2883
 
    assert(!_instance.name.empty());
2884
 
 
2885
 
    out << "application `" << _instance.name << "'";
2886
 
    out << sb;
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 << "'";
2893
 
 
2894
 
    if(!_instance.description.empty())
2895
 
    {
2896
 
        out << nl << "description = `" << _instance.description << "'";
2897
 
    }
2898
 
    if(!_instance.variables.empty())
2899
 
    {
2900
 
        out << nl << "variables";
2901
 
        out << sb;
2902
 
        for(StringStringDict::const_iterator p = _instance.variables.begin(); p != _instance.variables.end(); 
2903
 
            ++p)
2904
 
        {
2905
 
            out << nl << p->first << " = `" << p->second << "'";
2906
 
        }
2907
 
        out << eb;
2908
 
    }
2909
 
    if(!_instance.propertySets.empty())
2910
 
    {
2911
 
        PropertySetDescriptorDict::const_iterator q;
2912
 
        for(q = _instance.propertySets.begin(); q != _instance.propertySets.end(); ++q)
2913
 
        {
2914
 
            out << nl << "properties `" << q->first << "'";
2915
 
            out << sb;
2916
 
            if(!q->second.references.empty())
2917
 
            {
2918
 
                out << nl << "references = " << toString(q->second.references);
2919
 
            }
2920
 
            PropertyDescriptorSeq::const_iterator r;
2921
 
            for(r = q->second.properties.begin(); r != q->second.properties.end(); ++r)
2922
 
            {
2923
 
                out << nl << r->name << " = `" << r->value << "'";
2924
 
            }
2925
 
            out << eb;
2926
 
        }
2927
 
    }
2928
 
    if(!_instance.distrib.icepatch.empty())
2929
 
    {
2930
 
        out << nl << "distribution";
2931
 
        out << sb;
2932
 
        out << nl << "proxy = `" << _instance.distrib.icepatch << "'";
2933
 
        if(!_instance.distrib.directories.empty())
2934
 
        {
2935
 
            out << nl << "directories = `" << toString(_instance.distrib.directories) << "'";
2936
 
        }
2937
 
        out << eb;
2938
 
    }
2939
 
    if(!_instance.replicaGroups.empty())
2940
 
    {
2941
 
        out << nl << "replica groups";
2942
 
        out << sb;
2943
 
        ReplicaGroupDescriptorSeq::const_iterator p;
2944
 
        for(p = _instance.replicaGroups.begin(); p != _instance.replicaGroups.end(); ++p)
2945
 
        {
2946
 
            out << nl << "id = `" << p->id << "' load balancing = `";
2947
 
            if(!p->loadBalancing)
2948
 
            {
2949
 
                out << "default (return all endpoints)";
2950
 
            }
2951
 
            else if(RandomLoadBalancingPolicyPtr::dynamicCast(p->loadBalancing))
2952
 
            {
2953
 
                out << "random";
2954
 
            }
2955
 
            else if(RoundRobinLoadBalancingPolicyPtr::dynamicCast(p->loadBalancing))
2956
 
            {
2957
 
                out << "round-robin";
2958
 
            }
2959
 
            else if(AdaptiveLoadBalancingPolicyPtr::dynamicCast(p->loadBalancing))
2960
 
            {
2961
 
                out << "adaptive" ;
2962
 
            }
2963
 
            else
2964
 
            {
2965
 
                out << "<unknown load balancing policy>";
2966
 
            }
2967
 
            out << "'";
2968
 
        }
2969
 
        out << eb;
2970
 
    }
2971
 
    if(!_instance.serverTemplates.empty())
2972
 
    {
2973
 
        out << nl << "server templates";
2974
 
        out << sb;
2975
 
        TemplateDescriptorDict::const_iterator p;
2976
 
        for(p = _instance.serverTemplates.begin(); p != _instance.serverTemplates.end(); ++p)
2977
 
        {
2978
 
            out << nl << p->first;
2979
 
        }
2980
 
        out << eb;
2981
 
    }
2982
 
    if(!_instance.serviceTemplates.empty())
2983
 
    {
2984
 
        out << nl << "service templates";
2985
 
        out << sb;
2986
 
        TemplateDescriptorDict::const_iterator p;
2987
 
        for(p = _instance.serviceTemplates.begin(); p != _instance.serviceTemplates.end(); ++p)
2988
 
        {
2989
 
            out << nl << p->first;
2990
 
        }
2991
 
        out << eb;
2992
 
    }
2993
 
    if(!_nodes.empty())
2994
 
    {
2995
 
        for(NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p)
2996
 
        {
2997
 
            p->second.print(out);
2998
 
        }
2999
 
    }
3000
 
    out << eb;
3001
 
}
3002
 
 
3003
 
void
3004
 
ApplicationHelper::printDiff(Output& out, const ApplicationHelper& helper) const
3005
 
{
3006
 
    assert(!_instance.name.empty());
3007
 
 
3008
 
    out << "application `" << _def.name << "'";
3009
 
    out << sb;
3010
 
 
3011
 
    {
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())
3015
 
        {
3016
 
            out << nl << "variables udpated";
3017
 
        }    
3018
 
    }
3019
 
    {
3020
 
        if(_def.distrib != helper._def.distrib)
3021
 
        {
3022
 
            out << nl << "distribution updated";
3023
 
        }
3024
 
    }
3025
 
    {
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())
3029
 
        {
3030
 
            out << nl << "property sets udpated";
3031
 
        }
3032
 
    }
3033
 
    {
3034
 
        GetReplicaGroupId rk;
3035
 
        ReplicaGroupEq req;
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())
3040
 
        {
3041
 
            out << nl << "replica groups";
3042
 
            out << sb;
3043
 
            ReplicaGroupDescriptorSeq::iterator p = updated.begin();
3044
 
            while(p != updated.end())
3045
 
            {
3046
 
                ReplicaGroupDescriptorSeq::const_iterator r;
3047
 
                for(r = helper._def.replicaGroups.begin(); r != helper._def.replicaGroups.end(); 
3048
 
                    ++r)
3049
 
                {
3050
 
                    if(p->id == r->id)
3051
 
                    {
3052
 
                        out << nl << "replica group `" << r->id << "' updated";
3053
 
                        p = updated.erase(p);
3054
 
                        break;
3055
 
                    }
3056
 
                }
3057
 
                if(r == helper._def.replicaGroups.end())
3058
 
                {
3059
 
                    ++p;
3060
 
                }
3061
 
            }
3062
 
            for(p = updated.begin(); p != updated.end(); ++p)
3063
 
            {
3064
 
                out << nl << "replica group `" << p->id << "' added";
3065
 
            }
3066
 
            for(Ice::StringSeq::const_iterator q = removed.begin(); q != removed.end(); ++q)
3067
 
            {
3068
 
                out << nl << "replica group `" << *q << "' removed";
3069
 
            }
3070
 
            out << eb;
3071
 
        }
3072
 
    }
3073
 
 
3074
 
    {
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())
3080
 
        {
3081
 
            out << nl << "server templates";
3082
 
            out << sb;
3083
 
            for(TemplateDescriptorDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
3084
 
            {
3085
 
                if(helper._def.serverTemplates.find(p->first) == helper._def.serverTemplates.end())
3086
 
                {
3087
 
                    out << nl << "server template `" << p->first << "' added";
3088
 
                }
3089
 
            }
3090
 
            for(TemplateDescriptorDict::const_iterator q = updated.begin(); q != updated.end(); ++q)
3091
 
            {
3092
 
                if(helper._def.serverTemplates.find(q->first) != helper._def.serverTemplates.end())
3093
 
                {
3094
 
                    out << nl << "server template `" << q->first << "' updated";
3095
 
                }
3096
 
            }
3097
 
            for(Ice::StringSeq::const_iterator r = removed.begin(); r != removed.end(); ++r)
3098
 
            {
3099
 
                out << nl << "server template `" << *r << "' removed";
3100
 
            }
3101
 
            out << eb;
3102
 
        }
3103
 
    }
3104
 
    {
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())
3110
 
        {
3111
 
            out << nl << "service templates";
3112
 
            out << sb;
3113
 
            for(TemplateDescriptorDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
3114
 
            {
3115
 
                if(helper._def.serviceTemplates.find(p->first) == helper._def.serviceTemplates.end())
3116
 
                {
3117
 
                    out << nl << "service template `" << p->first << "' added";
3118
 
                }
3119
 
            }
3120
 
            for(TemplateDescriptorDict::const_iterator q = updated.begin(); q != updated.end(); ++q)
3121
 
            {
3122
 
                if(helper._def.serviceTemplates.find(q->first) != helper._def.serviceTemplates.end())
3123
 
                {
3124
 
                    out << nl << "service template `" << q->first << "' updated";
3125
 
                }
3126
 
            }
3127
 
            for(Ice::StringSeq::const_iterator r = removed.begin(); r != removed.end(); ++r)
3128
 
            {
3129
 
                out << nl << "service template `" << *r << "' removed";
3130
 
            }
3131
 
            out << eb;
3132
 
        }
3133
 
    }
3134
 
    {
3135
 
        NodeHelperDict updated = getDictUpdatedElts(helper._nodes, _nodes);
3136
 
        Ice::StringSeq removed = getDictRemovedElts(helper._nodes, _nodes);
3137
 
        if(!updated.empty() || !removed.empty())
3138
 
        {
3139
 
            out << nl << "nodes";
3140
 
            out << sb;
3141
 
            for(NodeHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p)
3142
 
            {
3143
 
                NodeHelperDict::const_iterator q = helper._nodes.find(p->first);
3144
 
                if(q == helper._nodes.end())
3145
 
                {
3146
 
                    p->second.print(out);
3147
 
                }
3148
 
            }
3149
 
            for(NodeHelperDict::const_iterator r = updated.begin(); r != updated.end(); ++r)
3150
 
            {
3151
 
                NodeHelperDict::const_iterator q = helper._nodes.find(r->first);
3152
 
                if(q != helper._nodes.end())
3153
 
                {
3154
 
                    r->second.printDiff(out, q->second);
3155
 
                }
3156
 
            }
3157
 
            for(Ice::StringSeq::const_iterator s = removed.begin(); s != removed.end(); ++s)
3158
 
            {
3159
 
                out << nl << "node `" << *s << "' removed";
3160
 
            }
3161
 
            out << eb;
3162
 
        }
3163
 
    }
3164
 
    out << eb;
3165
 
}
3166
 
 
3167
 
bool
3168
 
IceGrid::descriptorEqual(const ServerDescriptorPtr& lhs, const ServerDescriptorPtr& rhs)
3169
 
{
3170
 
    IceBoxDescriptorPtr lhsIceBox = IceBoxDescriptorPtr::dynamicCast(lhs);
3171
 
    IceBoxDescriptorPtr rhsIceBox = IceBoxDescriptorPtr::dynamicCast(rhs);
3172
 
    if(lhsIceBox && rhsIceBox)
3173
 
    {
3174
 
        return IceBoxHelper(lhsIceBox) == IceBoxHelper(rhsIceBox);
3175
 
    }
3176
 
    else if(!lhsIceBox && !rhsIceBox)
3177
 
    {
3178
 
        return ServerHelper(lhs) == ServerHelper(rhs);
3179
 
    }
3180
 
    else
3181
 
    {
3182
 
        return false;
3183
 
    }
3184
 
}
3185
 
 
3186
 
ServerHelperPtr
3187
 
IceGrid::createHelper(const ServerDescriptorPtr& desc)
3188
 
{
3189
 
    IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(desc);
3190
 
    if(iceBox)
3191
 
    {
3192
 
        return new IceBoxHelper(iceBox);
3193
 
    }
3194
 
    else
3195
 
    {
3196
 
        return new ServerHelper(desc);
3197
 
    }
3198
 
}