Search in sources :

Example 11 with RegistryException

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

the class DefaultManagedRepositoryAdmin method updateManagedRepository.

@Override
public Boolean updateManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation, boolean resetStats) throws RepositoryAdminException {
    log.debug("updateManagedConfiguration repo {} needStage {} resetStats {} ", managedRepository, needStageRepo, resetStats);
    // Ensure that the fields are valid.
    getRepositoryCommonValidator().basicValidation(managedRepository, true);
    getRepositoryCommonValidator().validateManagedRepository(managedRepository);
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration(managedRepository);
    updatedRepoConfig.setStageRepoNeeded(needStageRepo);
    org.apache.archiva.repository.ManagedRepository oldRepo = repositoryRegistry.getManagedRepository(managedRepository.getId());
    boolean stagingExists = false;
    if (oldRepo.supportsFeature(StagingRepositoryFeature.class)) {
        stagingExists = oldRepo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository() != null;
    }
    boolean updateIndexContext = !StringUtils.equals(updatedRepoConfig.getIndexDir(), managedRepository.getIndexDirectory());
    org.apache.archiva.repository.ManagedRepository newRepo;
    // TODO remove content from old if path has changed !!!!!
    try {
        newRepo = repositoryRegistry.putRepository(updatedRepoConfig, configuration);
        if (newRepo.supportsFeature(StagingRepositoryFeature.class)) {
            org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository();
            if (stagingRepo != null && !stagingExists) {
                triggerAuditEvent(stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
                addRepositoryRoles(stagingRepo.getId());
            }
        }
    } catch (RepositoryException e) {
        log.error("Could not update repository {}: {}", managedRepository.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
    } catch (RoleManagerException e) {
        log.error("Error during role update of stage repo {}", managedRepository.getId(), e);
        throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
    }
    triggerAuditEvent(managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO, auditInformation);
    try {
        getArchivaConfiguration().save(configuration);
    } catch (RegistryException | IndeterminateConfigurationException e) {
        log.error("Could not save repository configuration: {}", e.getMessage(), e);
        throw new RepositoryAdminException("Could not save repository configuration: " + e.getMessage());
    }
    // Save the repository configuration.
    RepositorySession repositorySession = getRepositorySessionFactory().createSession();
    try {
        if (resetStats) {
            log.debug("call repositoryStatisticsManager.deleteStatistics");
            getRepositoryStatisticsManager().deleteStatistics(repositorySession.getRepository(), managedRepository.getId());
            repositorySession.save();
        }
    } catch (MetadataRepositoryException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
    if (updateIndexContext) {
        try {
            repositoryRegistry.resetIndexingContext(newRepo);
        } catch (IndexUpdateFailedException e) {
            e.printStackTrace();
        }
    }
    return true;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Example 12 with RegistryException

use of org.apache.archiva.redback.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 : FileLockConfiguration(org.apache.archiva.admin.model.beans.FileLockConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ArchivaRuntimeConfiguration(org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration) Configuration(org.apache.archiva.configuration.Configuration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 13 with RegistryException

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

the class RepositoryRegistry method putRepository.

/**
 * Adds a remote repository, or overwrites the repository definition with the same id, if it exists already.
 * The modification is saved to the configuration immediately.
 *
 * @param remoteRepository the remote repository to add
 * @throws RepositoryException if an error occurs during configuration save
 */
public RemoteRepository putRepository(RemoteRepository remoteRepository) throws RepositoryException {
    rwLock.writeLock().lock();
    try {
        Configuration configuration = getArchivaConfiguration().getConfiguration();
        try {
            RemoteRepository repo = putRepository(remoteRepository, configuration);
            getArchivaConfiguration().save(configuration);
            return repo;
        } catch (RegistryException | IndeterminateConfigurationException e) {
            log.error("Error while saving remote repository {}", e.getMessage(), e);
            throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + 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)

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