continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmora...@apache.org
Subject svn commit: r780708 - in /continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache: continuum/purge/ maven/continuum/ maven/continuum/build/settings/ maven/continuum/scheduler/
Date Mon, 01 Jun 2009 16:29:32 GMT
Author: jmorales
Date: Mon Jun  1 16:29:31 2009
New Revision: 780708

URL: http://svn.apache.org/viewvc?rev=780708&view=rev
Log:
[CONTINUUM-2195] [CONTINUUM-2236] .Scheduler is updated when update or add a purgeConfiguration
or buildDefinition with schedule. Also delete schedules that are not associated with a buildDefinition
or purgeConfiguration when execute job process. I have created two groups for jobs whe add
a job to scheduler:
- PurgeConfiguration group.
- BuildDefinitionGroup.

Modified:
    continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java
    continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/build/settings/DefaultSchedulesActivator.java
    continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumBuildJob.java
    continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumPurgeJob.java

Modified: continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java?rev=780708&r1=780707&r2=780708&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java
Mon Jun  1 16:29:31 2009
@@ -27,8 +27,13 @@
 import org.apache.continuum.purge.task.PurgeTask;
 import org.apache.continuum.taskqueue.manager.TaskQueueManager;
 import org.apache.continuum.taskqueue.manager.TaskQueueManagerException;
+import org.apache.maven.continuum.build.settings.DefaultSchedulesActivator;
+import org.apache.maven.continuum.build.settings.SchedulesActivationException;
+import org.apache.maven.continuum.build.settings.SchedulesActivator;
 import org.apache.maven.continuum.model.project.Schedule;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.List;
 
