Search in sources :

Example 1 with RoleManagerException

use of org.apache.archiva.redback.role.RoleManagerException in project archiva by apache.

the class DefaultManagedRepositoryAdmin method deleteManagedRepository.

private Boolean deleteManagedRepository(ManagedRepositoryConfiguration repository, boolean deleteContent, Configuration config, boolean stagedOne) throws RepositoryAdminException {
    if (!stagedOne) {
        RepositorySession repositorySession = getRepositorySessionFactory().createSession();
        try {
            MetadataRepository metadataRepository = repositorySession.getRepository();
            metadataRepository.removeRepository(repository.getId());
            // invalidate cache
            namespacesCache.remove(repository.getId());
            log.debug("call repositoryStatisticsManager.deleteStatistics");
            getRepositoryStatisticsManager().deleteStatistics(metadataRepository, repository.getId());
            repositorySession.save();
        } catch (MetadataRepositoryException e) {
            // throw new RepositoryAdminException( e.getMessage(), e );
            log.warn("skip error during removing repository from MetadataRepository:{}", e.getMessage(), e);
        } finally {
            repositorySession.close();
        }
    }
    if (deleteContent) {
        // TODO could be async ? as directory can be huge
        Path dir = Paths.get(repository.getLocation());
        org.apache.archiva.common.utils.FileUtils.deleteQuietly(dir);
    }
    // olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
    List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(config.getProxyConnectors());
    for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) {
        if (StringUtils.equals(proxyConnector.getSourceRepoId(), repository.getId())) {
            config.removeProxyConnector(proxyConnector);
        }
    }
    Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
    if (repoToGroupMap != null) {
        if (repoToGroupMap.containsKey(repository.getId())) {
            List<String> repoGroups = repoToGroupMap.get(repository.getId());
            for (String repoGroup : repoGroups) {
                // copy to prevent UnsupportedOperationException
                RepositoryGroupConfiguration repositoryGroupConfiguration = config.findRepositoryGroupById(repoGroup);
                List<String> repos = new ArrayList<>(repositoryGroupConfiguration.getRepositories());
                config.removeRepositoryGroup(repositoryGroupConfiguration);
                repos.remove(repository.getId());
                repositoryGroupConfiguration.setRepositories(repos);
                config.addRepositoryGroup(repositoryGroupConfiguration);
            }
        }
    }
    try {
        removeRepositoryRoles(repository);
    } catch (RoleManagerException e) {
        throw new RepositoryAdminException("fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e);
    }
    try {
        final RepositoryRegistry reg = getRepositoryRegistry();
        if (reg.getManagedRepository(repository.getId()) != null) {
            reg.removeRepository(reg.getManagedRepository(repository.getId()));
        }
    } catch (RepositoryException e) {
        throw new RepositoryAdminException("Removal of repository " + repository.getId() + " failed: " + e.getMessage());
    }
    saveConfiguration(config);
    return Boolean.TRUE;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Path(java.nio.file.Path) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) List(java.util.List) ArrayList(java.util.ArrayList) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Example 2 with RoleManagerException

use of org.apache.archiva.redback.role.RoleManagerException in project archiva by apache.

the class DefaultManagedRepositoryAdmin method addManagedRepository.

@Override
public Boolean addManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation) throws RepositoryAdminException {
    log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
    getRepositoryCommonValidator().basicValidation(managedRepository, false);
    getRepositoryCommonValidator().validateManagedRepository(managedRepository);
    triggerAuditEvent(managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
    ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration(managedRepository);
    if (needStageRepo) {
        repoConfig.setStageRepoNeeded(true);
    }
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    try {
        org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository(repoConfig, configuration);
        log.debug("Added new repository {}", newRepo.getId());
        org.apache.archiva.repository.ManagedRepository stagingRepo = null;
        addRepositoryRoles(newRepo.getId());
        if (newRepo.supportsFeature(StagingRepositoryFeature.class)) {
            StagingRepositoryFeature stf = newRepo.getFeature(StagingRepositoryFeature.class).get();
            stagingRepo = stf.getStagingRepository();
            if (stf.isStageRepoNeeded() && stagingRepo != null) {
                addRepositoryRoles(stagingRepo.getId());
                triggerAuditEvent(stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
            }
        }
        saveConfiguration(configuration);
        // scan repository when adding of repository is successful
        try {
            if (newRepo.isScanned()) {
                scanRepository(newRepo.getId(), true);
            }
            if (stagingRepo != null && stagingRepo.isScanned()) {
                scanRepository(stagingRepo.getId(), true);
            }
        } catch (Exception e) {
            log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
        }
    } catch (RepositoryException e) {
        log.error("Could not add managed repository {}" + managedRepository);
        throw new RepositoryAdminException("Could not add repository " + e.getMessage());
    } catch (RoleManagerException e) {
        log.error("Could not add repository roles for repository [{}]: {}", managedRepository.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Could not add roles to repository " + e.getMessage());
    }
    return Boolean.TRUE;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) TaskQueueException(org.apache.archiva.redback.components.taskqueue.TaskQueueException) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryException(org.apache.archiva.repository.RepositoryException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) IOException(java.io.IOException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Example 3 with RoleManagerException

use of org.apache.archiva.redback.role.RoleManagerException 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)

Aggregations

RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)3 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)3 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)3 RoleManagerException (org.apache.archiva.redback.role.RoleManagerException)3 RepositoryException (org.apache.archiva.repository.RepositoryException)3 Configuration (org.apache.archiva.configuration.Configuration)2 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)2 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)2 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)2 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)2 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)1 TaskQueueException (org.apache.archiva.redback.components.taskqueue.TaskQueueException)1 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)1 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)1