You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ba...@apache.org on 2015/04/11 14:39:38 UTC
svn commit: r1672871 - in /continuum/trunk:
continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/
continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/
cont...
Author: batkinson
Date: Sat Apr 11 12:39:38 2015
New Revision: 1672871
URL: http://svn.apache.org/r1672871
Log:
Integrated agent and master directory purge code using builder.
Added:
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/CleanAllPurgeExecutor.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutor.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/PurgeBuilder.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/RemoveDirHandler.java
- copied, changed from r1672870, continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java
Removed:
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/CleanAllPurgeExecutor.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DaysOldDirectoryPurgeExecutor.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/RetentionCountDirectoryPurgeExecutor.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/agent/DirectoryPurgeExecutorFactoryImpl.java
Modified:
continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentPurgeManager.java
continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java
continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/repo/RepositoryPurgeExecutorFactoryImpl.java
Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentPurgeManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentPurgeManager.java?rev=1672871&r1=1672870&r2=1672871&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentPurgeManager.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentPurgeManager.java Sat Apr 11 12:39:38 2015
@@ -46,7 +46,7 @@ public class DefaultBuildAgentPurgeManag
@Requirement
private BuildAgentConfigurationService buildAgentConfigurationService;
- @Requirement( hint = "distributed" )
+ @Requirement
private DirectoryPurgeExecutorFactory dirExecutorFactory;
@Requirement
Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java?rev=1672871&r1=1672870&r2=1672871&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java Sat Apr 11 12:39:38 2015
@@ -20,7 +20,6 @@ package org.apache.continuum.buildagent.
*/
import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
-import org.apache.continuum.purge.executor.dir.agent.DirectoryPurgeExecutorFactoryImpl;
import org.apache.continuum.utils.file.FileSystemManager;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
@@ -29,6 +28,8 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import static org.apache.continuum.purge.ContinuumPurgeConstants.PURGE_DIRECTORY_RELEASES;
+import static org.apache.continuum.purge.ContinuumPurgeConstants.PURGE_DIRECTORY_WORKING;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -97,7 +98,7 @@ public class BuildAgentPurgeManagerTest
throws Exception
{
int ignored = 1;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.WORKING_TYPE, ignored, ignored, true );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_WORKING, ignored, ignored, true );
assertEquals( RELEASE_DIRS + REGULAR_FILES, fileCount() );
}
@@ -106,7 +107,7 @@ public class BuildAgentPurgeManagerTest
throws Exception
{
int ignored = 1;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.RELEASE_TYPE, ignored, ignored, true );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_RELEASES, ignored, ignored, true );
assertEquals( WORKING_DIRS + REGULAR_FILES, fileCount() );
}
@@ -115,8 +116,8 @@ public class BuildAgentPurgeManagerTest
throws Exception
{
int ignored = 1;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.WORKING_TYPE, ignored, ignored, true );
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.RELEASE_TYPE, ignored, ignored, true );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_WORKING, ignored, ignored, true );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_RELEASES, ignored, ignored, true );
assertEquals( REGULAR_FILES, fileCount() );
}
@@ -124,8 +125,7 @@ public class BuildAgentPurgeManagerTest
throws Exception
{
int retainedWorking = 2;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.WORKING_TYPE, NONE, retainedWorking,
- false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_WORKING, NONE, retainedWorking, false );
assertEquals( RELEASE_DIRS + REGULAR_FILES + retainedWorking, fileCount() );
}
@@ -133,8 +133,7 @@ public class BuildAgentPurgeManagerTest
throws Exception
{
int retainedReleases = 4;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.RELEASE_TYPE, NONE, retainedReleases,
- false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_RELEASES, NONE, retainedReleases, false );
assertEquals( WORKING_DIRS + retainedReleases + REGULAR_FILES, fileCount() );
}
@@ -142,10 +141,8 @@ public class BuildAgentPurgeManagerTest
throws Exception
{
int retainedReleases = 4, retainedWorking = 2;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.WORKING_TYPE, NONE, retainedWorking,
- false );
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.RELEASE_TYPE, NONE, retainedReleases,
- false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_WORKING, NONE, retainedWorking, false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_RELEASES, NONE, retainedReleases, false );
assertEquals( retainedWorking + retainedReleases + REGULAR_FILES, fileCount() );
}
@@ -153,7 +150,7 @@ public class BuildAgentPurgeManagerTest
throws Exception
{
int maxAge = 1, ineligibleWorkDirs = WORKING_DIRS - OLD_WORKING_DIRS;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.WORKING_TYPE, maxAge, NONE, false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_WORKING, maxAge, NONE, false );
assertEquals( RELEASE_DIRS + ineligibleWorkDirs + REGULAR_FILES, fileCount() );
}
@@ -161,7 +158,7 @@ public class BuildAgentPurgeManagerTest
throws Exception
{
int maxAge = 1, ineligibleReleaseDirs = RELEASE_DIRS - OLD_RELEASE_DIRS;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.RELEASE_TYPE, maxAge, NONE, false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_RELEASES, maxAge, NONE, false );
assertEquals( WORKING_DIRS + ineligibleReleaseDirs + REGULAR_FILES, fileCount() );
}
@@ -171,8 +168,8 @@ public class BuildAgentPurgeManagerTest
int maxAge = 1;
int ineligibleWorkDirs = WORKING_DIRS - OLD_WORKING_DIRS;
int ineligibleReleaseDirs = RELEASE_DIRS - OLD_RELEASE_DIRS;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.WORKING_TYPE, maxAge, NONE, false );
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.RELEASE_TYPE, maxAge, NONE, false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_WORKING, maxAge, NONE, false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_RELEASES, maxAge, NONE, false );
assertEquals( ineligibleWorkDirs + ineligibleReleaseDirs + REGULAR_FILES, fileCount() );
}
@@ -183,8 +180,7 @@ public class BuildAgentPurgeManagerTest
int retainWorking = 5;
int ineligibleWorkDirs = WORKING_DIRS - OLD_WORKING_DIRS;
int expectedWorkDirs = retainWorking + ineligibleWorkDirs;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.WORKING_TYPE, maxAge, retainWorking,
- false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_WORKING, maxAge, retainWorking, false );
assertEquals( RELEASE_DIRS + expectedWorkDirs + REGULAR_FILES, fileCount() );
}
@@ -195,8 +191,7 @@ public class BuildAgentPurgeManagerTest
int retainRelease = 1;
int ineligibleReleaseDirs = RELEASE_DIRS - OLD_RELEASE_DIRS;
int expectedReleaseDirs = retainRelease + ineligibleReleaseDirs;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.RELEASE_TYPE, maxAge, retainRelease,
- false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_RELEASES, maxAge, retainRelease, false );
assertEquals( WORKING_DIRS + expectedReleaseDirs + REGULAR_FILES, fileCount() );
}
@@ -209,10 +204,8 @@ public class BuildAgentPurgeManagerTest
int ineligibleReleaseDirs = RELEASE_DIRS - OLD_RELEASE_DIRS;
int expectedWorkDirs = retainWorking + ineligibleWorkDirs;
int expectedReleaseDirs = retainRelease + ineligibleReleaseDirs;
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.WORKING_TYPE, maxAge, retainWorking,
- false );
- purgeManager.executeDirectoryPurge( DirectoryPurgeExecutorFactoryImpl.RELEASE_TYPE, maxAge, retainRelease,
- false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_WORKING, maxAge, retainWorking, false );
+ purgeManager.executeDirectoryPurge( PURGE_DIRECTORY_RELEASES, maxAge, retainRelease, false );
assertEquals( expectedReleaseDirs + expectedWorkDirs + REGULAR_FILES, fileCount() );
}
Modified: continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java?rev=1672871&r1=1672870&r2=1672871&view=diff
==============================================================================
--- continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java (original)
+++ continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java Sat Apr 11 12:39:38 2015
@@ -29,8 +29,12 @@ public class ContinuumPurgeConstants
public static final String PURGE_DIRECTORY_RELEASES = "releases";
+ public static final String PURGE_DIRECTORY_WORKING = "working";
+
public static final String PURGE_DIRECTORY_BUILDOUTPUT = "buildOutput";
+ public static final String RELEASE_DIR_PATTERN = "releases-*";
+
public static final String PURGE = "PURGE";
public static final String PURGE_REPO_CONTENTS = "Purge All Repository Contents";
Added: continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/CleanAllPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/CleanAllPurgeExecutor.java?rev=1672871&view=auto
==============================================================================
--- continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/CleanAllPurgeExecutor.java (added)
+++ continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/CleanAllPurgeExecutor.java Sat Apr 11 12:39:38 2015
@@ -0,0 +1,101 @@
+package org.apache.continuum.purge.executor.dir;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.continuum.purge.ContinuumPurgeConstants;
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutor;
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutorException;
+import org.apache.continuum.utils.file.FileSystemManager;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author Maria Catherine Tan
+ */
+public class CleanAllPurgeExecutor
+ implements ContinuumPurgeExecutor
+{
+ private FileSystemManager fsManager;
+
+ private final String purgeType;
+
+ public CleanAllPurgeExecutor( FileSystemManager fsManager, String purgeType )
+ {
+ this.fsManager = fsManager;
+ this.purgeType = purgeType;
+ }
+
+ public void purge( String path )
+ throws ContinuumPurgeExecutorException
+ {
+ File dir = new File( path );
+ try
+ {
+ if ( ContinuumPurgeConstants.PURGE_DIRECTORY_RELEASES.equals( purgeType ) )
+ {
+ PurgeBuilder.purge( dir )
+ .dirs()
+ .namedLike( ContinuumPurgeConstants.RELEASE_DIR_PATTERN )
+ .executeWith( new RemoveDirHandler( fsManager ) );
+ }
+ else if ( ContinuumPurgeConstants.PURGE_DIRECTORY_BUILDOUTPUT.equals( purgeType ) )
+ {
+ PurgeBuilder.purge( dir )
+ .dirs()
+ .executeWith( new WipeDirHandler( fsManager ) );
+ }
+ else if ( ContinuumPurgeConstants.PURGE_DIRECTORY_WORKING.equals( purgeType ) )
+ {
+ PurgeBuilder.purge( dir )
+ .dirs()
+ .notNamedLike( ContinuumPurgeConstants.RELEASE_DIR_PATTERN )
+ .executeWith( new RemoveDirHandler( fsManager ) );
+ }
+ }
+ catch ( PurgeBuilderException e )
+ {
+ throw new ContinuumPurgeExecutorException( "purge failed: " + e.getMessage() );
+ }
+ }
+}
+
+class WipeDirHandler
+ implements Handler
+{
+ FileSystemManager fsManager;
+
+ WipeDirHandler( FileSystemManager fsManager )
+ {
+ this.fsManager = fsManager;
+ }
+
+ public void handle( File dir )
+ {
+ try
+ {
+ fsManager.wipeDir( dir );
+ }
+ catch ( IOException e )
+ {
+ //swallow?
+ }
+ }
+}
\ No newline at end of file
Added: continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutor.java?rev=1672871&view=auto
==============================================================================
--- continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutor.java (added)
+++ continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutor.java Sat Apr 11 12:39:38 2015
@@ -0,0 +1,133 @@
+package org.apache.continuum.purge.executor.dir;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutor;
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutorException;
+import org.apache.continuum.utils.file.FileSystemManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.apache.continuum.purge.ContinuumPurgeConstants.*;
+
+/**
+ * @author Maria Catherine Tan
+ */
+public class DirectoryPurgeExecutor
+ implements ContinuumPurgeExecutor
+{
+ private Logger log = LoggerFactory.getLogger( DirectoryPurgeExecutor.class );
+
+ private final FileSystemManager fsManager;
+
+ private final int daysOlder;
+
+ private final int retentionCount;
+
+ private final String directoryType;
+
+ public DirectoryPurgeExecutor( FileSystemManager fsManager, int daysOlder, int retentionCount,
+ String directoryType )
+ {
+ this.fsManager = fsManager;
+ this.daysOlder = daysOlder;
+ this.retentionCount = retentionCount;
+ this.directoryType = directoryType;
+ }
+
+ public void purge( String path )
+ throws ContinuumPurgeExecutorException
+ {
+ try
+ {
+ File dir = new File( path );
+ if ( PURGE_DIRECTORY_RELEASES.equals( directoryType ) )
+ {
+ PurgeBuilder.purge( dir )
+ .dirs()
+ .namedLike( RELEASE_DIR_PATTERN )
+ .olderThan( daysOlder )
+ .inAgeOrder()
+ .retainLast( retentionCount )
+ .executeWith( new RemoveDirHandler( fsManager ) );
+ }
+ else if ( PURGE_DIRECTORY_WORKING.equals( directoryType ) )
+ {
+ PurgeBuilder.purge( dir )
+ .dirs()
+ .notNamedLike( RELEASE_DIR_PATTERN )
+ .olderThan( daysOlder )
+ .inAgeOrder()
+ .retainLast( retentionCount )
+ .executeWith( new RemoveDirHandler( fsManager ) );
+ }
+ else if ( PURGE_DIRECTORY_BUILDOUTPUT.equals( directoryType ) )
+ {
+ for ( File projectDir : dir.listFiles() )
+ {
+ if ( projectDir.isDirectory() )
+ {
+ PurgeBuilder.purge( projectDir )
+ .dirs()
+ .olderThan( daysOlder )
+ .inAgeOrder()
+ .retainLast( retentionCount )
+ .executeWith( new BuildOutputHandler( fsManager ) );
+ }
+ }
+ }
+ }
+ catch ( PurgeBuilderException pbe )
+ {
+ throw new ContinuumPurgeExecutorException( "purge failed: " + pbe.getMessage() );
+ }
+ }
+}
+
+class BuildOutputHandler
+ implements Handler
+{
+ FileSystemManager fsManager;
+
+ BuildOutputHandler( FileSystemManager fsManager )
+ {
+ this.fsManager = fsManager;
+ }
+
+ public void handle( File dir )
+ {
+ try
+ {
+ fsManager.removeDir( dir );
+ File logFile = new File( dir.getAbsoluteFile() + ".log.txt" );
+ if ( logFile.exists() )
+ {
+ logFile.delete();
+ }
+ }
+ catch ( IOException e )
+ {
+ //swallow?
+ }
+ }
+}
\ No newline at end of file
Modified: continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java?rev=1672871&r1=1672870&r2=1672871&view=diff
==============================================================================
--- continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java (original)
+++ continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java Sat Apr 11 12:39:38 2015
@@ -19,7 +19,6 @@ package org.apache.continuum.purge.execu
* under the License.
*/
-import org.apache.continuum.purge.executor.CleanAllPurgeExecutor;
import org.apache.continuum.purge.executor.ContinuumPurgeExecutor;
import org.apache.continuum.utils.file.FileSystemManager;
import org.codehaus.plexus.component.annotations.Component;
@@ -38,12 +37,6 @@ public class DirectoryPurgeExecutorFacto
{
return new CleanAllPurgeExecutor( fsManager, dirType );
}
-
- if ( daysOld > 0 )
- {
- return new DaysOldDirectoryPurgeExecutor( fsManager, daysOld, retentionCount, dirType );
- }
-
- return new RetentionCountDirectoryPurgeExecutor( fsManager, retentionCount, dirType );
+ return new DirectoryPurgeExecutor( fsManager, daysOld, retentionCount, dirType );
}
}
Added: continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/PurgeBuilder.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/PurgeBuilder.java?rev=1672871&view=auto
==============================================================================
--- continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/PurgeBuilder.java (added)
+++ continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/PurgeBuilder.java Sat Apr 11 12:39:38 2015
@@ -0,0 +1,266 @@
+package org.apache.continuum.purge.executor.dir;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.io.DirectoryWalker;
+import org.apache.commons.io.filefilter.AgeFileFilter;
+import org.apache.commons.io.filefilter.AndFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import static java.util.Collections.EMPTY_LIST;
+import static org.apache.commons.io.comparator.LastModifiedFileComparator.LASTMODIFIED_COMPARATOR;
+import static org.apache.commons.io.filefilter.DirectoryFileFilter.DIRECTORY;
+import static org.apache.commons.io.filefilter.FileFileFilter.FILE;
+import static org.apache.commons.io.filefilter.TrueFileFilter.TRUE;
+
+public class PurgeBuilder
+{
+ public static Purge purge( File dir )
+ {
+ return new PurgeDelegate( dir );
+ }
+}
+
+interface Purge
+{
+ Purge dirs();
+
+ Purge files();
+
+ Purge namedLike( String pattern );
+
+ Purge notNamedLike( String pattern );
+
+ Purge olderThan( int ageInDays );
+
+ Purge inAgeOrder();
+
+ Purge retainLast( int min );
+
+ void executeWith( Handler handler )
+ throws PurgeBuilderException;
+
+ List<File> list()
+ throws PurgeBuilderException;
+}
+
+interface Handler
+{
+ void handle( File f );
+}
+
+class PurgeBuilderException
+ extends Exception
+{
+ public PurgeBuilderException( String message )
+ {
+ super( message );
+ }
+}
+
+class PurgeDelegate
+ implements Purge
+{
+ private static long MILLIS_IN_DAY = 24 * 60 * 26 * 1000;
+
+ private File root;
+
+ boolean recursive;
+
+ private int maxScanDepth = -1;
+
+ private AndFileFilter filter;
+
+ private Comparator<File> ordering;
+
+ private int retainMin;
+
+ public PurgeDelegate( File root )
+ {
+ this.root = root;
+ filter = new AndFileFilter();
+ filter.addFileFilter( TRUE );
+ retainMin = 0;
+ }
+
+ public Purge dirs()
+ {
+ filter.addFileFilter( DIRECTORY );
+ return this;
+ }
+
+ public Purge files()
+ {
+ filter.addFileFilter( FILE );
+ return this;
+ }
+
+ public Purge namedLike( String pattern )
+ {
+ filter.addFileFilter( new WildcardFileFilter( pattern ) );
+ return this;
+ }
+
+ public Purge notNamedLike( String pattern )
+ {
+ filter.addFileFilter( new NotFileFilter( new WildcardFileFilter( pattern ) ) );
+ return this;
+ }
+
+ public Purge olderThan( int age )
+ {
+ if ( age > 0 )
+ {
+ filter.addFileFilter( new AgeFileFilter( System.currentTimeMillis() - age * MILLIS_IN_DAY ) );
+ }
+ return this;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public Purge inAgeOrder()
+ {
+ ordering = LASTMODIFIED_COMPARATOR;
+ return this;
+ }
+
+ public Purge retainLast( int min )
+ {
+ if ( min > 0 )
+ {
+ retainMin = min;
+ }
+ return this;
+ }
+
+ public void executeWith( Handler handler )
+ throws PurgeBuilderException
+ {
+ for ( File file : list() )
+ {
+ handler.handle( file );
+ }
+ }
+
+ public List<File> list()
+ throws PurgeBuilderException
+ {
+ List<File> files = listRoot();
+ if ( retainMin > 0 )
+ {
+ sort( files );
+ int limit = files.size() - retainMin;
+ return limit < 0 ? EMPTY_LIST : files.subList( 0, limit );
+ }
+ return files;
+ }
+
+ private void sort( List<File> files )
+ {
+ if ( ordering != null )
+ {
+ Collections.sort( files, ordering );
+ }
+ }
+
+ private List<File> listRoot()
+ throws PurgeBuilderException
+ {
+ if ( !root.exists() )
+ {
+ throw new PurgeBuilderException( String.format( "purge root %s does not exist", root ) );
+ }
+ if ( !root.isDirectory() )
+ {
+ throw new PurgeBuilderException( String.format( "purge root %s is not a directory", root ) );
+ }
+ if ( !root.canRead() )
+ {
+ throw new PurgeBuilderException( String.format( "purge root %s is not readable", root ) );
+ }
+
+ if ( !recursive )
+ {
+ maxScanDepth = 1;
+ }
+
+ try
+ {
+ return new PurgeScanner( root, filter, maxScanDepth ).scan();
+ }
+ catch ( IOException e )
+ {
+ throw new PurgeBuilderException( "failure during scan: " + e.getMessage() );
+ }
+ }
+}
+
+class PurgeScanner
+ extends DirectoryWalker
+{
+ private File root;
+
+ private FileFilter filter;
+
+ PurgeScanner( File root, FileFilter filter, int depth )
+ {
+ super( null, depth );
+ this.root = root;
+ this.filter = filter;
+ }
+
+ public List<File> scan()
+ throws IOException
+ {
+ List<File> scanned = new ArrayList<File>();
+ walk( root, scanned );
+ return scanned;
+ }
+
+ @Override
+ protected void handleFile( File file, int depth, Collection results )
+ throws IOException
+ {
+ if ( filter.accept( file ) )
+ {
+ results.add( file );
+ }
+ }
+
+ @Override
+ protected boolean handleDirectory( File directory, int depth, Collection results )
+ throws IOException
+ {
+ if ( !root.equals( directory ) && filter.accept( directory ) )
+ {
+ results.add( directory );
+ }
+ return true;
+ }
+}
\ No newline at end of file
Copied: continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/RemoveDirHandler.java (from r1672870, continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java)
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/RemoveDirHandler.java?p2=continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/RemoveDirHandler.java&p1=continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java&r1=1672870&r2=1672871&rev=1672871&view=diff
==============================================================================
--- continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/DirectoryPurgeExecutorFactoryImpl.java (original)
+++ continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/dir/RemoveDirHandler.java Sat Apr 11 12:39:38 2015
@@ -19,31 +19,30 @@ package org.apache.continuum.purge.execu
* under the License.
*/
-import org.apache.continuum.purge.executor.CleanAllPurgeExecutor;
-import org.apache.continuum.purge.executor.ContinuumPurgeExecutor;
import org.apache.continuum.utils.file.FileSystemManager;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-@Component( role = DirectoryPurgeExecutorFactory.class )
-public class DirectoryPurgeExecutorFactoryImpl
- implements DirectoryPurgeExecutorFactory
+import java.io.File;
+import java.io.IOException;
+
+class RemoveDirHandler
+ implements Handler
{
- @Requirement
- private FileSystemManager fsManager;
+ FileSystemManager fsManager;
+
+ RemoveDirHandler( FileSystemManager fsManager )
+ {
+ this.fsManager = fsManager;
+ }
- public ContinuumPurgeExecutor create( boolean deleteAll, int daysOld, int retentionCount, String dirType )
+ public void handle( File dir )
{
- if ( deleteAll )
+ try
{
- return new CleanAllPurgeExecutor( fsManager, dirType );
+ fsManager.removeDir( dir );
}
-
- if ( daysOld > 0 )
+ catch ( IOException e )
{
- return new DaysOldDirectoryPurgeExecutor( fsManager, daysOld, retentionCount, dirType );
+ //swallow?
}
-
- return new RetentionCountDirectoryPurgeExecutor( fsManager, retentionCount, dirType );
}
}
Modified: continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/repo/RepositoryPurgeExecutorFactoryImpl.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/repo/RepositoryPurgeExecutorFactoryImpl.java?rev=1672871&r1=1672870&r2=1672871&view=diff
==============================================================================
--- continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/repo/RepositoryPurgeExecutorFactoryImpl.java (original)
+++ continuum/trunk/continuum-purge/src/main/java/org/apache/continuum/purge/executor/repo/RepositoryPurgeExecutorFactoryImpl.java Sat Apr 11 12:39:38 2015
@@ -19,9 +19,8 @@ package org.apache.continuum.purge.execu
* under the License.
*/
-import org.apache.continuum.purge.ContinuumPurgeConstants;
-import org.apache.continuum.purge.executor.CleanAllPurgeExecutor;
import org.apache.continuum.purge.executor.ContinuumPurgeExecutor;
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutorException;
import org.apache.continuum.purge.executor.MultiplexedPurgeExecutor;
import org.apache.continuum.purge.repository.content.RepositoryManagedContent;
import org.apache.continuum.purge.repository.scanner.RepositoryScanner;
@@ -29,6 +28,9 @@ import org.apache.continuum.utils.file.F
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
+import java.io.File;
+import java.io.IOException;
+
@Component( role = RepositoryPurgeExecutorFactory.class )
public class RepositoryPurgeExecutorFactoryImpl
implements RepositoryPurgeExecutorFactory
@@ -44,7 +46,7 @@ public class RepositoryPurgeExecutorFact
{
if ( deleteAll )
{
- return new CleanAllPurgeExecutor( fsManager, ContinuumPurgeConstants.PURGE_REPOSITORY );
+ return new CleanAllPurgeExecutor( fsManager );
}
ContinuumPurgeExecutor executor;
@@ -66,3 +68,28 @@ public class RepositoryPurgeExecutorFact
return new ScanningPurgeExecutor( scanner, executor );
}
}
+
+class CleanAllPurgeExecutor
+ implements ContinuumPurgeExecutor
+{
+
+ FileSystemManager fsManager;
+
+ CleanAllPurgeExecutor( FileSystemManager fsManager )
+ {
+ this.fsManager = fsManager;
+ }
+
+ public void purge( String path )
+ throws ContinuumPurgeExecutorException
+ {
+ try
+ {
+ fsManager.wipeDir( new File( path ) );
+ }
+ catch ( IOException e )
+ {
+ throw new ContinuumPurgeExecutorException( "failed to remove repo" + path, e );
+ }
+ }
+}
\ No newline at end of file