@@ -43,10 +48,12 @@
 public class DefaultContinuumPurgeManager
     implements ContinuumPurgeManager
 {
+    private static final Logger log = LoggerFactory.getLogger( DefaultContinuumPurgeManager.class
);
+    
     /**
      * @plexus.requirement
      */
-    private ProjectDao projectDao;
+    private SchedulesActivator schedulesActivator;
 
     /**
      * @plexus.requirement
@@ -87,6 +94,20 @@
                 purgeDirectory( dirPurge );
             }
         }
+        
+        if ( ( repoPurgeList == null || repoPurgeList.isEmpty() ) && ( dirPurgeList
== null || dirPurgeList.isEmpty() ) )
+        {
+            // This purge is not enable for a purge process.
+            try
+            {
+                schedulesActivator.unactivateOrphanPurgeSchedule( schedule );
+            }
+            catch ( SchedulesActivationException e )
+            {
+                log.debug( String.format( "Can't unactivate orphan schedule '%s' for purgeConfiguration",
+                                          schedule.getName() ) );
+            }
+        }
     }
 
     public void purgeRepository( RepositoryPurgeConfiguration repoPurge )

Modified: continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=780708&r1=780707&r2=780708&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
Mon Jun  1 16:29:31 2009
@@ -270,6 +270,7 @@
     {
         Runtime.getRuntime().addShutdownHook( new Thread()
         {
+            @Override
             public void run()
             {
                 try
@@ -927,7 +928,16 @@
             if ( projectsMap == null || projectsMap.size() == 0 )
             {
                 log.debug( "no builds attached to schedule" );
-                // We don't have projects attached to this schedule
+                try
+                {
+                    schedulesActivator.unactivateOrphanBuildSchedule( schedule );
+                }
+                catch ( SchedulesActivationException e )
+                {
+                    log.debug( "Can't unactivate orphan shcedule for buildDefinitions" );
+                }
+                // We don't have projects attached to this schedule. This is because it's
only is setting for a
+                // templateBuildDefinition
                 return;
             }
 
@@ -2091,11 +2101,14 @@
         throws ContinuumException
     {
         HashMap<String, Object> context = new HashMap<String, Object>();
+        Schedule schedule = buildDefinition.getSchedule();
 
         AbstractContinuumAction.setBuildDefinition( context, buildDefinition );
         AbstractContinuumAction.setProjectId( context, projectId );
 
         executeAction( "add-build-definition-to-project", context );
+        
+        activeBuildDefinitionSchedule( schedule );
 
         return AbstractContinuumAction.getBuildDefinition( context );
     }
@@ -2104,8 +2117,10 @@
         throws ContinuumException
     {
         HashMap<String, Object> context = new HashMap<String, Object>();
+        BuildDefinition buildDefinition = getBuildDefinition( buildDefinitionId );
+        Schedule schedule = buildDefinition.getSchedule();
 
-        AbstractContinuumAction.setBuildDefinition( context, getBuildDefinition( buildDefinitionId
) );
+        AbstractContinuumAction.setBuildDefinition( context, buildDefinition );
         AbstractContinuumAction.setProjectId( context, projectId );
 
         executeAction( "remove-build-definition-from-project", context );
@@ -2115,11 +2130,14 @@
         throws ContinuumException
     {
         HashMap<String, Object> context = new HashMap<String, Object>();
+        Schedule schedule = buildDefinition.getSchedule();
 
         AbstractContinuumAction.setBuildDefinition( context, buildDefinition );
         AbstractContinuumAction.setProjectId( context, projectId );
 
         executeAction( "update-build-definition-from-project", context );
+        
+        activeBuildDefinitionSchedule( schedule );
 
         return AbstractContinuumAction.getBuildDefinition( context );
     }
@@ -2128,11 +2146,14 @@
         throws ContinuumException
     {
         HashMap<String, Object> context = new HashMap<String, Object>();
+        Schedule schedule = buildDefinition.getSchedule();
 
         AbstractContinuumAction.setBuildDefinition( context, buildDefinition );
         AbstractContinuumAction.setProjectGroupId( context, projectGroupId );
 
         executeAction( "add-build-definition-to-project-group", context );
+        
+        activeBuildDefinitionSchedule( schedule );
 
         return AbstractContinuumAction.getBuildDefinition( context );
     }
@@ -2152,11 +2173,14 @@
         throws ContinuumException
     {
         HashMap<String, Object> context = new HashMap<String, Object>();
+        Schedule schedule = buildDefinition.getSchedule();
 
         AbstractContinuumAction.setBuildDefinition( context, buildDefinition );
         AbstractContinuumAction.setProjectGroupId( context, projectGroupId );
 
         executeAction( "update-build-definition-from-project-group", context );
+        
+        activeBuildDefinitionSchedule( schedule );
 
         return AbstractContinuumAction.getBuildDefinition( context );
     }
@@ -2258,6 +2282,9 @@
     private void updateSchedule( Schedule schedule, boolean updateScheduler )
         throws ContinuumException
     {
+        
+        Schedule old = getSchedule( schedule.getId() );
+        
         storeSchedule( schedule );
 
         if ( updateScheduler )
@@ -2266,14 +2293,15 @@
             {
                 if ( schedule.isActive() )
                 {
-                    // I unactivate it before if it's already active
-                    schedulesActivator.unactivateSchedule( schedule, this );
+                    // I unactivate old shcedule (could change name) before if it's already
active
+                    schedulesActivator.unactivateSchedule( old, this );
 
                     schedulesActivator.activateSchedule( schedule, this );
                 }
                 else
                 {
-                    schedulesActivator.unactivateSchedule( schedule, this );
+                    // Unactivate old because could change name in new schedule
+                    schedulesActivator.unactivateSchedule( old, this );
                 }
             }
             catch ( SchedulesActivationException e )
@@ -2347,7 +2375,30 @@
             throw logAndCreateException( "Error while storing schedule.", ex );
         }
     }
-
+    
+    public void activePurgeSchedule( Schedule schedule )
+    {
+        try
+        {
+            schedulesActivator.activatePurgeSchedule( schedule, this );
+        }
+        catch ( SchedulesActivationException e )
+        {
+            log.error( "Can't activate schedule for purgeConfiguration" );
+        }
+    }
+    
+    public void activeBuildDefinitionSchedule( Schedule schedule )
+    {
+        try
+        {
+            schedulesActivator.activateBuildSchedule( schedule, this );
+        }
+        catch ( SchedulesActivationException e )
+        {
+            log.error( "Can't activate schedule for buildDefinition" );
+        }
+    }
     // ----------------------------------------------------------------------
     // Working copy
     // ----------------------------------------------------------------------

Modified: continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/build/settings/DefaultSchedulesActivator.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/build/settings/DefaultSchedulesActivator.java?rev=780708&r1=780707&r2=780708&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/build/settings/DefaultSchedulesActivator.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/build/settings/DefaultSchedulesActivator.java
Mon Jun  1 16:29:31 2009
@@ -82,7 +82,7 @@
      */
     private Scheduler scheduler;
 
-    //private int delay = 3600;
+    // private int delay = 3600;
     private static final int delay = 1;
 
     public void activateSchedules( Continuum continuum )
@@ -94,42 +94,27 @@
 
         for ( Schedule schedule : schedules )
         {
-            if ( StringUtils.isEmpty( schedule.getCronExpression() ) )
-            {
-                // TODO: this can possibly be removed but it's here now to
-                // weed out any bugs
-                log.info( "Not scheduling " + schedule.getName() );
-
-                continue;
-            }
-
-            try
+            if ( schedule.isActive() )
             {
-                // check schedule job class
-                if ( isScheduleFromBuildJob( schedule ) )
+                try
                 {
-                    schedule( schedule, continuum, ContinuumBuildJob.class );
+                    activateSchedule( schedule, continuum );
                 }
-
-                if ( isScheduleFromPurgeJob( schedule ) )
+                catch ( SchedulesActivationException e )
                 {
-                    schedule( schedule, continuum, ContinuumPurgeJob.class );
-                }
-            }
-            catch ( SchedulesActivationException e )
-            {
-                log.error( "Can't activate schedule '" + schedule.getName() + "'", e );
+                    log.error( "Can't activate schedule '" + schedule.getName() + "'", e
);
 
-                schedule.setActive( false );
+                    schedule.setActive( false );
 
-                try
-                {
-                    scheduleDao.storeSchedule( schedule );
-                }
-                catch ( ContinuumStoreException e1 )
-                {
-                    throw new SchedulesActivationException( "Can't desactivate schedule '"
+ schedule.getName() + "'",
-                                                            e );
+                    try
+                    {
+                        scheduleDao.storeSchedule( schedule );
+                    }
+                    catch ( ContinuumStoreException e1 )
+                    {
+                        throw new SchedulesActivationException( "Can't desactivate schedule
'" + schedule.getName()
+                            + "'", e );
+                    }
                 }
             }
         }
@@ -138,16 +123,31 @@
     public void activateSchedule( Schedule schedule, Continuum continuum )
         throws SchedulesActivationException
     {
-        log.info( "Activating schedule " + schedule.getName() );
+        if ( schedule != null )
+        {
+            log.info( "Activating schedule " + schedule.getName() );
 
-        if ( isScheduleFromBuildJob( schedule ) )
+            activateBuildSchedule( schedule, continuum );
+
+            activatePurgeSchedule( schedule, continuum );
+        }
+    }
+
+    public void activateBuildSchedule( Schedule schedule, Continuum continuum )
+        throws SchedulesActivationException
+    {
+        if ( schedule != null && schedule.isActive() && isScheduleFromBuildJob(
schedule ) )
         {
-            schedule( schedule, continuum, ContinuumBuildJob.class );
+            schedule( schedule, continuum, ContinuumBuildJob.class, ContinuumBuildJob.BUILD_GROUP
);
         }
+    }
 
-        if ( isScheduleFromPurgeJob( schedule ) )
+    public void activatePurgeSchedule( Schedule schedule, Continuum continuum )
+        throws SchedulesActivationException
+    {
+        if ( schedule != null && schedule.isActive() && isScheduleFromPurgeJob(
schedule ) )
         {
-            schedule( schedule, continuum, ContinuumPurgeJob.class );
+            schedule( schedule, continuum, ContinuumPurgeJob.class, ContinuumPurgeJob.PURGE_GROUP
);
         }
     }
 
@@ -156,16 +156,50 @@
     {
         log.info( "Deactivating schedule " + schedule.getName() );
 
-        unschedule( schedule );
+        unactivateBuildSchedule( schedule );
+        unactivatePurgeSchedule( schedule );
+    }
+
+    public void unactivateOrphanBuildSchedule( Schedule schedule )
+        throws SchedulesActivationException
+    {
+        if ( schedule != null && !isScheduleFromBuildJob( schedule ) )
+        {
+            unactivateBuildSchedule( schedule );
+        }
     }
 
-    protected void schedule( Schedule schedule, Continuum continuum, Class jobClass )
+    public void unactivateOrphanPurgeSchedule( Schedule schedule )
         throws SchedulesActivationException
     {
-        if ( !schedule.isActive() )
+        if ( schedule != null && !isScheduleFromPurgeJob( schedule ) )
         {
-            log.info( "Schedule \"" + schedule.getName() + "\" is disabled." );
+            unactivatePurgeSchedule( schedule );
+        }
+    }
+
+    private void unactivateBuildSchedule( Schedule schedule )
+        throws SchedulesActivationException
+    {
+        log.debug( "Deactivating schedule " + schedule.getName() + " for Build Process" );
 
+        unschedule( schedule, ContinuumBuildJob.BUILD_GROUP );
+    }
+
+    private void unactivatePurgeSchedule( Schedule schedule )
+        throws SchedulesActivationException
+    {
+        log.debug( "Deactivating schedule " + schedule.getName() + " for Purge Process" );
+
+        unschedule( schedule, ContinuumPurgeJob.PURGE_GROUP );
+    }
+
+    protected void schedule( Schedule schedule, Continuum continuum, Class jobClass, String
group )
+        throws SchedulesActivationException
+    {
+        if ( StringUtils.isEmpty( schedule.getCronExpression() ) )
+        {
+            log.info( "Not scheduling " + schedule.getName() );
             return;
         }
 
@@ -177,9 +211,9 @@
 
         dataMap.put( ContinuumSchedulerConstants.SCHEDULE, schedule );
 
-        //the name + group makes the job unique
+        // the name + group makes the job unique
 
-        JobDetail jobDetail = new JobDetail( schedule.getName(), org.quartz.Scheduler.DEFAULT_GROUP,
jobClass );
+        JobDetail jobDetail = new JobDetail( schedule.getName(), group, jobClass );
 
         jobDetail.setJobDataMap( dataMap );
 
@@ -189,7 +223,7 @@
 
         trigger.setName( schedule.getName() );
 
-        trigger.setGroup( org.quartz.Scheduler.DEFAULT_GROUP );
+        trigger.setGroup( group );
 
         Date startTime = new Date( System.currentTimeMillis() + delay * 1000 );
 
@@ -218,7 +252,7 @@
         }
     }
 
