From 48b1538702ca763f0beb6fca0d11f62a8fc444d2 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Mon, 13 May 2013 16:23:22 +0000 Subject: [MRM-1751] add merged index ttl to repo group configuration + unit tests git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1481952 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/mdo/configuration.mdo | 8 ++ .../archiva/admin/model/beans/RepositoryGroup.java | 26 ++++++- .../group/DefaultRepositoryGroupAdmin.java | 10 ++- .../repository/group/RepositoryGroupAdminTest.java | 87 +++++++++++++++++++++- .../services/DefaultRepositoryGroupService.java | 11 +-- .../rest/services/RepositoryGroupServiceTest.java | 4 +- .../org/apache/archiva/i18n/default.properties | 1 + .../main/webapp/js/archiva/repository-groups.js | 8 +- .../webapp/js/templates/archiva/repositories.html | 7 ++ .../archiva/webdav/ArchivaDavResourceFactory.java | 3 +- 10 files changed, 149 insertions(+), 16 deletions(-) (limited to 'archiva-modules') diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index 43b383819..209e62b58 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -848,6 +848,14 @@ /.indexer The path of the merged index. + + mergedIndexTtl + 1.4.0+ + int + false + 30 + The time to live of the merged index of the repository group. + repositories 1.2.0+ diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java index 371e7d488..047724dbe 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java @@ -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 ) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java index 047b8494b..ef43c1042 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java @@ -68,7 +68,7 @@ public class DefaultRepositoryGroupAdmin { repositoriesGroups.add( new RepositoryGroup( repositoryGroupConfiguration.getId(), new ArrayList( 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 ) ) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java index 84135d4d8..a79d724d0 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java @@ -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 ); + } + } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java index 4b1882bb4..1b5759101 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java @@ -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( - 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( - 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( - repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ), - getAuditInformation() ); + repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ) + .mergedIndexTtl( repoGroup.getMergedIndexTtl() ), getAuditInformation() ); } catch ( RepositoryAdminException e ) { diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoryGroupServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoryGroupServiceTest.java index c872d8268..017505859 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoryGroupServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoryGroupServiceTest.java @@ -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" ); diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties index c528c028b..c2f9f35b7 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties @@ -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) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/repository-groups.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/repository-groups.js index ce567c882..337c7e51a 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/repository-groups.js +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/repository-groups.js @@ -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 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); } }); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html index 9435f207b..1f73a0dca 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html @@ -1442,6 +1442,13 @@ data-bind="value: repositoryGroup.mergedIndexPath"/> +
+ +
+ +
+
{{if repositoryGroup.id()}} diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index 954e8039c..67f0c1786 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -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() ); -- cgit v1.2.3