Search in sources :

Example 6 with RegistryException

use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.

the class DefaultArchivaConfiguration method handleUpgradeConfiguration.

/**
 * Handle upgrade to newer version
 */
private void handleUpgradeConfiguration() throws RegistryException, IndeterminateConfigurationException {
    List<String> dbConsumers = Arrays.asList("update-db-artifact", "update-db-repository-metadata");
    // remove database consumers if here
    List<String> intersec = ListUtils.intersection(dbConsumers, configuration.getRepositoryScanning().getKnownContentConsumers());
    if (!intersec.isEmpty()) {
        List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers().size());
        for (String knowContentConsumer : configuration.getRepositoryScanning().getKnownContentConsumers()) {
            if (!dbConsumers.contains(knowContentConsumer)) {
                knowContentConsumers.add(knowContentConsumer);
            }
        }
        configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
    }
    // ensure create-archiva-metadata is here
    if (!configuration.getRepositoryScanning().getKnownContentConsumers().contains("create-archiva-metadata")) {
        List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers());
        knowContentConsumers.add("create-archiva-metadata");
        configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
    }
    // ensure duplicate-artifacts is here
    if (!configuration.getRepositoryScanning().getKnownContentConsumers().contains("duplicate-artifacts")) {
        List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers());
        knowContentConsumers.add("duplicate-artifacts");
        configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
    }
    Registry defaultOnlyConfiguration = readDefaultOnlyConfiguration();
    // Currently we check only for configuration version change, not certain version numbers.
    if (hasConfigVersionChanged(configuration, defaultOnlyConfiguration)) {
        updateCheckPathDefaults(configuration, defaultOnlyConfiguration);
        String newVersion = defaultOnlyConfiguration.getString("version");
        if (newVersion == null) {
            throw new IndeterminateConfigurationException("The default configuration has no version information!");
        }
        configuration.setVersion(newVersion);
        try {
            save(configuration);
        } catch (IndeterminateConfigurationException e) {
            log.error("Error occured during configuration update to new version: {}", e.getMessage());
        } catch (RegistryException e) {
            log.error("Error occured during configuration update to new version: {}", e.getMessage());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CommonsConfigurationRegistry(org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry) Registry(org.apache.archiva.components.registry.Registry) RegistryException(org.apache.archiva.components.registry.RegistryException)

Example 7 with RegistryException

use of org.apache.archiva.components.registry.RegistryException 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 8 with RegistryException

use of org.apache.archiva.components.registry.RegistryException 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 9 with RegistryException

use of org.apache.archiva.components.registry.RegistryException 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 RegistryException

use of org.apache.archiva.components.registry.RegistryException 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)10 Configuration (org.apache.archiva.configuration.model.Configuration)7 IndeterminateConfigurationException (org.apache.archiva.configuration.provider.IndeterminateConfigurationException)6 RepositoryException (org.apache.archiva.repository.RepositoryException)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)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 Registry (org.apache.archiva.components.registry.Registry)2 CommonsConfigurationRegistry (org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry)2 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)2 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)2 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)2 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)2 ArrayList (java.util.ArrayList)1 PostConstruct (javax.annotation.PostConstruct)1 ArchivaRuntimeConfiguration (org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration)1 FileLockConfiguration (org.apache.archiva.admin.model.beans.FileLockConfiguration)1