summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/Database.h
blob: 054d54ce99fd40995de89967a91da049c6e5523c (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
// **********************************************************************
//
// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_GRID_DATABASE_H
#define ICE_GRID_DATABASE_H

#include <IceUtil/Mutex.h>
#include <IceUtil/Shared.h>
#include <Freeze/ConnectionF.h>
#include <Ice/CommunicatorF.h>
#include <IceGrid/Admin.h>
#include <IceGrid/Internal.h>
#include <IceGrid/StringApplicationInfoDict.h>
#include <IceGrid/IdentityObjectInfoDict.h>
#include <IceGrid/StringAdapterInfoDict.h>
#include <IceGrid/ServerCache.h>
#include <IceGrid/NodeCache.h>
#include <IceGrid/ReplicaCache.h>
#include <IceGrid/ObjectCache.h>
#include <IceGrid/AllocatableObjectCache.h>
#include <IceGrid/AdapterCache.h>

namespace IceGrid
{

class TraceLevels;
typedef IceUtil::Handle<TraceLevels> TraceLevelsPtr;

class NodeSessionI;
typedef IceUtil::Handle<NodeSessionI> NodeSessionIPtr;

class RegistryObserverTopic;
typedef IceUtil::Handle<RegistryObserverTopic> RegistryObserverTopicPtr;

class NodeObserverTopic;
typedef IceUtil::Handle<NodeObserverTopic> NodeObserverTopicPtr;

class ReplicaSessionI;
typedef IceUtil::Handle<ReplicaSessionI> ReplicaSessionIPtr;

class AdminSessionI;

class ServerEntry;
typedef IceUtil::Handle<ServerEntry> ServerEntryPtr;

class ApplicationHelper;

class Database : public IceUtil::Shared, public IceUtil::Monitor<IceUtil::Mutex>
{
public:
    
    Database(const Ice::ObjectAdapterPtr&, const IceStorm::TopicManagerPrx&, const std::string&, int, 
	     const TraceLevelsPtr&);
    virtual ~Database();
    
    void destroy();

    std::string getInstanceName() const;
    const TraceLevelsPtr& getTraceLevels() const { return _traceLevels; }
    const Ice::CommunicatorPtr& getCommunicator() const { return _communicator; }
    const Ice::ObjectAdapterPtr& getInternalAdapter() { return _internalAdapter; }

    void clearTopics();
    RegistryObserverTopicPtr getRegistryObserverTopic() const;
    NodeObserverTopicPtr getNodeObserverTopic() const;
    int getSessionTimeout() const { return _sessionTimeout; }

    int lock(AdminSessionI*, const std::string&);
    void unlock(AdminSessionI*);

    void init(int serial);
    void initMaster();
    void initReplica(int, const ApplicationInfoSeq&, const AdapterInfoSeq&, const ObjectInfoSeq&);

    void setClientProxy(const Ice::ObjectPrx&);
    void setServerProxy(const Ice::ObjectPrx&);
    Ice::ObjectPrx getClientProxy() const;
    Ice::ObjectPrx getServerProxy() const;
    void updateReplicatedWellKnownObjects();

    void addApplicationDescriptor(AdminSessionI*, const ApplicationDescriptor&, int = -1);
    void updateApplicationDescriptor(AdminSessionI*, const ApplicationUpdateDescriptor&, int = -1);
    void syncApplicationDescriptor(AdminSessionI*, const ApplicationDescriptor&);
    void instantiateServer(AdminSessionI*, const std::string&, const std::string&, const ServerInstanceDescriptor&);
    void removeApplicationDescriptor(AdminSessionI*, const std::string&, int = -1);

    ApplicationDescriptor getApplicationDescriptor(const std::string&);
    Ice::StringSeq getAllApplications(const std::string& = std::string());

    void addNode(const std::string&, const NodeSessionIPtr&);
    NodePrx getNode(const std::string&) const;
    NodeInfo getNodeInfo(const std::string&) const;
    void removeNode(const std::string&, const NodeSessionIPtr&, bool);
    Ice::StringSeq getAllNodes(const std::string& = std::string());

    void addReplica(const std::string&, const ReplicaSessionIPtr&);
    void removeReplica(const std::string&, const ReplicaSessionIPtr&, bool);

    ServerInfo getServerInfo(const std::string&, bool = false);
    ServerPrx getServer(const std::string&, bool = true);
    ServerPrx getServerWithTimeouts(const std::string&, int&, int&, std::string&, bool = true);
    Ice::StringSeq getAllServers(const std::string& = std::string());
    Ice::StringSeq getAllNodeServers(const std::string&);

    bool setAdapterDirectProxy(const std::string&, const std::string&, const Ice::ObjectPrx&, int = -1);
    Ice::ObjectPrx getAdapterDirectProxy(const std::string&);
    void removeAdapter(const std::string&);
    AdapterPrx getAdapter(const std::string&, const std::string&, bool = true);
    std::vector<std::pair<std::string, AdapterPrx> > getAdapters(const std::string&, int&, bool&);
    AdapterInfoSeq getAdapterInfo(const std::string&);
    Ice::StringSeq getAllAdapters(const std::string& = std::string());

    void addObject(const ObjectInfo&, bool = false, int = -1);
    void removeObject(const Ice::Identity&, int = -1);
    void updateObject(const Ice::ObjectPrx&, int = -1);

    void allocateObject(const Ice::Identity&, const ObjectAllocationRequestPtr&);
    void allocateObjectByType(const std::string&, const ObjectAllocationRequestPtr&);
    void releaseObject(const Ice::Identity&, const SessionIPtr&);

    Ice::ObjectPrx getObjectProxy(const Ice::Identity&);
    Ice::ObjectPrx getObjectByType(const std::string&);
    Ice::ObjectPrx getObjectByTypeOnLeastLoadedNode(const std::string&, LoadSample);
    Ice::ObjectProxySeq getObjectsByType(const std::string&);
    ObjectInfo getObjectInfo(const Ice::Identity&);
    ObjectInfoSeq getObjectInfosByType(const std::string&);
    ObjectInfoSeq getAllObjectInfos(const std::string& = std::string());

private:

    void checkForAddition(const ApplicationHelper&);
    void checkForUpdate(const ApplicationHelper&, const ApplicationHelper&);

    void checkServerForAddition(const std::string&);
    void checkAdapterForAddition(const std::string&);
    void checkObjectForAddition(const Ice::Identity&);

    void load(const ApplicationHelper&, ServerEntrySeq&, int);
    void unload(const ApplicationHelper&, ServerEntrySeq&);
    void reload(const ApplicationHelper&, const ApplicationHelper&, ServerEntrySeq&, int);
    void finishUpdate(ServerEntrySeq&, const ApplicationUpdateDescriptor&, const ApplicationInfo&, 
		      const ApplicationDescriptor&);

    void checkSessionLock(AdminSessionI*);

    friend struct AddComponent;

    static const std::string _applicationDbName;
    static const std::string _objectDbName;
    static const std::string _adapterDbName;
    static const std::string _replicaGroupDbName;
  
    const Ice::CommunicatorPtr _communicator;
    const Ice::ObjectAdapterPtr _internalAdapter;
    const IceStorm::TopicManagerPrx _topicManager;
    const std::string _envName;
    const std::string _instanceName;
    const TraceLevelsPtr _traceLevels;
    const int _sessionTimeout;

    ReplicaCache _replicaCache;
    NodeCache _nodeCache;
    AdapterCache _adapterCache;
    ObjectCache _objectCache;
    AllocatableObjectCache _allocatableObjectCache;
    ServerCache _serverCache;

    RegistryObserverTopicPtr _registryObserverTopic;
    NodeObserverTopicPtr _nodeObserverTopic;

    Ice::ObjectPrx _clientProxy;
    Ice::ObjectPrx _serverProxy;

    Freeze::ConnectionPtr _connection;
    StringApplicationInfoDict _applications;
    IdentityObjectInfoDict _objects;
    StringAdapterInfoDict _adapters;
    
    AdminSessionI* _lock;
    std::string _lockUserId;
    int _serial;
    std::set<std::string> _updating;
};
typedef IceUtil::Handle<Database> DatabasePtr;

};

#endif