summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2013-12-17 07:28:54 +0000
committerOlivier Lamy <olamy@apache.org>2013-12-17 07:28:54 +0000
commitaf520c00cfe4ffb0790a30e916f538b84ee8667b (patch)
treeb923d139fb309c1d08e2ad56b66a11b34b42a213 /archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src
parentb67de4117e723519ca95277c77b983a9ca69b867 (diff)
downloadarchiva-af520c00cfe4ffb0790a30e916f538b84ee8667b.tar.gz
archiva-af520c00cfe4ffb0790a30e916f538b84ee8667b.zip
[MRM-1746] build merged index for groups with a cron schedule
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1551473 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java30
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java45
2 files changed, 75 insertions, 0 deletions
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 f1e7edd62..e35c74c06 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
@@ -27,7 +27,11 @@ import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.ConfigurationEvent;
+import org.apache.archiva.configuration.ConfigurationListener;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
+import org.apache.archiva.redback.components.registry.RegistryListener;
+import org.apache.archiva.scheduler.MergedRemoteIndexesScheduler;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +42,7 @@ import javax.inject.Inject;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -60,6 +65,9 @@ public class DefaultRepositoryGroupAdmin
@Inject
private ManagedRepositoryAdmin managedRepositoryAdmin;
+ @Inject
+ private MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler;
+
private File groupsDirectory;
@PostConstruct
@@ -71,8 +79,22 @@ public class DefaultRepositoryGroupAdmin
{
groupsDirectory.mkdirs();
}
+
+ try
+ {
+ for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() )
+ {
+ mergedRemoteIndexesScheduler.schedule( repositoryGroup );
+ }
+ }
+ catch ( RepositoryAdminException e )
+ {
+ log.warn( "fail to getRepositoriesGroups {}", e.getMessage(), e );
+ }
+
}
+
@Override
public File getMergedIndexDirectory( String repositoryGroupId )
{
@@ -121,10 +143,12 @@ public class DefaultRepositoryGroupAdmin
repositoryGroupConfiguration.setRepositories( repositoryGroup.getRepositories() );
repositoryGroupConfiguration.setMergedIndexPath( repositoryGroup.getMergedIndexPath() );
repositoryGroupConfiguration.setMergedIndexTtl( repositoryGroup.getMergedIndexTtl() );
+ repositoryGroupConfiguration.setCronExpression( repositoryGroup.getCronExpression() );
Configuration configuration = getArchivaConfiguration().getConfiguration();
configuration.addRepositoryGroup( repositoryGroupConfiguration );
saveConfiguration( configuration );
triggerAuditEvent( repositoryGroup.getId(), null, AuditEvent.ADD_REPO_GROUP, auditInformation );
+ mergedRemoteIndexesScheduler.schedule( repositoryGroup );
return Boolean.TRUE;
}
@@ -134,6 +158,8 @@ public class DefaultRepositoryGroupAdmin
Configuration configuration = getArchivaConfiguration().getConfiguration();
RepositoryGroupConfiguration repositoryGroupConfiguration =
configuration.getRepositoryGroupsAsMap().get( repositoryGroupId );
+ mergedRemoteIndexesScheduler.unschedule(
+ new RepositoryGroup( repositoryGroupId, Collections.<String>emptyList() ) );
if ( repositoryGroupConfiguration == null )
{
throw new RepositoryAdminException(
@@ -141,6 +167,7 @@ public class DefaultRepositoryGroupAdmin
}
configuration.removeRepositoryGroup( repositoryGroupConfiguration );
triggerAuditEvent( repositoryGroupId, null, AuditEvent.DELETE_REPO_GROUP, auditInformation );
+
return Boolean.TRUE;
}
@@ -166,6 +193,7 @@ public class DefaultRepositoryGroupAdmin
repositoryGroupConfiguration.setRepositories( repositoryGroup.getRepositories() );
repositoryGroupConfiguration.setMergedIndexPath( repositoryGroup.getMergedIndexPath() );
repositoryGroupConfiguration.setMergedIndexTtl( repositoryGroup.getMergedIndexTtl() );
+ repositoryGroupConfiguration.setCronExpression( repositoryGroup.getCronExpression() );
configuration.addRepositoryGroup( repositoryGroupConfiguration );
saveConfiguration( configuration );
@@ -173,6 +201,8 @@ public class DefaultRepositoryGroupAdmin
{
triggerAuditEvent( repositoryGroup.getId(), null, AuditEvent.MODIFY_REPO_GROUP, auditInformation );
}
+ mergedRemoteIndexesScheduler.unschedule( repositoryGroup );
+ mergedRemoteIndexesScheduler.schedule( repositoryGroup );
return Boolean.TRUE;
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java
new file mode 100644
index 000000000..54552a53c
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java
@@ -0,0 +1,45 @@
+package org.apache.archiva.admin.mock;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.admin.model.beans.RepositoryGroup;
+import org.apache.archiva.scheduler.MergedRemoteIndexesScheduler;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service
+public class MockMergedRemoteIndexesScheduler
+ implements MergedRemoteIndexesScheduler
+{
+
+ @Override
+ public void schedule( RepositoryGroup repositoryGroup )
+ {
+ // no op
+ }
+
+ @Override
+ public void unschedule( RepositoryGroup repositoryGroup )
+ {
+ // no op
+ }
+}