1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
// $Id$
#include "ace/iosfwd.h"
#include "dance/Logger/Log_Macros.h"
#include "NodeApplicationManager_Impl.h"
#include "dance/NodeApplication/NodeApplication_Impl.h"
#include "dance/DAnCE_PropertiesC.h"
#include "dance/DAnCE_Utility.h"
#include "ace/Unbounded_Set.h"
#include "tao/ORB.h"
#include "tao/Object.h"
using namespace DAnCE;
using namespace DAnCE::Utility;
NodeApplicationManager_Impl::NodeApplicationManager_Impl (CORBA::ORB_ptr orb,
PortableServer::POA_ptr poa,
DAnCE::ArtifactInstallation_ptr installer,
const ACE_CString& node_name,
const PROPERTY_MAP &properties)
: orb_ (CORBA::ORB::_duplicate (orb)),
poa_ (PortableServer::POA::_duplicate (poa)),
installer_ (DAnCE::ArtifactInstallation::_duplicate (installer)),
application_ (0),
node_name_ (node_name),
properties_ ()
{
DANCE_TRACE ("NodeApplicationManager_Impl::NodeApplicationManager_Impl");
DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_DEBUG, DLINFO
ACE_TEXT(" NodeApplicationManager_Impl::NodeApplicationManager_Impl - ")
ACE_TEXT("Initializing for node '%C' starting...\n"),
node_name.c_str()));
PROPERTY_MAP::const_iterator i = properties.begin ();
while (!i.done ())
{
DANCE_TRACE_LOG (DANCE_LOG_DETAILED_TRACE,
(LM_DEBUG, DLINFO
ACE_TEXT("NodeApplicationManager_Impl::NodeApplicationManager_Impl - ")
ACE_TEXT("Binding value for property %C\n"), i->key ().c_str ()));
this->properties_.bind (i->key (), i->item ());
i.advance ();
}
const ACE_TCHAR *ior = 0;
if (get_property_value (DAnCE::INSTANCE_NC, this->properties_, ior) ||
get_property_value (DAnCE::DOMAIN_NC, this->properties_, ior))
{
try
{
CORBA::Object_var obj = this->orb_->string_to_object (ior);
this->instance_nc_ = CosNaming::NamingContext::_narrow (obj);
}
catch (const CORBA::Exception &e)
{
DANCE_ERROR (DANCE_LOG_NONFATAL_ERROR,
(LM_ERROR, DLINFO
ACE_TEXT("NodeApplicationManager_Impl::NodeApplicationManager_Impl - ")
ACE_TEXT("Unable to resolve the instance naming context:%C\n"),
e._info ().c_str ()));
}
DANCE_DEBUG (DANCE_LOG_MINOR_EVENT,
(LM_DEBUG, DLINFO
ACE_TEXT("NodeApplicationManager_Impl::NodeApplicationManager_Impl - ")
ACE_TEXT("Successfully resolved the instance naming context.\n")));
}
else DANCE_DEBUG (DANCE_LOG_MAJOR_DEBUG_INFO,
(LM_DEBUG, DLINFO
ACE_TEXT("NodeApplicationManager_Impl::NodeApplicationManager_Impl - ")
ACE_TEXT("No instance NC was provided\n")));
}
NodeApplicationManager_Impl::~NodeApplicationManager_Impl()
{
DANCE_TRACE ("NodeApplicationManager_Impl::~NodeApplicationManager_Impl");
try
{
// initialize installer
this->installer_->initialize ();
// install artifacts for each sub plan and update path and libpath
// properties for the locality manager instance of each sub plan
// also pass the installer reference in a property
for (LocalitySplitter::TSubPlanIterator itplan = this->split_plan_.plans ().begin ();
itplan != this->split_plan_.plans ().end ();
++itplan)
{
// remove all artifacts for this sub plan
this->installer_->remove_all ((*itplan).int_id_.UUID. in ());
}
// cleanup installer resources
this->installer_->clear ();
if (this->application_ != 0)
{
CORBA::Object_var app =
this->poa_->servant_to_reference (this->application_);
PortableServer::ObjectId_var id = this->poa_->reference_to_id (app);
this->poa_->deactivate_object (id);
delete this->application_;
this->application_ = 0;
}
}
catch (...)
{
DANCE_ERROR (DANCE_LOG_NONFATAL_ERROR,
(LM_ERROR, DLINFO
ACE_TEXT("NodeApplicationManager_Impl::~NodeApplicationManager_Impl - ")
ACE_TEXT("Caught exception in NodeApplicationManager destructor\n")));
}
}
void
NodeApplicationManager_Impl::preparePlan (const Deployment::DeploymentPlan& plan)
{
DANCE_TRACE ("NodeApplicationManager_Impl::preparePlan");
DANCE_DEBUG (DANCE_LOG_MINOR_EVENT,
(LM_TRACE, DLINFO
ACE_TEXT("NodeApplicationManager_impl::preparePlan - ")
ACE_TEXT("Performing locality split on plan %C.\n"),
plan.UUID.in ()));
this->split_plan_.split_plan (plan);
DANCE_DEBUG (DANCE_LOG_EVENT_TRACE,
(LM_TRACE, DLINFO
ACE_TEXT("NodeApplicationManager_impl::preparePlan - ")
ACE_TEXT("Plan %C successfully split into %u localities.\n"),
plan.UUID.in (),
this->split_plan_.plans ().current_size ()));
// initialize installer
this->installer_->initialize ();
// install artifacts for each sub plan and update path and libpath
// properties for the locality manager instance of each sub plan
// also pass the installer reference in a property
for (LocalitySplitter::TSubPlanIterator itplan = this->split_plan_.plans ().begin ();
itplan != this->split_plan_.plans ().end ();
++itplan)
{
ACE_Unbounded_Set<ACE_CString> artifact_paths;
::Deployment::DeploymentPlan &sub_plan = (*itplan).int_id_;
LocalitySplitter::TSubPlanKey &sub_plan_key = (*itplan).ext_id_;
DANCE_DEBUG (DANCE_LOG_MINOR_EVENT,
(LM_TRACE, DLINFO
ACE_TEXT("NodeApplicationManager_impl::preparePlan - ")
ACE_TEXT("Installing %u artifacts for locality %C.\n"),
sub_plan.artifact.length (),
sub_plan.UUID.in ()));
// install artifacts
for (CORBA::ULong i=0;
i < sub_plan.artifact.length ();
++i)
{
this->installer_->install(sub_plan.UUID.in (),
sub_plan.artifact[i]);
CORBA::String_var location =
this->installer_->get_artifact_location (sub_plan.UUID.in (),
sub_plan.artifact[i].name.in ());
// modify artifact descriptor location field to reflect the installed
// artifact's location
CORBA::ULong loc_last = sub_plan.artifact[i].location.length ();
sub_plan.artifact[i].location.length (loc_last + 1);
for (CORBA::ULong iloc = loc_last;
iloc > 0;
--iloc)
{
// shift all locations 1 position to the back to make room for the installed
// location
sub_plan.artifact[i].location[iloc] = sub_plan.artifact[i].location[iloc - 1];
}
// store installed location as first in list
sub_plan.artifact[i].location[0] = location._retn ();
// collect all unique paths
ACE_CString path (sub_plan.artifact[i].location[0].in (),
0, false); // avoid copying
ACE_CString::size_type pos = path.rfind (ACE_DIRECTORY_SEPARATOR_CHAR_A);
if (pos != ACE_CString::npos)
{
artifact_paths.insert (path.substr (0, pos>0 ? pos : 1));
}
}
// get locality manager deployment descriptors
::Deployment::InstanceDeploymentDescription& lm_idd =
sub_plan.instance[sub_plan_key.locality_manager_instance ()];
::Deployment::MonolithicDeploymentDescription& lm_mdd =
sub_plan.implementation[lm_idd.implementationRef];
// update path and libpath properties of sub plan locality manager
if (artifact_paths.size () > 0)
{
ACE_CString search_path;
for (ACE_Unbounded_Set<ACE_CString>::iterator it = artifact_paths.begin ();
it != artifact_paths.end ();
++it)
{
if (!search_path.empty ())
search_path += ACE_TEXT_ALWAYS_CHAR (ACE_LD_SEARCH_PATH_SEPARATOR_STR);
search_path += *it;
}
// update PATH
ACE_CString new_path;
const char* prop_val = 0;
if (DAnCE::Utility::get_property_value (DAnCE::DANCE_LM_PATH,
lm_mdd.execParameter,
prop_val) && prop_val != 0)
{
new_path += prop_val;
new_path += ACE_TEXT_ALWAYS_CHAR (ACE_LD_SEARCH_PATH_SEPARATOR_STR);
new_path += search_path;
}
else
{
new_path.set (search_path.c_str (), false); // avoid copying
}
DAnCE::Utility::update_property_value (DAnCE::DANCE_LM_PATH,
lm_mdd.execParameter,
new_path.c_str ());
// On windows these two search paths are the same
#if !defined (ACE_WIN32)
// update LIBPATH
new_path.clear ();
prop_val = 0;
if (DAnCE::Utility::get_property_value (DAnCE::DANCE_LM_LIBPATH,
lm_mdd.execParameter,
prop_val) && prop_val != 0)
{
new_path += prop_val;
new_path += ACE_TEXT_ALWAYS_CHAR (ACE_LD_SEARCH_PATH_SEPARATOR_STR);
new_path += search_path;
}
else
{
new_path.set (search_path.c_str (), false); // avoid copying
}
DAnCE::Utility::update_property_value (DAnCE::DANCE_LM_LIBPATH,
lm_mdd.execParameter,
new_path.c_str ());
#endif
}
const char *config_file;
if (DAnCE::Utility::get_property_value (DAnCE::DANCE_LM_CONFIGFILE,
this->properties_,
config_file))
{
DAnCE::Utility::update_property_value<const char *> (DAnCE::DANCE_LM_CONFIGFILE,
lm_idd.configProperty,
config_file);
}
DAnCE::Utility::update_property_value<CosNaming::NamingContext_ptr> (
DAnCE::LOCALITY_NAMINGCONTEXT,
lm_idd.configProperty,
this->instance_nc_. in ());
// pass installer reference as an execParameter property
DAnCE::Utility::update_property_value<DAnCE::ArtifactInstallation_ptr> (
DAnCE::DANCE_LM_INSTALLER,
lm_mdd.execParameter,
this->installer_.in ());
}
// cleanup installer resources
// (does *not* cleanup install registry; just signals end of install actions)
this->installer_->clear ();
DANCE_DEBUG (DANCE_LOG_EVENT_TRACE,
(LM_TRACE, DLINFO
ACE_TEXT("NodeApplicationManager_impl::preparePlan - ")
ACE_TEXT("Finished preparing plan %C.\n"),
plan.UUID.in ()));
}
Deployment::Application_ptr
NodeApplicationManager_Impl::startLaunch (const Deployment::Properties &prop,
Deployment::Connections_out providedReference)
{
DANCE_TRACE ("NodeApplicationManager_Impl::startLaunch");
// Creating NodeApplication object
DANCE_DEBUG (DANCE_LOG_MINOR_EVENT,
(LM_TRACE, DLINFO ACE_TEXT("NodeApplicationManager_impl::startLaunch - ")
ACE_TEXT("Initializing NodeApplication\n")));
ACE_NEW_THROW_EX (this->application_,
NodeApplication_Impl (this->orb_.in(),
this->poa_.in(),
this->installer_.in (),
this->node_name_,
this->properties_),
CORBA::NO_MEMORY ());
DANCE_DEBUG (DANCE_LOG_TRACE,
(LM_TRACE, DLINFO
ACE_TEXT("NodeApplicationManager_impl::startLaunch - ")
ACE_TEXT("Instructing NodeApplication to prepare locality managers.\n")));
this->application_->prepare_instances (this->split_plan_.plans ());
DANCE_DEBUG (DANCE_LOG_TRACE,
(LM_TRACE, DLINFO
ACE_TEXT("NodeApplicationManager_impl::startLaunch - ")
ACE_TEXT("Instructing NodeApplication to start launch localities.\n")));
this->application_->start_launch_instances (prop, providedReference);
DANCE_DEBUG (DANCE_LOG_EVENT_TRACE,
(LM_DEBUG, DLINFO
ACE_TEXT("NodeApplicationManager_impl::startLaunch - ")
ACE_TEXT("Activating NodeApplication servant\n")));
PortableServer::ObjectId_var as_id =
this->poa_->activate_object (this->application_);
CORBA::Object_var as_obj = this->poa_->id_to_reference (as_id.in ());
Deployment::Application_var app = Deployment::Application::_narrow (as_obj.in ());
if (CORBA::is_nil (app))
{
DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR,
(LM_ERROR, DLINFO,
"NodeApplicationManager_Impl::startLaunch - ",
"NodeApplication servant failed to activate\n"));
throw ::Deployment::StartError ("NodeApplication",
"Activation failure");
}
return app._retn ();
}
void
NodeApplicationManager_Impl::destroyApplication (Deployment::Application_ptr application)
{
DANCE_TRACE ("NodeApplicationManager_Impl::destroyApplication");
try
{
if (!application->_is_equivalent (this->poa_->servant_to_reference (this->application_)))
{
DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR,
(LM_ERROR, DLINFO
ACE_TEXT("NodeApplicationManager_Impl::destroyApplication - ")
ACE_TEXT("application is equivalent to current application\n")));
throw ::Deployment::StopError("NodeApplicationManager",
"Wrong application passed to destroyApplication");
}
this->application_->remove_instances ();
PortableServer::ObjectId_var id = this->poa_->reference_to_id (application);
this->poa_->deactivate_object (id);
delete this->application_;
this->application_ = 0;
}
catch (const CORBA::SystemException &)
{
throw;
}
catch (const Deployment::StopError &)
{
throw;
}
catch (const CORBA::UserException &e)
{
DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR,
(LM_ERROR, DLINFO
ACE_TEXT("NodeApplicationManager_Impl::destroyApplication failed ")
ACE_TEXT ("with UserException %C(%C) \"%C\"\n"),
e._name(), e._rep_id(), e._info().c_str()));
throw Deployment::StopError(e._name(), e._info().c_str());
}
catch (...)
{
DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
ACE_TEXT("NodeApplicationManager_Impl::destroyApplication failed ")
ACE_TEXT("with unknown exception.\n")));
throw Deployment::StopError("NodeApplicatoinManager", "Unknown C++ exception in destroyApplication");
}
}
|