use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class PropagateErrorsDownloadPolicyTest method testPolicyIgnore.
@Test
public void testPolicyIgnore() throws Exception {
DownloadErrorPolicy policy = lookupPolicy();
StorageAsset localFile = getFile();
Properties request = createRequest();
Exception ex = new RuntimeException();
Map<String, Exception> exMap = new HashMap<>();
assertFalse(policy.applyPolicy(PropagateErrorsDownloadPolicy.IGNORE, request, localFile, ex, exMap));
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class SnapshotsPolicyTest method assertSnapshotPolicy.
private void assertSnapshotPolicy(PolicyOption setting, String path, boolean createLocalFile) throws Exception {
PreDownloadPolicy policy = lookupPolicy();
Properties request = new Properties();
request.setProperty("filetype", path.endsWith("/maven-metadata.xml") ? "metadata" : "artifact");
if (path.contains("1.0-SNAPSHOT")) {
request.setProperty("version", "1.0-SNAPSHOT");
}
if (path.contains("2.0")) {
request.setProperty("version", "2.0");
}
StorageAsset targetDir = ChecksumPolicyTest.getTestFile("target/test-policy/");
StorageAsset localFile = targetDir.resolve(path);
Files.deleteIfExists(localFile.getFilePath());
if (createLocalFile) {
Files.createDirectories(localFile.getParent().getFilePath());
org.apache.archiva.common.utils.FileUtils.writeStringToFile(localFile.getFilePath(), FILE_ENCODING, "random-junk");
Files.setLastModifiedTime(localFile.getFilePath(), FileTime.fromMillis(Files.getLastModifiedTime(localFile.getFilePath()).toMillis() - generatedLocalFileUpdateDelta));
}
policy.applyPolicy(setting, request, localFile);
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class DefaultRepositoryProxyHandler method fetchMetadataFromProxies.
@Override
public ProxyFetchResult fetchMetadataFromProxies(ManagedRepository repository, String rawLogicalPath) {
String logicalPath;
if (rawLogicalPath.startsWith("/")) {
logicalPath = rawLogicalPath.substring(1);
} else {
logicalPath = rawLogicalPath;
}
StorageAsset localFile = repository.getAsset(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.isEnabled()) {
continue;
}
RemoteRepository targetRepository = connector.getTargetRepository();
StorageAsset localRepoFile = toLocalRepoFile(repository, targetRepository.getContent(), 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.getId(), e);
} catch (NotModifiedException e) {
log.debug("Metadata {} not updated on remote repository '{}'.", logicalPath, targetRepository.getId(), e);
} catch (ProxyException e) {
log.warn("Transfer error from repository {} for versioned Metadata {}, continuing to next repository. Error message: {}", targetRepository.getId(), logicalPath, e.getMessage());
log.debug("Full stack trace", e);
}
}
if (hasBeenUpdated(localFile, originalTimestamp)) {
metadataNeedsUpdating = true;
}
if (metadataNeedsUpdating || !localFile.exists()) {
try {
metadataTools.updateMetadata(repository.getContent(), logicalPath);
} catch (RepositoryMetadataException e) {
log.warn("Unable to update metadata {}:{}", localFile.getPath(), e.getMessage(), e);
}
}
if (fileExists(localFile)) {
return new ProxyFetchResult(localFile, metadataNeedsUpdating);
}
return new ProxyFetchResult(null, false);
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class DefaultRepositoryProxyHandler method fetchFromProxies.
@Override
public StorageAsset fetchFromProxies(ManagedRepository repository, String path) {
StorageAsset localFile = repository.getAsset(path);
// no update policies for these paths
if (localFile.exists()) {
return null;
}
Properties requestProperties = new Properties();
requestProperties.setProperty("filetype", "resource");
requestProperties.setProperty("managedRepositoryId", repository.getId());
List<ProxyConnector> connectors = getProxyConnectors(repository);
for (ProxyConnector connector : connectors) {
if (!connector.isEnabled()) {
continue;
}
RemoteRepository targetRepository = connector.getTargetRepository();
requestProperties.setProperty("remoteRepositoryId", targetRepository.getId());
String targetPath = path;
try {
StorageAsset downloadedFile = transferFile(connector, targetRepository, targetPath, repository, localFile, requestProperties, false);
if (fileExists(downloadedFile)) {
log.debug("Successfully transferred: {}", downloadedFile.getPath());
return downloadedFile;
}
} catch (NotFoundException e) {
log.debug("Resource {} not found on repository \"{}\".", path, targetRepository.getId());
} catch (NotModifiedException e) {
log.debug("Resource {} not updated on repository \"{}\".", path, targetRepository.getId());
} catch (ProxyException e) {
log.warn("Transfer error from repository {} for resource {}, continuing to next repository. Error message: {}", targetRepository.getId(), path, e.getMessage());
log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Transfer error from repository \"{}" + "\" for resource {}, continuing to next repository. Error message: {}", targetRepository.getId(), path, e.getMessage(), e);
}
}
log.debug("Exhausted all target repositories, resource {} not found.", path);
return null;
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class PropagateErrorsOnUpdateDownloadPolicyTest method testPolicyQueue.
@Test
public void testPolicyQueue() throws Exception {
DownloadErrorPolicy policy = lookupPolicy();
StorageAsset localFile = getFile();
Properties request = createRequest();
Exception ex = new RuntimeException();
Map<String, Exception> exMap = new HashMap<>();
if (localFile.exists()) {
localFile.getStorage().removeAsset(localFile);
}
assertTrue(policy.applyPolicy(PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT, request, localFile, ex, exMap));
localFile.create();
assertFalse(policy.applyPolicy(PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT, request, localFile, ex, exMap));
}
Aggregations