Fixing proxy connector handling

This commit is contained in:
Martin Stockhammer 2019-09-12 13:10:22 +02:00
parent 9948797e50
commit d9d8796665
6 changed files with 36 additions and 13 deletions

View File

@ -27,6 +27,9 @@ import org.apache.archiva.proxy.model.NetworkProxy;
import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.repository.*;
import org.apache.archiva.repository.events.Event;
import org.apache.archiva.repository.events.RepositoryEventListener;
import org.apache.archiva.repository.events.RepositoryRegistryEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@ -44,7 +47,7 @@ import java.util.stream.Collectors;
*/
@SuppressWarnings( "SpringJavaInjectionPointsAutowiringInspection" )
@Service("proxyRegistry#default")
public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListener {
public class ArchivaProxyRegistry implements ProxyRegistry, RepositoryEventListener {
private static final Logger log = LoggerFactory.getLogger(ArchivaProxyRegistry.class);
@ -74,10 +77,10 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
if (repositoryProxyHandlers == null) {
repositoryProxyHandlers = new ArrayList<>();
}
archivaConfiguration.addListener( this );
updateHandler();
updateConnectors();
updateNetworkProxies();
repositoryRegistry.register(this, RepositoryRegistryEvent.RegistryEventType.RELOADED);
}
private ArchivaConfiguration getArchivaConfiguration() {
@ -125,7 +128,9 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
getArchivaConfiguration().getConfiguration().getProxyConnectors();
connectorList = proxyConnectorConfigurations.stream()
.map(configuration -> buildProxyConnector(configuration))
.map(this::buildProxyConnector)
.filter(Optional::isPresent)
.map(Optional::get)
.sorted(comparator).collect(Collectors.toList());
connectorMap = connectorList.stream().collect(Collectors.groupingBy(a -> a.getSourceRepository().getId()));
for (RepositoryProxyHandler handler : repositoryProxyHandlers) {
@ -139,7 +144,7 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
return policies.stream().collect( Collectors.toMap( Function.identity(), p -> PolicyUtil.findOption( policyConfig.get(p.getId()), p ) ) );
}
private ProxyConnector buildProxyConnector(ProxyConnectorConfiguration configuration) {
private Optional<ProxyConnector> buildProxyConnector(ProxyConnectorConfiguration configuration) {
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setOrder(configuration.getOrder());
proxyConnector.setBlacklist(configuration.getBlackListPatterns());
@ -153,10 +158,16 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
proxyConnector.setProperties(configuration.getProperties());
proxyConnector.setProxyId(configuration.getProxyId());
ManagedRepository srcRepo = repositoryRegistry.getManagedRepository(configuration.getSourceRepoId());
if (srcRepo==null) {
return Optional.empty();
}
proxyConnector.setSourceRepository(srcRepo);
RemoteRepository targetRepo = repositoryRegistry.getRemoteRepository(configuration.getTargetRepoId());
if (targetRepo==null) {
return Optional.empty();
}
proxyConnector.setTargetRepository(targetRepo);
return proxyConnector;
return Optional.of(proxyConnector);
}
@Override
@ -183,11 +194,6 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
return this.handlerMap.containsKey(type);
}
@Override
public void configurationEvent(ConfigurationEvent event) {
log.debug("Config changed updating proxy list");
init( );
}
@Override
public List<ProxyConnector> getProxyConnectors() {
@ -205,4 +211,12 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
{
init();
}
@Override
public void raise(Event event) {
log.debug("Reload happened, updating proxy list");
if (event.getType()== RepositoryRegistryEvent.RegistryEventType.RELOADED) {
init();
}
}
}

View File

@ -316,7 +316,6 @@ public class ManagedRepositoryAdminTest
managedRepositoryAdmin.updateManagedRepository( repo, true, getFakeAuditInformation(), false );
repo = managedRepositoryAdmin.getManagedRepository( repoId );
System.err.println("REPOSITORY "+repo.getLocation());
assertNotNull( repo );
assertEquals( newName, repo.getName() );
assertEquals( Paths.get( repoLocation ).toAbsolutePath(), Paths.get( repo.getLocation() ).toAbsolutePath() );

View File

@ -219,6 +219,8 @@ public class HttpProxyTransferTest
// Configure Connector (usually done within archiva.xml configuration)
addConnector();
managedDefaultRepository = repositoryRegistry.getManagedRepository(MANAGED_ID).getContent();
Path expectedFile = Paths.get( managedDefaultRepository.getRepoRoot() ).resolve( path );
Files.deleteIfExists( expectedFile );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );

View File

@ -19,6 +19,7 @@ package org.apache.archiva.dependency.tree.maven2;
*/
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
import org.eclipse.aether.internal.impl.DefaultRepositoryLayoutProvider;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -49,6 +50,7 @@ public class ArchivaRepositoryConnectorFactory
public ArchivaRepositoryConnectorFactory()
{
// no op but empty constructor needed by aether
delegate.setRepositoryLayoutProvider(new DefaultRepositoryLayoutProvider());
}
@Override

View File

@ -22,6 +22,8 @@ package org.apache.archiva.repository.maven2;
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.configuration.*;
import org.apache.archiva.repository.*;
import org.apache.archiva.repository.events.Event;
import org.apache.archiva.repository.events.RepositoryValueEvent;
import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
import org.apache.archiva.repository.features.IndexCreationFeature;
@ -347,7 +349,9 @@ public class MavenRepositoryProvider implements RepositoryProvider {
cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
if (remoteIndexFeature.getIndexUri()!=null) {
cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
}
cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
@ -495,7 +499,7 @@ public class MavenRepositoryProvider implements RepositoryProvider {
}
@Override
public <T> void raise(RepositoryEvent<T> event) {
public void raise(Event event) {
//
}

View File

@ -81,6 +81,8 @@ public class DependencyTreeBuilderTestMaven3
repoConfig.setId( TEST_REPO_ID );
repoConfig.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString() );
configuration.addManagedRepository( repoConfig );
config.getConfiguration().getProxyConnectors().clear();
config.save( configuration );
repositoryRegistry.reload();