Skip to content

Commit

Permalink
Add Proxy Site cache support for provider PathDB instance
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Jan 20, 2025
1 parent 60d5e5e commit 97eff26
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 11 deletions.
9 changes: 9 additions & 0 deletions filers/default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,14 @@
<groupId>org.commonjava.indy</groupId>
<artifactId>indy-subsys-metrics</artifactId>
</dependency>
<dependency>
<groupId>org.commonjava.indy</groupId>
<artifactId>indy-subsys-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@
import org.commonjava.indy.content.IndyChecksumAdvisor;
import org.commonjava.indy.content.SpecialPathSetProducer;
import org.commonjava.indy.filer.def.conf.DefaultStorageProviderConfiguration;
import org.commonjava.maven.galley.cache.pathmapped.PathMappedCacheProviderConfig;
import org.commonjava.o11yphant.metrics.api.Meter;
import org.commonjava.o11yphant.metrics.api.MetricRegistry;
import org.commonjava.o11yphant.metrics.api.Timer;
import org.commonjava.o11yphant.metrics.DefaultMetricsManager;
import org.commonjava.indy.subsys.metrics.conf.IndyMetricsConfig;
import org.commonjava.indy.subsys.cassandra.CassandraClient;
import org.commonjava.indy.subsys.cassandra.config.CassandraConfig;
import org.commonjava.indy.subsys.metrics.conf.IndyMetricsConfig;
import org.commonjava.maven.galley.GalleyInitException;
import org.commonjava.maven.galley.cache.CacheProviderFactory;
import org.commonjava.maven.galley.cache.partyline.PartyLineCacheProviderFactory;
import org.commonjava.maven.galley.cache.pathmapped.PathMappedCacheProviderConfig;
import org.commonjava.maven.galley.cache.pathmapped.PathMappedCacheProviderFactory;
import org.commonjava.maven.galley.config.TransportManagerConfig;
import org.commonjava.maven.galley.io.ChecksummingTransferDecorator;
Expand All @@ -54,10 +50,14 @@
import org.commonjava.maven.galley.spi.io.TransferDecorator;
import org.commonjava.maven.galley.spi.metrics.TimingProvider;
import org.commonjava.maven.galley.transport.htcli.UploadMetadataGenTransferDecorator;
import org.commonjava.o11yphant.metrics.DefaultMetricsManager;
import org.commonjava.o11yphant.metrics.api.Meter;
import org.commonjava.o11yphant.metrics.api.MetricRegistry;
import org.commonjava.o11yphant.metrics.api.Timer;
import org.commonjava.storage.pathmapped.config.DefaultPathMappedStorageConfig;
import org.commonjava.storage.pathmapped.config.PathMappedStorageConfig;
import org.commonjava.storage.pathmapped.pathdb.datastax.CassandraPathDB;
import org.commonjava.storage.pathmapped.metrics.MeasuredPathDB;
import org.commonjava.storage.pathmapped.pathdb.datastax.CassandraPathDB;
import org.commonjava.storage.pathmapped.spi.PathDB;
import org.commonjava.storage.pathmapped.spi.PhysicalStore;
import org.slf4j.Logger;
Expand All @@ -75,17 +75,23 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.BiConsumer;
import java.util.function.Function;

import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.commonjava.o11yphant.metrics.util.NameUtils.getSupername;
import static org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor.ChecksumAdvice.CALCULATE_AND_WRITE;
import static org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor.ChecksumAdvice.NO_DECORATE;
import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.*;
import static org.commonjava.o11yphant.metrics.util.NameUtils.getSupername;
import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_HOST;
import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_KEYSPACE;
import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_PASS;
import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_PORT;
import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_REPLICATION_FACTOR;
import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_USER;

@SuppressWarnings( "unused" )
@ApplicationScoped
Expand Down Expand Up @@ -148,6 +154,8 @@ public class DefaultGalleyStorageProvider

