Search in sources :

Example 6 with RegistryException

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

the class RepositoryRegistry method putRepository.

/**
 * Adds a new repository or updates the repository with the same id, if it exists already.
 * The configuration is saved immediately.
 *
 * @param remoteRepositoryConfiguration the repository configuration
 * @return the updated or created repository
 * @throws RepositoryException if an error occurs, or the configuration is not valid.
 */
public RemoteRepository putRepository(RemoteRepositoryConfiguration remoteRepositoryConfiguration) throws RepositoryException {
    rwLock.writeLock().lock();
    try {
        final String id = remoteRepositoryConfiguration.getId();
        final RepositoryType repositoryType = RepositoryType.valueOf(remoteRepositoryConfiguration.getType());
        Configuration configuration = getArchivaConfiguration().getConfiguration();
        RemoteRepository repo = remoteRepositories.get(id);
        RemoteRepositoryConfiguration oldCfg = repo != null ? getProvider(repositoryType).getRemoteConfiguration(repo) : null;
        repo = putRepository(remoteRepositoryConfiguration, configuration);
        try {
            getArchivaConfiguration().save(configuration);
        } catch (IndeterminateConfigurationException | RegistryException e) {
            if (oldCfg != null) {
                getProvider(repositoryType).updateRemoteInstance((EditableRemoteRepository) repo, oldCfg);
            }
            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());
        }
        return repo;
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 7 with RegistryException

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

the class RepositoryRegistry method removeRepository.

/**
 * Removes the remote repository from the registry and configuration.
 * The change is saved to the configuration immediately.
 *
 * @param remoteRepository the remote repository to remove
 * @throws RepositoryException if a error occurs during configuration save
 */
public void removeRepository(RemoteRepository remoteRepository) throws RepositoryException {
    final String id = remoteRepository.getId();
    RemoteRepository repo = getRemoteRepository(id);
    if (repo != null) {
        rwLock.writeLock().lock();
        try {
            repo = remoteRepositories.remove(id);
            if (repo != null) {
                Configuration configuration = getArchivaConfiguration().getConfiguration();
                doRemoveRepo(repo, configuration);
                getArchivaConfiguration().save(configuration);
            }
        } catch (RegistryException | IndeterminateConfigurationException e) {
            // Rollback
            log.error("Could not save config after repository removal: {}", e.getMessage(), e);
            remoteRepositories.put(repo.getId(), repo);
            throw new RepositoryException("Could not save configuration after repository removal: " + e.getMessage());
        } finally {
            rwLock.writeLock().unlock();
        }
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 8 with RegistryException

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

the class RepositoryRegistry method removeRepository.

/**
 * Removes a managed repository from the registry and configuration, if it exists.
 * The change is saved to the configuration immediately.
 *
 * @param managedRepository the managed repository to remove
 * @throws RepositoryException if a error occurs during configuration save
 */
public void removeRepository(ManagedRepository managedRepository) throws RepositoryException {
    final String id = managedRepository.getId();
    ManagedRepository repo = getManagedRepository(id);
    if (repo != null) {
        rwLock.writeLock().lock();
        try {
            repo = managedRepositories.remove(id);
            if (repo != null) {
                repo.close();
                Configuration configuration = getArchivaConfiguration().getConfiguration();
                ManagedRepositoryConfiguration cfg = configuration.findManagedRepositoryById(id);
                if (cfg != null) {
                    configuration.removeManagedRepository(cfg);
                }
                getArchivaConfiguration().save(configuration);
            }
        } catch (RegistryException | IndeterminateConfigurationException e) {
            // Rollback
            log.error("Could not save config after repository removal: {}", e.getMessage(), e);
            managedRepositories.put(repo.getId(), repo);
            throw new RepositoryException("Could not save configuration after repository removal: " + e.getMessage());
        } finally {
            rwLock.writeLock().unlock();
        }
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 9 with RegistryException

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

the class FileTypes method initialize.

@PostConstruct
public void initialize() {
    // TODO: why is this done by hand?
    // TODO: ideally, this would be instantiated by configuration instead, and not need to be a component
    String errMsg = "Unable to load default archiva configuration for FileTypes: ";
    try {
        CommonsConfigurationRegistry commonsRegistry = new CommonsConfigurationRegistry();
        // Configure commonsRegistry
        Field fld = commonsRegistry.getClass().getDeclaredField("configuration");
        fld.setAccessible(true);
        fld.set(commonsRegistry, new CombinedConfiguration());
        commonsRegistry.addConfigurationFromResource("org/apache/archiva/configuration/default-archiva.xml");
        // Read configuration as it was intended.
        ConfigurationRegistryReader configReader = new ConfigurationRegistryReader();
        Configuration defaultConfig = configReader.read(commonsRegistry);
        initialiseTypeMap(defaultConfig);
    } catch (RegistryException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    } catch (SecurityException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    }
    this.archivaConfiguration.addChangeListener(this);
}
Also used : Field(java.lang.reflect.Field) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) CommonsConfigurationRegistry(org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry) ConfigurationRegistryReader(org.apache.archiva.configuration.io.registry.ConfigurationRegistryReader) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) PostConstruct(javax.annotation.PostConstruct)

Example 10 with RegistryException

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

the class ArchivaConfigurationTest method testLoadConfigurationFromInvalidBothLocationsOnDisk.

@Test
public void testLoadConfigurationFromInvalidBothLocationsOnDisk() throws Exception {
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-not-allowed-to-write-to-both");
    Configuration config = archivaConfiguration.getConfiguration();
    try {
        archivaConfiguration.save(config);
        fail("Should have thrown a RegistryException because the configuration can't be saved.");
    } catch (RegistryException e) {
    /* expected exception */
    }
}
Also used : ContextConfiguration(org.springframework.test.context.ContextConfiguration) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) Test(org.junit.Test)

Aggregations

RegistryException (org.apache.archiva.redback.components.registry.RegistryException)13 Configuration (org.apache.archiva.configuration.Configuration)8 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)8 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)7 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)6 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)6 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)5 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 CommonsConfigurationRegistry (org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry)3 PostConstruct (javax.annotation.PostConstruct)2 CacheConfiguration (org.apache.archiva.admin.model.beans.CacheConfiguration)2 Registry (org.apache.archiva.redback.components.registry.Registry)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 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 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)1 ConfigurationRegistryReader (org.apache.archiva.configuration.io.registry.ConfigurationRegistryReader)1