*/
void setIndexingContext(ArchivaIndexingContext context);
+ /**
+ * Sets the last repository state.
+ * @param state the state value
+ */
+ void setLastState(RepositoryState state);
}
*/
boolean isOpen();
-
+ /**
+ * Returns the last state of this repository instance. As multiple repository instances may point to the
+ * same repository, this is only a representation of the last state, when this particular instance was
+ * used by the registry.
+ *
+ * @return the last known state of this repository instance
+ */
+ default RepositoryState getLastState() {
+ return RepositoryState.CREATED;
+ }
}
* This is the generic interface that handles different repository flavours, currently for
* ManagedRepository, RemoteRepository and RepositoryGroup
*
+ * Lifecycle/states of a repository:
+ * <ul>
+ * <li>Instance created: This state is reached by the newInstance-methods. The instance is created, filled with the
+ * corresponding attribute data and references are updated. References are object references to other repositories, if they exist.
+ * The instance is not registered on the registry (stored) and configuration is not updated.</li>
+ * <li>Instance registered: Instances added/updated by the put()-methods are created and registered on the registry.
+ * If all goes well, the configuration is updated.</li>
+ * <li>Instance initialized: </li>
+ * </ul>
+ *
+ *
* @author Martin Stockhammer <martin_s@apache.org>
*/
public interface RepositoryHandler<R extends Repository, C>
--- /dev/null
+package org.apache.archiva.repository;
+/*
+ * 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.
+ */
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public enum RepositoryState
+{
+ CREATED(0),REFERENCES_SET(100),SAVED(200),INITIALIZED(300),REGISTERED(400),UNREGISTERED(500),CLOSED(600);
+
+ private final int orderNumber;
+
+ RepositoryState( int orderNumber )
+ {
+ this.orderNumber = orderNumber;
+ }
+
+ public int getOrderNumber() {
+ return orderNumber;
+ }
+}
import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.repository.EditableRepository;
import org.apache.archiva.repository.RepositoryCapabilities;
+import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.UnsupportedFeatureException;
import org.apache.archiva.repository.event.*;
String schedulingDefinition = "0 0 02 * * ?";
private String layout = "default";
public static final CronDefinition CRON_DEFINITION = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
+ private RepositoryState state;
private final EventManager eventManager;
sf.getStagingRepository().close();
}
}
+ setLastState( RepositoryState.CLOSED );
}
}
protected RepositoryStorage getStorage() {
return storage;
}
+
+
+ @Override
+ public RepositoryState getLastState( )
+ {
+ return this.state;
+ }
+
+ @Override
+ public void setLastState( RepositoryState state )
+ {
+ this.state = state;
+ }
}
* under the License.
*/
+import org.apache.archiva.repository.EditableRepository;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryHandler;
+import org.apache.archiva.repository.RepositoryState;
+import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.repository.validation.CombinedValidator;
import org.apache.archiva.repository.validation.RepositoryValidator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
*/
public abstract class AbstractRepositoryHandler<R extends Repository, C> implements RepositoryHandler<R, C>
{
+
+ private static final Logger log = LoggerFactory.getLogger( AbstractRepositoryHandler.class );
+
protected List<RepositoryValidator<R>> initValidators( Class<R> clazz, List<RepositoryValidator<? extends Repository>> repositoryGroupValidatorList) {
if (repositoryGroupValidatorList!=null && repositoryGroupValidatorList.size()>0) {
return repositoryGroupValidatorList.stream( ).filter(
return new CombinedValidator<>( clazz, initValidators( clazz, repositoryGroupValidatorList ) );
}
+ protected void setLastState(Repository repo, RepositoryState state) {
+ if (repo instanceof EditableRepository ) {
+ if (state.getOrderNumber()>repo.getLastState().getOrderNumber())
+ {
+ ( (EditableRepository) repo ).setLastState( state );
+ }
+ } else {
+ log.error( "Found a not editable repository instance: {}, {}", repo.getId( ), repo.getClass().getName() );
+ }
+ }
}
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryCapabilities;
import org.apache.archiva.repository.RepositoryGroup;
+import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.StandardCapabilities;
import org.apache.archiva.repository.base.AbstractRepository;
feature.setLocalIndexPath( repositoryStorage.getRoot( ).resolve(".indexer") );
feature.setLocalPackedIndexPath( repositoryStorage.getRoot( ).resolve(".index") );
addFeature( feature );
+ setLastState( RepositoryState.CREATED );
}
@Override
import org.apache.archiva.configuration.IndeterminateConfigurationException;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler;
+import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.base.AbstractRepositoryHandler;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.base.ConfigurationHandler;
}
mergedRemoteIndexesScheduler.schedule( repositoryGroup,
indexDirectory );
+ setLastState( repositoryGroup, RepositoryState.INITIALIZED );
}
public StorageAsset getMergedIndexDirectory( RepositoryGroup group )
{
RepositoryGroup repositoryGroup = provider.createRepositoryGroup( config );
updateReferences( repositoryGroup, config );
+ if (repositoryGroup instanceof EditableRepository)
+ {
+ ( (EditableRepository) repositoryGroup ).setLastState( RepositoryState.REFERENCES_SET );
+ }
return repositoryGroup;
}
-
/**
* Adds a new repository group to the current list, or replaces the repository group definition with
* the same id, if it exists already.
}
configuration.addRepositoryGroup( newCfg );
configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
+ setLastState( repositoryGroup, RepositoryState.SAVED );
initialize( repositoryGroup );
}
finally
configLock.unlock( );
}
repositoryGroups.put( id, repositoryGroup );
+ setLastState( repositoryGroup, RepositoryState.REGISTERED );
return repositoryGroup;
}
catch ( Exception e )
}
configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
updateReferences( currentRepository, repositoryGroupConfiguration );
+ setLastState( currentRepository, RepositoryState.REFERENCES_SET );
initialize( currentRepository );
this.repositoryGroups.put( id, currentRepository );
+ setLastState( currentRepository, RepositoryState.REGISTERED );
}
catch ( IndeterminateConfigurationException | RegistryException | RepositoryException e )
{
log.error( "Fatal error, config save during rollback failed: {}", e.getMessage( ), e );
}
updateReferences( oldRepository, oldCfg );
+ setLastState( oldRepository, RepositoryState.REFERENCES_SET );
initialize( oldRepository );
+ repositoryGroups.put( id, oldRepository );
+ setLastState( oldRepository, RepositoryState.REGISTERED );
+ } else {
+ repositoryGroups.remove( id );
}
log.error( "Could not save the configuration for repository group {}: {}", id, e.getMessage( ), e );
if (e instanceof RepositoryException) {
else
{
repo = repositoryRegistry.getProvider( repoType ).createRepositoryGroup( repositoryGroupConfiguration );
+ setLastState( repo, RepositoryState.CREATED );
}
replaceOrAddRepositoryConfig( repositoryGroupConfiguration, configuration );
updateReferences( repo, repositoryGroupConfiguration );
+ setLastState( repo, RepositoryState.REFERENCES_SET );
return repo;
}
configuration.removeRepositoryGroup( cfg );
}
this.configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
+ setLastState( repo, RepositoryState.UNREGISTERED );
}
}
{
configuration.removeRepositoryGroup( cfg );
}
+ setLastState( repo, RepositoryState.UNREGISTERED );
}
}
RepositoryGroupConfiguration cfg = provider.getRepositoryGroupConfiguration( repo );
RepositoryGroup cloned = provider.createRepositoryGroup( cfg );
cloned.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry );
+ setLastState( cloned, RepositoryState.CREATED );
return cloned;
}
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryCapabilities;
import org.apache.archiva.repository.RepositoryRequestInfo;
+import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.StandardCapabilities;
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
{
super( RepositoryType.MAVEN, id, name, repositoryStorage );
initFeatures();
+ setLastState( RepositoryState.CREATED );
}
public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage repositoryStorage )
{
super( primaryLocale, type, id, name, repositoryStorage);
initFeatures();
+ setLastState( RepositoryState.CREATED );
}
private void initFeatures() {
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryCapabilities;
+import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.StandardCapabilities;
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
{
super( RepositoryType.MAVEN, id, name, storage);
initFeatures();
+ setLastState( RepositoryState.CREATED );
}
public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage )
{
super( primaryLocale, type, id, name, storage );
initFeatures();
+ setLastState( RepositoryState.CREATED );
}
private void initFeatures() {
class RepositoryGroupHandlerTest
{
- @Test
- void init( )
- {
- }
@Test
void initializeFromConfig( )
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryCapabilities;
import org.apache.archiva.repository.RepositoryRequestInfo;
+import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.StandardCapabilities;
import org.apache.archiva.repository.UnsupportedFeatureException;
super( RepositoryType.MAVEN, id, name, storage);
this.indexCreationFeature = new IndexCreationFeature(this, this);
setLocation(storage.getRoot().getFilePath().toUri());
+ setLastState( RepositoryState.CREATED );
}
public MavenManagedRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
{
super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
setLocation(storage.getRoot().getFilePath().toUri());
+ setLastState( RepositoryState.CREATED );
}
@Override
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RepositoryCapabilities;
+import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.StandardCapabilities;
import org.apache.archiva.repository.UnsupportedFeatureException;
{
super( RepositoryType.MAVEN, id, name, storage );
this.indexCreationFeature = new IndexCreationFeature(this, this);
-
+ setLastState( RepositoryState.CREATED );
}
public MavenRemoteRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
{
super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
this.indexCreationFeature = new IndexCreationFeature(this, this);
+ setLastState( RepositoryState.CREATED );
}
@Override
import org.apache.archiva.repository.EditableRepositoryGroup;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryCapabilities;
+import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.StandardCapabilities;
import org.apache.archiva.repository.base.group.AbstractRepositoryGroup;
public MavenRepositoryGroup(String id, String name, FilesystemStorage storage) {
super(RepositoryType.MAVEN, id, name, storage);
init();
+ setLastState( RepositoryState.CREATED );
}
public MavenRepositoryGroup(Locale primaryLocale, String id, String name, FilesystemStorage storage) {
super(primaryLocale, RepositoryType.MAVEN, id, name, storage);
init();
+ setLastState( RepositoryState.CREATED );
}
private Path getRepositoryPath() {