Search in sources :

Example 1 with ProxyFetchResult

use of org.apache.archiva.proxy.model.ProxyFetchResult in project archiva by apache.

the class DefaultRepositoryProxyConnectors method fetchMetadataFromProxies.

@Override
public ProxyFetchResult fetchMetadataFromProxies(ManagedRepositoryContent repository, String logicalPath) {
    Path localFile = Paths.get(repository.getRepoRoot(), logicalPath);
    Properties requestProperties = new Properties();
    requestProperties.setProperty("filetype", "metadata");
    boolean metadataNeedsUpdating = false;
    long originalTimestamp = getLastModified(localFile);
    List<ProxyConnector> connectors = new ArrayList<>(getProxyConnectors(repository));
    for (ProxyConnector connector : connectors) {
        if (connector.isDisabled()) {
            continue;
        }
        RemoteRepositoryContent targetRepository = connector.getTargetRepository();
        Path localRepoFile = toLocalRepoFile(repository, targetRepository, logicalPath);
        long originalMetadataTimestamp = getLastModified(localRepoFile);
        try {
            transferFile(connector, targetRepository, logicalPath, repository, localRepoFile, requestProperties, true);
            if (hasBeenUpdated(localRepoFile, originalMetadataTimestamp)) {
                metadataNeedsUpdating = true;
            }
        } catch (NotFoundException e) {
            log.debug("Metadata {} not found on remote repository '{}'.", logicalPath, targetRepository.getRepository().getId(), e);
        } catch (NotModifiedException e) {
            log.debug("Metadata {} not updated on remote repository '{}'.", logicalPath, targetRepository.getRepository().getId(), e);
        } catch (ProxyException | RepositoryAdminException e) {
            log.warn("Transfer error from repository {} for versioned Metadata {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), logicalPath, e.getMessage());
            log.debug("Full stack trace", e);
        }
    }
    if (hasBeenUpdated(localFile, originalTimestamp)) {
        metadataNeedsUpdating = true;
    }
    if (metadataNeedsUpdating || !Files.exists(localFile)) {
        try {
            metadataTools.updateMetadata(repository, logicalPath);
        } catch (RepositoryMetadataException e) {
            log.warn("Unable to update metadata {}:{}", localFile.toAbsolutePath(), e.getMessage(), e);
        }
    }
    if (fileExists(localFile)) {
        return new ProxyFetchResult(localFile, metadataNeedsUpdating);
    }
    return new ProxyFetchResult(null, false);
}
Also used : Path(java.nio.file.Path) ProxyFetchResult(org.apache.archiva.proxy.model.ProxyFetchResult) ArrayList(java.util.ArrayList) Properties(java.util.Properties) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) RemoteRepositoryContent(org.apache.archiva.repository.RemoteRepositoryContent) ProxyConnector(org.apache.archiva.proxy.model.ProxyConnector)

Aggregations

Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 ProxyConnector (org.apache.archiva.proxy.model.ProxyConnector)1 ProxyFetchResult (org.apache.archiva.proxy.model.ProxyFetchResult)1 RemoteRepositoryContent (org.apache.archiva.repository.RemoteRepositoryContent)1 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)1