use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.
the class AbstractProxyTestCase method saveConnector.
protected void saveConnector(String sourceRepoId, String targetRepoId, PolicyOption checksumPolicy, PolicyOption releasePolicy, PolicyOption snapshotPolicy, PolicyOption cacheFailuresPolicy, PolicyOption errorPolicy, PolicyOption errorOnUpdatePolicy, boolean disabled) {
ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
connectorConfig.setSourceRepoId(sourceRepoId);
connectorConfig.setTargetRepoId(targetRepoId);
connectorConfig.setProxyId(sourceRepoId);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_CHECKSUM, checksumPolicy.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_RELEASES, releasePolicy.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotPolicy.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, cacheFailuresPolicy.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS, errorPolicy.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS_ON_UPDATE, errorOnUpdatePolicy.getId());
connectorConfig.setDisabled(disabled);
int count = config.getConfiguration().getProxyConnectors().size();
config.getConfiguration().addProxyConnector(connectorConfig);
// Proper Triggering ...
String prefix = "proxyConnectors.proxyConnector(" + count + ")";
config.triggerChange(prefix + ".sourceRepoId", connectorConfig.getSourceRepoId());
config.triggerChange(prefix + ".targetRepoId", connectorConfig.getTargetRepoId());
config.triggerChange(prefix + ".proxyId", connectorConfig.getProxyId());
config.triggerChange(prefix + ".policies.releases", connectorConfig.getPolicy("releases", ""));
config.triggerChange(prefix + ".policies.checksum", connectorConfig.getPolicy("checksum", ""));
config.triggerChange(prefix + ".policies.snapshots", connectorConfig.getPolicy("snapshots", ""));
config.triggerChange(prefix + ".policies.cache-failures", connectorConfig.getPolicy("cache-failures", ""));
config.triggerChange(prefix + ".policies.propagate-errors", connectorConfig.getPolicy("propagate-errors", ""));
config.triggerChange(prefix + ".policies.propagate-errors-on-update", connectorConfig.getPolicy("propagate-errors-on-update", ""));
}
use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.
the class HttpProxyTransferTest method addConnector.
private void addConnector() {
ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
connectorConfig.setProxyId(PROXY_ID);
connectorConfig.setSourceRepoId(MANAGED_ID);
connectorConfig.setTargetRepoId(PROXIED_ID);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_CHECKSUM, ChecksumPolicy.FIX.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ONCE.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.ONCE.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, CachedFailuresPolicy.NO.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS, PropagateErrorsDownloadPolicy.QUEUE.getId());
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS_ON_UPDATE, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT.getId());
int count = config.getConfiguration().getProxyConnectors().size();
config.getConfiguration().addProxyConnector(connectorConfig);
// Proper Triggering ...
String prefix = "proxyConnectors.proxyConnector(" + count + ")";
((MockConfiguration) config).triggerChange(prefix + ".sourceRepoId", connectorConfig.getSourceRepoId());
}
use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.
the class RepositoryServletProxiedPluginSnapshotPolicyTest method assertGetProxiedSnapshotsArtifactWithPolicy.
private void assertGetProxiedSnapshotsArtifactWithPolicy(int expectation, PolicyOption snapshotsPolicy, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp) throws Exception {
// --- Setup
setupSnapshotsRemoteRepo();
setupCleanInternalRepo();
saveConfiguration();
String resourcePath = "org/apache/archiva/archivatest-maven-plugin/4.0-alpha-1-SNAPSHOT/archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42.jar";
String expectedRemoteContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-remote-contents";
String expectedManagedContents = null;
Path remoteFile = populateRepo(remoteSnapshots, resourcePath, expectedRemoteContents);
if (hasManagedCopy) {
expectedManagedContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-managed-contents";
Path managedFile = populateRepo(repoRootInternal, resourcePath, expectedManagedContents);
Files.setLastModifiedTime(managedFile, FileTime.fromMillis(Files.getLastModifiedTime(remoteFile).toMillis() + deltaManagedToRemoteTimestamp));
}
archivaConfiguration.getConfiguration().setProxyConnectors(new ArrayList<ProxyConnectorConfiguration>(0));
setupSnapshotConnector(REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy);
saveConfiguration();
// --- Execution
// process the response code later, not via an exception.
// HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/" + resourcePath);
WebResponse response = getServletUnitClient().getResponse(request);
switch(expectation) {
case EXPECT_MANAGED_CONTENTS:
assertResponseOK(response);
assertTrue("Invalid Test Case: Can't expect managed contents with " + "test that doesn't have a managed copy in the first place.", hasManagedCopy);
assertEquals("Expected managed file contents", expectedManagedContents, response.getContentAsString());
break;
case EXPECT_REMOTE_CONTENTS:
assertResponseOK(response);
assertEquals("Expected remote file contents", expectedRemoteContents, response.getContentAsString());
break;
case EXPECT_NOT_FOUND:
assertResponseNotFound(response);
assertManagedFileNotExists(repoRootInternal, resourcePath);
break;
}
}
use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.
the class ArchivaConfigurationTest method testRemoveLastElements.
@Test
public void testRemoveLastElements() throws Exception {
Path baseFile = getTestFile("target/test/test-file.xml");
Files.deleteIfExists(baseFile);
assertFalse(Files.exists(baseFile));
Path userFile = getTestFile("target/test/test-file-user.xml");
Files.deleteIfExists(userFile);
assertFalse(Files.exists(userFile));
Files.createDirectories(baseFile.getParent());
FileUtils.copyFile(getTestFile("src/test/conf/conf-single-list-elements.xml").toFile(), baseFile.toFile());
Files.createDirectories(userFile.getParent());
FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-remove-central");
archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get(0);
assertNotNull(repositoryGroup);
configuration.removeRepositoryGroup(repositoryGroup);
assertTrue(configuration.getRepositoryGroups().isEmpty());
RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("central");
assertNotNull(repository);
configuration.removeRemoteRepository(repository);
assertTrue(configuration.getRemoteRepositories().isEmpty());
ManagedRepositoryConfiguration managedRepository = configuration.getManagedRepositoriesAsMap().get("snapshots");
assertNotNull(managedRepository);
configuration.removeManagedRepository(managedRepository);
assertTrue(configuration.getManagedRepositories().isEmpty());
ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get(0);
assertNotNull(proxyConnector);
configuration.removeProxyConnector(proxyConnector);
assertTrue(configuration.getProxyConnectors().isEmpty());
NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get("proxy");
assertNotNull(networkProxy);
configuration.removeNetworkProxy(networkProxy);
assertTrue(configuration.getNetworkProxies().isEmpty());
LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get(0);
assertNotNull(path);
configuration.removeLegacyArtifactPath(path);
assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
String consumer = scanning.getKnownContentConsumers().get(0);
assertNotNull(consumer);
scanning.removeKnownContentConsumer(consumer);
// default values
assertFalse(scanning.getKnownContentConsumers().isEmpty());
consumer = scanning.getInvalidContentConsumers().get(0);
assertNotNull(consumer);
scanning.removeInvalidContentConsumer(consumer);
assertTrue(scanning.getInvalidContentConsumers().isEmpty());
archivaConfiguration.save(configuration);
archivaConfiguration = lookup(ArchivaConfiguration.class, "test-read-saved");
configuration = archivaConfiguration.getConfiguration();
assertNull(configuration.getRemoteRepositoriesAsMap().get("central"));
assertTrue(configuration.getRepositoryGroups().isEmpty());
assertNull(configuration.getManagedRepositoriesAsMap().get("snapshots"));
assertTrue(configuration.getProxyConnectors().isEmpty());
assertNull(configuration.getNetworkProxiesAsMap().get("proxy"));
assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
scanning = configuration.getRepositoryScanning();
assertFalse(scanning.getKnownContentConsumers().isEmpty());
assertTrue(scanning.getInvalidContentConsumers().isEmpty());
}
use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration 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) {
boolean success = false;
try (RepositorySession repositorySession = getRepositorySessionFactory().createSession()) {
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeRepository(repositorySession, repository.getId());
// invalidate cache
namespacesCache.remove(repository.getId());
repositorySession.save();
success = true;
} catch (MetadataRepositoryException e) {
// throw new RepositoryAdminException( e.getMessage(), e );
log.warn("skip error during removing repository from MetadataRepository:{}", e.getMessage(), e);
success = false;
} catch (MetadataSessionException e) {
log.warn("skip error during removing repository from MetadataRepository:{}", e.getMessage(), e);
success = false;
}
if (success) {
log.debug("call repositoryStatisticsManager.deleteStatistics");
try {
getRepositoryStatisticsManager().deleteStatistics(repository.getId());
} catch (MetadataRepositoryException e) {
e.printStackTrace();
}
}
}
// 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);
}
}
try {
removeRepositoryRoles(repository);
} catch (RoleManagerException e) {
throw new RepositoryAdminException("fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e);
}
try {
org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository(repository.getId());
if (repo != null) {
repositoryRegistry.removeRepository(repo, config);
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);
}
}
} catch (RepositoryException e) {
throw new RepositoryAdminException("Removal of repository " + repository.getId() + " failed: " + e.getMessage());
}
saveConfiguration(config);
return Boolean.TRUE;
}
Aggregations