Search in sources :

Example 6 with IndeterminateConfigurationException

use of org.apache.archiva.configuration.provider.IndeterminateConfigurationException in project archiva by apache.

the class RemoteRepositoryHandler method put.

@Override
public RemoteRepository put(RemoteRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
    final String id = repositoryConfiguration.getId();
    final RepositoryType repositoryType = RepositoryType.valueOf(repositoryConfiguration.getType());
    final RepositoryProvider provider = getProvider(repositoryType);
    ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
    configLock.lock();
    RemoteRepository repo = null;
    RemoteRepository oldRepository = null;
    Configuration configuration = null;
    try {
        boolean updated = false;
        configuration = getConfigurationHandler().getBaseConfiguration();
        repo = getRepositories().get(id);
        oldRepository = repo == null ? null : clone(repo, id);
        if (repo == null) {
            repo = put(repositoryConfiguration, configuration);
        } else {
            setRepositoryDefaults(repositoryConfiguration);
            provider.updateRemoteInstance((EditableRemoteRepository) repo, repositoryConfiguration);
            updated = true;
            pushEvent(LifecycleEvent.UPDATED, repo);
        }
        registerNewRepository(repositoryConfiguration, repo, configuration, updated);
    } catch (IndeterminateConfigurationException | RegistryException e) {
        if (oldRepository != null) {
            RemoteRepositoryConfiguration oldCfg = provider.getRemoteConfiguration(oldRepository);
            provider.updateRemoteInstance((EditableRemoteRepository) repo, oldCfg);
            rollback(configuration, oldRepository, e, oldCfg);
        } else {
            getRepositories().remove(id);
        }
        log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(), e);
        throw new RepositoryException("Could not save the configuration for repository " + id + ": " + e.getMessage());
    } finally {
        configLock.unlock();
    }
    return repo;
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryType(org.apache.archiva.repository.RepositoryType) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RegistryException(org.apache.archiva.components.registry.RegistryException) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository)

Aggregations

RegistryException (org.apache.archiva.components.registry.RegistryException)6 Configuration (org.apache.archiva.configuration.model.Configuration)6 IndeterminateConfigurationException (org.apache.archiva.configuration.provider.IndeterminateConfigurationException)6 RepositoryException (org.apache.archiva.repository.RepositoryException)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 RepositoryProvider (org.apache.archiva.repository.RepositoryProvider)3 RepositoryType (org.apache.archiva.repository.RepositoryType)3 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 CacheConfiguration (org.apache.archiva.admin.model.beans.CacheConfiguration)2 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)2 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)2 ArchivaRuntimeConfiguration (org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration)1 FileLockConfiguration (org.apache.archiva.admin.model.beans.FileLockConfiguration)1 LdapConfiguration (org.apache.archiva.admin.model.beans.LdapConfiguration)1 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)1 AbstractRepositoryConfiguration (org.apache.archiva.configuration.model.AbstractRepositoryConfiguration)1 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)1 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)1 UserConfiguration (org.apache.archiva.redback.configuration.UserConfiguration)1