Search in sources :

Example 1 with IndeterminateConfigurationException

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

the class DefaultRedbackRuntimeConfigurationAdmin method updateRedbackRuntimeConfiguration.

@Override
public void updateRedbackRuntimeConfiguration(RedbackRuntimeConfiguration redbackRuntimeConfiguration) throws RepositoryAdminException {
    org.apache.archiva.configuration.model.RedbackRuntimeConfiguration runtimeConfiguration = build(redbackRuntimeConfiguration);
    Configuration configuration = archivaConfiguration.getConfiguration();
    configuration.setRedbackRuntimeConfiguration(runtimeConfiguration);
    try {
        archivaConfiguration.save(configuration);
    } catch (RegistryException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    } catch (IndeterminateConfigurationException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) UserConfiguration(org.apache.archiva.redback.configuration.UserConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.components.registry.RegistryException)

Example 2 with IndeterminateConfigurationException

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

the class ManagedRepositoryHandler method put.

@Override
public ManagedRepository put(ManagedRepositoryConfiguration 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();
    ManagedRepository repo = null;
    ManagedRepository 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.updateManagedInstance((EditableManagedRepository) repo, repositoryConfiguration);
            updated = true;
            pushEvent(LifecycleEvent.UPDATED, repo);
        }
        registerNewRepository(repositoryConfiguration, repo, configuration, updated);
    } catch (IndeterminateConfigurationException | RegistryException e) {
        if (oldRepository != null) {
            ManagedRepositoryConfiguration oldCfg = provider.getManagedConfiguration(oldRepository);
            provider.updateManagedInstance((EditableManagedRepository) 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 : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) 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) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 3 with IndeterminateConfigurationException

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

the class AbstractRepositoryHandler method remove.

/**
 * Removes a repository group from the registry and configuration, if it exists.
 * The change is saved to the configuration immediately.
 *
 * @param id the id of the repository group to remove
 * @throws RepositoryException if an error occurs during configuration save
 */
@Override
public void remove(String id) throws RepositoryException {
    R repo = get(id);
    if (repo != null) {
        try {
            repo = getRepositories().remove(id);
            if (repo != null) {
                deactivateRepository(repo);
                Configuration configuration = this.configurationHandler.getBaseConfiguration();
                C cfg = findRepositoryConfiguration(configuration, id);
                if (cfg != null) {
                    removeRepositoryConfiguration(configuration, cfg);
                }
                this.configurationHandler.save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
                setLastState(repo, RepositoryState.UNREGISTERED);
            }
        } catch (RegistryException | IndeterminateConfigurationException e) {
            // Rollback
            log.error("Could not save config after repository removal: {}", e.getMessage(), e);
            getRepositories().put(repo.getId(), repo);
            throw new RepositoryException("Could not save configuration after repository removal: " + e.getMessage());
        }
    }
}
Also used : AbstractRepositoryConfiguration(org.apache.archiva.configuration.model.AbstractRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryException(org.apache.archiva.repository.RepositoryException) RegistryException(org.apache.archiva.components.registry.RegistryException)

Example 4 with IndeterminateConfigurationException

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

the class DefaultArchivaRuntimeConfigurationAdmin method updateArchivaRuntimeConfiguration.

@Override
public void updateArchivaRuntimeConfiguration(ArchivaRuntimeConfiguration archivaRuntimeConfiguration) throws RepositoryAdminException {
    Configuration configuration = archivaConfiguration.getConfiguration();
    configuration.setArchivaRuntimeConfiguration(build(archivaRuntimeConfiguration));
    try {
        archivaConfiguration.save(configuration);
    } catch (RegistryException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    } catch (IndeterminateConfigurationException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) FileLockConfiguration(org.apache.archiva.admin.model.beans.FileLockConfiguration) ArchivaRuntimeConfiguration(org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.components.registry.RegistryException)

Example 5 with IndeterminateConfigurationException

use of org.apache.archiva.configuration.provider.IndeterminateConfigurationException 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)

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