Search in sources :

Example 26 with RepositoryException

use of org.apache.archiva.repository.RepositoryException 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 27 with RepositoryException

use of org.apache.archiva.repository.RepositoryException 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 28 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class RepositoryProviderMock method updateRemoteInstance.

@SuppressWarnings("unchecked")
@Override
public void updateRemoteInstance(EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration) throws RepositoryException {
    try {
        remoteRepository.setName(remoteRepository.getPrimaryLocale(), configuration.getName());
        remoteRepository.setBaseUri(new URI(""));
        remoteRepository.setDescription(remoteRepository.getPrimaryLocale(), configuration.getDescription());
        remoteRepository.setLayout(configuration.getLayout());
        remoteRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
        remoteRepository.setCheckPath(configuration.getCheckPath());
        remoteRepository.setExtraHeaders(configuration.getExtraHeaders());
        remoteRepository.setExtraParameters(configuration.getExtraParameters());
        remoteRepository.setTimeout(Duration.ofSeconds(configuration.getTimeout()));
        char[] pwd = configuration.getPassword() == null ? "".toCharArray() : configuration.getPassword().toCharArray();
        remoteRepository.setCredentials(new PasswordCredentials(configuration.getUsername(), pwd));
        remoteRepository.setLocation(new URI(configuration.getUrl() == null ? "" : configuration.getUrl()));
        RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
        rif.setDownloadRemoteIndexOnStartup(configuration.isDownloadRemoteIndexOnStartup());
        rif.setDownloadRemoteIndex(configuration.isDownloadRemoteIndex());
        rif.setIndexUri(new URI(configuration.getIndexDir()));
        rif.setDownloadTimeout(Duration.ofSeconds(configuration.getRemoteDownloadTimeout()));
        rif.setProxyId(configuration.getRemoteDownloadNetworkProxyId());
    } catch (Exception e) {
        throw new RepositoryException("Error", e);
    }
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) URI(java.net.URI) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 29 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class MavenRepositoryProvider method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
    if (!(remoteRepository instanceof MavenRemoteRepository)) {
        log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
        throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
    }
    RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
    cfg.setType(remoteRepository.getType().toString());
    cfg.setId(remoteRepository.getId());
    cfg.setName(remoteRepository.getName());
    cfg.setDescription(remoteRepository.getDescription());
    cfg.setUrl(remoteRepository.getLocation().toString());
    cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
    cfg.setCheckPath(remoteRepository.getCheckPath());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        if (creds instanceof PasswordCredentials) {
            PasswordCredentials pCreds = (PasswordCredentials) creds;
            cfg.setPassword(new String(pCreds.getPassword()));
            cfg.setUsername(pCreds.getUsername());
        }
    }
    cfg.setLayout(remoteRepository.getLayout());
    cfg.setExtraParameters(remoteRepository.getExtraParameters());
    cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
    cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get();
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
    cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
    cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
    cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
    cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
    cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
    return cfg;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 30 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class MavenRepositoryProvider method updateRemoteInstance.

@Override
public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
    setBaseConfig(repo, cfg);
    repo.setCheckPath(cfg.getCheckPath());
    repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
    try {
        repo.setLocation(new URI(cfg.getUrl()));
    } catch (UnsupportedURIException | URISyntaxException e) {
        log.error("Could not set remote url " + cfg.getUrl());
        throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl());
    }
    repo.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
    RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
    remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
    remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
    remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
    remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
    if (cfg.isDownloadRemoteIndex()) {
        try {
            remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl()));
        } catch (URISyntaxException e) {
            log.error("Could not set remote index url " + cfg.getRemoteIndexUrl());
            remoteIndexFeature.setDownloadRemoteIndex(false);
            remoteIndexFeature.setDownloadRemoteIndexOnStartup(false);
        }
    }
    for (Object key : cfg.getExtraHeaders().keySet()) {
        repo.addExtraHeader(key.toString(), cfg.getExtraHeaders().get(key).toString());
    }
    for (Object key : cfg.getExtraParameters().keySet()) {
        repo.addExtraParameter(key.toString(), cfg.getExtraParameters().get(key).toString());
    }
    PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
    if (cfg.getPassword() != null && cfg.getUsername() != null) {
        credentials.setPassword(cfg.getPassword().toCharArray());
        credentials.setUsername(cfg.getUsername());
        repo.setCredentials(credentials);
    } else {
        credentials.setPassword(new char[0]);
    }
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    if (cfg.getIndexDir() != null) {
        indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
    }
    if (cfg.getPackedIndexDir() != null) {
        indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
    }
    log.debug("Updated remote instance {}", repo);
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedURIException(org.apache.archiva.repository.UnsupportedURIException) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

RepositoryException (org.apache.archiva.repository.RepositoryException)33 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)14 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)13 Path (java.nio.file.Path)12 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)12 IOException (java.io.IOException)11 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)11 Configuration (org.apache.archiva.configuration.Configuration)7 ArtifactReference (org.apache.archiva.model.ArtifactReference)7 URI (java.net.URI)6 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)6 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)6 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)6 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)6 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)6 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)5 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)5 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)4 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)4