]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1751] add merged index ttl to repo group configuration + unit tests
authorMaria Odea B. Ching <oching@apache.org>
Mon, 13 May 2013 16:23:22 +0000 (16:23 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 13 May 2013 16:23:22 +0000 (16:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1481952 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoryGroupServiceTest.java
archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/repository-groups.js
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java

index 43b3838193fff2dc47b72f23390619f7ddd8d1ad..209e62b58a9c4f0b13548b3f4b664d4c26b2490c 100644 (file)
           <defaultValue>/.indexer</defaultValue>
           <description>The path of the merged index.</description>
         </field>
+        <field>
+          <name>mergedIndexTtl</name>
+          <version>1.4.0+</version>
+          <type>int</type>
+          <required>false</required>
+          <defaultValue>30</defaultValue>
+          <description>The time to live of the merged index of the repository group.</description>
+        </field>
         <field>
           <name>repositories</name>
           <version>1.2.0+</version>
index 371e7d488f8bed11223297d76970699fa3837f01..047724dbeb6f04cb42f62b67ff65b969b83521c3 100644 (file)
@@ -46,6 +46,11 @@ public class RepositoryGroup
      */
     private String mergedIndexPath = "/.indexer";
 
+    /**
+     * The TTL (time to live) of the repo group's merged index.
+     */
+    private int mergedIndexTtl = 30;
+
     public RepositoryGroup()
     {
         // no op
@@ -132,12 +137,29 @@ public class RepositoryGroup
         this.mergedIndexPath = mergedIndexPath;
     }
 
-    public RepositoryGroup mergedIndexPath( String mergedIndexPath )
-    {
+    public int getMergedIndexTtl() {
+        return mergedIndexTtl;
+    }
+
+    /**
+     * Set the TTL of the repo group's merged index.
+     *
+     * @param mergedIndexTtl
+     */
+    public void setMergedIndexTtl(int mergedIndexTtl) {
+        this.mergedIndexTtl = mergedIndexTtl;
+    }
+
+    public RepositoryGroup mergedIndexPath( String mergedIndexPath ) {
         this.mergedIndexPath = mergedIndexPath;
         return this;
     }
 
+    public RepositoryGroup mergedIndexTtl( int mergedIndexTtl ) {
+        this.mergedIndexTtl = mergedIndexTtl;
+        return this;
+    }
+
     public boolean equals( Object other )
     {
         if ( this == other )
index 047b8494b19a583c656048d5584411c7afadc99f..ef43c104233260a629c83e78ff0e833863fcb3e4 100644 (file)
@@ -68,7 +68,7 @@ public class DefaultRepositoryGroupAdmin
         {
             repositoriesGroups.add( new RepositoryGroup( repositoryGroupConfiguration.getId(), new ArrayList<String>(
                 repositoryGroupConfiguration.getRepositories() ) ).mergedIndexPath(
-                repositoryGroupConfiguration.getMergedIndexPath() ) );
+                repositoryGroupConfiguration.getMergedIndexPath() ).mergedIndexTtl( repositoryGroupConfiguration.getMergedIndexTtl() ) );
         }
 
         return repositoriesGroups;
@@ -93,10 +93,12 @@ public class DefaultRepositoryGroupAdmin
     {
         validateRepositoryGroup( repositoryGroup, false );
         validateManagedRepositoriesExists( repositoryGroup.getRepositories() );
+
         RepositoryGroupConfiguration repositoryGroupConfiguration = new RepositoryGroupConfiguration();
         repositoryGroupConfiguration.setId( repositoryGroup.getId() );
         repositoryGroupConfiguration.setRepositories( repositoryGroup.getRepositories() );
         repositoryGroupConfiguration.setMergedIndexPath( repositoryGroup.getMergedIndexPath() );
+        repositoryGroupConfiguration.setMergedIndexTtl( repositoryGroup.getMergedIndexTtl() );
         Configuration configuration = getArchivaConfiguration().getConfiguration();
         configuration.addRepositoryGroup( repositoryGroupConfiguration );
         saveConfiguration( configuration );
@@ -141,6 +143,7 @@ public class DefaultRepositoryGroupAdmin
 
         repositoryGroupConfiguration.setRepositories( repositoryGroup.getRepositories() );
         repositoryGroupConfiguration.setMergedIndexPath( repositoryGroup.getMergedIndexPath() );
+        repositoryGroupConfiguration.setMergedIndexTtl( repositoryGroup.getMergedIndexTtl() );
         configuration.addRepositoryGroup( repositoryGroupConfiguration );
 
         saveConfiguration( configuration );
@@ -282,6 +285,11 @@ public class DefaultRepositoryGroupAdmin
                 "Invalid character(s) found in identifier. Only the following characters are allowed: alphanumeric, '.', '-' and '_'" );
         }
 
+        if ( repositoryGroup.getMergedIndexTtl() <= 0)
+        {
+            throw new RepositoryAdminException( "Merged Index TTL must be greater than 0." );
+        }
+
         Configuration configuration = getArchivaConfiguration().getConfiguration();
 
         if ( configuration.getRepositoryGroupsAsMap().containsKey( repoGroupId ) )
index 84135d4d84f0367be2d923f655aa4fd4276843d0..a79d724d08d3cdea386d45141b0baeb084d70701 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.archiva.admin.repository.group;
  * under the License.
  */
 
+import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.admin.model.beans.RepositoryGroup;
 import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
@@ -67,6 +68,10 @@ public class RepositoryGroupAdminTest
             assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
                           repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
 
+            // verify if default values were saved
+            assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
+            assertEquals("/.indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
+
             repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
 
             assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
@@ -100,7 +105,8 @@ public class RepositoryGroupAdminTest
 
             managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
 
-            RepositoryGroup repositoryGroup = new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one" ) );
+            RepositoryGroup repositoryGroup = new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one" ) )
+                    .mergedIndexTtl( 20 ).mergedIndexPath( "/.nonDefaultPath" );
 
             mockAuditListener.clearEvents();
 
@@ -111,6 +117,8 @@ public class RepositoryGroupAdminTest
             assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
             assertEquals( Arrays.asList( "test-new-one" ),
                           repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
+            assertEquals( 20, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
+            assertEquals( "/.nonDefaultPath", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
 
             repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
             assertNotNull( repositoryGroup );
@@ -143,9 +151,8 @@ public class RepositoryGroupAdminTest
         }
     }
 
-
     @Test
-    public void addAndDeleteGroupWithRemowingManagedRepo()
+    public void addAndDeleteGroupWithRemovedManagedRepo()
         throws Exception
     {
         try
@@ -199,4 +206,78 @@ public class RepositoryGroupAdminTest
             managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
         }
     }
+
+    @Test( expected = RepositoryAdminException.class )
+    public void testAddGroupWithInvalidMergedIndexTtl() throws Exception {
+        try {
+            ManagedRepository managedRepositoryOne =
+                    getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
+
+            ManagedRepository managedRepositoryTwo =
+                    getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
+
+            managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
+
+            managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
+
+            RepositoryGroup repositoryGroup =
+                    new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) )
+                    .mergedIndexTtl( -1 );
+
+            mockAuditListener.clearEvents();
+
+            repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
+        }
+        finally
+        {
+            mockAuditListener.clearEvents();
+            managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
+            managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
+        }
+    }
+
+    @Test( expected = RepositoryAdminException.class )
+    public void testAddAndUpdateGroupWithInvalidMergedIndexTtl() throws Exception {
+        try {
+            ManagedRepository managedRepositoryOne =
+                    getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
+
+            ManagedRepository managedRepositoryTwo =
+                    getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
+
+            managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
+
+            managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
+
+            RepositoryGroup repositoryGroup =
+                    new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
+
+            mockAuditListener.clearEvents();
+
+            repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
+
+            assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
+            assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
+            assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
+            assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
+                    repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
+
+            // verify if default values were saved
+            assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
+            assertEquals("/.indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
+
+            repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
+            assertNotNull( repositoryGroup );
+
+            repositoryGroup.mergedIndexTtl( -1 );
+
+            repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
+        }
+        finally
+        {
+            mockAuditListener.clearEvents();
+            managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
+            managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
+        }
+    }
 }
