summaryrefslogtreecommitdiff
path: root/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.cpp
blob: b7e72723dec91be6ded3038d8a0732618d137dff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
#include "Artifact_Installation_Impl.h"
#include "dance/Logger/Log_Macros.h"

#if !defined (__ACE_INLINE__)
#include "Artifact_Installation_Impl.inl"
#endif

#include "ace/Auto_Ptr.h"

namespace DAnCE
  {
    /*
     *  ArtifactRegistry
     */

    ArtifactRegistry::ArtifactRegistry (TCONDITION& condition, bool locked)
      : condition_ (condition),
        locked_ (locked),
        install_count_ (0)
    {
      DANCE_TRACE ("ArtifactRegistry::constructor");
    }

    ArtifactRegistry::~ArtifactRegistry ()
    {
      DANCE_TRACE ("ArtifactRegistry::destructor");
    }

    /*
     *  ArtifactInstallation_Impl
     */

    ArtifactInstallation_Impl::THandlerMap ArtifactInstallation_Impl::handlers_;
    ArtifactInstallation_Impl::TLOCK ArtifactInstallation_Impl::handler_lock_;

    ArtifactInstallation_Impl::ArtifactInstallation_Impl ()
      : POA_DAnCE::ArtifactInstallation (),
        artifacts_condition_ (artifacts_lock_)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::constructor");
    }

    ArtifactInstallation_Impl::~ArtifactInstallation_Impl ()
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::destructor");
    }

    void ArtifactInstallation_Impl::initialize ()
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::initialize");

      ACE_GUARD_REACTION (TLOCK,
                          handler_guard_,
                          handler_lock_,
                          throw Deployment::PlanError (
                            "ArtifactInstallation_Impl::initialize",
                            "ArtifactInstallation handler lock failed"));

      THandlerMap::iterator it = handlers_.end ();
      for (it = handlers_.begin ();
           it != handlers_.end ();
           ++it)
        {
          (*it).second->initialize ();
        }
    }

    void ArtifactInstallation_Impl::clear ()
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::clear");

      ACE_GUARD_REACTION (TLOCK,
                          handler_guard_,
                          handler_lock_,
                          throw Deployment::PlanError (
                            "ArtifactInstallation_Impl::clear",
                            "ArtifactInstallation handler lock failed"));

      THandlerMap::iterator it = handlers_.end ();
      for (it = handlers_.begin ();
           it != handlers_.end ();
           ++it)
        {
          (*it).second->clear ();
        }
    }

    void ArtifactInstallation_Impl::install (
      const char * plan_uuid,
      const ::Deployment::ArtifactDeploymentDescription & artifact)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::install");

      std::string name = artifact.name.in ();

      // allocate (and lock) the artifact registry for the given plan
      ArtifactRegistry::Guard ar_guard (this->allocate_artifact_registry (plan_uuid, name));

      DANCE_DEBUG (DANCE_LOG_MINOR_EVENT,
        (LM_TRACE,  DLINFO ACE_TEXT("ArtifactInstallation_Impl::install - ")
        ACE_TEXT ("installation request for plan %C, artifact %C\n"),
        plan_uuid, name.c_str ()));

      // check to see if artifact has already been previously installed
      if (ar_guard->install_count () > 0)
        {
          DANCE_DEBUG (DANCE_LOG_DETAILED_TRACE, (LM_TRACE,
            DLINFO ACE_TEXT("ArtifactInstallation_Impl::install - ")
            ACE_TEXT ("detected previously installed plan %C, artifact %C @ location %C\n"),
            plan_uuid, name.c_str (), ar_guard->location ().c_str ()));

          // just increment install count and return
          ar_guard->increment_install_count ();
          return;
        }

      // extract artifact properties
      ArtifactInstallationHandler::TPropertyMap properties;
      for (CORBA::ULong i=0; i < artifact.execParameter.length () ;++i)
        {
          Deployment::Property property = artifact.execParameter[i];
          char* prop_val;
          if (property.value >>= CORBA::Any::to_string (prop_val, 0))
            {
              properties[property.name.in ()] = prop_val;
            }
          else
            {
              // @will    this appears to be my first non fatal error
              DANCE_ERROR   (DANCE_LOG_NONFATAL_ERROR,
                (LM_ERROR,  DLINFO ACE_TEXT("ArtifactInstallation_Impl::install - ")
                 ACE_TEXT ("failed to extract property %C for plan %C, artifact %C; ")
                 ACE_TEXT ("property will be ignored\n"),
                 property.name.in (), plan_uuid, name.c_str ()));
            }
        }

      // attempt to install the artifact going through the alternative locations
      CORBA::ULong loc_n = 0;
      while (loc_n < artifact.location.length ())
        {
          try
            {
              std::string location = artifact.location[loc_n].in ();

              DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
                DLINFO ACE_TEXT("ArtifactInstallation_Impl::install -")
                ACE_TEXT (" installation attempt for plan %C, artifact %C")
                ACE_TEXT (" @ location[%u] %C\n"),
                plan_uuid, name.c_str (), loc_n, location.c_str ()));

              // parse protocol stack & path; URI = <protocol>:[<protocol>:[...]]//<path>
              TProtocolStack prot_stack;
              this->parse_uri (plan_uuid, location, prot_stack);

              // if no protocols specified no further action necessary
              if (!prot_stack.empty ())
                {
                  // process protocol handlers from last to first
                  while (!prot_stack.empty ())
                    {
                      std::string protocol = prot_stack.top ();

                      DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
                        DLINFO ACE_TEXT("ArtifactInstallation_Impl::install -")
                        ACE_TEXT (" handling protocol %C for artifact %C @ location %C from plan %C\n"),
                        protocol.c_str (), name.c_str (),
                        location.c_str (), plan_uuid));

                      // find protocol handler and install
                      if (!this->install_i (plan_uuid, protocol, location, properties))
                        {
                          // we are about to throw an exception,
                          // so this is a terminal error message
                          DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR,
                            DLINFO ACE_TEXT("ArtifactInstallation_Impl::install -")
                            ACE_TEXT (" unknown protocol %C for artifact %C from plan %C\n"),
                            protocol.c_str (), name.c_str (), plan_uuid));

                          std::string err ("unknown installation protocol ");
                          err += protocol;
                          throw Deployment::PlanError (plan_uuid,
                                                       err.c_str ());
                        }

                      DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
                        DLINFO ACE_TEXT("ArtifactInstallation_Impl::install -")
                        ACE_TEXT (" protocol %C installed artifact %C @")
                        ACE_TEXT (" location %C from plan %C to location %C\n"),
                        protocol.c_str (), name.c_str (),
                        location.c_str (), plan_uuid, location.c_str ()));

                      // register installed version for later removal
                      ar_guard->versions ().push_back (
                          ArtifactRegistry::Version(protocol, location));

                      // remove handled protocol
                      prot_stack.pop ();
                    }

                  // check property settings and clean installation intermediates if required
                  ArtifactInstallationProperties property_reader (properties);
                  const std::string& propval = property_reader.get_property (
                    ArtifactInstallationProperties::PROP_KEEP_INTERMEDIATES);
                  if (propval != "yes" && propval != "true")
                    {
                      this->remove_intermediates (plan_uuid, name, *ar_guard);
                    }
                }
              else
                {
                  // just register the artifact without protocol
                  ar_guard->versions ().push_back (
                      ArtifactRegistry::Version(std::string(),location));
                }

              // we successfully installed the artifact so increment the install count
              ar_guard->increment_install_count ();

              DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
                DLINFO ACE_TEXT("ArtifactInstallation_Impl::install - ")
                ACE_TEXT ("installed plan %C, artifact %C @ location %C\n"),
                plan_uuid, name.c_str (), location.c_str ()));

              return; // artifact successfully installed
            }
          catch (Deployment::PlanError& ex)
            {
              // since we do not yet know if this is fatal or not, I'm indicating this
              // is non fatal
              DANCE_DEBUG (DANCE_LOG_NONFATAL_ERROR, (LM_ERROR,
                DLINFO ACE_TEXT("ArtifactInstallation_Impl::install -")
                ACE_TEXT (" installation failed for plan %C,")
                ACE_TEXT (" artifact %C @ location[%u] %C : %C\n"),
                plan_uuid, name.c_str (), loc_n, artifact.location[loc_n].in (),
                ex.reason.in ()));

              // artifact installation failed for this location; clean up anything left behind
              this->remove_i (plan_uuid, name.c_str (), &ar_guard, false);

              // if we have alternates we continue otherwise we fail finally
              if (++loc_n >= artifact.location.length ())
                {
                  throw; // rethrow exception
                }

              // try alternate
            }
        }
    }

    void ArtifactInstallation_Impl::parse_uri (const char* plan_uuid,
        std::string& location,
        TProtocolStack& protstack)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::parse_uri");

      DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE,
        DLINFO ACE_TEXT("ArtifactInstallation_Impl::parse_uri -")
        ACE_TEXT (" parsing location %C for plan %C\n"),
                       location.c_str (), plan_uuid));

      std::string loctmp = location;
      std::string::size_type p;
      while ((p = loctmp.find (':')) != std::string::npos)
        {
          if (p == 0)
            {
              std::string err ("malformed location ");
              err += location;
              throw Deployment::PlanError (plan_uuid,
                                           err.c_str ());
            }

          std::string prot = loctmp.substr (0, p);
          protstack.push (prot);

          DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE,
            DLINFO ACE_TEXT("ArtifactInstallation_Impl::parse_uri -")
            ACE_TEXT (" parsed protocol %C from location %C for plan %C\n"),
            prot.c_str (), location.c_str (), plan_uuid));

          loctmp = loctmp.substr (p+1);
        }

      // did we find any protocol specifier?
      if (!protstack.empty ())
        {
          // check for path separator
          p = loctmp.find ("//");
          if (p != 0)
            {
              std::string err ("malformed location ");
              err += location;
              throw Deployment::PlanError (plan_uuid,
                                           err.c_str ());
            }

          // remove path separator
          location = loctmp.substr (2);
        }
    }

    bool ArtifactInstallation_Impl::install_i (const std::string& plan_uuid,
        const std::string& protocol,
        std::string& location,
        const TPropertyMap& properties)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::install_i");

      ACE_GUARD_REACTION (TLOCK,
                          handler_guard_,
                          handler_lock_,
                          throw Deployment::PlanError (
                            plan_uuid.c_str (),
                            "ArtifactInstallation handler lock failed"));

      // find protocol handler
      THandlerMap::iterator ith = handlers_.find (protocol);
      if (ith != handlers_.end ())
        {
          // activate protocol installation handler
          // after successful installation the protocol handler will update
          // the location to the installed version
          ith->second->install (plan_uuid, location, properties);
          return true;
        }
      return false;
    }

    ArtifactRegistry*
    ArtifactInstallation_Impl::allocate_artifact_registry (const std::string& plan_uuid,
                                                           const std::string& name)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::allocate_artifact_registry");

      ACE_GUARD_REACTION (TLOCK,
                          artifacts_guard_,
                          artifacts_lock_,
                          throw Deployment::PlanError (
                            plan_uuid.c_str (),
                            "artifacts lock failed"));

      while (true)
        {
          // get existing or create new
          ArtifactRegistry* ar = 0;
          TArtifactsMap& plan_map = this->artifacts_[plan_uuid];
          TArtifactsMap::iterator it_art = plan_map.find (name);
          if (it_art == plan_map.end ())
            {
              ACE_NEW_NORETURN (ar, ArtifactRegistry (this->artifacts_condition_,
                                                      true));
              if (ar == 0)
                {
                  throw Deployment::PlanError (
                    plan_uuid.c_str (),
                    "out of memory");
                }
              plan_map[name] = ar;
              return ar; // we created it locked so we're ready
            }
          else
            {
              ar = it_art->second;
            }

          // lock
          if (ar->is_locked ())
            {
              // registry is locked by another thread so wait
              if (this->artifacts_condition_.wait () != 0)
                {
                  throw Deployment::PlanError (
                    plan_uuid.c_str (),
                    "artifact registry lock failed");
                }
            }
          else
            {
              // we're free to set the lock
              ar->set_locked ();
              return ar;
            }
        }
      return 0;
    }

    ArtifactRegistry*
    ArtifactInstallation_Impl::lock_artifact_registry (const std::string& plan_uuid,
                                                       const std::string& name)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::lock_artifact_registry");

      ACE_GUARD_REACTION (TLOCK,
                          artifacts_guard_,
                          artifacts_lock_,
                          throw Deployment::PlanError (
                            plan_uuid.c_str (),
                            "artifacts lock failed"));

      while (true)
        {
          // get existing
          TArtifactsMap& plan_map = this->artifacts_[plan_uuid];
          TArtifactsMap::iterator it_art = plan_map.find (name);
          if (it_art == plan_map.end ())
            {
              std::string err ("unknown artifact ");
              err += name;
              throw Deployment::PlanError (
                plan_uuid.c_str (),
                err.c_str ());
            }
          ArtifactRegistry* ar = it_art->second;

          // lock
          if (ar->is_locked ())
            {
              // registry is locked by another thread so wait
              if (this->artifacts_condition_.wait () != 0)
                {
                  throw Deployment::PlanError (
                    plan_uuid.c_str (),
                    "artifact registry lock failed");
                }
            }
          else
            {
              // we're free to set the lock
              ar->set_locked ();
              return ar;
            }
        }
      return 0;
    }

    void ArtifactInstallation_Impl::remove (
      const char * plan_uuid,
      const char * artifact_name)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::remove");

      DANCE_DEBUG (DANCE_LOG_EVENT_TRACE,
        (LM_TRACE,  DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove -")
         ACE_TEXT (" uninstall request for artifact %C from plan %C\n"),
         artifact_name, plan_uuid));

      ArtifactRegistry* ar =
          this->remove_artifact_registry (plan_uuid, artifact_name);

      if (ar == 0)
        return; // nothing to do yet

      this->remove_i (plan_uuid, artifact_name, ar);
    }

    void ArtifactInstallation_Impl::remove_all (const char * plan_uuid)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::remove_all");

      DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
        DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove_all -")
        ACE_TEXT (" removing versions for plan %C\n"),
        plan_uuid));

      // this method removes all installed artifacts irrespective of
      // install count!

      TArtifactsMap artifacts_map;
      this->remove_artifacts_map (plan_uuid, artifacts_map);

      for (TArtifactsMap::iterator ita = artifacts_map.begin ();
           ita != artifacts_map.end ();
           ++ita)
        {
          this->remove_i (plan_uuid, ita->first.c_str (), ita->second);
        }
    }

    void ArtifactInstallation_Impl::remove_intermediates (
        const std::string& plan_uuid,
        const std::string& artifact_name,
        ArtifactRegistry& artifact_reg)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::remove_intermediates");

      ACE_GUARD_REACTION (TLOCK,
                          handler_guard_,
                          handler_lock_,
                          throw Deployment::PlanError (
                            plan_uuid.c_str (),
                            "ArtifactInstallation handler lock failed"));

      DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE,
        DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove_intermediates -")
        ACE_TEXT (" removing intermediate versions for artifact %C from plan %C\n"),
        artifact_name.c_str (), plan_uuid.c_str ()));

      ArtifactRegistry::TVersions& versions = artifact_reg.versions ();
      while (versions.size () > 1)
        {
          // find protocol handler
          THandlerMap::iterator ith = handlers_.find (versions.front ().protocol_);
          if (ith == handlers_.end ())
            {
              DANCE_DEBUG (DANCE_LOG_NONFATAL_ERROR, (LM_ERROR,
                DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove_intermediates -")
                ACE_TEXT (" cannot find protocol %C to remove version")
                ACE_TEXT (" @ location %C for artifact %C from plan %C\n"),
                versions.front ().protocol_.c_str (),
                versions.front ().location_.c_str (),
                artifact_name.c_str (), plan_uuid.c_str ()));
            }
          else
            {
              DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
                DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove_intermediates -")
                ACE_TEXT (" removing version of protocol %C")
                ACE_TEXT ("@ %C for artifact %C from plan %C\n"),
                versions.front ().protocol_.c_str (),
                versions.front ().location_.c_str (),
                artifact_name.c_str (), plan_uuid.c_str ()));

              ith->second->remove (plan_uuid, versions.front ().location_);
            }
          versions.erase (versions.begin ());
        }
    }

    void ArtifactInstallation_Impl::remove_i (const char * plan_uuid,
                                              const char * artifact_name,
                                              ArtifactRegistry* artifact_reg,
                                              bool do_delete)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::remove_i");

      ACE_GUARD_REACTION (TLOCK,
                          handler_guard_,
                          handler_lock_,
                          throw Deployment::PlanError (
                            plan_uuid,
                            "ArtifactInstallation handler lock failed"));

      ACE_Auto_Ptr<ArtifactRegistry> safe_artifact_reg (do_delete ? artifact_reg : 0);

      for (ArtifactRegistry::TVersions::iterator iti =
             artifact_reg->versions ().begin ();
           iti != artifact_reg->versions ().end ();
           ++iti)
        {
          // in case no protocol registered there is nothing to remove
          if (!iti->protocol_.empty ())
            {
              // find protocol handler
              THandlerMap::iterator ith = handlers_.find (iti->protocol_);
              if (ith == handlers_.end ())
                {
                  DANCE_DEBUG (DANCE_LOG_NONFATAL_ERROR, (LM_ERROR,
                    DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove_i - ")
                    ACE_TEXT ("cannot find protocol %C to remove version ")
                    ACE_TEXT ("@ location %C for artifact %C from plan %C\n"),
                    iti->protocol_.c_str (), iti->location_.c_str (),
                    artifact_name, plan_uuid));
                }
              else
                {
                  DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
                    DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove_i - ")
                    ACE_TEXT ("removing version of protocol %C @ %C for artifact %C from plan %C\n"),
                    iti->protocol_.c_str (), iti->location_.c_str (),
                    artifact_name, plan_uuid));

                  ith->second->remove (plan_uuid, iti->location_);
                }
            }
        }
    }

    ArtifactRegistry* ArtifactInstallation_Impl::remove_artifact_registry (
      const std::string& plan_uuid,
      const std::string& name)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::remove_artifact_registry");

      ArtifactRegistry* ar = 0;

      // lock the artifact registry for the given plan
      ArtifactRegistry::Guard ar_guard (this->lock_artifact_registry (plan_uuid, name));

      // check to see if artifact has already been previously installed
      if (ar_guard->install_count () > 0)
        {
          // decrement install count
          ar_guard->decrement_install_count ();
          // only if we reach 0, we really remove artifacts
          if (ar_guard->install_count () == 0)
            {
              ACE_GUARD_REACTION (TLOCK,
                                  artifacts_guard_,
                                  artifacts_lock_,
                                  throw Deployment::PlanError (
                                    plan_uuid.c_str (),
                                    "artifacts lock failed"));

              DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
                DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove -")
                ACE_TEXT (" removing versions for artifact %C from plan %C\n"),
                name.c_str (), plan_uuid.c_str ()));

              // erase the artifact registry
              this->artifacts_[plan_uuid].erase (name);

              ar = &ar_guard;
            }
        }
      return ar;
    }

    void ArtifactInstallation_Impl::remove_artifacts_map (
      const std::string& plan_uuid,
      TArtifactsMap& artifacts_map)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::remove_artifacts_map");

      ACE_GUARD_REACTION (TLOCK,
                          artifacts_guard_,
                          artifacts_lock_,
                          throw Deployment::PlanError (
                            plan_uuid.c_str (),
                            "artifacts lock failed"));

      TArtifactsRegistry::iterator it_reg = this->artifacts_.find (plan_uuid);
      if (it_reg != this->artifacts_.end ())
        {
          artifacts_map = it_reg->second;
          this->artifacts_.erase (it_reg);
        }
    }

    char * ArtifactInstallation_Impl::get_artifact_location (
      const char * plan_uuid,
      const char * artifact_name)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::get_artifact_location");

      ACE_GUARD_REACTION (TLOCK,
                          artifacts_guard_,
                          artifacts_lock_,
                          throw Deployment::PlanError (
                            plan_uuid,
                            "artifacts lock failed"));

      TArtifactsRegistry::iterator it_reg = this->artifacts_.find (plan_uuid);
      if (it_reg != this->artifacts_.end ())
        {
          TArtifactsMap::iterator it_art = it_reg->second.find (artifact_name);
          if (it_art != it_reg->second.end ())
            {
              return CORBA::string_dup (it_art->second->location ().c_str ());
            }
        }
      return 0;
    }

    int ArtifactInstallation_Impl::register_handler (ArtifactInstallationHandler* aih)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::register_handler");

      if (aih != 0)
        {
          ACE_GUARD_RETURN (TLOCK, guard_, handler_lock_, -1);

          DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
            DLINFO ACE_TEXT("ArtifactInstallation_Impl::register_handler -")
            ACE_TEXT(" %C:// handler\n"),
            aih->protocol_prefix ().c_str ()));
          ArtifactInstallation_Impl::handlers_[aih->protocol_prefix ()] = aih;
        }

      return 0;
    }

    int ArtifactInstallation_Impl::deregister_handler (ArtifactInstallationHandler* aih)
    {
      DANCE_TRACE ("ArtifactInstallation_Impl::deregister_handler");

      if (aih != 0)
        {
          ACE_GUARD_RETURN (TLOCK, guard_, handler_lock_, -1);

          THandlerMap::iterator it_aih =
            ArtifactInstallation_Impl::handlers_.find (aih->protocol_prefix ());
          if (it_aih->second == aih)
            {
              DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE,
                DLINFO ACE_TEXT("ArtifactInstallation_Impl::deregister_handler -")
                ACE_TEXT(" %C:// handler\n"),
                aih->protocol_prefix ().c_str ()));
              ArtifactInstallation_Impl::handlers_.erase (it_aih);
            }
        }

      return 0;
    }
  }