summaryrefslogtreecommitdiff
path: root/DAnCE/dance/LocalityManager/Scheduler/Events/Action_Base.cpp
blob: 8e1627990ae23fbe926f8f76f17cf3ecbadec8c9 (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
// $Id$
#include "Action_Base.h"

#include "tao/AnyTypeCode/ExceptionA.h"
#include "dance/Logger/Log_Macros.h"
#include "dance/DAnCE_Utility.h"

namespace DAnCE
{
  Action_Base::Action_Base (Event_Future holder,
                            const char *name,
                            const char *instance_type)
    : Deployment_Event (holder, name, instance_type)
  {
    CORBA::Any *tmp;
    ACE_NEW_THROW_EX (tmp,
                      ::CORBA::Any (),
                      CORBA::NO_MEMORY ());
    instance_excep_ = tmp;
  }

  Action_Base::~Action_Base (void)
  {

  }

  int
  Action_Base::call (void)
  {
    DANCE_DEBUG (DANCE_LOG_DETAILED_TRACE,
                 (LM_TRACE, DLINFO
                  ACE_TEXT ("Action_Base::call - ")
                  ACE_TEXT ("Entering Action_Base\n")));

    try
      {
        const Plugin_Manager::INTERCEPTORS &interceptors =
          PLUGIN_MANAGER::instance ()->fetch_interceptors ();

        DANCE_DEBUG (DANCE_LOG_TRACE,
                     (LM_TRACE, DLINFO
                      ACE_TEXT ("Action_Base::call - ")
                      ACE_TEXT ("Invoking pre-install interceptors\n")));
        for (Plugin_Manager::INTERCEPTORS::const_iterator i = interceptors.begin ();
             i != interceptors.end ();
             ++i)
          {
            this->invoke_pre_interceptor (i);
          }

        if (this->instance_type_.c_str () == 0)
          {
            this->create_unexpected_exception (this->name_,
                                               "Invalid Instance Type");
          }

        ::DAnCE::InstanceDeploymentHandler_var handler =
            PLUGIN_MANAGER::instance ()->fetch_installation_handler (this->instance_type_.c_str ());

        if (CORBA::is_nil (handler))
          {
            this->create_unexpected_exception (this->name_,
                                               "Unable to load appropriate instance handler");
          }

        try
          {
            this->invoke (handler.in ());
          }
        catch (CORBA::UserException &ex)
          {
            DANCE_ERROR (DANCE_LOG_ERROR,
                         (LM_ERROR, DLINFO
                          ACE_TEXT ("Action_Base::call - ")
                          ACE_TEXT ("Caught CORBA UserException while processing instance ")
                          ACE_TEXT ("<%C>\n"),
                          this->name_.c_str ()));
            this->instance_excep_ = DAnCE::Utility::create_any_from_user_exception (ex);
          }
        catch (CORBA::SystemException &ex)
          {
            DANCE_ERROR (DANCE_LOG_ERROR,
                         (LM_ERROR, DLINFO
                          ACE_TEXT ("Action_Base::call - ")
                          ACE_TEXT ("Caught CORBA SystemException while processing instance ")
                          ACE_TEXT ("<%C>\n"),
                          this->name_.c_str ()));
            this->instance_excep_ = DAnCE::Utility::create_any_from_exception (ex);
          }
        catch (...)
          {
            DANCE_ERROR (DANCE_LOG_ERROR,
                         (LM_ERROR, DLINFO
                          ACE_TEXT ("Action_Base::call - ")
                          ACE_TEXT ("Caught C++ exception while processing instance ")
                          ACE_TEXT ("<%C>\n"),
                          this->name_.c_str ()));

            this->create_unexpected_exception (this->name_,
                                               "Caught unknown C++ exception from install");
          }

        Event_Result result (this->name_, this->instance_excep_.ptr () != 0);
        if (!interceptors.empty ())
          {
            DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO
                              ACE_TEXT ("Action_Base::call - ")
                              ACE_TEXT ("Invoking post-action interceptors\n")));
            for (Plugin_Manager::INTERCEPTORS::const_iterator i = interceptors.begin ();
                i != interceptors.end ();
                ++i)
              {
                this->invoke_post_interceptor (i);
              }

            this->create_valid_result (result);
            result.exception_ = false;
          }
        else
          {
            DANCE_DEBUG (DANCE_LOG_ERROR,
                         (LM_TRACE, DLINFO
                          ACE_TEXT ("Action_Base::call - ")
                          ACE_TEXT ("No post-install interceptors; directly propagating result\n")));
            if (result.exception_)
              result.contents_ = this->instance_excep_._retn ();
            else
              this->create_valid_result (result);
          }

        DANCE_DEBUG (DANCE_LOG_DETAILED_TRACE,
                     (LM_TRACE, DLINFO
                      ACE_TEXT ("Action_Base::call - ")
                      ACE_TEXT ("Signaling result for instance <%C>\n"),
                      this->name_.c_str ()));
        this->holder_.set (result);
      }
    catch (CORBA::UserException &ex)
      {
        DANCE_ERROR (DANCE_LOG_ERROR,
                     (LM_ERROR, DLINFO
                      ACE_TEXT ("Action_Base::call - ")
                      ACE_TEXT ("CORBA UserException propagated from interceptors for instance ")
                      ACE_TEXT ("<%C>\n"),
                      this->name_.c_str ()));

        Event_Result result (this->name_, true);

        try
          {
            result.contents_ = DAnCE::Utility::create_any_from_user_exception (ex);
          }
        catch (...) { }

        this->holder_.set (result);
        return -1;
      }
    catch (CORBA::SystemException &ex)
      {
        DANCE_ERROR (DANCE_LOG_ERROR,
                     (LM_ERROR, DLINFO
                      ACE_TEXT ("Action_Base::call - ")
                      ACE_TEXT ("CORBA SystemException propagated from interceptors for instance ")
                      ACE_TEXT ("<%C>\n"),
                      this->name_.c_str ()));

        Event_Result result (this->name_, true);

        try {
          result.contents_ = DAnCE::Utility::create_any_from_exception (ex);
        }
        catch (...) { }

        this->holder_.set (result);
        return -1;
      }
    return 0;
  }
}