summaryrefslogtreecommitdiff
path: root/Output_Adapters/DAnCE_Output_Adapter/Admin_exec.cpp
blob: b8aab8605b326e0a4b471db3b6e2436aae114957 (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
#include "Admin_exec.h"
#include "ciao/CIAO_common.h"
#include "ciao/Containers/Container_Base.h"
#include "Config_Handlers/DP_Handler.h"
#include "Config_Handlers/XML_Typedefs.h"
#include "Config_Handlers/Deployment.hpp"
#include "Config_Handlers/DnC_Dump.h"
#include <sstream>

namespace CIAO
{
  namespace RACE
  {
    namespace DAnCE_OA
    {
      namespace CIDL_DAnCE_OA_Impl
      {
        Admin_exec_i::Admin_exec_i (
          DAnCE_OA_Component_Context *context,
          const char * repoman_id,
          Logger &logger)
          : DAnCE::Plan_Launcher::Plan_Launcher_Base_Impl (dynamic_cast<CIAO::Container_i *>
							   (this->context_->_ciao_the_Container ())->the_ORB (),
							   0,
							   0),
            context_ (context),
            repoman_id_ (CORBA::string_dup (repoman_id)),
            repoman_ (false),
            logger_ (logger)
        {
          std::string msg;

          if (this->repoman_id_.in () != 0)
            {
              msg = "Trying to initialize the RM PLANNER with ID: ";
              msg += this->repoman_id_.in();
              this->logger_.log (msg);


              if (this->plan_gen_.init (dynamic_cast <CIAO::Container_i *> (this->context_->_ciao_the_Container ())->the_ORB (),
                                        true,
                                        this->repoman_id_.in ()))
                {
                  this->repoman_ = true;
                  msg = "Done!";
                  this->logger_.log (msg);
                }
              else
                {
                  msg = "DAnCE_OA::Admin_exec:: Error while "
                        "initializing the repoman plan_generator!";
                  this->logger_.log (msg);
                }
            }
          else {
            msg = "DAnCE_OA::Admin_exec:: No repoman ID provided "
                  "to constructor.\n";
            this->logger_.log (msg);
          }
        }

        Admin_exec_i::~Admin_exec_i (void)
        {
        }

        bool
        Admin_exec_i::deploy_plan (const ::Deployment::DeploymentPlan &plan)
        {
          try
            {
              // First let's dump the plan to a file.
              // using namespace CIAO::Config_Handlers;
              // DP_Handler reverse_handler (plan);
              // xercesc::DOMDocument *the_xsc (XML_HELPER->create_dom (0));
              // deploymentPlan (*reverse_handler.xsc (), the_xsc);
              // std::string dom_out (plan.UUID.in ());
              // dom_out += ".cdp";
              // XML_HELPER->write_DOM (the_xsc, dom_out.c_str());
              // delete the_xsc;
              // Now do the remaining stuff.
              //              Deployment::DnC_Dump::dump (plan);
              ACE_CString uuid (this->launch_plan (plan));
              std::string msg;
              if (uuid.c_str () == 0)
                {
                  msg = "Unable to launch plan with UUID ";
                  msg += plan.UUID.in ();
                  this->logger_.log (msg);
                }
              else
                {
                  msg = "Plan ";
                  msg += plan.UUID.in ();
                  msg += " was deployed!";
                  this->logger_.log (msg);
                  return true;
                }

            }
          catch (DAnCE::Plan_Launcher::Plan_Launcher_Base_Impl::Deployment_Failure &)
            {
              std::string msg = "Exception caught::Unable to "
                                "launch plan with UUID ";
              msg += plan.UUID.in ();
              this->logger_.log (msg);
            }
          return false;
        }

        bool
        Admin_exec_i::redeploy_plan (const ::Deployment::DeploymentPlan &plan)
        {
          throw CORBA::NO_IMPLEMENT ();
          
          /*
          try
            {
              ACE_CString uuid (this->re_launch_plan (plan));

              if (uuid.c_str () == 0)
                {
                  std::string msg = "Unable to relaunch plan with UUID ";
                  msg += plan.UUID.in ();
                  this->logger_.log (msg);
                }
              else
                {
                  std::string msg = "Successfully relaunched plan with UUID ";
                  msg += plan.UUID.in ();
                  this->logger_.log (msg);

                  return true;
                }

            }
          catch (Plan_Launcher::Plan_Launcher_i::Deployment_Failure &)
            {
              std::string msg = "Exception caught::Unable to "
                                "relaunch plan with UUID ";
              msg += plan.UUID.in ();
              this->logger_.log (msg);
            }
          return false;
          */
        }

        ::CORBA::Boolean
        Admin_exec_i::deploy_string
        (const ::CIAO::RACE::OperationalString & op_string)
        {
          std::string msg	= "In DANCE_OA::deploy string()";
          this->logger_.log (msg);


          ::Deployment::DeploymentPlan plan;

          if (this->opstring_to_dplan (op_string, plan))
            {
              return this->deploy_plan (plan);
            }
          else
            {
              msg = "deploy_string()::Failed to generate dp from opstring.";
              msg += plan.UUID.in ();

              return false;
            }

          return false;
        }


        ::CORBA::Boolean
        Admin_exec_i::redeploy_string
        (const ::CIAO::RACE::OperationalString & op_string)
        {
          ::Deployment::DeploymentPlan plan;

          if (this->opstring_to_dplan (op_string, plan))
            {
              return this->redeploy_plan (plan);
            }
          else
            {
              return false;
            }
        }

        bool
        Admin_exec_i::opstring_to_dplan (
          const ::CIAO::RACE::OperationalString &op_string,
          ::Deployment::DeploymentPlan &plan)
        {
          std::string msg;
          /// We need the repo man to convert an operational string to a
          /// deployment plan if the artifact information is not available
          /// in the operational string. We first check if the repoman is
          /// avaialble. If not, we check if the artifact info is avaialble
          /// in the operational string structure. Else, we bail out.
          if (!this->repoman_)
            {
              msg = "DANCE_OA::opstring_to_dplan(): this->repoman_ not set";
              this->logger_.log (msg);
            }
          else if (op_string.implementation.length() == 0)
            {
              msg = "DANCE_OA::opstring_to_dplan(): opstring does not "
                    "conatin any info about the implemenations!"
                    "\nTherefore, bailing out!\n";
              this->logger_.log (msg);
              return false;
            }

          // Populate the label, UUID, connections, and info property
          // fields of the deployment plan.
          plan.label = op_string.name;
          plan.UUID = op_string.ID;
          plan.connection = op_string.dataLink;
          plan.infoProperty = op_string.infoProperty;

          /// If the opstring contains the artifact and implementation
          /// info, we copy them over directly. Else, we rely on the
          /// plan_generator to populate these fields.
          if (op_string.implementation.length() != 0 &&
              op_string.artifact.length() != 0)
            {
              plan.implementation = op_string.implementation;
              plan.artifact = op_string.artifact;
              /// Now copy over each instance description.
              for (CORBA::ULong itr = 0;
                   itr < op_string.instance.length (); ++itr)
                {

                  ::CIAO::RACE::InstanceDescription op_instance =
                    op_string.instance [itr];
                  ::Deployment::InstanceDeploymentDescription instance;
                  instance.name = op_instance.name;
                  instance.node = op_instance.node;
                  instance.implementationRef = op_instance.implementationRef;
                  instance.configProperty = op_instance.configProperty;
                  CORBA::ULong cur_len = plan.instance.length ();
                  plan.instance.length (cur_len+1);
                  plan.instance [cur_len] = instance;

                }
            }

          else
            {
              /// Now, populate the instance, implementation, and artifact
              /// fields of the deployment plan using the plan generator.
              int position;
              for (CORBA::ULong itr = 0;
                   itr < op_string.instance.length (); ++itr)
                {

                  ::CIAO::RACE::InstanceDescription op_instance =
                    op_string.instance [itr];
                  if (this->plan_gen_.generate_plan
                      (plan,
                       op_instance.suggestedImpl.in (),
                       position))
                    {
                      ::Deployment::InstanceDeploymentDescription instance;
                      instance.name = op_instance.name;

                      // @@ This is a temporaty hack. Later on we must be
                      // using the simple bin packer do perform the node
                      // assignment.
                      instance.node = op_instance.node;
                      //instance.node = CORBA::string_dup("SPACE");
                      instance.implementationRef = position;
                      instance.configProperty = op_instance.configProperty;
                      CORBA::ULong cur_len = plan.instance.length ();
                      plan.instance.length (cur_len+1);
                      plan.instance [cur_len] = instance;

                    }
                  else
                    {
                      msg = "Given suggested type is not "
                            "available in the Repoman!!\n Bailing out....";
                      this->logger_.log (msg);
                      return false;
                    }
                }
            }

          return true;
        }

        ::CORBA::Boolean
        Admin_exec_i::tear_down_string (const char *ID )
        {
          std::stringstream msg;
          try
            {
              if (this->teardown_plan(ID))
                {
                  msg << "DANCE_OA::tear_down_string(): "
                      <<   "successfully torn down plan with UUID "
                      << ID
                      << std::endl;
                  this->logger_.log (msg.str());
                  return true;
                }
              else
                {
                  msg << "DANCE_OA::tear_down_string():Oops! "
                      << "Error while tearing down plan with UUID: "
                      << ID
                      << std::endl;;
                  this->logger_.log (msg.str());

                }
            }
          catch (CORBA::Exception &ex)
            {
              msg << "DANCE_OA::tear_down_string():Exeption caught ";
              msg << ex._info().c_str();
              this->logger_.log (msg.str());
            }
          return false;
        }

      }
    }
  }
}