]> source.dussan.org Git - archiva.git/blob
eb8fbd306803304fdc7c889887eb2d31941290b3
[archiva.git] /
1 package org.apache.archiva.repository.base.group;
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19
20 import org.apache.archiva.components.registry.RegistryException;
21 import org.apache.archiva.configuration.Configuration;
22 import org.apache.archiva.configuration.IndeterminateConfigurationException;
23 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
24 import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler;
25 import org.apache.archiva.repository.RepositoryState;
26 import org.apache.archiva.repository.base.AbstractRepositoryHandler;
27 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
28 import org.apache.archiva.repository.base.ConfigurationHandler;
29 import org.apache.archiva.repository.validation.CheckedResult;
30 import org.apache.archiva.repository.EditableRepository;
31 import org.apache.archiva.repository.EditableRepositoryGroup;
32 import org.apache.archiva.repository.ManagedRepository;
33 import org.apache.archiva.repository.Repository;
34 import org.apache.archiva.repository.RepositoryException;
35 import org.apache.archiva.repository.RepositoryGroup;
36 import org.apache.archiva.repository.RepositoryHandler;
37 import org.apache.archiva.repository.RepositoryProvider;
38 import org.apache.archiva.repository.RepositoryType;
39 import org.apache.archiva.repository.event.RepositoryEvent;
40 import org.apache.archiva.repository.features.IndexCreationFeature;
41 import org.apache.archiva.repository.storage.StorageAsset;
42 import org.apache.archiva.repository.validation.RepositoryChecker;
43 import org.apache.archiva.repository.validation.RepositoryValidator;
44 import org.apache.archiva.repository.validation.ValidationError;
45 import org.apache.commons.lang3.StringUtils;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48 import org.springframework.stereotype.Service;
49
50 import javax.annotation.PostConstruct;
51 import javax.annotation.PreDestroy;
52 import javax.inject.Named;
53 import java.io.IOException;
54 import java.nio.file.Files;
55 import java.nio.file.Path;
56 import java.util.Collection;
57 import java.util.Collections;
58 import java.util.HashMap;
59 import java.util.Iterator;
60 import java.util.LinkedHashMap;
61 import java.util.List;
62 import java.util.Map;
63 import java.util.Optional;
64 import java.util.concurrent.locks.ReentrantReadWriteLock;
65 import java.util.stream.Collectors;
66
67 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
68
69 /**
70  * This class manages repository groups for the RepositoryRegistry.
71  * It is tightly coupled with the {@link ArchivaRepositoryRegistry}.
72  *
73  * @author Martin Stockhammer <martin_s@apache.org>
74  */
75 @Service( "repositoryGroupHandler#default" )
76 public class RepositoryGroupHandler
77     extends AbstractRepositoryHandler<RepositoryGroup, RepositoryGroupConfiguration>
78     implements RepositoryHandler<RepositoryGroup, RepositoryGroupConfiguration>
79 {
80     private static final Logger log = LoggerFactory.getLogger( RepositoryGroupHandler.class );
81
82     private final ArchivaRepositoryRegistry repositoryRegistry;
83     private final ConfigurationHandler configurationHandler;
84     private final MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler;
85
86     private final Map<String, RepositoryGroup> repositoryGroups = new HashMap<>( );
87     private final RepositoryValidator<RepositoryGroup> validator;
88
89     private Path groupsDirectory;
90
91
92     /**
93      * Creates a new instance. All dependencies are injected on the constructor.
94      *
95      * @param repositoryRegistry           the registry. To avoid circular dependencies via DI, this class registers itself on the registry.
96      * @param configurationHandler         the configuration handler is used to retrieve and save configuration.
97      * @param mergedRemoteIndexesScheduler the index scheduler is used for merging the indexes from all group members
98      * @param repositoryValidatorList the list of validators that are registered
99      */
100     public RepositoryGroupHandler( ArchivaRepositoryRegistry repositoryRegistry,
101                                    ConfigurationHandler configurationHandler,
102                                    @Named( "mergedRemoteIndexesScheduler#default" ) MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler,
103                                    List<RepositoryValidator<? extends Repository>> repositoryValidatorList
104                                    )
105     {
106         this.configurationHandler = configurationHandler;
107         this.mergedRemoteIndexesScheduler = mergedRemoteIndexesScheduler;
108         this.repositoryRegistry = repositoryRegistry;
109         this.validator = getCombinedValidatdor( RepositoryGroup.class, repositoryValidatorList );
110     }
111
112     @Override
113     @PostConstruct
114     public void init( )
115     {
116         log.debug( "Initializing repository group handler " + repositoryRegistry.toString( ) );
117         initializeStorage( );
118         // We are registering this class on the registry. This is necessary to avoid circular dependencies via injection.
119         this.repositoryRegistry.registerGroupHandler( this );
120     }
121
122     @Override
123     public void initializeFromConfig( )
124     {
125         this.repositoryGroups.clear( );
126         this.repositoryGroups.putAll( newInstancesFromConfig( ) );
127         for ( RepositoryGroup group : this.repositoryGroups.values( ) )
128         {
129             activateRepository( group );
130         }
131     }
132
133     private void initializeStorage( )
134     {
135         Path baseDir = this.configurationHandler.getArchivaConfiguration( ).getRepositoryGroupBaseDir( );
136         if ( !Files.exists( baseDir ) )
137         {
138             try
139             {
140                 Files.createDirectories( baseDir );
141             }
142             catch ( IOException e )
143             {
144                 log.error( "Could not create group base directory: {}", e.getMessage( ), e );
145             }
146         }
147         this.groupsDirectory = baseDir;
148     }
149
150     @Override
151     public void activateRepository( RepositoryGroup repositoryGroup )
152     {
153         StorageAsset indexDirectory = getMergedIndexDirectory( repositoryGroup );
154         if ( !indexDirectory.exists( ) )
155         {
156             try
157             {
158                 indexDirectory.create( );
159             }
160             catch ( IOException e )
161             {
162                 log.error( "Could not create index directory {} for group {}: {}", indexDirectory, repositoryGroup.getId( ), e.getMessage( ) );
163             }
164         }
165         Path groupPath = groupsDirectory.resolve( repositoryGroup.getId( ) );
166         if ( !Files.exists( groupPath ) )
167         {
168             try
169             {
170                 Files.createDirectories( groupPath );
171             }
172             catch ( IOException e )
173             {
174                 log.error( "Could not create repository group directory {}", groupPath );
175             }
176         }
177         mergedRemoteIndexesScheduler.schedule( repositoryGroup,
178             indexDirectory );
179         setLastState( repositoryGroup, RepositoryState.INITIALIZED );
180     }
181
182     public StorageAsset getMergedIndexDirectory( RepositoryGroup group )
183     {
184         if ( group != null )
185         {
186             return group.getFeature( IndexCreationFeature.class ).get( ).getLocalIndexPath( );
187         }
188         else
189         {
190             return null;
191         }
192     }
193
194
195     @Override
196     public Map<String, RepositoryGroup> newInstancesFromConfig( )
197     {
198         try
199         {
200             List<RepositoryGroupConfiguration> repositoryGroupConfigurations =
201                 this.configurationHandler.getBaseConfiguration( ).getRepositoryGroups( );
202
203             if ( repositoryGroupConfigurations == null )
204             {
205                 return Collections.emptyMap( );
206             }
207
208             Map<String, RepositoryGroup> repositoryGroupMap = new LinkedHashMap<>( repositoryGroupConfigurations.size( ) );
209
210             Map<RepositoryType, RepositoryProvider> providerMap = repositoryRegistry.getRepositoryProviderMap( );
211             for ( RepositoryGroupConfiguration repoConfig : repositoryGroupConfigurations )
212             {
213                 RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
214                 if ( providerMap.containsKey( repositoryType ) )
215                 {
216                     try
217                     {
218                         RepositoryGroup repo = createNewRepositoryGroup( providerMap.get( repositoryType ), repoConfig );
219                         repositoryGroupMap.put( repo.getId( ), repo );
220                     }
221                     catch ( Exception e )
222                     {
223                         log.error( "Could not create repository group {}: {}", repoConfig.getId( ), e.getMessage( ), e );
224                     }
225                 }
226             }
227             return repositoryGroupMap;
228         }
229         catch ( Throwable e )
230         {
231             log.error( "Could not initialize repositories from config: {}", e.getMessage( ), e );
232             return Collections.emptyMap( );
233         }
234     }
235
236     @Override
237     public RepositoryGroup newInstance( final RepositoryType type, String id ) throws RepositoryException
238     {
239         RepositoryProvider provider = repositoryRegistry.getProvider( type );
240         RepositoryGroupConfiguration config = new RepositoryGroupConfiguration( );
241         config.setId( id );
242         return createNewRepositoryGroup( provider, config );
243     }
244
245     @Override
246     public RepositoryGroup newInstance( final RepositoryGroupConfiguration repositoryConfiguration ) throws RepositoryException
247     {
248         RepositoryType type = RepositoryType.valueOf( repositoryConfiguration.getType( ) );
249         RepositoryProvider provider = repositoryRegistry.getProvider( type );
250         return createNewRepositoryGroup( provider, repositoryConfiguration );
251     }
252
253     private RepositoryGroup createNewRepositoryGroup( RepositoryProvider provider, RepositoryGroupConfiguration config ) throws RepositoryException
254     {
255         RepositoryGroup repositoryGroup = provider.createRepositoryGroup( config );
256         updateReferences( repositoryGroup, config );
257         if (repositoryGroup instanceof EditableRepository)
258         {
259             ( (EditableRepository) repositoryGroup ).setLastState( RepositoryState.REFERENCES_SET );
260         }
261         return repositoryGroup;
262     }
263
264     /**
265      * Adds a new repository group to the current list, or replaces the repository group definition with
266      * the same id, if it exists already.
267      * The change is saved to the configuration immediately.
268      *
269      * @param repositoryGroup the new repository group.
270      * @throws RepositoryException if the new repository group could not be saved to the configuration.
271      */
272     @Override
273     public RepositoryGroup put( final RepositoryGroup repositoryGroup ) throws RepositoryException
274     {
275         final String id = repositoryGroup.getId( );
276         RepositoryGroup originRepoGroup = repositoryGroups.remove( id );
277         try
278         {
279             if ( originRepoGroup != null && originRepoGroup != repositoryGroup )
280             {
281                 this.mergedRemoteIndexesScheduler.unschedule( originRepoGroup );
282                 originRepoGroup.close( );
283             }
284             RepositoryProvider provider = repositoryRegistry.getProvider( repositoryGroup.getType( ) );
285             RepositoryGroupConfiguration newCfg = provider.getRepositoryGroupConfiguration( repositoryGroup );
286             ReentrantReadWriteLock.WriteLock configLock = this.configurationHandler.getLock( ).writeLock( );
287             configLock.lock( );
288             try
289             {
290                 Configuration configuration = this.configurationHandler.getBaseConfiguration( );
291                 updateReferences( repositoryGroup, newCfg );
292                 RepositoryGroupConfiguration oldCfg = configuration.findRepositoryGroupById( id );
293                 if ( oldCfg != null )
294                 {
295                     configuration.removeRepositoryGroup( oldCfg );
296                 }
297                 configuration.addRepositoryGroup( newCfg );
298                 configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
299                 setLastState( repositoryGroup, RepositoryState.SAVED );
300                 activateRepository( repositoryGroup );
301             }
302             finally
303             {
304                 configLock.unlock( );
305             }
306             repositoryGroups.put( id, repositoryGroup );
307             setLastState( repositoryGroup, RepositoryState.REGISTERED );
308             return repositoryGroup;
309         }
310         catch ( Exception e )
311         {
312             // Rollback
313             if ( originRepoGroup != null )
314             {
315                 repositoryGroups.put( id, originRepoGroup );
316             }
317             else
318             {
319                 repositoryGroups.remove( id );
320             }
321             log.error( "Exception during configuration update {}", e.getMessage( ), e );
322             throw new RepositoryException( "Could not save the configuration" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ), e);
323         }
324     }
325
326     /**
327      * Adds a new repository group or updates the repository with the same id, if it exists already.
328      * The configuration is saved immediately.
329      *
330      * @param repositoryGroupConfiguration the repository configuration
331      * @return the updated or created repository
332      * @throws RepositoryException if an error occurs, or the configuration is not valid.
333      */
334     @Override
335     public RepositoryGroup put( RepositoryGroupConfiguration repositoryGroupConfiguration ) throws RepositoryException
336     {
337         final String id = repositoryGroupConfiguration.getId( );
338         final RepositoryType repositoryType = RepositoryType.valueOf( repositoryGroupConfiguration.getType( ) );
339         final RepositoryProvider provider = repositoryRegistry.getProvider( repositoryType );
340         RepositoryGroup currentRepository;
341         ReentrantReadWriteLock.WriteLock configLock = this.configurationHandler.getLock( ).writeLock( );
342         configLock.lock( );
343         try
344         {
345             Configuration configuration = this.configurationHandler.getBaseConfiguration( );
346             currentRepository = repositoryRegistry.getRepositoryGroup( id );
347             RepositoryGroup oldRepository = currentRepository == null ? null : clone( currentRepository );
348             try
349             {
350
351                 if (currentRepository==null) {
352                     currentRepository = put( repositoryGroupConfiguration, configuration );
353                 } else
354                 {
355                     setRepositoryGroupDefaults( repositoryGroupConfiguration );
356                     provider.updateRepositoryGroupInstance( (EditableRepositoryGroup) currentRepository, repositoryGroupConfiguration );
357                 }
358                 configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
359                 updateReferences( currentRepository, repositoryGroupConfiguration );
360                 setLastState( currentRepository, RepositoryState.REFERENCES_SET );
361                 activateRepository( currentRepository );
362                 this.repositoryGroups.put( id, currentRepository );
363                 setLastState( currentRepository, RepositoryState.REGISTERED );
364             }
365             catch ( IndeterminateConfigurationException | RegistryException | RepositoryException e )
366             {
367                 // Trying a rollback
368                 if ( oldRepository != null  )
369                 {
370                     RepositoryGroupConfiguration oldCfg = provider.getRepositoryGroupConfiguration( oldRepository );
371                     provider.updateRepositoryGroupInstance( (EditableRepositoryGroup) currentRepository, oldCfg);
372                     replaceOrAddRepositoryConfig( oldCfg, configuration );
373                     try
374                     {
375                         configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
376                     }
377                     catch ( IndeterminateConfigurationException | RegistryException indeterminateConfigurationException )
378                     {
379                         log.error( "Fatal error, config save during rollback failed: {}", e.getMessage( ), e );
380                     }
381                     updateReferences( oldRepository, oldCfg  );
382                     setLastState( oldRepository, RepositoryState.REFERENCES_SET );
383                     activateRepository( oldRepository );
384                     repositoryGroups.put( id, oldRepository );
385                     setLastState( oldRepository, RepositoryState.REGISTERED );
386                 } else {
387                     repositoryGroups.remove( id );
388                 }
389                 log.error( "Could not save the configuration for repository group {}: {}", id, e.getMessage( ), e );
390                 if (e instanceof RepositoryException) {
391                     throw (RepositoryException) e;
392                 } else
393                 {
394                     throw new RepositoryException( "Could not save the configuration for repository group " + id + ": " + e.getMessage( ) );
395                 }
396             }
397         }
398         finally
399         {
400             configLock.unlock( );
401         }
402         return currentRepository;
403     }
404
405     @Override
406     public RepositoryGroup put( RepositoryGroupConfiguration repositoryGroupConfiguration, Configuration configuration ) throws RepositoryException
407     {
408         final String id = repositoryGroupConfiguration.getId( );
409         final RepositoryType repoType = RepositoryType.valueOf( repositoryGroupConfiguration.getType( ) );
410         RepositoryGroup repo;
411         setRepositoryGroupDefaults( repositoryGroupConfiguration );
412         if ( repositoryGroups.containsKey( id ) )
413         {
414             repo = clone( repositoryGroups.get( id ) );
415             if ( repo instanceof EditableRepositoryGroup )
416             {
417                 repositoryRegistry.getProvider( repoType ).updateRepositoryGroupInstance( (EditableRepositoryGroup) repo, repositoryGroupConfiguration );
418             }
419             else
420             {
421                 throw new RepositoryException( "The repository is not editable " + id );
422             }
423         }
424         else
425         {
426             repo = repositoryRegistry.getProvider( repoType ).createRepositoryGroup( repositoryGroupConfiguration );
427             setLastState( repo, RepositoryState.CREATED );
428         }
429         replaceOrAddRepositoryConfig( repositoryGroupConfiguration, configuration );
430         updateReferences( repo, repositoryGroupConfiguration );
431         setLastState( repo, RepositoryState.REFERENCES_SET );
432         return repo;
433     }
434
435     @Override
436     public <D> CheckedResult<RepositoryGroup, D> putWithCheck( RepositoryGroupConfiguration repositoryConfiguration, RepositoryChecker<RepositoryGroup, D> checker ) throws RepositoryException
437     {
438         final String id = repositoryConfiguration.getId( );
439         RepositoryGroup currentGroup = repositoryGroups.get( id );
440         Configuration configuration = configurationHandler.getBaseConfiguration( );
441         RepositoryGroup repositoryGroup = put( repositoryConfiguration, configuration );
442         CheckedResult<RepositoryGroup, D> result;
443         if ( currentGroup == null )
444         {
445             result = checker.apply( repositoryGroup );
446         }
447         else
448         {
449             result = checker.applyForUpdate( repositoryGroup );
450         }
451         if ( result.isValid( ) )
452         {
453             put( result.getRepository() );
454         }
455         return result;
456     }
457
458
459     private void setRepositoryGroupDefaults( RepositoryGroupConfiguration repositoryGroupConfiguration )
460     {
461         if ( StringUtils.isEmpty( repositoryGroupConfiguration.getMergedIndexPath( ) ) )
462         {
463             repositoryGroupConfiguration.setMergedIndexPath( DEFAULT_INDEX_PATH );
464         }
465         if ( repositoryGroupConfiguration.getMergedIndexTtl( ) <= 0 )
466         {
467             repositoryGroupConfiguration.setMergedIndexTtl( 300 );
468         }
469         if ( StringUtils.isEmpty( repositoryGroupConfiguration.getCronExpression( ) ) )
470         {
471             repositoryGroupConfiguration.setCronExpression( "0 0 03 ? * MON" );
472         }
473     }
474
475     private void replaceOrAddRepositoryConfig( RepositoryGroupConfiguration repositoryGroupConfiguration, Configuration configuration )
476     {
477         RepositoryGroupConfiguration oldCfg = configuration.findRepositoryGroupById( repositoryGroupConfiguration.getId( ) );
478         if ( oldCfg != null )
479         {
480             configuration.removeRepositoryGroup( oldCfg );
481         }
482         configuration.addRepositoryGroup( repositoryGroupConfiguration );
483     }
484
485     public void removeRepositoryFromGroups( ManagedRepository repo )
486     {
487         if ( repo != null )
488         {
489             repositoryGroups.values( ).stream( ).filter( repoGroup -> repoGroup instanceof EditableRepository ).
490                 map( repoGroup -> (EditableRepositoryGroup) repoGroup ).forEach( repoGroup -> repoGroup.removeRepository( repo ) );
491         }
492     }
493
494     /**
495      * Removes a repository group from the registry and configuration, if it exists.
496      * The change is saved to the configuration immediately.
497      *
498      * @param id the id of the repository group to remove
499      * @throws RepositoryException if a error occurs during configuration save
500      */
501     @Override
502     public void remove( final String id ) throws RepositoryException
503     {
504         RepositoryGroup repo = get( id );
505         if ( repo != null )
506         {
507             try
508             {
509                 repo = repositoryGroups.remove( id );
510                 if ( repo != null )
511                 {
512                     this.mergedRemoteIndexesScheduler.unschedule( repo );
513                     repo.close( );
514                     Configuration configuration = this.configurationHandler.getBaseConfiguration( );
515                     RepositoryGroupConfiguration cfg = configuration.findRepositoryGroupById( id );
516                     if ( cfg != null )
517                     {
518                         configuration.removeRepositoryGroup( cfg );
519                     }
520                     this.configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
521                     setLastState( repo, RepositoryState.UNREGISTERED );
522                 }
523
524             }
525             catch ( RegistryException | IndeterminateConfigurationException e )
526             {
527                 // Rollback
528                 log.error( "Could not save config after repository removal: {}", e.getMessage( ), e );
529                 repositoryGroups.put( repo.getId( ), repo );
530                 throw new RepositoryException( "Could not save configuration after repository removal: " + e.getMessage( ) );
531             }
532         }
533     }
534
535     @Override
536     public void remove( String id, Configuration configuration ) throws RepositoryException
537     {
538         RepositoryGroup repo = repositoryGroups.get( id );
539         if ( repo != null )
540         {
541             repo = repositoryGroups.remove( id );
542             if ( repo != null )
543             {
544                 this.mergedRemoteIndexesScheduler.unschedule( repo );
545                 repo.close( );
546                 RepositoryGroupConfiguration cfg = configuration.findRepositoryGroupById( id );
547                 if ( cfg != null )
548                 {
549                     configuration.removeRepositoryGroup( cfg );
550                 }
551                 setLastState( repo, RepositoryState.UNREGISTERED );
552             }
553         }
554         Iterator<RepositoryGroupConfiguration> cfgIter = configuration.getRepositoryGroups( ).iterator( );
555         while(cfgIter.hasNext()) {
556             RepositoryGroupConfiguration el = cfgIter.next( );
557             if (id.equals( el.getId() )) {
558                 cfgIter.remove( );
559                 break;
560             }
561         }
562     }
563
564     @Override
565     public RepositoryGroup get( String groupId )
566     {
567         return repositoryGroups.get( groupId );
568     }
569
570     @Override
571     public RepositoryGroup clone( RepositoryGroup repo ) throws RepositoryException
572     {
573         RepositoryProvider provider = repositoryRegistry.getProvider( repo.getType( ) );
574         RepositoryGroupConfiguration cfg = provider.getRepositoryGroupConfiguration( repo );
575         RepositoryGroup cloned = provider.createRepositoryGroup( cfg );
576         cloned.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry );
577         setLastState( cloned, RepositoryState.CREATED );
578         return cloned;
579     }
580
581     @Override
582     public void updateReferences( RepositoryGroup repo, RepositoryGroupConfiguration repositoryConfiguration ) throws RepositoryException
583     {
584         if ( repo instanceof EditableRepositoryGroup && repositoryConfiguration!=null)
585         {
586             EditableRepositoryGroup eGroup = (EditableRepositoryGroup) repo;
587             eGroup.setRepositories( repositoryConfiguration.getRepositories( ).stream( )
588                 .map( repositoryRegistry::getManagedRepository ).collect( Collectors.toList( ) ) );
589         }
590
591     }
592
593     @Override
594     public Collection<RepositoryGroup> getAll( )
595     {
596         return repositoryGroups.values( );
597     }
598
599     @Override
600     public RepositoryValidator<RepositoryGroup> getValidator( )
601     {
602         return this.validator;
603     }
604
605     @Override
606     public CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> validateRepository( RepositoryGroup repository )
607     {
608         return this.validator.apply( repository );
609
610     }
611
612     @Override
613     public CheckedResult<RepositoryGroup,Map<String, List<ValidationError>>> validateRepositoryForUpdate( RepositoryGroup repository )
614     {
615         return this.validator.applyForUpdate( repository );
616     }
617     @Override
618     public boolean hasRepository( String id )
619     {
620         return repositoryGroups.containsKey( id );
621     }
622
623     @PreDestroy
624     private void destroy( )
625     {
626         this.close( );
627     }
628
629     @Override
630     public void close( )
631     {
632         for ( RepositoryGroup group : repositoryGroups.values( ) )
633         {
634             try
635             {
636                 mergedRemoteIndexesScheduler.unschedule( group );
637                 group.close( );
638             }
639             catch ( Throwable e )
640             {
641                 log.error( "Could not close repository group {}: {}", group.getId( ), e.getMessage( ) );
642             }
643         }
644         this.repositoryGroups.clear( );
645     }
646
647 }