Skip to content

Commit f28aae8

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

File tree

7 files changed

+223
-6
lines changed

7 files changed

+223
-6
lines changed

addons/pkg-maven/common/src/test/java/org/commonjava/indy/pkg/maven/content/MavenContentFilteringTransferDecoratorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.commonjava.maven.galley.model.Location;
2525
import org.commonjava.maven.galley.model.Transfer;
2626
import org.commonjava.maven.galley.model.TransferOperation;
27+
import org.commonjava.maven.galley.proxy.NoOpProxySitesCache;
2728
import org.commonjava.maven.galley.transport.htcli.internal.HttpDownload;
2829
import org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation;
2930
import org.commonjava.o11yphant.metrics.DefaultMetricRegistry;
@@ -154,7 +155,7 @@ private Transfer getTestHttpTransfer(final String path, final String content) th
154155
assertThat( transfer.exists(), equalTo( false ) );
155156

156157
HttpDownload dl = new HttpDownload( url, location, transfer, new HashMap<>(), new EventMetadata(),
157-
fixture.getHttp().getHttp(), new ObjectMapper(), true, metricRegistry, metricConfig );
158+
fixture.getHttp().getHttp(), new ObjectMapper(), true, metricRegistry, metricConfig, new NoOpProxySitesCache() );
158159

159160
return dl.call().getTransfer();
160161
}

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 -->

subsys/groovy/src/test/java/org/commonjava/indy/subsys/template/fixture/TestProvider.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,21 @@
3434
import org.commonjava.maven.galley.io.NoOpTransferDecorator;
3535
import org.commonjava.maven.galley.io.TransferDecoratorManager;
3636
import org.commonjava.maven.galley.nfc.MemoryNotFoundCache;
37+
import org.commonjava.maven.galley.proxy.NoOpProxySitesCache;
3738
import org.commonjava.maven.galley.spi.cache.CacheProvider;
3839
import org.commonjava.maven.galley.spi.event.FileEventManager;
3940
import org.commonjava.maven.galley.spi.nfc.NotFoundCache;
41+
import org.commonjava.maven.galley.spi.proxy.ProxySitesCache;
4042
import org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration;
41-
import org.commonjava.maven.galley.transport.htcli.conf.GlobalProxyConfig;
4243
import org.junit.rules.TemporaryFolder;
4344

4445
import javax.annotation.PostConstruct;
4546
import javax.annotation.PreDestroy;
4647
import javax.enterprise.context.ApplicationScoped;
47-
import javax.enterprise.inject.Alternative;
4848
import javax.enterprise.inject.Default;
4949
import javax.enterprise.inject.Produces;
5050
import javax.inject.Inject;
5151
import java.io.IOException;
52-
import java.util.ArrayList;
53-
import java.util.List;
5452

5553
import static org.junit.Assert.fail;
5654

@@ -65,6 +63,8 @@ public class TestProvider
6563

6664
private NotFoundCache nfc;
6765

66+
private ProxySitesCache proxySitesCache;
67+
6868
private StoreDataManager storeDataManager;
6969

7070
private ObjectMapper objectMapper;
@@ -94,6 +94,7 @@ public void setup()
9494
{
9595
storeDataManager = new MemoryStoreDataManager( true );
9696
nfc = new MemoryNotFoundCache();
97+
proxySitesCache = new NoOpProxySitesCache();
9798
objectMapper = new IndyObjectMapper( false );
9899
fileEventManager = new NoOpFileEventManager();
99100
transferDecorator = new NoOpTransferDecorator();
@@ -135,6 +136,12 @@ public NotFoundCache getNfc()
135136
return nfc;
136137
}
137138

139+
@Produces
140+
public ProxySitesCache getProxySitesCache()
141+
{
142+
return proxySitesCache;
143+
}
144+
138145
@Produces
139146
@Standalone
140147
@Default

0 commit comments

Comments
 (0)