-    private void unschedule( Schedule schedule )
+    private void unschedule( Schedule schedule, String group )
         throws SchedulesActivationException
     {
         try
@@ -227,10 +261,10 @@
             {
                 log.info( "Stopping active schedule \"" + schedule.getName() + "\"." );
 
-                scheduler.interruptSchedule( schedule.getName(), org.quartz.Scheduler.DEFAULT_GROUP
);
+                scheduler.interruptSchedule( schedule.getName(), group );
             }
 
-            scheduler.unscheduleJob( schedule.getName(), org.quartz.Scheduler.DEFAULT_GROUP
);
+            scheduler.unscheduleJob( schedule.getName(), group );
         }
         catch ( SchedulerException e )
         {
@@ -241,7 +275,9 @@
     private boolean isScheduleFromBuildJob( Schedule schedule )
     {
         List<BuildDefinition> buildDef = buildDefinitionDao.getBuildDefinitionsBySchedule(
schedule.getId() );
-
+        // Take account templateBuildDefinition too.
+        // A improvement will be add schedule only for active buildDefinition, but it would
need activate
+        // schedule job in add project and add group process
         return buildDef.size() > 0;
 
     }

Modified: continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumBuildJob.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumBuildJob.java?rev=780708&r1=780707&r2=780708&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumBuildJob.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumBuildJob.java
Mon Jun  1 16:29:31 2009
@@ -34,6 +34,8 @@
 public class ContinuumBuildJob
     extends AbstractJob
 {
+    public static final String BUILD_GROUP = "BUILD_GROUP";
+
     public void execute( JobExecutionContext context )
     {
         if ( isInterrupted() )

Modified: continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumPurgeJob.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumPurgeJob.java?rev=780708&r1=780707&r2=780708&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumPurgeJob.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/scheduler/ContinuumPurgeJob.java
Mon Jun  1 16:29:31 2009
@@ -36,6 +36,8 @@
 public class ContinuumPurgeJob
     extends AbstractJob
 {
+    public static final String PURGE_GROUP = "PURGE_GROUP";
+	
     public void execute( JobExecutionContext context )
     {
         if ( isInterrupted() )



Mime
View raw message