KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > virtualdatabase > protocol > VirtualDatabaseConfiguration


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Copyright (C) 2006 Continuent, Inc.
7  * Contact: sequoia@continuent.org
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________.
23  */

24
25 package org.continuent.sequoia.controller.virtualdatabase.protocol;
26
27 import java.io.Serializable JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.continuent.hedera.common.Member;
32 import org.continuent.sequoia.common.i18n.Translate;
33 import org.continuent.sequoia.common.jmx.management.BackendInfo;
34 import org.continuent.sequoia.common.log.Trace;
35 import org.continuent.sequoia.controller.backend.DatabaseBackend;
36 import org.continuent.sequoia.controller.requestmanager.distributed.DistributedRequestManager;
37 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
38
39 /**
40  * Transports the configuration of a virtual database to remote controllers so
41  * that compatibility checking can be performed.
42  *
43  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
44  * @version 1.0
45  */

46 public class VirtualDatabaseConfiguration
47     extends DistributedVirtualDatabaseMessage
48 {
49   private static final long serialVersionUID = -4753828540599620782L;
50
51   private String JavaDoc controllerName;
52   private String JavaDoc controllerJmxName;
53   private String JavaDoc vdbName;
54   private String JavaDoc groupName = null;
55   private ArrayList JavaDoc vLogins;
56   private int schedulerRAIDbLevel;
57   private int loadBalancerRAIDbLevel;
58   private List JavaDoc /* <BackendInfo> */backendInfos;
59
60   /**
61    * @return Returns the controllerName.
62    */

63   public String JavaDoc getControllerName()
64   {
65     return controllerName;
66   }
67
68   /**
69    * Returns the controllerJmxName value.
70    *
71    * @return Returns the controllerJmxName.
72    */

73   public String JavaDoc getControllerJmxName()
74   {
75     return controllerJmxName;
76   }
77
78   /**
79    * Constructs a new <code>VirtualDatabaseConfiguration</code> object from a
80    * <code>DistributedVirtualDatabase</code>.
81    *
82    * @param dvdb The distributed virtual database to get configuration from.
83    */

84   public VirtualDatabaseConfiguration(DistributedVirtualDatabase dvdb)
85   {
86     this.controllerName = dvdb.getControllerName();
87     this.controllerJmxName = dvdb.viewOwningController();
88     this.vdbName = dvdb.getVirtualDatabaseName();
89     this.groupName = dvdb.getGroupName();
90     this.vLogins = dvdb.getAuthenticationManager().getVirtualLogins();
91     this.schedulerRAIDbLevel = dvdb.getRequestManager().getScheduler()
92         .getRAIDbLevel();
93     this.loadBalancerRAIDbLevel = dvdb.getRequestManager().getLoadBalancer()
94         .getRAIDbLevel();
95     this.backendInfos = DatabaseBackend.toBackendInfos(dvdb.getBackends());
96   }
97
98   /**
99    * Check if the local distributed virtual database is compatible with this
100    * virtual database configuration.
101    *
102    * @param localDvdb The local distributed virtual database
103    * @return an array of objects containing:
104    * <ul>
105    * <li>Boolean.TRUE if both configurations are compatible,
106    * Boolean.FALSE otherwise
107    * <li>a List of VirtualDatabaseUser objects if there are missing vdb
108    * users, null otherwise
109    * </ul>
110    */

111   private Object JavaDoc[] isCompatible(DistributedVirtualDatabase localDvdb)
112   {
113     Object JavaDoc[] ret = new Object JavaDoc[2];
114     ret[0] = Boolean.FALSE;
115     ret[1] = null;
116     try
117     {
118       if (controllerName.equals(localDvdb.getControllerName()))
119       {
120         localDvdb
121             .getLogger()
122             .warn(
123                 Translate
124                     .get("virtualdatabase.distributed.configuration.checking.duplicate.controller.name"));
125         return ret;
126       }
127
128       // Sanity checks for virtual database name and group name
129
if (!vdbName.equals(localDvdb.getVirtualDatabaseName()))
130       {
131         localDvdb
132             .getLogger()
133             .warn(
134                 Translate
135                     .get("virtualdatabase.distributed.configuration.checking.mismatch.name"));
136         return ret;
137       }
138       if (!groupName.equals(localDvdb.getGroupName()))
139       {
140         localDvdb
141             .getLogger()
142             .warn(
143                 Translate
144                     .get("virtualdatabase.distributed.configuration.checking.mismatch.groupname"));
145         return ret;
146       }
147
148       // Scheduler and Load Balancer checking
149
if (schedulerRAIDbLevel != localDvdb.getRequestManager().getScheduler()
150           .getRAIDbLevel())
151       {
152         localDvdb
153             .getLogger()
154             .warn(
155                 Translate
156                     .get("virtualdatabase.distributed.configuration.checking.mismatch.scheduler"));
157         return ret;
158       }
159
160       if (loadBalancerRAIDbLevel != localDvdb.getRequestManager()
161           .getLoadBalancer().getRAIDbLevel())
162       {
163         localDvdb
164             .getLogger()
165             .warn(
166                 Translate
167                     .get("virtualdatabase.distributed.configuration.checking.mismatch.loadbalancer"));
168         return ret;
169       }
170
171       // Checking backendInfos
172
int size = backendInfos.size();
173       for (int i = 0; i < size; i++)
174       {
175         BackendInfo b = (BackendInfo) backendInfos.get(i);
176         if (!localDvdb.isCompatibleBackend(b))
177         {
178           localDvdb
179               .getLogger()
180               .warn(
181                   Translate
182                       .get(
183                           "virtualdatabase.distributed.configuration.checking.mismatch.backend.shared",
184                           b.getName()));
185           return ret;
186         }
187       }
188
189       // Authentication managers must contains the same set of elements but
190
// possibly in different orders (equals require the element to be in the
191
// same order).
192
if (!localDvdb.getAuthenticationManager().getVirtualLogins().containsAll(
193           vLogins))
194       {
195         localDvdb
196             .getLogger()
197             .warn(
198                 Translate
199                     .get("virtualdatabase.distributed.configuration.checking.mismatch.vlogins"));
200         return ret;
201       }
202
203       // Special case: the joining vdb will try to become compatible by
204
// dynamically creating the missing vd users.
205
// WARNING: don't move this test around, it does expect to be the last
206
// test performed, meaning that if missing vdb users can be added the
207
// configurations will effectively become compatible.
208
if (!vLogins.containsAll(localDvdb.getAuthenticationManager()
209           .getVirtualLogins()))
210       {
211         localDvdb
212             .getLogger()
213             .warn(
214                 Translate
215                     .get("virtualdatabase.distributed.configuration.checking.mismatch.vlogins"));
216         List JavaDoc additionalVdbUsers = new ArrayList JavaDoc(localDvdb
217             .getAuthenticationManager().getVirtualLogins());
218         additionalVdbUsers.removeAll(vLogins);
219         ret[0] = Boolean.TRUE;
220         ret[1] = additionalVdbUsers;
221         return ret;
222       }
223
224       // Ok, all tests succeeded, configuration is compatible
225
ret[0] = Boolean.TRUE;
226       return ret;
227     }
228     catch (Exception JavaDoc e)
229     {
230       localDvdb.getLogger().error(
231           Translate
232               .get("virtualdatabase.distributed.configuration.checking.error"),
233           e);
234       return ret;
235     }
236   }
237
238   /**
239    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
240    * org.continuent.hedera.common.Member)
241    */

242   public Object JavaDoc handleMessageSingleThreaded(DistributedVirtualDatabase dvdb,
243       Member sender)
244   {
245     return null;
246   }
247
248   /**
249    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
250    * org.continuent.hedera.common.Member, java.lang.Object)
251    */

252   public Serializable JavaDoc handleMessageMultiThreaded(
253       DistributedVirtualDatabase dvdb, Member sender,
254       Object JavaDoc handleMessageSingleThreadedResult)
255   {
256     Trace logger = dvdb.getLogger();
257     if (logger.isInfoEnabled())
258       logger.info("Checking virtual database configuration from "
259           + getControllerName());
260
261     Object JavaDoc[] ret = isCompatible(dvdb);
262     if (!dvdb.isLocalSender(sender) && !((Boolean JavaDoc) ret[0]).booleanValue())
263     {
264       // Failure
265
return new VirtualDatabaseConfigurationResponse(
266           DistributedVirtualDatabase.INCOMPATIBLE_CONFIGURATION, (List JavaDoc) ret[1]);
267     }
268
269     // Configuration is compatible, add it to our controller list
270
dvdb.addRemoteControllerJmxName(sender, controllerJmxName);
271
272     // Send back our local configuration
273
try
274     {
275       dvdb.sendLocalConfiguration(sender);
276     }
277     catch (Exception JavaDoc e)
278     {
279       return e;
280     }
281
282     if (logger.isInfoEnabled())
283       logger.info("Controller " + getControllerName()
284           + " is compatible with the local configuration");
285     return new VirtualDatabaseConfigurationResponse(
286         ((DistributedRequestManager) dvdb.getRequestManager())
287             .getControllerId(), (List JavaDoc) ret[1]);
288   }
289
290 }
Popular Tags