summaryrefslogtreecommitdiff
path: root/trunk/CIAO/DAnCE/NodeManager/NodeManager_Impl.h
blob: cf9be0c67203e650dcb5da0104b0596bf3f5798d (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
// -*- C++ -*-
//=============================================================================
/**
 *  @file NodeManager_Impl.h
 *
 *  $Id$
 *
 *  This file contains servant implementation for Deployment:NodeManager
 *  interface. In the current design of the NodeManager, each NodeManager
 *  could manage one or more NodeApplication Managers.
 *  Though, the name intuitively suggests
 *  that there be one NodeManager  for every node, our design, allows
 *  the end-user to have multiple components run on the same node.
 *
 *  @author Arvind S. Krishna <arvindk@dre.vanderbilt.edu>
 *  @author Gan Deng <dengg@dre.vanderbilt.edu>
 */
//=============================================================================


#ifndef CIAO_NODEMANAGER_IMPL_H
#define CIAO_NODEMANAGER_IMPL_H
#include /**/ "ace/pre.h"

#include "Interfaces/NodeManagerDaemonS.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#if defined (_MSC_VER)
# pragma warning(push)
# pragma warning (disable:4250)
#endif /* _MSC_VER */

#include "NodeManager_svnt_export.h"
#include "NAM_Map.h"
#include "MonitorController.h"
#include "ace/Vector_T.h"

namespace CIAO
{
  class NodeApplicationManager_Impl_Base;

  /**
   * @class NodeManager_Impl
   *
   * @brief Servant implementation CIAO's daemon process control
   * interface
   *
   * This class implements the CIAO:NodeManagerDaemon interface.
   *
   */
  class NodeManager_svnt_Export NodeManager_Impl_Base
    : public virtual POA_CIAO::NodeManagerDaemon
  {
  public:
    /// A struct that tracks the reference count of a particular
    /// component as well as the "child_plan_uuid" where the component is
    /// actually installed
    typedef struct _ref_count_info
    {
      ACE_CString plan_uuid_;
      size_t count_;
    } Ref_Count_Info;

    /// Constructor
    NodeManager_Impl_Base (const char *name,
                      CORBA::ORB_ptr orb,
                      PortableServer::POA_ptr p,
                      const char * nodeapp_loc,
                      const char* nodeapp_options,
                      int spawn_delay);

    /// Initializes the NodeManager.
    virtual void init ();

    /// POA operation..
    virtual PortableServer::POA_ptr _default_POA (void);

    /// CIAO::Daemon defined attributes/operations.
    virtual char * name ();

    virtual void shutdown ();

    virtual void joinDomain (const Deployment::Domain & domain,
                             Deployment::TargetManager_ptr manager,
                             Deployment::Logger_ptr log
                             );

    virtual void leaveDomain ();

    virtual ::Deployment::NodeApplicationManager_ptr
    preparePlan (const Deployment::DeploymentPlan &plan);

    virtual void
    destroyManager (Deployment::NodeApplicationManager_ptr appManager);

    /// CIAO specific extension, which is particularly useful for dealing with
    /// shared components issue
    virtual void destroyPlan (const Deployment::DeploymentPlan & plan);

    /// CIAO specific extension, return a set of shared components
    virtual ::Deployment::ComponentPlans *
    get_shared_components ();

    /// RACE specific extension. Modify the priority of a node application
    /// process.

    virtual ::CORBA::Long
    set_priority (
        const char * plan_id,
        const char * cid,
        const ::Deployment::Sched_Params & nm_params);

    // ********* CIAO Specific Helper functions ************

    virtual ::Components::FacetDescriptions *
    get_all_facets (ACE_CString & name);

    virtual ::Components::ConsumerDescriptions *
    get_all_consumers (ACE_CString & name);

    virtual void
    set_all_facets (ACE_CString &name,
                   const ::Components::FacetDescriptions_var & facets);

    virtual void
    set_all_consumers (ACE_CString &name,
                       const ::Components::ConsumerDescriptions_var & consumers);

    // ********* Function added for getting component ids...

    struct Component_Ids
    {
      ACE_Unbounded_Set <ACE_CString> cid_seq_;
      pid_t process_id_;
    };

    virtual void push_component_id_info (Component_Ids comps);


    Component_Ids get_component_detail ();

  private:
    /// Validate the child deployment plan. In particular, we are
    /// trying to verify that all the component instances within this
    /// child deployment plan have the same "server_resource_id"
    /// assigned.
    bool validate_plan (const Deployment::DeploymentPlan &plan);

  protected:
    /// Since this class is reference counted, making this
    /// destructor protected to enforce proper memory managment
    /// through the reference counting mechanism (i.e. to
    /// disallow calling operator delete() on an instance of
    /// this class.
    virtual ~NodeManager_Impl_Base (void);

    virtual ::CIAO::NodeApplicationManager_Impl_Base *
    create_node_app_manager (CORBA::ORB_ptr orb,
                             PortableServer::POA_ptr poa)
      =0;

    /// Actual implementation of the @c get_shared_components IDL operation
    virtual ::Deployment::ComponentPlans *
    get_shared_components_i (void);

    /// A helper method that convert ACE_Unbounded_Set to CORBA StringSeq
    CORBA::StringSeq * shared_components_seq (void);

    /// Keep a pointer to the managing ORB serving this servant.
    CORBA::ORB_var orb_;

    /// Keep a pointer to the managing POA.
    PortableServer::POA_var poa_;

    /// My Canonical name.
    CORBA::String_var name_;

    /// NodeApplication location
    CORBA::String_var nodeapp_location_;

    /// NodeApplication options
    CORBA::String_var nodeapp_options_;

    /// Cached callback POA.
    PortableServer::POA_var callback_poa_;

    /// Spawn delay for the NodeAppMgr
    int spawn_delay_;

    /// Cache reference of last NodeAppManager
    /// Deployment::NodeApplicationManager_var manager_;
    NAM_Map map_;

    /// A reference count map for the components installed on this node
    /// @@TODO We should also keep the information about *where* the
    /// component is installed
    typedef
    ACE_Hash_Map_Manager_Ex <ACE_CString,
                             Ref_Count_Info,
                             ACE_Hash<ACE_CString>,
                             ACE_Equal_To<ACE_CString>,
                             ACE_Null_Mutex> Reference_Count_Map;
    typedef Reference_Count_Map::iterator Ref_Count_Iterator;

    Reference_Count_Map ref_count_map_;

    /// A set to track the names of shared component instances
    ACE_Unbounded_Set<ACE_CString> shared_components_;

    /// Cached object references of ports (facets/consumers) of
    /// all components. This is useful for getting the port object
    /// references of "shared components". The key in the map
    /// is the component instance name.
    typedef
    ACE_Hash_Map_Manager_Ex <ACE_CString,
                             Components::FacetDescriptions_var,
                             ACE_Hash<ACE_CString>,
                             ACE_Equal_To<ACE_CString>,
                             ACE_Null_Mutex> Component_Facets_Map;

    Component_Facets_Map comp_facets_map_;

    typedef
    ACE_Hash_Map_Manager_Ex <ACE_CString,
                             Components::ConsumerDescriptions_var,
                             ACE_Hash<ACE_CString>,
                             ACE_Equal_To<ACE_CString>,
                             ACE_Null_Mutex> Component_Consumers_Map;

    Component_Consumers_Map comp_consumers_map_;

    /// The MonitorController pointer
    auto_ptr <MonitorController> monitor_controller_;

    /// The set of Components
    Component_Ids components_;
  };


  /**
   * @class NodeManager_Impl
   *
   */
  class NodeManager_svnt_Export NodeManager_Impl
    : public virtual NodeManager_Impl_Base
  {
  public:

    /// Constructor
    NodeManager_Impl (const char *name,
                     CORBA::ORB_ptr orb,
                     PortableServer::POA_ptr p,
                     const char * nodeapp_loc,
                     const char * nodeapp_options,
                     int spawn_delay);

  protected:
    /// Since this class is reference counted, making this
    /// destructor protected to enforce proper memory managment
    /// through the reference counting mechanism (i.e. to
    /// disallow calling operator delete() on an instance of
    /// this class.
    virtual ~NodeManager_Impl (void);

    virtual ::CIAO::NodeApplicationManager_Impl_Base *
    create_node_app_manager (CORBA::ORB_ptr orb,
                             PortableServer::POA_ptr poa);
  };

  class NodeApplicationManager_Impl;
  struct Static_Config_EntryPoints_Maps;

  /**
   * @class Static_NodeManager_Impl
   *
   */
  class NodeManager_svnt_Export Static_NodeManager_Impl
    : public virtual NodeManager_Impl_Base
  {
  public:

    /// Constructor
    Static_NodeManager_Impl (const char *name,
                            CORBA::ORB_ptr orb,
                            PortableServer::POA_ptr p,
                            const char * nodeapp_loc,
                            const char * nodeapp_options,
                            int spawn_delay,
                            Static_Config_EntryPoints_Maps* static_config_entrypoints_maps
                            );

    void destroyManager
    (Deployment::NodeApplicationManager_ptr manager);

  protected:
    /// Since this class is reference counted, making this
    /// destructor protected to enforce proper memory managment
    /// through the reference counting mechanism (i.e. to
    /// disallow calling operator delete() on an instance of
    /// this class.
    virtual ~Static_NodeManager_Impl (void);

    virtual ::CIAO::NodeApplicationManager_Impl_Base *
    create_node_app_manager (CORBA::ORB_ptr orb,
                             PortableServer::POA_ptr poa);

    Static_Config_EntryPoints_Maps* static_config_entrypoints_maps_;
  };

}

#if defined(_MSC_VER)
#pragma warning(pop)
#endif /* _MSC_VER */

#include /**/ "ace/post.h"
#endif /* CIAO_NODEMANAGER_IMPL_H */