git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1481952 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.4-M4
@@ -848,6 +848,14 @@ | |||
<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> |
@@ -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 ) |
@@ -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 ) ) |
@@ -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 ); | |||
} | |||
} | |||
} |
@@ -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 ) | |||
{ |
@@ -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" ); | |||
@@ -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) |
@@ -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); | |||
} | |||
}); |
@@ -1442,6 +1442,13 @@ | |||
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()}} |
@@ -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() ); |