diff options
author | Maria Odea B. Ching <oching@apache.org> | 2013-05-13 16:23:22 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2013-05-13 16:23:22 +0000 |
commit | 48b1538702ca763f0beb6fca0d11f62a8fc444d2 (patch) | |
tree | e010bd1d19ce2f4f5898c59d0cc338a2a744e805 /archiva-modules/archiva-base | |
parent | a8bacd7de495ae2422abd4bffb14431ceb4cf7a7 (diff) | |
download | archiva-48b1538702ca763f0beb6fca0d11f62a8fc444d2.tar.gz archiva-48b1538702ca763f0beb6fca0d11f62a8fc444d2.zip |
[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
Diffstat (limited to 'archiva-modules/archiva-base')
4 files changed, 125 insertions, 6 deletions
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 @@ -849,6 +849,14 @@ <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> <association> 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<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 ) ) 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 ); + } + } } |