portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager PsmlImporter.java
Date Mon, 19 Jul 2004 04:25:09 GMT
taylor      2004/07/18 21:25:09

  Modified:    src/java/org/apache/jetspeed/services/registry
                        RegistryImporter.java HybridRegistryService.java
               src/java/org/apache/jetspeed/services/psmlmanager
                        PsmlImporter.java
  Log:
  - improved Registry Importer's error checking and logging
  - now handling dup keys, they can be optionally replaced or skipped
    use this setting in RegistryImport.properties
  
  services.RegistryImporter.replace.imported.entries = false
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.4       +100 -73   jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/RegistryImporter.java
  
  Index: RegistryImporter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/RegistryImporter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RegistryImporter.java	14 Jul 2004 22:35:01 -0000	1.3
  +++ RegistryImporter.java	19 Jul 2004 04:25:09 -0000	1.4
  @@ -39,14 +39,14 @@
        * Static initialization of the logger for this class
        */
       private static final JetspeedLogger logger =
  -        JetspeedLogFactoryService.getLogger(RegistryImporter.class.getName());
  +        JetspeedLogFactoryService.getLogger("importer");
       protected boolean check = true;
       public RegistryImporter()
       {
       }
       public static void main(String args[])
       {
  -        System.out.println("***** Registry Importer *****");
  +        logAndPrint("***** Registry Importer *****");
           boolean checkImport = true;
           //
           // initialize and bootstrap services
  @@ -62,72 +62,34 @@
                       TurbineServices.getInstance()).getResources(RegistryService.SERVICE_NAME);
               
           }
  -        catch (Exception e)
  +        catch (Throwable t)
           {
               String msg =
                   "Registry Importer: error initializing Turbine configuration";
  -            logger.error(msg, e);
  -            System.out.println(msg);
  -            e.printStackTrace();
  -            System.exit(0);
  +            logAndPrintError(msg, t);
  +            System.exit(1);
           }
  +        
           //
           // get a handle to the exporter service
           //
  -        RegistryService exporterService = null;
  -        RegistryService importerService = null;
  -        try
  -        {
  -            exporterService =
  -                (RegistryService) ServiceUtil.getServiceByName(
  -                    "Registry");
  -        }
  -        catch (org.apache.turbine.services.InstantiationException e)
  -        {
  -            String msg =
  -                "Registry Importer: error loading Registry Exporter Service";
  -            logger.error(msg, e);
  -            System.out.println(msg);
  -            e.printStackTrace();
  -            System.exit(0);
  -        }
  -        //
  -        // get a handle to the importer service
  -        //
  -        try
  -        {
  -            importerService =
  -                (RegistryService) ServiceUtil.getServiceByName(
  -                    "RegistryImporter");
  -        }
  -        catch (org.apache.turbine.services.InstantiationException e)
  -        {
  -            String msg =
  -                "Registry Importer: error loading Registry Importer Service";
  -            logger.error(msg, e);
  -            System.out.println(msg);
  -            e.printStackTrace();
  -            System.exit(0);
  -        }
  -        if (exporterService
  -            .getClass()
  -            .getName()
  -            .equals(importerService.getClass().getName()))
  +        RegistryService exporterService = getService("Registry", "Exporter");
  +        RegistryService importerService = getService("RegistryImporter", "Importer"); 
      
  +        
  +        if (exporterService.getClass().getName().equals(importerService.getClass().getName()))
           {
               String msg =
                   "Registry Importer Error: Importer Class cannot equal Exporter Class.";
  -            logger.error(msg);
  -            System.out.println(msg);
  -            System.exit(0);
  +            logAndPrintError(msg, null);
  +            System.exit(1);
           }
  +                
           RegistryImporter importer = new RegistryImporter();
           boolean ran = importer.run(exporterService, importerService);
  -        if (ran)
  -        {
  -            System.out.println("**** Registry Importer - completed");
  -        }
  -        System.exit(1);
  +        logAndPrint("**** Registry Importer - completed");
  +        System.exit(0);                    
       }
  +    
       public boolean run(
           RegistryService exporterService,
           RegistryService importerService)
  @@ -135,38 +97,54 @@
           String msg;
           int registryCount = 0;
           int entryCount = 0;
  +        int skipCount = 0;
           try
           {
  -            msg =
  -                "Running with Importer Service: " + importerService.getClass();
  -            System.out.println(msg);
  -            logger.info(msg);
  -            msg =
  -                "Running with Exporter Service: " + exporterService.getClass();
  -            System.out.println(msg);
  -            logger.info(msg);
  +            msg = "Running with Importer Service: " + importerService.getClass();
  +            logAndPrint(msg);
  +            msg = "Running with Exporter Service: " + exporterService.getClass();
  +            logAndPrint(msg);
               Enumeration e = importerService.getNames();
                           
               while (e.hasMoreElements())
               {
                   String registryName = (String) e.nextElement();
  -                System.out.println("Exporting Registry: " + registryName);
  +                logAndPrint("Exporting Registry: " + registryName);
                   Registry importRegistry = importerService.get(registryName);
                   Registry exportRegistry = exporterService.get(registryName);
  -                
  -                
  +                                
                   Enumeration enum = exportRegistry.getEntries();
                   while (enum.hasMoreElements())
                   {
                       RegistryEntry exportEntry = (RegistryEntry) enum.nextElement();
  -                    System.out.println("Importing into Registry: " + registryName + ",
Entry = " + exportEntry.getName());
   
                       if (registryName.equals(org.apache.jetspeed.services.Registry.SECURITY))
                   
                       {
  -                        importerService.addEntry(registryName, exportEntry);
  +                        if (null == importerService.getEntry(registryName, exportEntry.getName()))
  +                        {
  +                            importerService.addEntry(registryName, exportEntry);
  +                            logAndPrint("Imported into Registry: " + registryName + ",
Entry = " + exportEntry.getName());                            
  +                            entryCount++;                                             
  
  +                        }
  +                        else
  +                        {
  +                            if (importerService instanceof HybridRegistryService)
  +                            {
  +                                HybridRegistryService hybrid = (HybridRegistryService)importerService;
  +                                if (hybrid.getReplaceImportedEntries())
  +                                {
  +                                    importerService.addEntry(registryName, exportEntry);
  +                                    logAndPrint("Imported (update) into Registry: " + registryName
+ ", Entry = " + exportEntry.getName());
  +                                    entryCount++;                                     
                                              
  +                                }
  +                                else
  +                                {
  +                                    logAndPrint("Skipping Entry, already exists: " + registryName
+ ", Entry = " + exportEntry.getName());
  +                                    skipCount++;                                      
                                                                                 
  +                                }
  +                            }
  +                        }                                                            
                       }
  -                    
  -                    entryCount++;                    
                   }
                   registryCount++;
               }
  @@ -177,10 +155,59 @@
               e.printStackTrace();
               return false;
           }
  -        msg = "Registry Importer completed. Exported " + registryCount + " registries,
" + entryCount + " total registry entries.";
  -        System.out.println(msg);
  -        logger.info(msg);
  +        msg = "*** Registry Importer completed ***";
  +        logAndPrint(msg);
  +        msg = "Total Registries imported      : " + registryCount;        
  +        logAndPrint(msg);
  +        msg = "Total Registry Entries imported: " + entryCount;
  +        logAndPrint(msg);
  +        msg = "Total Registry Entries skipped : " + skipCount;
  +        logAndPrint(msg);
           return true;
       }
   
  +    private static final void logAndPrint(String msg)
  +    {
  +        System.out.println(msg);
  +        logger.info(msg);        
  +    }
  +
  +    private static final void logAndPrintError(String msg, Throwable t)
  +    {
  +        System.err.println(msg);
  +        if (null == t)
  +        {
  +            logger.error(msg);
  +        }
  +        else
  +        {
  +            logger.error(msg, t);
  +        }
  +    }
  +    
  +    private static final RegistryService getService(String serviceName, String serviceMode)
  +    {
  +        RegistryService service = null;
  +        
  +        try
  +        {
  +            service = (RegistryService) ServiceUtil.getServiceByName(serviceName);    
               
  +        }
  +        catch (org.apache.turbine.services.InstantiationException e)
  +        {
  +            String msg =
  +                "Registry Importer: error loading Registry " + serviceMode + " Service";
  +            logAndPrintError(msg, e);
  +            System.exit(1);
  +        }
  +        
  +        if (false == service.getInit())
  +        {
  +            String msg =
  +                "Registry Importer: error initializing Registry " + serviceMode + " Service";
  +            logAndPrintError(msg, null);
  +            System.exit(1);            
  +        }
  +        return service;
  +    }
   }
  
  
  
  1.6       +37 -24    jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/HybridRegistryService.java
  
  Index: HybridRegistryService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/HybridRegistryService.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HybridRegistryService.java	15 Jul 2004 00:14:39 -0000	1.5
  +++ HybridRegistryService.java	19 Jul 2004 04:25:09 -0000	1.6
  @@ -33,8 +33,6 @@
   import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
   import org.apache.jetspeed.services.logging.JetspeedLogger;
   import org.apache.turbine.services.InitializationException;
  -import org.apache.turbine.services.TurbineServices;
  -import org.apache.turbine.services.resources.ResourceService;
   
   /**
    * Implements the Jetspeed Registry Service interface, with a hybrid of Database and File-based
(Castor)
  @@ -53,6 +51,7 @@
       private Hashtable dbRegistries = new Hashtable();
       private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(HybridRegistryService.class.getName());
       private boolean hybrid = true;
  +    private boolean replaceImportedEntries = false;
           
       
       /**
  @@ -69,11 +68,12 @@
   
           try
           {
  -            // get the list of managed Registries in the Database
  +            setInit(false);
               
  -            // dst ResourceService rs = serviceConf.getResources("database.default");
  +            replaceImportedEntries = getConfiguration().getBoolean("replace.imported.entries");
  +
  +            // get the list of managed Registries in the Database            
               Iterator iterator = getConfiguration().getKeys("database.default");
  -            // dst Iterator iterator = rs.getKeys();                
               while (iterator.hasNext())
               {
                   String key = (String)iterator.next();
  @@ -90,14 +90,20 @@
           setInit(true);        
       }
       
  +    public boolean getReplaceImportedEntries()
  +    {
  +        return this.replaceImportedEntries;
  +    }
  +    
       private void loadCache(String registryName, Registry registry)
  +    throws InitializationException
       {
           LocalRegistry local = (LocalRegistry)registry;
           try
           {
               if (registryName.equals(org.apache.jetspeed.services.Registry.SECURITY))
  -            {
  -                Iterator extent = SecurityDbEntryPeer.fetchExtent().iterator();
  +            {                
  +                Iterator extent = SecurityDbEntryPeer.fetchExtent().iterator();       
        
                   while (extent.hasNext())
                   {
                       SecurityEntry se = (SecurityEntry)extent.next();
  @@ -105,9 +111,10 @@
                   }
               }
           }
  -        catch (Exception e)
  +        catch (Throwable t)
           {
  -            logger.error("Failed to load cache for registry: " + registryName, e);
  +            logger.error("Failed to load cache for registry: " + registryName, t);
  +            throw new InitializationException("Unable to initialize HybridRegistryService
cache", t); 
           }
       }
       
  @@ -221,7 +228,6 @@
           }
           else
           {
  -            // System.out.println(" +++ Getting from cache");                
           }
           return entry;        
       }
  @@ -248,23 +254,30 @@
       
       public void removeEntry(String registryName, String entryName)
       {
  -        LocalRegistry registry = (LocalRegistry)dbRegistries.get(registryName);
  -        if (null == registry)
  +        try
           {
  -            if (hybrid)
  +            LocalRegistry registry = (LocalRegistry)dbRegistries.get(registryName);
  +            if (null == registry)
               {
  -                super.removeEntry(registryName, entryName);
  +                if (hybrid)
  +                {
  +                    super.removeEntry(registryName, entryName);
  +                }
  +                return;            
  +            }                    
  +            if (entryName == null)
  +            {
  +                return;
  +            }
  +            if (registryName.equals(org.apache.jetspeed.services.Registry.SECURITY))
  +            {                                         
  +                    SecurityDbEntryPeer.removeSecurityEntry(entryName);        
  +                    registry.removeLocalEntry(entryName);
               }
  -            return;            
  -        }                    
  -        if (entryName == null)
  -        {
  -            return;
           }
  -        if (registryName.equals(org.apache.jetspeed.services.Registry.SECURITY))
  -        {                                         
  -                SecurityDbEntryPeer.removeSecurityEntry(entryName);        
  -                registry.removeLocalEntry(entryName);
  +        catch (RegistryException e)
  +        {
  +            
           }
       }
   
  
  
  
  1.17      +6 -6      jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlImporter.java
  
  Index: PsmlImporter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlImporter.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- PsmlImporter.java	23 Feb 2004 03:32:51 -0000	1.16
  +++ PsmlImporter.java	19 Jul 2004 04:25:09 -0000	1.17
  @@ -89,7 +89,7 @@
               logger.error(msg, e);
               System.out.println(msg);
               e.printStackTrace();
  -            System.exit(0);
  +            System.exit(1);
           }
   
           //
  @@ -108,7 +108,7 @@
               logger.error(msg, e);
               System.out.println(msg);
               e.printStackTrace();
  -            System.exit(0);
  +            System.exit(1);
           }
   
           //
  @@ -124,7 +124,7 @@
               logger.error(msg, e);
               System.out.println(msg);
               e.printStackTrace();
  -            System.exit(0);
  +            System.exit(1);
           }
   
           if (exporterService.getClass().getName().equals(importerService.getClass().getName()))
  @@ -132,7 +132,7 @@
               String msg = "PSML Importer Error: Importer Class cannot equal Exporter Class.";
               logger.error(msg);
               System.out.println(msg);
  -            System.exit(0);
  +            System.exit(1);
           }
   
           PsmlImporter importer = new PsmlImporter();
  @@ -144,7 +144,7 @@
               System.out.println("**** PSML Importer - completed");
           }        
   
  -        System.exit(1);
  +        System.exit(0);
   
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message