Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions api/src/main/java/org/commonjava/maven/galley/model/Transfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;

import static org.apache.commons.lang.StringUtils.join;

Expand Down Expand Up @@ -518,6 +519,21 @@ public void setResource( ConcreteResource resource )
this.resource = resource;
}

public Set<String> getProxySitesCache()
{
return provider.getProxySitesCache();
}

public boolean isProxySite( String site )
{
return provider.isProxySite( site );
}

public void saveProxySite( String site )
{
provider.saveProxySite( site );
}

@Override
public boolean equals( final Object o )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,31 @@ void createAlias( ConcreteResource from, ConcreteResource to )

AdminView asAdminView ();

Set<String> getProxySitesCache();

boolean isProxySite( String site );

void saveProxySite( String site );

interface AdminView extends CacheProvider
{
boolean isFileBased();

default File getDetachedFile( ConcreteResource resource ) { return null; }
default File getDetachedFile( ConcreteResource resource )
{
return null;
}

/**
* Expose GC in case the caller wants to run it directly, especially in functional test
*/
default void gc() {}
default void gc()
{
}

default void close() {}
default void close()
{
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
Expand Down Expand Up @@ -515,4 +516,21 @@ public PartyLineCacheProviderConfig getConfig()
{
return config;
}

@Override
public Set<String> getProxySitesCache()
{
return null;
}

@Override
public boolean isProxySite( String site )
{
return false;
}

@Override
public void saveProxySite( String site )
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
*/
package org.commonjava.maven.galley.cache.pathmapped;

import org.commonjava.maven.galley.model.SpecialPathInfo;
import org.commonjava.maven.galley.spi.io.SpecialPathManager;
import org.commonjava.maven.galley.util.PathUtils;
import org.commonjava.storage.pathmapped.core.PathMappedFileManager;
import org.commonjava.maven.galley.io.TransferDecoratorManager;
import org.commonjava.maven.galley.model.ConcreteResource;
import org.commonjava.maven.galley.model.Location;
import org.commonjava.maven.galley.model.SpecialPathInfo;
import org.commonjava.maven.galley.model.Transfer;
import org.commonjava.maven.galley.spi.cache.CacheProvider;
import org.commonjava.maven.galley.spi.event.FileEventManager;
import org.commonjava.maven.galley.spi.io.PathGenerator;
import org.commonjava.maven.galley.spi.io.SpecialPathManager;
import org.commonjava.maven.galley.util.PathUtils;
import org.commonjava.storage.pathmapped.core.PathMappedFileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,6 +36,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -409,6 +410,24 @@ public void stopReporting()
{
}

@Override
public Set<String> getProxySitesCache()
{
return fileManager.getProxySitesCache();
}

@Override
public boolean isProxySite( final String site )
{
return fileManager.isProxySite( site );
}

@Override
public void saveProxySite( String site )
{
fileManager.saveProxySite( site );
}

public PathMappedFileManager getPathMappedFileManager()
{
return fileManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<class>org.commonjava.storage.pathmapped.pathdb.jpa.model.JpaReverseKey</class>
<class>org.commonjava.storage.pathmapped.pathdb.jpa.model.JpaReverseMap</class>
<class>org.commonjava.storage.pathmapped.pathdb.jpa.model.JpaReclaim</class>
<class>org.commonjava.storage.pathmapped.pathdb.jpa.model.JpaProxySite</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -442,4 +443,21 @@ public void close()
}
}
}

@Override
public Set<String> getProxySitesCache()
{
return null;
}

@Override
public boolean isProxySite( String site )
{
return false;
}

