Search in sources :

Example 6 with RepositoryProvider

use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.

the class ArchivaRepositoryRegistry method initialize.

@PostConstruct
private void initialize() {
    rwLock.writeLock().lock();
    try {
        log.debug("Initializing repository registry");
        initializeManagedRepositories();
        initializeRemoteRepositories();
        initializeRepositoryGroups();
        for (RepositoryProvider provider : repositoryProviders) {
            provider.addRepositoryEventHandler(this);
        }
        this.configurationHandler.addListener(this);
        registerEventHandler(EventType.ROOT, centralEventManager);
    } finally {
        rwLock.writeLock().unlock();
    }
    pushEvent(new RepositoryRegistryEvent(RepositoryRegistryEvent.RELOADED, this));
    if (managed_initialized.get() && remote_initialized.get() && groups_initalized.get()) {
        pushEvent(new RepositoryRegistryEvent(RepositoryRegistryEvent.INITIALIZED, this));
    }
}
Also used : RepositoryRegistryEvent(org.apache.archiva.repository.event.RepositoryRegistryEvent) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) PostConstruct(javax.annotation.PostConstruct)

Example 7 with RepositoryProvider

use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.

the class RepositoryGroupHandler method newInstance.

@Override
public RepositoryGroup newInstance(final RepositoryGroupConfiguration repositoryConfiguration) throws RepositoryException {
    RepositoryType type = RepositoryType.valueOf(repositoryConfiguration.getType());
    RepositoryProvider provider = getProvider(type);
    return createNewRepositoryGroup(provider, repositoryConfiguration);
}
Also used : RepositoryType(org.apache.archiva.repository.RepositoryType) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 8 with RepositoryProvider

use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.

the class RepositoryGroupHandler method clone.

@Override
public RepositoryGroup clone(RepositoryGroup repo, String newId) throws RepositoryException {
    RepositoryProvider provider = getProvider(repo.getType());
    RepositoryGroupConfiguration cfg = provider.getRepositoryGroupConfiguration(repo);
    cfg.setId(newId);
    RepositoryGroup cloned = provider.createRepositoryGroup(cfg);
    cloned.registerEventHandler(RepositoryEvent.ANY, repositoryRegistry);
    setLastState(cloned, RepositoryState.CREATED);
    return cloned;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 9 with RepositoryProvider

use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.

the class RepositoryGroupHandler method put.

/**
 * Adds a new repository group or updates the repository with the same id, if it exists already.
 * The configuration is saved immediately.
 *
 * @param repositoryGroupConfiguration the repository configuration
 * @return the updated or created repository
 * @throws RepositoryException if an error occurs, or the configuration is not valid.
 */
@Override
public RepositoryGroup put(RepositoryGroupConfiguration repositoryGroupConfiguration) throws RepositoryException {
    final String id = repositoryGroupConfiguration.getId();
    final RepositoryType repositoryType = RepositoryType.valueOf(repositoryGroupConfiguration.getType());
    final RepositoryProvider provider = getProvider(repositoryType);
    RepositoryGroup currentRepository;
    ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
    configLock.lock();
    try {
        Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
        currentRepository = getRepositories().get(id);
        RepositoryGroup oldRepository = currentRepository == null ? null : clone(currentRepository, id);
        try {
            boolean updated = false;
            if (currentRepository == null) {
                currentRepository = put(repositoryGroupConfiguration, configuration);
            } else {
                setRepositoryGroupDefaults(repositoryGroupConfiguration);
                provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, repositoryGroupConfiguration);
                updated = true;
                pushEvent(LifecycleEvent.UPDATED, currentRepository);
            }
            registerNewRepository(repositoryGroupConfiguration, currentRepository, configuration, updated);
        } catch (IndeterminateConfigurationException | RegistryException | RepositoryException e) {
            // Trying a rollback
            if (oldRepository != null) {
                RepositoryGroupConfiguration oldCfg = provider.getRepositoryGroupConfiguration(oldRepository);
                provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, oldCfg);
                rollback(configuration, oldRepository, e, oldCfg);
            } else {
                getRepositories().remove(id);
            }
            log.error("Could not save the configuration for repository group {}: {}", id, e.getMessage(), e);
            if (e instanceof RepositoryException) {
                throw (RepositoryException) e;
            } else {
                throw new RepositoryException("Could not save the configuration for repository group " + id + ": " + e.getMessage());
            }
        }
    } finally {
        configLock.unlock();
    }
    return currentRepository;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryType(org.apache.archiva.repository.RepositoryType) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryException(org.apache.archiva.repository.RepositoryException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RegistryException(org.apache.archiva.components.registry.RegistryException) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup)

Example 10 with RepositoryProvider

use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.

the class ManagedRepositoryHandler method clone.

@Override
public ManagedRepository clone(ManagedRepository repo, String id) throws RepositoryException {
    RepositoryProvider provider = getProvider(repo.getType());
    ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(repo);
    cfg.setId(id);
    ManagedRepository cloned = provider.createManagedInstance(cfg);
    cloned.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
    setLastState(cloned, RepositoryState.CREATED);
    return cloned;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Aggregations

RepositoryProvider (org.apache.archiva.repository.RepositoryProvider)18 RepositoryException (org.apache.archiva.repository.RepositoryException)9 Configuration (org.apache.archiva.configuration.model.Configuration)7 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)7 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)7 RepositoryType (org.apache.archiva.repository.RepositoryType)7 RegistryException (org.apache.archiva.components.registry.RegistryException)6 IndeterminateConfigurationException (org.apache.archiva.configuration.provider.IndeterminateConfigurationException)6 ManagedRepository (org.apache.archiva.repository.ManagedRepository)6 EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)5 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)4 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)4 RemoteRepository (org.apache.archiva.repository.RemoteRepository)4 IOException (java.io.IOException)3 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)3 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)3 RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)3 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)2 IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)2 EditableRepository (org.apache.archiva.repository.EditableRepository)2