Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

VirtualDatabaseConfiguration.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2005 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.virtualdatabase.protocol;
00026 
00027 import java.io.Serializable;
00028 import java.util.ArrayList;
00029 import java.util.HashMap;
00030 import java.util.List;
00031 
00032 import org.objectweb.cjdbc.common.i18n.Translate;
00033 import org.objectweb.cjdbc.common.jmx.JmxConstants;
00034 import org.objectweb.cjdbc.common.shared.BackendInfo;
00035 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema;
00036 import org.objectweb.cjdbc.controller.jmx.RmiConnector;
00037 import org.objectweb.cjdbc.controller.requestmanager.RAIDbLevels;
00038 import org.objectweb.cjdbc.controller.virtualdatabase.DistributedVirtualDatabase;
00039 
00040 /**
00041  * Transports the configuration of a virtual database to remote controllers so
00042  * that compatibility checking can be performed.
00043  * 
00044  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00045  * @version 1.0
00046  */
00047 public class VirtualDatabaseConfiguration implements Serializable
00048 {
00049   private String         controllerName;
00050   private String         controllerJmxName;
00051   private String         vdbName;
00052   private String         groupName = null;
00053   private ArrayList      vLogins;
00054   private int            schedulerRAIDbLevel;
00055   private int            loadBalancerRAIDbLevel;
00056   private DatabaseSchema dbs;
00057   private ArrayList      backends;
00058   private HashMap        backendPolicies;
00059 
00060   // Jmx Information
00061   private String         rmiHostname;
00062   private String         rmiPort;
00063 
00064   /**
00065    * @return Returns the controllerName.
00066    */
00067   public String getControllerName()
00068   {
00069     return controllerName;
00070   }
00071 
00072   /**
00073    * Returns the controllerJmxName value.
00074    * 
00075    * @return Returns the controllerJmxName.
00076    */
00077   public String getControllerJmxName()
00078   {
00079     return controllerJmxName;
00080   }
00081 
00082   /**
00083    * Constructs a new <code>VirtualDatabaseConfiguration</code> object from a
00084    * <code>DistributedVirtualDatabase</code>.
00085    * 
00086    * @param dvdb The distributed virtual database to get configuration from.
00087    */
00088   public VirtualDatabaseConfiguration(DistributedVirtualDatabase dvdb)
00089   {
00090     this.controllerName = dvdb.getControllerName();
00091     this.controllerJmxName = dvdb.viewOwningController();
00092     this.vdbName = dvdb.getVirtualDatabaseName();
00093     this.groupName = dvdb.getGroupName();
00094     this.vLogins = dvdb.getAuthenticationManager().getVirtualLogins();
00095     this.schedulerRAIDbLevel = dvdb.getRequestManager().getScheduler()
00096         .getRAIDbLevel();
00097     this.loadBalancerRAIDbLevel = dvdb.getRequestManager().getLoadBalancer()
00098         .getRAIDbLevel();
00099     this.dbs = dvdb.getRequestManager().getDatabaseSchema();
00100     this.backends = dvdb.getBackendsInfo(dvdb.getBackends());
00101     this.backendPolicies = dvdb.getBackendRecoveryPolicy();
00102 
00103     List connectors = RmiConnector.getRmiConnectors();
00104     if (connectors.size() > 0)
00105     {
00106       RmiConnector rmi = (RmiConnector) connectors.get(0);
00107       rmiHostname = rmi.getHostName();
00108       rmiPort = "" + rmi.getPort();
00109     }
00110     else
00111     {
00112       rmiHostname = controllerName.substring(0, controllerName.indexOf(":"));
00113       rmiPort = "" + JmxConstants.DEFAULT_JMX_RMI_PORT;
00114     }
00115   }
00116 
00117   /**
00118    * @return Returns the rmiHostname.
00119    */
00120   public String getRmiHostname()
00121   {
00122     return rmiHostname;
00123   }
00124 
00125   /**
00126    * @return Returns the rmiPort.
00127    */
00128   public String getRmiPort()
00129   {
00130     return rmiPort;
00131   }
00132 
00133   /**
00134    * Check if the local distributed virtual database is compatible with this
00135    * virtual database configuration.
00136    * 
00137    * @param localDvdb The local distributed virtual database
00138    * @return true if both configurations are compatible, false otherwise
00139    */
00140   public boolean isCompatible(DistributedVirtualDatabase localDvdb)
00141   {
00142     try
00143     {
00144       if (controllerName.equals(localDvdb.getControllerName()))
00145       {
00146         localDvdb.logger
00147             .warn(Translate
00148                 .get("virtualdatabase.distributed.configuration.checking.duplicate.controller.name"));
00149         return false;
00150       }
00151 
00152       // Sanity checks for virtual database name and group name
00153       if (!vdbName.equals(localDvdb.getVirtualDatabaseName()))
00154       {
00155         localDvdb.logger
00156             .warn(Translate
00157                 .get("virtualdatabase.distributed.configuration.checking.mismatch.name"));
00158         return false;
00159       }
00160       if (!groupName.equals(localDvdb.getGroupName()))
00161       {
00162         localDvdb.logger
00163             .warn(Translate
00164                 .get("virtualdatabase.distributed.configuration.checking.mismatch.groupname"));
00165         return false;
00166       }
00167 
00168       // Authentication managers must contains the same set of elements but
00169       // possibly in different orders (equals require the element to be in the
00170       // same order).
00171       if (!vLogins.containsAll(localDvdb.getAuthenticationManager()
00172           .getVirtualLogins())
00173           || !localDvdb.getAuthenticationManager().getVirtualLogins()
00174               .containsAll(vLogins))
00175       {
00176         localDvdb.logger
00177             .warn(Translate
00178                 .get("virtualdatabase.distributed.configuration.checking.mismatch.vlogins"));
00179         return false;
00180       }
00181 
00182       // Scheduler and Load Balancer checking
00183       if (schedulerRAIDbLevel != localDvdb.getRequestManager().getScheduler()
00184           .getRAIDbLevel())
00185       {
00186         localDvdb.logger
00187             .warn(Translate
00188                 .get("virtualdatabase.distributed.configuration.checking.mismatch.scheduler"));
00189         return false;
00190       }
00191 
00192       if (loadBalancerRAIDbLevel != localDvdb.getRequestManager()
00193           .getLoadBalancer().getRAIDbLevel())
00194       {
00195         localDvdb.logger
00196             .warn(Translate
00197                 .get("virtualdatabase.distributed.configuration.checking.mismatch.loadbalancer"));
00198         return false;
00199       }
00200 
00201       // Checking backends
00202       int size = backends.size();
00203       for (int i = 0; i < size; i++)
00204       {
00205         BackendInfo b = (BackendInfo) backends.get(i);
00206         if (!localDvdb.isCompatibleBackend(b))
00207         {
00208           localDvdb.logger
00209               .warn(Translate
00210                   .get(
00211                       "virtualdatabase.distributed.configuration.checking.mismatch.backend.shared",
00212                       b.getName()));
00213           return false;
00214         }
00215       }
00216 
00217       // Database schema checking (if any)
00218       if (dbs == null)
00219       {
00220         localDvdb.logger
00221             .warn(Translate
00222                 .get("virtualdatabase.distributed.configuration.checking.noschema"));
00223       }
00224       else
00225       {
00226         // Check database schemas compatibility
00227         switch (loadBalancerRAIDbLevel)
00228         {
00229           case RAIDbLevels.RAIDb0 :
00230             // There must be no overlap between schemas
00231             if (dbs.equals(localDvdb.getRequestManager().getDatabaseSchema()))
00232             {
00233               localDvdb.logger
00234                   .warn(Translate
00235                       .get("virtualdatabase.distributed.configuration.checking.mismatch.databaseschema"));
00236               return false;
00237             }
00238             break;
00239           case RAIDbLevels.SingleDB :
00240           case RAIDbLevels.RAIDb1 :
00241             // Schemas must be identical
00242             if (!dbs.equals(localDvdb.getRequestManager().getDatabaseSchema()))
00243             {
00244               localDvdb.logger
00245                   .warn(Translate
00246                       .get("virtualdatabase.distributed.configuration.checking.mismatch.databaseschema"));
00247               return false;
00248             }
00249             break;
00250           case RAIDbLevels.RAIDb2 :
00251             // Common parts of the schema must be identical
00252             if (!dbs.isCompatibleWith(localDvdb.getRequestManager()
00253                 .getDatabaseSchema()))
00254             {
00255               localDvdb.logger
00256                   .warn(Translate
00257                       .get("virtualdatabase.distributed.configuration.checking.mismatch.databaseschema"));
00258               return false;
00259             }
00260             break;
00261           default :
00262             localDvdb.logger.error("Unsupported RAIDb level: "
00263                 + loadBalancerRAIDbLevel);
00264             return false;
00265         }
00266       }
00267 
00268       // Ok, all tests succeeded, configuration is compatible
00269       return true;
00270     }
00271     catch (Exception e)
00272     {
00273       localDvdb.logger.error(Translate
00274           .get("virtualdatabase.distributed.configuration.checking.error"), e);
00275       return false;
00276     }
00277   }
00278 
00279   /**
00280    * Returns the backendPolicies value.
00281    * 
00282    * @return Returns the backendPolicies.
00283    */
00284   public HashMap getBackendPolicies()
00285   {
00286     return backendPolicies;
00287   }
00288 
00289 }

Generated on Mon Apr 11 22:01:35 2005 for C-JDBC by  doxygen 1.3.9.1