33import com .weareadaptive .nexus .casc .plugin .internal .config .*;
44import org .apache .shiro .util .ThreadContext ;
55import org .eclipse .sisu .Description ;
6- import org .elasticsearch .cluster .metadata .MappingMetaData ;
76import org .sonatype .nexus .CoreApi ;
87import org .sonatype .nexus .blobstore .api .BlobStore ;
98import org .sonatype .nexus .blobstore .api .BlobStoreConfiguration ;
2120import org .sonatype .nexus .repository .routing .*;
2221import org .sonatype .nexus .repository .config .Configuration ;
2322import org .sonatype .nexus .repository .manager .RepositoryManager ;
24- import org .sonatype .nexus .repository .security .RepositoryPermissionChecker ;
2523import org .sonatype .nexus .security .SecurityApi ;
2624import org .sonatype .nexus .security .SecuritySystem ;
2725import org .sonatype .nexus .security .authz .AuthorizationManager ;
@@ -67,8 +65,6 @@ public class NexusCascPlugin extends StateGuardLifecycleSupport {
6765 private final RealmManager realmManager ;
6866 private final CapabilityRegistry capabilityRegistry ;
6967 private final RoutingRuleStore routingRuleStore ;
70- private final RoutingRuleHelper routingRuleHelper ;
71- private final RepositoryPermissionChecker repositoryPermissionChecker ;
7268
7369 @ Inject
7470 public NexusCascPlugin (
@@ -82,9 +78,7 @@ public NexusCascPlugin(
8278 final BlobStoreManager blobStoreManager ,
8379 final RealmManager realmManager ,
8480 final CapabilityRegistry capabilityRegistry ,
85- final RoutingRuleStore routingRuleStore ,
86- final RoutingRuleHelper routingRuleHelper ,
87- final RepositoryPermissionChecker repositoryPermissionChecker
81+ final RoutingRuleStore routingRuleStore
8882 ) throws IllegalAccessException , NoSuchMethodException , InvocationTargetException {
8983 this .baseUrlManager = baseUrlManager ;
9084 this .coreApi = coreApi ;
@@ -97,8 +91,6 @@ public NexusCascPlugin(
9791 this .realmManager = realmManager ;
9892 this .capabilityRegistry = capabilityRegistry ;
9993 this .routingRuleStore = routingRuleStore ;
100- this .routingRuleHelper = routingRuleHelper ;
101- this .repositoryPermissionChecker = repositoryPermissionChecker ;
10294 }
10395
10496 @ Override
@@ -397,12 +389,6 @@ private void applyRepositoryConfig(ConfigRepository repository) {
397389
398390 if (repository .getRoutingRules () != null && !repository .getRoutingRules ().isEmpty ()) {
399391 repository .getRoutingRules ().forEach (this ::applyRoutingRuleConfig );
400- routingRuleStore .list ().forEach (existingRule -> {
401- if (repository .getRoutingRules ().stream ().noneMatch (rr -> existingRule .name ().equals (rr .getName ()))) {
402- log .info ("Pruning routing rule {}" , existingRule .name ());
403- routingRuleStore .delete (existingRule );
404- }
405- });
406392 }
407393
408394 if (repository .getRepositories () != null ) {
@@ -475,6 +461,24 @@ private void applyRepositoryConfig(ConfigRepository repository) {
475461 log .warn ("repository.pruneRepositories has no effect when no repositories are configured!" );
476462 }
477463
464+ // Prune routing rules that are not in use
465+ if (repository .getRoutingRules () != null && !repository .getRoutingRules ().isEmpty ()) {
466+ List <EntityId > existingRoutingRuleIdsInUse = new ArrayList <>();
467+ repositoryManager .browse ().forEach (existingRepo -> {
468+ existingRoutingRuleIdsInUse .add (existingRepo .getConfiguration ().getRoutingRuleId ());
469+ });
470+ routingRuleStore .list ().forEach (existingRule -> {
471+ if (repository .getRoutingRules ().stream ().noneMatch (rr -> existingRule .name ().equals (rr .getName ()))) {
472+ if (existingRoutingRuleIdsInUse .stream ().noneMatch (id -> id .equals (existingRule .id ()))) {
473+ log .info ("Pruning routing rule {}" , existingRule .name ());
474+ routingRuleStore .delete (existingRule );
475+ } else {
476+ log .error ("Routing rule {} is still in use" , existingRule .name ());
477+ }
478+ }
479+ });
480+ }
481+
478482 // we prune blob stores here as pruned repos might rely on them
479483 if (repository .getBlobStores () != null && repository .getPruneBlobStores () != null && repository .getPruneBlobStores ()) {
480484 blobStoreManager .browse ().forEach (existingBlobStore -> {
0 commit comments