summaryrefslogtreecommitdiff
path: root/CIAO/DAnCE/FaultCorrelationManager/FaultCorrelationManager_Impl.cpp
blob: 9f0a0d887720666e3c81dc5ec923c3c0f3a4f665 (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    FaultCorrelationManager_Impl.cpp
 *
 *  $Id$
 *
 *  @author Friedhelm Wolf <fwolf@dre.vanderbilt.edu>
 */
//=============================================================================

#include "FaultCorrelationManager_Impl.h"
#include "ciao/FTComponentServer/CIAO_PropertiesC.h"
#include "DAnCE/Logger/Log_Macros.h"

namespace DAnCE
{
  FaultCorrelationManager_Impl::FaultCorrelationManager_Impl (
    CORBA::ORB_ptr orb,
    DAnCE::ExecutionManagerDaemon_ptr exec_mgr,
    const PROPERTY_MAP & options)
    : orb_ (CORBA::ORB::_duplicate (orb)),
      exec_mgr_ (DAnCE::ExecutionManagerDaemon::_duplicate (exec_mgr)),
      properties_ (options.current_size ())
  {
    PROPERTY_MAP::const_iterator i = options.begin ();
    while (!i.done ())
      {
        DANCE_DEBUG ((LM_TRACE, DLINFO "FaultCorrelationManager_Impl::FaulCorrelationManager_Impl - "
                      "Binding property %C provided by caller.\n", i->key ().c_str ()));
        this->properties_.bind (i->key (), i->item ());
        i.advance ();
      }
  }

  FaultCorrelationManager_Impl::~FaultCorrelationManager_Impl()
  {
  }

  void
  FaultCorrelationManager_Impl::stop_failver_unit (const char * /* fou_id */)
  {
  }

  void
  FaultCorrelationManager_Impl::proc_failure (const char * object_id,
                                              const char * node_id)
  {
    TObjectIdMap node;
    if (nodes_.find (node_id,
                     node) != 0)
      {
        DANCE_DEBUG ((LM_WARNING,
                      "FCM::proc_failure (%C, %C): node '%C' not found.\n",
                      object_id,
                      node_id,
                      node_id));
        return;
      }

    ACE_CString component_id = node[object_id];

    if (component_id.length () == 0)
      {
        DANCE_DEBUG ((LM_WARNING,
                      "FCM::proc_failure (%C, %C): "
                      "object_id '%C' on '%C' not found.\n",
                      object_id,
                      node_id,
                      object_id,
                      node_id));
        return;
      }

    ACE_CString plan_id;
    if (instances_.find (component_id,
                         plan_id) != 0)
      {
        DANCE_DEBUG ((LM_WARNING,
                      "FCM::proc_failure (%C, %C): "
                      "plan for component '%C' not found.\n",
                      object_id,
                      node_id,
                      component_id.c_str ()));
        return;
      }

    DANCE_DEBUG ((LM_TRACE, 
                  "FCM::proc_failure (%C, %C): "
                  "caused by component '%C' in plan '%C'.\n",
                  object_id,
                  node_id,
                  component_id.c_str (),
                  plan_id.c_str ()));

    try
      {
        Deployment::DomainApplicationManager_var dam;

        if (dams_.find (plan_id.c_str (),
                        dam) != 0)
          {
            DANCE_DEBUG ((LM_TRACE, 
                          "FCM::proc_failure (%C, %C): "
                          "could not resolce DAM for plan '%C'.\n",
                          object_id,
                          node_id,
                          plan_id.c_str ()));
          }

        Deployment::Applications_var apps = dam->getApplications();

        for (size_t i = 0; i < apps->length(); ++i)
          {
            dam->destroyApplication(apps[i]);
          }

        exec_mgr_->destroyManager (dam.in ());

        DANCE_DEBUG ((LM_TRACE, 
                      "FCM::proc_failure (%C, %C): "
                      "plan '%C' was shutdown sucessfully.\n",
                      object_id,
                      node_id,
                      plan_id.c_str ()));
      }
    catch (const CORBA::Exception & ex)
      {
        DANCE_DEBUG ((LM_ERROR,
                      "FCM::proc_failure caught %n",
                      ex._info ().c_str ()));
      }
  }

  ::Deployment::DomainApplicationManager_ptr
  FaultCorrelationManager_Impl::preparePlan (
        const ::Deployment::DeploymentPlan & plan,
        ::Deployment::ResourceCommitmentManager_ptr resourceCommitment)
  {
    Deployment::DomainApplicationManager_var dam =
      exec_mgr_->preparePlan (plan, resourceCommitment);

    dams_.bind (plan.UUID.in(), 
                Deployment::DomainApplicationManager::_duplicate (dam.in ()));

    this->process_deployment_plan (plan);

    return Deployment::DomainApplicationManager::_duplicate (dam.in ());
  }
    
  ::Deployment::DomainApplicationManagers * 
  FaultCorrelationManager_Impl::getManagers (void)
  {
    return exec_mgr_->getManagers ();
  }

  void
  FaultCorrelationManager_Impl::destroyManager (
    Deployment::DomainApplicationManager_ptr manager)
  {
    Deployment::DeploymentPlan_var plan = manager->getPlan ();

    dams_.unbind (plan->UUID.in ());

    exec_mgr_->destroyManager (manager);
  }

  void
  FaultCorrelationManager_Impl::shutdown (void)
  {
    exec_mgr_->shutdown ();
  }

  void
  FaultCorrelationManager_Impl::process_deployment_plan (
    const Deployment::DeploymentPlan &  plan)
  {
    // add all found component instances to the map
    const Deployment::InstanceDeploymentDescription id;
    for (CORBA::ULong i = 0; i < plan.instance.length (); ++i)
      {        
        // add component with the plan id it belongs to
        instances_.bind (plan.instance[i].name.in (), 
                         plan.UUID.in ());

        DANCE_DEBUG ((LM_TRACE, 
                      "FCM: instance[%C] -> plan[%C]\n",
                      plan.instance[i].name.in (), 
                      plan.UUID.in ()));

        // find object_id property if existing
        CORBA::String_var object_id (
          this->get_property (CIAO::Deployment::OBJECT_ID,
                              plan.instance[i].configProperty));

        if (object_id.in () == 0)
          object_id = plan.instance[i].name.in ();

        TObjectIdMap oidmap;
        if (nodes_.find (plan.instance[i].node.in (),
                         oidmap) == 0)
          {
            // the new component to exisiting node map
            oidmap[object_id.in ()] = plan.instance[i].name.in ();
            nodes_.rebind (plan.instance[i].node.in (),
                           oidmap);
          }
        else
          {
            // if no entry for this node exists, add a new one
            TObjectIdMap om;
            om[object_id.in ()] = plan.instance[i].name.in ();
            nodes_.bind (plan.instance[i].node.in (),
                         om);
          }

        DANCE_DEBUG ((LM_TRACE, 
                      "FCM: node[%C] -> oid[%C] -> instance[%C]\n",
                      plan.instance[i].node.in (), 
                      object_id.in (),
                      plan.instance[i].name.in ()));
      }
  }

  char * 
  FaultCorrelationManager_Impl::get_property (
    const char * name, 
    const Deployment::Properties & properties)
  {
    for (CORBA::ULong i = 0; i < properties.length (); ++i)
      {
        if (ACE_OS::strcmp (name,
                            properties[i].name.in ()) == 0)
          {
            const CORBA::Any & value = properties[i].value;
            const char * cval;
            if (value >>= cval)
              return CORBA::string_dup (cval);

            break;
          }
      }

    return 0;
  }

};