Skip to content

Commit 496913b

Browse files
committed
Add Proxy Site cache support and API resource
1 parent 1eb3d70 commit 496913b

File tree

5 files changed

+210
-1
lines changed

5 files changed

+210
-1
lines changed

core/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@
151151
<groupId>org.commonjava.indy</groupId>
152152
<artifactId>indy-schedule-common</artifactId>
153153
</dependency>
154+
<dependency>
155+
<groupId>org.commonjava.indy</groupId>
156+
<artifactId>indy-subsys-jaxrs</artifactId>
157+
</dependency>
158+
<dependency>
159+
<groupId>io.swagger</groupId>
160+
<artifactId>swagger-annotations</artifactId>
161+
<scope>compile</scope>
162+
</dependency>
154163

155164
</dependencies>
156165

core/src/main/java/org/commonjava/indy/core/inject/CoreProvider.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.commonjava.indy.subsys.infinispan.BasicCacheHandle;
2424
import org.commonjava.indy.subsys.infinispan.CacheProducer;
2525
import org.commonjava.maven.galley.spi.nfc.NotFoundCache;
26+
import org.commonjava.maven.galley.spi.proxy.ProxySitesCache;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

@@ -32,6 +33,8 @@
3233
import javax.enterprise.inject.Instance;
3334
import javax.enterprise.inject.Produces;
3435
import javax.inject.Inject;
36+
import java.util.Collections;
37+
import java.util.Set;
3538

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

@@ -61,6 +64,8 @@ public class CoreProvider
6164

6265
private IndyObjectMapper objectMapper;
6366