@Override
public void saveProxySite( String site )
{
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<projectEmail>https://github.com/Commonjava/galley</projectEmail>
<atlasVersion>1.1.3</atlasVersion>
<partylineVersion>1.16</partylineVersion>
<pathmappedStorageVersion>2.5</pathmappedStorageVersion>
<pathmappedStorageVersion>3.0-SNAPSHOT</pathmappedStorageVersion>
<weftVersion>1.24</weftVersion>
<jhttpcVersion>1.14</jhttpcVersion>
<infinispanVersion>9.4.7.Final</infinispanVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
*/
package org.commonjava.maven.galley.testing.core.cache;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.commonjava.maven.galley.cache.SimpleLockingSupport;
Expand All @@ -33,6 +25,13 @@
import org.commonjava.maven.galley.spi.cache.CacheProvider;
import org.commonjava.maven.galley.spi.event.FileEventManager;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.Set;

public class TestCacheProvider
implements CacheProvider
{
Expand Down Expand Up @@ -300,4 +299,20 @@ public void stopReporting()
lockingSupport.stopReporting();
}

@Override
public Set<String> getProxySitesCache()
{
return null;
}

@Override
public boolean isProxySite( String site )
{
return false;
}

@Override
public void saveProxySite( String site )
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;

import static org.commonjava.o11yphant.trace.TraceManager.addFieldToActiveSpan;

Expand Down Expand Up @@ -104,13 +105,25 @@ protected boolean executeHttp()
{
int tries = 1;
boolean doProxy = false;
String site = location.getHost();
try
{
while ( tries > 0 )
{
tries--;
try
{
// if the site is in memory, go with proxy directly, avoid to query db frequently through isProxySite
if ( getProxySitesCache().contains( site ) )
{
doProxy = true;
}
// if the site is not in memory, query db through isProxySite
else if ( isProxySite( site ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those sites already in the whitelist, this will check it every request, right ? it's better to avoid that if it's the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sswguo yeah, that's the point. I'll try to add another mem cache for whitelist, and any first successful request going to the site without proxy will add into it, the following access on this whitelist site will check the mem cache instead to avoid frequent db query.
I'm doing refactor on Commonjava/path-mapped-storage#121, will amend this point together.

{
doProxy = true;
getProxySitesCache().add( site ); // add the site into memory
}
client = http.createClient( location, doProxy );
response = client.execute( request, http.createContext( location ) );

Expand Down Expand Up @@ -144,24 +157,26 @@ else if ( !doProxy ) // never do with proxy, retry with proxy
{
tries = 1;
doProxy = true;
getProxySitesCache().add( site ); // add the site into memory
saveProxySite( site ); // add the site into db
logger.debug( "Retry to execute with global proxy for {}", url );
}
else // already did proxy, still timeout
{
addFieldToActiveSpan( "target-error-reason", "timeout" );
addFieldToActiveSpan( "target-error", e.getClass().getSimpleName() );
throw new TransferTimeoutException( location, url,
"Repository remote request failed for: {}. Reason: {}", e,
url, e.getMessage() );
"Retried with proxy, repository remote request timeout failed for: {}. Reason: {}",
e, url, e.getMessage() );
}
}
catch ( final IOException e )
{
addFieldToActiveSpan( "target-error-reason", "I/O" );
addFieldToActiveSpan( "target-error", e.getClass().getSimpleName() );
throw new TransferLocationException( location,
"Repository remote request failed for: {}. Reason: {}", e, url,
e.getMessage() );
"Repository remote request IO failed for: {}. Reason: {}", e,
url, e.getMessage() );
}
catch ( TransferLocationException e )
{
Expand All @@ -173,7 +188,7 @@ else if ( !doProxy ) // never do with proxy, retry with proxy
{
addFieldToActiveSpan( "target-error-reason", "unknown" );
addFieldToActiveSpan( "target-error", e.getClass().getSimpleName() );
throw new TransferException( "Repository remote request failed for: {}. Reason: {}", e, url,
throw new TransferException( "Repository remote request Galley failed for: {}. Reason: {}", e, url,
e.getMessage() );
}
}
Expand All @@ -200,7 +215,6 @@ else if ( !doProxy ) // never do with proxy, retry with proxy
}

/* for GET/HEAD request, need to override below two methods for writeMetadata() */

protected Transfer getTransfer()
{
return null;
Expand Down Expand Up @@ -307,4 +321,18 @@ protected void cleanup()
response = null;
}

private boolean isProxySite( String site )
{
return getTransfer().isProxySite( site );
}

private void saveProxySite( String site )
{
getTransfer().saveProxySite( site );
}

private Set<String> getProxySitesCache()
{
return getTransfer().getProxySitesCache();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
*/
package org.commonjava.maven.galley.transport.htcli.testutil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.commonjava.maven.galley.cache.SimpleLockingSupport;
Expand All @@ -33,6 +25,13 @@
import org.commonjava.maven.galley.spi.cache.CacheProvider;
import org.commonjava.maven.galley.spi.event.FileEventManager;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.Set;

public class TestCacheProvider
implements CacheProvider
{
Expand Down Expand Up @@ -299,4 +298,21 @@ public void stopReporting()
{
lockingSupport.stopReporting();
}

@Override
public Set<String> getProxySitesCache()
{
return null;
}

@Override
public boolean isProxySite( String site )
{
return false;
}

@Override
public void saveProxySite( String site )
{
}
}
Loading