aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2013-12-16 06:53:27 +0000
committerOlivier Lamy <olamy@apache.org>2013-12-16 06:53:27 +0000
commit28898793f51c03b1259d3a1b1f1612f450cf634c (patch)
treeea881bdcdd181731e1056654106ecd6f477714c9 /archiva-modules/archiva-base
parentc2d4f8bce1588f39ed80078c89939b3df746f9be (diff)
downloadarchiva-28898793f51c03b1259d3a1b1f1612f450cf634c.tar.gz
archiva-28898793f51c03b1259d3a1b1f1612f450cf634c.zip
start refactoring merging remote indexes to have a cron job doing it
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1551122 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo10
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java4
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java33
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java30
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java3
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java26
6 files changed, 94 insertions, 12 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 c64f8f8e6..df3f41f89 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
@@ -857,6 +857,16 @@
<description>The time to live of the merged index of the repository group.</description>
</field>
<field>
+ <name>mergedIndexCronExpression</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <description>
+ When to run the index merging for this group.
+ No default value.
+ </description>
+ <defaultValue></defaultValue>
+ </field>
+ <field>
<name>repositories</name>
<version>1.2.0+</version>
<association>
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java
index beccab06e..4a939cb49 100644
--- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java
@@ -80,8 +80,8 @@ public class DefaultIndexMerger
StopWatch stopWatch = new StopWatch();
stopWatch.reset();
stopWatch.start();
- File tempRepoFile = Files.createTempDir();
- tempRepoFile.deleteOnExit();
+
+ File tempRepoFile = indexMergerRequest.getMergedIndexDirectory();
String tempRepoId = tempRepoFile.getName();
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java
index a7a3b656f..e99e3d562 100644
--- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java
@@ -18,6 +18,7 @@ package org.apache.archiva.indexer.merger;
* under the License.
*/
+import java.io.File;
import java.util.Collection;
/**
@@ -44,6 +45,8 @@ public class IndexMergerRequest
private int mergedIndexTtl;
+ private File mergedIndexDirectory;
+
public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId )
{
this.repositoriesIds = repositoriesIds;
@@ -54,8 +57,8 @@ public class IndexMergerRequest
/**
* @since 1.4-M4
*/
- public IndexMergerRequest(Collection<String> repositoriesIds, boolean packIndex, String groupId,
- String mergedIndexPath, int mergedIndexTtl)
+ public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId,
+ String mergedIndexPath, int mergedIndexTtl )
{
this.repositoriesIds = repositoriesIds;
this.packIndex = packIndex;
@@ -104,14 +107,33 @@ public class IndexMergerRequest
this.mergedIndexPath = mergedIndexPath;
}
- public int getMergedIndexTtl() {
+ public int getMergedIndexTtl()
+ {
return mergedIndexTtl;
}
- public void setMergedIndexTtl(int mergedIndexTtl) {
+ public void setMergedIndexTtl( int mergedIndexTtl )
+ {
this.mergedIndexTtl = mergedIndexTtl;
}
+ public File getMergedIndexDirectory()
+ {
+ return mergedIndexDirectory;
+ }
+
+ public void setMergedIndexDirectory( File mergedIndexDirectory )
+ {
+ this.mergedIndexDirectory = mergedIndexDirectory;
+ }
+
+ public IndexMergerRequest mergedIndexDirectory( File mergedIndexDirectory )
+ {
+ this.mergedIndexDirectory = mergedIndexDirectory;
+ return this;
+ }
+
+
@Override
public String toString()
{
@@ -120,7 +142,8 @@ public class IndexMergerRequest
sb.append( ", packIndex=" ).append( packIndex );
sb.append( ", groupId='" ).append( groupId ).append( '\'' );
sb.append( ", mergedIndexPath='" ).append( mergedIndexPath ).append( '\'' );
- sb.append( ", mergedIndexTtl='" ).append( mergedIndexTtl ).append( '\'' );
+ sb.append( ", mergedIndexTtl=" ).append( mergedIndexTtl );
+ sb.append( ", mergedIndexDirectory='" ).append( mergedIndexDirectory ).append( '\'' );
sb.append( '}' );
return sb.toString();
}
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 047724dbe..535d309d4 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
@@ -51,6 +51,12 @@ public class RepositoryGroup
*/
private int mergedIndexTtl = 30;
+ /**
+ * default model value is empty so none
+ * @since 2.0.0
+ */
+ private String mergedIndexCronExpression;
+
public RepositoryGroup()
{
// no op
@@ -160,6 +166,22 @@ public class RepositoryGroup
return this;
}
+ public String getMergedIndexCronExpression()
+ {
+ return mergedIndexCronExpression;
+ }
+
+ public void setMergedIndexCronExpression( String mergedIndexCronExpression )
+ {
+ this.mergedIndexCronExpression = mergedIndexCronExpression;
+ }
+
+ public RepositoryGroup mergedIndexCronExpression( String mergedIndexCronExpression )
+ {
+ this.mergedIndexCronExpression = mergedIndexCronExpression;
+ return this;
+ }
+
public boolean equals( Object other )
{
if ( this == other )
@@ -188,10 +210,12 @@ public class RepositoryGroup
@Override
public String toString()
{
- final StringBuilder sb = new StringBuilder();
- sb.append( "RepositoryGroup" );
- sb.append( "{id='" ).append( id ).append( '\'' );
+ final StringBuilder sb = new StringBuilder( "RepositoryGroup{" );
+ sb.append( "id='" ).append( id ).append( '\'' );
sb.append( ", repositories=" ).append( repositories );
+ sb.append( ", mergedIndexPath='" ).append( mergedIndexPath ).append( '\'' );
+ sb.append( ", mergedIndexTtl=" ).append( mergedIndexTtl );
+ sb.append( ", mergedIndexCronExpression='" ).append( mergedIndexCronExpression ).append( '\'' );
sb.append( '}' );
return sb.toString();
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java
index 5f191d279..007248f6f 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java
@@ -22,6 +22,7 @@ import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.RepositoryGroup;
+import java.io.File;
import java.util.List;
import java.util.Map;
@@ -73,4 +74,6 @@ public interface RepositoryGroupAdmin
*/
Map<String, List<String>> getRepositoryToGroupMap()
throws RepositoryAdminException;
+
+ File getMergedIndexDirectory( String repositoryGroupId );
}
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 ef43c1042..f1e7edd62 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
@@ -33,7 +33,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
import javax.inject.Inject;
+import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -58,6 +60,25 @@ public class DefaultRepositoryGroupAdmin
@Inject
private ManagedRepositoryAdmin managedRepositoryAdmin;
+ private File groupsDirectory;
+
+ @PostConstruct
+ public void initialize()
+ {
+ String appServerBase = getRegistry().getString( "appserver.base" );
+ groupsDirectory = new File( appServerBase + File.separatorChar + "groups" );
+ if ( !groupsDirectory.exists() )
+ {
+ groupsDirectory.mkdirs();
+ }
+ }
+
+ @Override
+ public File getMergedIndexDirectory( String repositoryGroupId )
+ {
+ return new File( groupsDirectory, repositoryGroupId );
+ }
+
public List<RepositoryGroup> getRepositoriesGroups()
throws RepositoryAdminException
{
@@ -68,7 +89,8 @@ public class DefaultRepositoryGroupAdmin
{
repositoriesGroups.add( new RepositoryGroup( repositoryGroupConfiguration.getId(), new ArrayList<String>(
repositoryGroupConfiguration.getRepositories() ) ).mergedIndexPath(
- repositoryGroupConfiguration.getMergedIndexPath() ).mergedIndexTtl( repositoryGroupConfiguration.getMergedIndexTtl() ) );
+ repositoryGroupConfiguration.getMergedIndexPath() ).mergedIndexTtl(
+ repositoryGroupConfiguration.getMergedIndexTtl() ) );
}
return repositoriesGroups;
@@ -285,7 +307,7 @@ public class DefaultRepositoryGroupAdmin
"Invalid character(s) found in identifier. Only the following characters are allowed: alphanumeric, '.', '-' and '_'" );
}
- if ( repositoryGroup.getMergedIndexTtl() <= 0)
+ if ( repositoryGroup.getMergedIndexTtl() <= 0 )
{
throw new RepositoryAdminException( "Merged Index TTL must be greater than 0." );
}