Skip to content

Commit

Permalink
Add Proxy Site cache support and API resource
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Feb 7, 2025
1 parent 1eb3d70 commit 0b373b8
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 3 deletions.
9 changes: 9 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@
<groupId>org.commonjava.indy</groupId>
<artifactId>indy-schedule-common</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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.commonjava.indy.subsys.infinispan.BasicCacheHandle;
import org.commonjava.indy.subsys.infinispan.CacheProducer;
import org.commonjava.maven.galley.spi.nfc.NotFoundCache;
import org.commonjava.maven.galley.spi.proxy.ProxySitesCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,6 +33,8 @@
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import java.util.Collections;
import java.util.Set;

import static org.commonjava.indy.conf.DefaultIndyConfiguration.CASSANDRA_NFC_PROVIDER;

Expand Down Expand Up @@ -61,6 +64,8 @@ public class CoreProvider

private IndyObjectMapper objectMapper;

private ProxySitesCache proxySitesCache;

public CoreProvider()
{
}
Expand All @@ -70,8 +75,10 @@ public void init()
{
this.objectMapper = new IndyObjectMapper( objectMapperModules, objectMapperModuleSets );

System.out.println( "6666651" );
String nfcProvider = indyConfiguration.getNfcProvider();
logger.info( "Apply nfc provider: {}", nfcProvider );

if ( CASSANDRA_NFC_PROVIDER.equals( nfcProvider ) )
{
notFoundCache = new CassandraNotFoundCache( indyConfiguration, cacheProducer,
Expand All @@ -91,11 +98,45 @@ public IndyObjectMapper getIndyObjectMapper()
return objectMapper;
}


private volatile NotFoundCache notFoundCache;

@Produces
@Default
public NotFoundCache getNotFoundCache() { return notFoundCache; }
public NotFoundCache getNotFoundCache()
{
return notFoundCache;
}

@Produces
@Default
public ProxySitesCache getProxySitesCache()
{
this.proxySitesCache = new MemoryProxySitesCache();
return proxySitesCache;
}

public Set<String> getProxySites()
{
if ( proxySitesCache != null )
{
return proxySitesCache.getProxySites();
}
return Collections.emptySet();
}

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

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

public void deleteAllProxySites()
{
proxySitesCache.deleteAllProxySites();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.commonjava.indy.core.inject;

import org.commonjava.maven.galley.spi.proxy.ProxySitesCache;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import java.util.HashSet;
import java.util.Set;

@ApplicationScoped
@Alternative
public class MemoryProxySitesCache
implements ProxySitesCache
{

protected Set<String> proxySitesCache = new HashSet<>();

@Override
public Set<String> getProxySites()
{
return proxySitesCache;
}

@Override
public boolean isProxySite( String site )
{
return proxySitesCache.contains( site );
}

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

@Override
public void deleteProxySite( String site )
{
proxySitesCache.remove( site );
}

@Override
public void deleteAllProxySites()
{
proxySitesCache.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.commonjava.indy.core.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.core.inject.CoreProvider;
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.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
CoreProvider 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.getProxySites();
logger.info( "Proxy Site Cache list: {}", cache );
return ( cache == null || cache.isEmpty() ) ?
Response.status( Response.Status.NOT_FOUND ).build() :
Response.ok( cache ).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 );
return Response.ok().build();
}

@ApiOperation( "Delete All Proxy Sites." )
@ApiResponse( code = 200, message = "Delete complete." )
@Path( "/all" )
@DELETE
public Response doDeleteAll()
{
provider.deleteAllProxySites();
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

0 comments on commit 0b373b8

Please sign in to comment.