67+
private ProxySitesCache proxySitesCache;
68+
6469
public CoreProvider()
6570
{
6671
}
@@ -69,6 +74,7 @@ public CoreProvider()
6974
public void init()
7075
{
7176
this.objectMapper = new IndyObjectMapper( objectMapperModules, objectMapperModuleSets );
77+
this.proxySitesCache = new MemoryProxySitesCache();
7278

7379
String nfcProvider = indyConfiguration.getNfcProvider();
7480
logger.info( "Apply nfc provider: {}", nfcProvider );
@@ -98,4 +104,35 @@ public IndyObjectMapper getIndyObjectMapper()
98104
@Default
99105
public NotFoundCache getNotFoundCache() { return notFoundCache; }
100106

107+
@Produces
108+
@Default
109+
public ProxySitesCache getProxySitesCache()
110+
{
111+
return proxySitesCache;
112+
}
113+
114+
public Set<String> getProxySites()
115+
{
116+
if ( proxySitesCache != null )
117+
{
118+
return proxySitesCache.getProxySites();
119+
}
120+
return Collections.emptySet();
121+
}
122+
123+
public void saveProxySite( String site )
124+
{
125+
proxySitesCache.saveProxySite( site );
126+
}
127+
128+
public void deleteProxySite( String site )
129+
{
130+
proxySitesCache.deleteProxySite( site );
131+
}
132+
133+
public void deleteAllProxySites()
134+
{
135+
proxySitesCache.deleteAllProxySites();
136+
}
137+
101138
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (C) 2011-2023 Red Hat, Inc. (https://github.com/Commonjava/indy)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.commonjava.indy.core.inject;
17+
18+
import org.commonjava.maven.galley.spi.proxy.ProxySitesCache;
19+
20+
import javax.enterprise.context.ApplicationScoped;
21+
import javax.enterprise.inject.Alternative;
22+
import java.util.HashSet;
23+
import java.util.Set;
24+
25+
@ApplicationScoped
26+
@Alternative
27+
public class MemoryProxySitesCache
28+
implements ProxySitesCache
29+
{
30+
31+
protected Set<String> proxySitesCache = new HashSet<>();
32+
33+
@Override
34+
public Set<String> getProxySites()
35+
{
36+
return proxySitesCache;
37+
}
38+
39+
@Override
40+
public boolean isProxySite( String site )
41+
{
42+
return proxySitesCache.contains( site );
43+
}
44+
45+
@Override
46+
public void saveProxySite( String site )
47+
{
48+
proxySitesCache.add( site );
49+
}
50+
51+
@Override
52+
public void deleteProxySite( String site )
53+
{
54+
proxySitesCache.remove( site );
55+
}
56+
57+
@Override
58+
public void deleteAllProxySites()
59+
{
60+
proxySitesCache.clear();
61+
}
62+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (C) 2011-2023 Red Hat, Inc. (https://github.com/Commonjava/indy)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.commonjava.indy.core.jaxrs;
17+
18+
import io.swagger.annotations.Api;
19+
import io.swagger.annotations.ApiOperation;
20+
import io.swagger.annotations.ApiResponse;
21+
import io.swagger.annotations.ApiResponses;
22+
import org.commonjava.indy.bind.jaxrs.IndyResources;
23+
import org.commonjava.indy.bind.jaxrs.util.REST;
24+
import org.commonjava.indy.core.inject.CoreProvider;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
28+
import javax.enterprise.context.ApplicationScoped;
29+
import javax.inject.Inject;
30+
import javax.servlet.http.HttpServletRequest;
31+
import javax.ws.rs.DELETE;
32+
import javax.ws.rs.GET;
33+
import javax.ws.rs.PUT;
34+
import javax.ws.rs.Path;
35+
import javax.ws.rs.PathParam;
36+
import javax.ws.rs.Produces;
37+
import javax.ws.rs.core.Context;
38+
import javax.ws.rs.core.Response;
39+
import javax.ws.rs.core.StreamingOutput;
40+
import javax.ws.rs.core.UriInfo;
41+
import java.util.Set;
42+
43+
@Api( value = "Proxy Site Cache Access and Storage" )
44+
@Path( "/api/proxysite" )
45+
@ApplicationScoped
46+
@REST
47+
public class ProxySiteAccessResource
48+
implements IndyResources
49+
{
50+
protected final Logger logger = LoggerFactory.getLogger( getClass() );
51+
52+
@Inject
53+
CoreProvider provider;
54+
55+
@ApiOperation( "Retrieve All Proxy Sites." )
56+
@ApiResponses( { @ApiResponse( code = 404, message = "Site is not available" ),
57+
@ApiResponse( code = 200, response = StreamingOutput.class, message = "Site stream" ), } )
58+
@Produces( "application/json" )
59+
@Path( "/all" )
60+
@GET
61+
public Response doGet( @Context final UriInfo uriInfo, @Context final HttpServletRequest request )
62+
{
63+
Set<String> cache = provider.getProxySites();
64+
logger.info( "Proxy Site Cache list: {}", cache );
65+
return ( cache == null || cache.isEmpty() ) ?
66+
Response.status( Response.Status.NOT_FOUND ).build() :
67+
Response.ok( cache ).build();
68+
}
69+
70+
@ApiOperation( "Store Proxy Site." )
71+
@ApiResponses( { @ApiResponse( code = 201, message = "Site was stored successfully" ) } )
72+
@PUT
73+
@Path( "/{site}" )
74+
public Response doCreate( @PathParam( "site" ) final String site, @Context final HttpServletRequest request,
75+
@Context final UriInfo uriInfo )
76+
{
77+
provider.saveProxySite( site );
78+
return Response.created( uriInfo.getRequestUri() ).build();
79+
}
80+
81+
@ApiOperation( "Delete Proxy Site." )
82+
@ApiResponse( code = 200, message = "Delete complete." )
83+
@Path( "/{site}" )
84+
@DELETE
85+
public Response doDelete( @PathParam( "site" ) final String site )
86+
{
87+
provider.deleteProxySite( site );
88+
return Response.ok().build();
89+
}
90+
91+
@ApiOperation( "Delete All Proxy Sites." )
92+
@ApiResponse( code = 200, message = "Delete complete." )
93+
@Path( "/all" )
94+
@DELETE
95+
public Response doDeleteAll()
96+
{
97+
provider.deleteAllProxySites();
98+
return Response.ok().build();
99+
}
100+
101+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<indyModelVersion>1.5</indyModelVersion>
9595
<indyClientVersion>3.4.0</indyClientVersion>
9696
<atlasVersion>1.1.4</atlasVersion>
97-
<galleyVersion>1.17</galleyVersion>
97+
<galleyVersion>1.18-SNAPSHOT</galleyVersion>
9898
<weftVersion>1.24</weftVersion>
9999
<webdavVersion>3.2.1</webdavVersion>
100100
<!-- TODO: partyline is still needed for standalone mode, may be removed in future -->

0 commit comments

Comments
 (0)