private CacheProviderFactory cacheProviderFactory;

PathDB pathDB = null;

public DefaultGalleyStorageProvider()
{
}
Expand Down Expand Up @@ -205,7 +213,6 @@ private void setupCacheProviderFactory()

logger.info( "Initializing Cassandra-based path-mapping database for content storage." );

PathDB pathDB = null;
PathMappedStorageConfig pathMappedStorageConfig = getPathMappedStorageConfig();
if ( cassandraClient != null )
{
Expand Down Expand Up @@ -411,4 +418,35 @@ public synchronized CacheProvider getCacheProvider()

return cacheProvider;
}

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

public List<String> getProxySiteList()
{
return pathDB.getProxySiteList();
}

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

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

public void deleteProxySite( String site )
{
pathDB.deleteProxySite( site );
}

public void deleteAllProxySite()
{
pathDB.deleteAllProxySite();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.commonjava.indy.filer.def.jaxrs;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.commonjava.indy.bind.jaxrs.IndyResources;
import org.commonjava.indy.bind.jaxrs.util.REST;
import org.commonjava.indy.filer.def.DefaultGalleyStorageProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import javax.ws.rs.core.UriInfo;
import java.util.List;
import java.util.Set;

@Api( value = "Proxy Site Cache Access and Storage" )
@Path( "/api/proxysite" )
@ApplicationScoped
@REST
public class ProxySiteAccessResource
implements IndyResources
{
protected final Logger logger = LoggerFactory.getLogger( getClass() );

@Inject
DefaultGalleyStorageProvider provider;

@ApiOperation( "Retrieve All Proxy Sites." )
@ApiResponses( { @ApiResponse( code = 404, message = "Site is not available" ),
@ApiResponse( code = 200, response = StreamingOutput.class, message = "Site stream" ), } )
@Produces( "application/json" )
@Path( "/all" )
@GET
public Response doGet( @Context final UriInfo uriInfo, @Context final HttpServletRequest request )
{
Set<String> cache = provider.getProxySitesCache();
logger.info( "Proxy Site Cache list: {}", cache );
List<String> result = provider.getProxySiteList();
return ( result == null || result.isEmpty() ) ?
Response.status( Response.Status.NOT_FOUND ).build() :
Response.ok( result ).build();
}

@ApiOperation( "Store Proxy Site." )
@ApiResponses( { @ApiResponse( code = 201, message = "Site was stored successfully" ) } )
@PUT
@Path( "/{site}" )
public Response doCreate( @PathParam( "site" ) final String site, @Context final HttpServletRequest request,
@Context final UriInfo uriInfo )
{
provider.saveProxySite( site );
return Response.created( uriInfo.getRequestUri() ).build();
}

@ApiOperation( "Delete Proxy Site." )
@ApiResponse( code = 200, message = "Delete complete." )
@Path( "/{site}" )
@DELETE
public Response doDelete( @PathParam( "site" ) final String site )
{
provider.deleteProxySite( site );
provider.getProxySitesCache().remove( site );
return Response.ok().build();
}

@ApiOperation( "Delete All Proxy Sites." )
@ApiResponse( code = 200, message = "Delete complete." )
@Path( "/all" )
@DELETE
public Response doDeleteAll()
{
provider.deleteAllProxySite();
provider.getProxySitesCache().clear();
return Response.ok().build();
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<indyModelVersion>1.5</indyModelVersion>
<indyClientVersion>3.4.0</indyClientVersion>
<atlasVersion>1.1.4</atlasVersion>
<galleyVersion>1.17</galleyVersion>
<galleyVersion>1.18-SNAPSHOT</galleyVersion>
<weftVersion>1.24</weftVersion>
<webdavVersion>3.2.1</webdavVersion>
<!-- TODO: partyline is still needed for standalone mode, may be removed in future -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;

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

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

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

@Override
public void saveProxySite( String s )
{

}
}

0 comments on commit 97eff26

Please sign in to comment.