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

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

#ifndef FAULTCORRELATIONMANAGER_IMPL_H_
#define FAULTCORRELATIONMANAGER_IMPL_H_

#include <list>
#include <map>
#include <queue>
#include "ace/High_Res_Timer.h"
#include "ace/Hash_Map_Manager_T.h"
#include "ace/Map_Manager.h"
#include "ace/Thread_Mutex.h"
#include "ace/Task.h"
#include "ace/Condition_T.h"
#include "tao/ORB.h"
#include "FaultCorrelationManager_export.h"
#include "Interfaces/FaultCorrelationManagerS.h"
#include "Deployment/Deployment_common.h"
#include "Interfaces/ExecutionManagerDaemonC.h"
#include "orbsvcs/orbsvcs/LWFT/ReplicationManagerC.h"

namespace DAnCE
{
  /**
   *  @brief Implementation of a manager to provide fail-stop behavior
   *         for component deployments.
   */
  class FAULTCORRELATIONMANAGER_Export FaultCorrelationManager_Impl : 
    public virtual POA_DAnCE::FaultCorrelationManager,
    public ACE_Task_Base
  {
  public:
    // the fixed listener port is caused by the usage of CCM Object locator
    FaultCorrelationManager_Impl (CORBA::ORB_ptr orb,
                                  DAnCE::ExecutionManagerDaemon_ptr exec_mgr,
                                  ReplicationManager_ptr rep_mgr,
                                  const PROPERTY_MAP &options);

    virtual ~FaultCorrelationManager_Impl();

    virtual void stop_failover_unit (const char * fou_id);
    virtual FLARE::ApplicationList* FOU_participants(const char* app);


    // methods from inherited interfaces

    // FaultNotification
    virtual void app_failure (
        const char * host,
        const ::FLARE::ApplicationList & applications);

    // ExecutionManager
    virtual ::Deployment::DomainApplicationManager_ptr preparePlan (
        const ::Deployment::DeploymentPlan & plan,
        ::Deployment::ResourceCommitmentManager_ptr resourceCommitment);
    
    virtual ::Deployment::DomainApplicationManagers * getManagers (
        void);

    virtual void destroyManager (
        ::Deployment::DomainApplicationManager_ptr manager);

    virtual void shutdown (void);

    virtual int svc (void);

  private:

    // FaultNotification
    void app_failure_i (const char * host,
                        const char * application);

    void process_deployment_plan (const Deployment::DeploymentPlan & plan,
                                  bool deploy = true);

    char * get_property (const char * name,
                         const Deployment::Properties & properties);

    void add_constraints (const Deployment::DeploymentPlan & plan);

    void remove_constraints (const Deployment::DeploymentPlan & plan);

    RankListConstraints * get_constraints (void);

  private:
    typedef ACE_Map_Manager<ACE_CString, 
                            Deployment::DomainApplicationManager_var, 
                            ACE_Null_Mutex> TDomainManagers;

    typedef ACE_Map_Manager<ACE_CString,
                            ACE_CString,
                            ACE_Null_Mutex> TStringMap;

    typedef std::map<ACE_CString, ACE_CString> TObjectIdMap;

    typedef ACE_Map_Manager<ACE_CString,
                            TObjectIdMap,
                            ACE_Null_Mutex> TNodeMap;

    typedef TStringMap TInstancesOfPlan;

    struct FailureInfo 
    {
      ACE_CString host;
      ACE_CString application;
    };

  typedef std::list<ACE_CString> RANKLIST_CONSTRAINT;

  typedef ACE_Hash_Map_Manager_Ex <
    ACE_CString,
    RANKLIST_CONSTRAINT,
    ACE_Hash<ACE_CString>,
    ACE_Equal_To<ACE_CString>,
    ACE_Null_Mutex> RANKLIST_CONSTRAINT_MAP;

  private:
    CORBA::ORB_var orb_;

    DAnCE::ExecutionManagerDaemon_var exec_mgr_;

    ReplicationManager_var rep_mgr_;

    PROPERTY_MAP properties_;

    TDomainManagers dams_;

    TInstancesOfPlan instances_;
    ACE_Thread_Mutex instances_lock_;

    TNodeMap nodes_;

    RANKLIST_CONSTRAINT_MAP constraints_;

    // these parts belong the role as active object
    bool stop_;

    ACE_Thread_Mutex app_failure_lock_;

    ACE_Condition <ACE_Thread_Mutex> new_notification_;

    std::queue <FailureInfo> notification_queue_;

    ACE_High_Res_Timer timer_;

    struct TFouShutdownTime {
      unsigned long shutdown;
      ACE_Time_Value start_shutdown;
      ACE_Time_Value end_shutdown;
      std::string fou_id;
    };
    
    typedef std::list <TFouShutdownTime> SHUTDOWN_TIME_LIST;

    SHUTDOWN_TIME_LIST history_;

    ACE_Thread_Mutex history_lock_;
  };
}

#endif /* FAULTCORRELATIONMANAGER_IMPL_H_ */