index 4b1882bb49c032f3da355bc597f970b66c884c57..1b57591014d6d7bec9ba8e2f7514fa53a8376f34 100644 (file)
@@ -52,7 +52,8 @@ public class DefaultRepositoryGroupService
             for ( org.apache.archiva.admin.model.beans.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() )
             {
                 repositoriesGroups.add( new RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
-                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ) );
+                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() )
+                        .mergedIndexTtl( repoGroup.getMergedIndexTtl() ) );
             }
             return repositoriesGroups;
         }
@@ -82,8 +83,8 @@ public class DefaultRepositoryGroupService
         {
             return repositoryGroupAdmin.addRepositoryGroup(
                 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
-                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ),
-                getAuditInformation() );
+                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() )
+                    .mergedIndexTtl( repoGroup.getMergedIndexTtl() ), getAuditInformation() );
         }
         catch ( RepositoryAdminException e )
         {
@@ -98,8 +99,8 @@ public class DefaultRepositoryGroupService
         {
             return repositoryGroupAdmin.updateRepositoryGroup(
                 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
-                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ),
-                getAuditInformation() );
+                    repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() )
+                    .mergedIndexTtl( repoGroup.getMergedIndexTtl() ), getAuditInformation() );
         }
         catch ( RepositoryAdminException e )
         {
index c872d82682ee760bd5e9a7eaf0e1003ce0400208..0175058596e5641015991d118ba210151e8383ca 100644 (file)
@@ -51,11 +51,13 @@ public class RepositoryGroupServiceTest
 
         managedRepositoriesService.addManagedRepository( managedRepository );
 
-        RepositoryGroup repositoryGroup = new RepositoryGroup( "one", Arrays.asList( managedRepository.getId() ) );
+        RepositoryGroup repositoryGroup = new RepositoryGroup( "one", Arrays.asList( managedRepository.getId() ) )
+                .mergedIndexTtl( 40 );
 
         service.addRepositoryGroup( repositoryGroup );
         assertFalse( service.getRepositoriesGroups().isEmpty() );
         assertEquals( 1, service.getRepositoriesGroups().size() );
+        assertEquals( 40, service.getRepositoriesGroups().get(0).getMergedIndexTtl() );
 
         service.deleteRepositoryGroup( "one" );
 
index c528c028b8c55c0737c1576d1f5b86c2bac60159..c2f9f35b7911e4c1cc5c84fc00f5d8a617e89a79 100644 (file)
@@ -312,6 +312,7 @@ repository.groups.list=Repository Groups
 repository-groups.grid.tab.title=Repository Groups
 repository.group.delete.confirm=Are you sure to delete Repository Group {0} ?
 repository.group.mergedIndexPath=Merged Index Path
+repository.group.mergedIndexTtl=Merged Index Time to Live (in Minutes)
 
 #roles
 roles.bulk.save.confirm=Are you sure to update {0} Role(s)
index ce567c88272a4b3fa75fbfe7be4859ab40e41d92..337c7e51a67b7a3a878c99d93f61892adacfefc6 100644 (file)
@@ -20,7 +20,7 @@ define("archiva.repository-groups",["jquery","i18n","jquery.tmpl","bootstrap","j
   ,"knockout.simpleGrid","knockout.sortable"],
 function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,jqueryUi,ko) {
 
-  RepositoryGroup=function(id,repositories,mergedIndexPath){
+  RepositoryGroup=function(id,repositories,mergedIndexPath,mergedIndexTtl){
 
     var self=this;
 
@@ -32,6 +32,10 @@ function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,jqueryUi,ko) {
     this.mergedIndexPath=ko.observable(mergedIndexPath?mergedIndexPath:".indexer");
     this.mergedIndexPath.subscribe(function(newValue){self.modified(true)});
 
+    // private int mergedIndexTtl = 30;
+    this.mergedIndexTtl=ko.observable(mergedIndexTtl?mergedIndexTtl:30);
+    this.mergedIndexTtl.subscribe(function(newValue){self.modified(true)});
+
     // private List<String> repositories;
     this.repositories=ko.observableArray(repositories);
     this.repositories.subscribe(function(newValue){self.modified(true)});
@@ -414,7 +418,7 @@ function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,jqueryUi,ko) {
   }
 
   mapRepositoryGroup=function(data){
-    return new RepositoryGroup(data.id, mapStringArray(data.repositories),data.mergedIndexPath);
+    return new RepositoryGroup(data.id, mapStringArray(data.repositories),data.mergedIndexPath,data.mergedIndexTtl);
   }
 
 });
index 9435f207b9c517456cda1b073442cbb7a059e926..1f73a0dca3af276dbe5c065814b4855c4d858f3a 100644 (file)
                        data-bind="value: repositoryGroup.mergedIndexPath"/>
               </div>
           </div>
+          <div class="control-group">
+            <label class="control-label" for="mergedIndexPath">${$.i18n.prop('repository.group.mergedIndexTtl')}</label>
+            <div class="controls">
+                <input type="text" class="input-large required" id="mergedIndexTtl" name="mergedIndexTtl"
+                       data-bind="value: repositoryGroup.mergedIndexTtl"/>
+            </div>
+          </div>
           <div>
             <a href="${window.archivaRuntimeInfo.baseUrl}/repository/${repositoryGroup.id()}" target="_blank">
             {{if repositoryGroup.id()}}
index 954e8039cbe07422d7fd40fbc6eef5d5f6ed10fc..67f0c1786dee71d9ac43dfb963ae5ae065a795de 100644 (file)
@@ -1202,8 +1202,7 @@ public class ArchivaDavResourceFactory
 
             if ( tmp != null && tmp.getDirectory() != null && tmp.getDirectory().exists() )
             {
-                if ( System.currentTimeMillis() - tmp.getCreationTime() > ( indexMerger.getGroupMergedIndexTtl() * 60
-                    * 1000 ) )
+                if ( System.currentTimeMillis() - tmp.getCreationTime() > ( repositoryGroupConfiguration.getMergedIndexTtl() * 60 * 1000 ) )
                 {
                     log.debug( MarkerFactory.getMarker( "group.merged.index" ),
                                "tmp group index '{}' is too old so delete it", repositoryGroupConfiguration.getId() );