Search in sources :

Example 51 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class DefaultManagedRepositoryAdmin method deleteManagedRepository.

@Override
public Boolean deleteManagedRepository(String repositoryId, AuditInformation auditInformation, boolean deleteContent) throws RepositoryAdminException {
    Configuration config = getArchivaConfiguration().getConfiguration();
    ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById(repositoryId);
    if (repoConfig != null) {
        log.debug("Repo location " + repoConfig.getLocation());
        org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryId);
        org.apache.archiva.repository.ManagedRepository stagingRepository = null;
        if (repo != null) {
            try {
                if (repo.supportsFeature(StagingRepositoryFeature.class)) {
                    stagingRepository = repo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository();
                }
                repositoryRegistry.removeRepository(repo, config);
            } catch (RepositoryException e) {
                log.error("Removal of repository {} failed: {}", repositoryId, e.getMessage(), e);
                throw new RepositoryAdminException("Removal of repository " + repositoryId + " failed.");
            }
        } else {
            throw new RepositoryAdminException("A repository with that id does not exist");
        }
        triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation);
        if (repoConfig != null) {
            deleteManagedRepository(repoConfig, deleteContent, config, false);
        }
        // stage repo exists ?
        if (stagingRepository != null) {
            // do not trigger event when deleting the staged one
            ManagedRepositoryConfiguration stagingRepositoryConfig = config.findManagedRepositoryById(stagingRepository.getId());
            try {
                repositoryRegistry.removeRepository(stagingRepository);
                if (stagingRepositoryConfig != null) {
                    deleteManagedRepository(stagingRepositoryConfig, deleteContent, config, true);
                }
            } catch (RepositoryException e) {
                log.error("Removal of staging repository {} failed: {}", stagingRepository.getId(), e.getMessage(), e);
            }
        }
        try {
            saveConfiguration(config);
        } catch (Exception e) {
            throw new RepositoryAdminException("Error saving configuration for delete action" + e.getMessage(), e);
        }
        return Boolean.TRUE;
    } else {
        return Boolean.FALSE;
    }
}
Also used : 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) 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)

Example 52 with Configuration

use of org.apache.archiva.configuration.Configuration 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 53 with Configuration

use of org.apache.archiva.configuration.Configuration 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 54 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class DefaultProxyConnectorAdmin method addProxyConnector.

@Override
public Boolean addProxyConnector(ProxyConnector proxyConnector, AuditInformation auditInformation) throws RepositoryAdminException {
    if (getProxyConnector(proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId()) != null) {
        throw new RepositoryAdminException("Unable to add proxy connector, as one already exists with source repository id [" + proxyConnector.getSourceRepoId() + "] and target repository id [" + proxyConnector.getTargetRepoId() + "].");
    }
    validateProxyConnector(proxyConnector);
    proxyConnector.setBlackListPatterns(unescapePatterns(proxyConnector.getBlackListPatterns()));
    proxyConnector.setWhiteListPatterns(unescapePatterns(proxyConnector.getWhiteListPatterns()));
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    ProxyConnectorConfiguration proxyConnectorConfiguration = getProxyConnectorConfiguration(proxyConnector);
    configuration.addProxyConnector(proxyConnectorConfiguration);
    saveConfiguration(configuration);
    triggerAuditEvent(proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null, AuditEvent.ADD_PROXY_CONNECTOR, auditInformation);
    return Boolean.TRUE;
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 55 with Configuration

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

Aggregations

Configuration (org.apache.archiva.configuration.Configuration)63 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)30 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)29 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)21 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)19 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)16 NetworkConfiguration (org.apache.archiva.admin.model.beans.NetworkConfiguration)13 UiConfiguration (org.apache.archiva.admin.model.beans.UiConfiguration)13 WebappConfiguration (org.apache.archiva.configuration.WebappConfiguration)13 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)11 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)11 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)11 Before (org.junit.Before)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 Path (java.nio.file.Path)8 RepositoryException (org.apache.archiva.repository.RepositoryException)7 IOException (java.io.IOException)4 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)4