Skip to content

Commit

Permalink
GWC API Updates
Browse files Browse the repository at this point in the history
- BlobStoreConfig -> BLobStoreInfo
- Support BLobStoreAggregator
- Minor Gridset API changes
- Support Optional return type for TileLayerConfiguration
  • Loading branch information
tbarsballe committed Feb 15, 2018
1 parent 7d947a9 commit c0d3bb7
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;
import org.geowebcache.s3.S3BlobStoreConfig;
import org.geowebcache.s3.S3BlobStoreInfo;

/**
*
Expand All @@ -22,7 +22,7 @@ public class S3BlobStorePanel extends Panel {

private static final long serialVersionUID = -8237328668463257329L;

public S3BlobStorePanel(String id, final IModel<S3BlobStoreConfig> configModel) {
public S3BlobStorePanel(String id, final IModel<S3BlobStoreInfo> configModel) {
super(id, configModel);

add(new TextField<String>("bucket").setRequired(true).add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.geowebcache.s3.S3BlobStoreConfig;
import org.geowebcache.s3.S3BlobStoreInfo;

public class S3BlobStoreType implements BlobStoreType<S3BlobStoreConfig> {
public class S3BlobStoreType implements BlobStoreType<S3BlobStoreInfo> {
private static final long serialVersionUID = 7349157660150568235L;

@Override
Expand All @@ -17,20 +17,20 @@ public String toString(){
}

@Override
public S3BlobStoreConfig newConfigObject() {
S3BlobStoreConfig config = new S3BlobStoreConfig();
public S3BlobStoreInfo newConfigObject() {
S3BlobStoreInfo config = new S3BlobStoreInfo();
config.setEnabled(true);
config.setMaxConnections(50);
return config;
}

@Override
public Class<S3BlobStoreConfig> getConfigClass() {
return S3BlobStoreConfig.class;
public Class<S3BlobStoreInfo> getConfigClass() {
return S3BlobStoreInfo.class;
}

@Override
public Panel createPanel(String id, IModel<S3BlobStoreConfig> model) {
public Panel createPanel(String id, IModel<S3BlobStoreInfo> model) {
return new S3BlobStorePanel(id, model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<bean id="S3BlobStoreConfigProvider" class="org.geowebcache.s3.S3BlobStoreConfigProvider" depends-on="geoWebCacheExtensions">
<description>
Contributes XStream configuration settings to org.geowebcache.config.XMLConfiguration to encode S3BlobStoreConfig instances
Contributes XStream configuration settings to org.geowebcache.config.XMLConfiguration to encode S3BlobStoreInfo instances
</description>
</bean>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import org.apache.wicket.util.tester.FormTester;
import org.geoserver.gwc.GWC;
import org.geoserver.web.GeoServerWicketTestSupport;
import org.geowebcache.config.BlobStoreConfig;
import org.geowebcache.config.BlobStoreInfo;
import org.geowebcache.config.ConfigurationException;
import org.geowebcache.layer.TileLayer;
import org.geowebcache.s3.S3BlobStoreConfig;
import org.geowebcache.s3.S3BlobStoreInfo;
import org.junit.Test;

/**
Expand Down Expand Up @@ -75,22 +75,22 @@ public void testNew() throws ConfigurationException {
formTester.setValue("blobSpecificPanel:awsSecretKey", "mysecretkey");
tester.executeAjaxEvent("blobConfigContainer:blobStoreForm:save", "click");

List<BlobStoreConfig> blobStores = GWC.get().getBlobStores();
BlobStoreConfig config = blobStores.get(0);
assertTrue(config instanceof S3BlobStoreConfig);
List<BlobStoreInfo> blobStores = GWC.get().getBlobStores();
BlobStoreInfo config = blobStores.get(0);
assertTrue(config instanceof S3BlobStoreInfo);
assertEquals("myblobstore", config.getId());
assertEquals("mybucket", ((S3BlobStoreConfig) config).getBucket());
assertEquals("myaccesskey", ((S3BlobStoreConfig) config).getAwsAccessKey());
assertEquals("mysecretkey", ((S3BlobStoreConfig) config).getAwsSecretKey());
assertEquals(50, ((S3BlobStoreConfig) config).getMaxConnections().intValue());
assertEquals("mybucket", ((S3BlobStoreInfo) config).getBucket());
assertEquals("myaccesskey", ((S3BlobStoreInfo) config).getAwsAccessKey());
assertEquals("mysecretkey", ((S3BlobStoreInfo) config).getAwsSecretKey());
assertEquals(50, ((S3BlobStoreInfo) config).getMaxConnections().intValue());

GWC.get().removeBlobStores(Collections.singleton("myblobstore"));
}

@Test
public void testModify() throws Exception {
S3BlobStoreConfig sconfig = new S3BlobStoreConfig();
Field id = BlobStoreConfig.class.getDeclaredField("id");
S3BlobStoreInfo sconfig = new S3BlobStoreInfo();
Field id = BlobStoreInfo.class.getDeclaredField("id");
id.setAccessible(true);
id.set(sconfig, "myblobstore");
sconfig.setMaxConnections(50);
Expand All @@ -114,10 +114,10 @@ public void testModify() throws Exception {
formTester.submit();
tester.executeAjaxEvent("blobConfigContainer:blobStoreForm:save", "click");

BlobStoreConfig config = GWC.get().getBlobStores().get(0);
assertTrue(config instanceof S3BlobStoreConfig);
BlobStoreInfo config = GWC.get().getBlobStores().get(0);
assertTrue(config instanceof S3BlobStoreInfo);
assertEquals("yourblobstore", config.getId());
assertEquals("yourbucket", ((S3BlobStoreConfig) config).getBucket());
assertEquals("yourbucket", ((S3BlobStoreInfo) config).getBucket());

//test updated id!
layer = GWC.get().getTileLayerByName("cite:Lakes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import org.geoserver.web.GeoServerWicketTestSupport;
import org.geoserver.web.wicket.GeoServerDialog;
import org.geoserver.web.wicket.GeoServerTablePanel;
import org.geowebcache.config.BlobStoreConfig;
import org.geowebcache.config.FileBlobStoreConfig;
import org.geowebcache.config.BlobStoreInfo;
import org.geowebcache.config.FileBlobStoreInfo;
import org.geowebcache.layer.TileLayer;
import org.geowebcache.s3.S3BlobStoreConfig;
import org.geowebcache.s3.S3BlobStoreInfo;
import org.junit.Test;

/**
Expand All @@ -41,16 +41,16 @@ public class S3BlobStoresPageTest extends GeoServerWicketTestSupport {
private static final String ID_DUMMY1 = "zzz";
private static final String ID_DUMMY2 = "yyy";

public BlobStoreConfig dummyStore1() {
FileBlobStoreConfig config = new FileBlobStoreConfig(ID_DUMMY1);
public BlobStoreInfo dummyStore1() {
FileBlobStoreInfo config = new FileBlobStoreInfo(ID_DUMMY1);
config.setFileSystemBlockSize(1024);
config.setBaseDirectory("/tmp");
return config;
}

public BlobStoreConfig dummyStore2() throws Exception {
S3BlobStoreConfig config = new S3BlobStoreConfig();
Field id = BlobStoreConfig.class.getDeclaredField("id");
public BlobStoreInfo dummyStore2() throws Exception {
S3BlobStoreInfo config = new S3BlobStoreInfo();
Field id = BlobStoreInfo.class.getDeclaredField("id");
id.setAccessible(true);
id.set(config, ID_DUMMY2);
config.setBucket("bucket");
Expand All @@ -75,10 +75,10 @@ public void testPage() {
public void testBlobStores() throws Exception {
BlobStoresPage page = new BlobStoresPage();

BlobStoreConfig dummy1 = dummyStore1();
BlobStoreInfo dummy1 = dummyStore1();
GWC.get().addBlobStore(dummy1);

List<BlobStoreConfig> blobStores = GWC.get().getBlobStores();
List<BlobStoreInfo> blobStores = GWC.get().getBlobStores();

tester.startPage(page);

Expand All @@ -87,7 +87,7 @@ public void testBlobStores() throws Exception {
assertEquals(blobStores.size(), table.getDataProvider().size());
assertTrue(getStoresFromTable(table).contains(dummy1));

BlobStoreConfig dummy2 = dummyStore2();
BlobStoreInfo dummy2 = dummyStore2();
GWC.get().addBlobStore(dummy2);

assertEquals(blobStores.size() + 1, table.getDataProvider().size());
Expand Down Expand Up @@ -120,7 +120,7 @@ public void testDelete() throws Exception {

GeoServerTablePanel table = (GeoServerTablePanel) tester.getComponentFromLastRenderedPage("storesPanel");

BlobStoreConfig dummy1 = dummyStore1();
BlobStoreInfo dummy1 = dummyStore1();
GWC.get().addBlobStore(dummy1);

assertTrue(GWC.get().getBlobStores().contains(dummy1));
Expand Down Expand Up @@ -180,11 +180,11 @@ public void testDelete() throws Exception {

}

public List<BlobStoreConfig> getStoresFromTable(GeoServerTablePanel table) {
List<BlobStoreConfig> result = new ArrayList<BlobStoreConfig>();
public List<BlobStoreInfo> getStoresFromTable(GeoServerTablePanel table) {
List<BlobStoreInfo> result = new ArrayList<BlobStoreInfo>();
Iterator it = table.getDataProvider().iterator(0, table.size());
while (it.hasNext()) {
result.add( (BlobStoreConfig) it.next());
result.add( (BlobStoreInfo) it.next());
}
return result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.apache.wicket.util.tester.FormTester;
import org.geoserver.gwc.GWC;
import org.geoserver.web.GeoServerWicketTestSupport;
import org.geowebcache.config.BlobStoreConfig;
import org.geowebcache.config.BlobStoreInfo;
import org.geowebcache.config.ConfigurationException;
import org.geowebcache.layer.TileLayer;
import org.geowebcache.sqlite.MbtilesConfiguration;
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testModifyingAnExistingStore() throws Exception {
originalConfiguration.setRootDirectory("/tmp/gwc");
String storeId = UUID.randomUUID().toString();
// the setId method has package only visibility, so we set the value by reflection
Field id = BlobStoreConfig.class.getDeclaredField("id");
Field id = BlobStoreInfo.class.getDeclaredField("id");
id.setAccessible(true);
id.set(originalConfiguration, storeId);
// associate the store with a layer (it will be used to test store id update)
Expand Down Expand Up @@ -160,8 +160,8 @@ public void testModifyingAnExistingStore() throws Exception {
* Helper method that finds a GWC store by is id.
*/
private MbtilesConfiguration findStore(String storeId) {
List<BlobStoreConfig> configurations = GWC.get().getBlobStores();
for (BlobStoreConfig candidateConfiguration : configurations) {
List<BlobStoreInfo> configurations = GWC.get().getBlobStores();
for (BlobStoreInfo candidateConfiguration : configurations) {
if (candidateConfiguration instanceof MbtilesConfiguration && candidateConfiguration.getId().equals(storeId)) {
return (MbtilesConfiguration) candidateConfiguration;
}
Expand Down
10 changes: 2 additions & 8 deletions src/gwc/src/main/java/org/geoserver/gwc/GWC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1494,13 +1494,7 @@ public synchronized void modifyGridSet(final String oldGridSetName, final GridSe
}
}

// now no layer is referencing it

XMLConfiguration mainConfig = getXmlConfiguration();

mainConfig.removeGridset(oldGridSetName);
mainConfig.addOrReplaceGridSet(new XMLGridSet(newGridSet));
mainConfig.save();
//TODO: Verify we don't also need to remove from XMLConfiguration
getGridSetBroker().remove(oldGridSetName);
getGridSetBroker().put(newGridSet);

Expand Down Expand Up @@ -1844,7 +1838,7 @@ public static Geometry getAreaOfValidityAsGeometry(final CoordinateReferenceSyst
}

if (is900913Compatible) {
BoundingBox prescribedBounds = gridSetBroker.WORLD_EPSG3857.getBounds();
BoundingBox prescribedBounds = gridSetBroker.getWorldEpsg3857().getBounds();
return JTS.toGeometry(new Envelope(prescribedBounds.getMinX(), prescribedBounds
.getMaxX(), prescribedBounds.getMinY(), prescribedBounds.getMaxY()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.geoserver.gwc.layer;

import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand All @@ -29,6 +28,7 @@
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -159,26 +159,25 @@ public String getIdentifier() {
*/
@Deprecated
@Override
public List<GeoServerTileLayer> getTileLayers() {
Iterable<GeoServerTileLayer> layers = getLayers();
public List<TileLayer> getTileLayers() {
Iterable<TileLayer> layers = getLayers();
return Lists.newArrayList(layers);
}

/**
* @see TileLayerConfiguration#getLayers()
*/
@Override
public Collection<GeoServerTileLayer> getLayers() {
public Collection<TileLayer> getLayers() {
lock.acquireReadLock();
try {
final Set<String> layerNames = tileLayerCatalog.getLayerNames();

Function<String, GeoServerTileLayer> lazyLayerFetch =
layerName -> CatalogConfiguration.this.getLayer(layerName);
Function<String, Optional<TileLayer>> lazyLayerFetch = CatalogConfiguration.this::getLayer;

// removing the NULL results
return Lists.newArrayList(layerNames.stream().map(lazyLayerFetch::apply).collect(Collectors.toList())
.stream().filter(java.util.Objects::nonNull).collect(Collectors.toList()));
return Lists.newArrayList(layerNames.stream().map(lazyLayerFetch).collect(Collectors.toList())
.stream().filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
} finally {
lock.releaseReadLock();
}
Expand Down Expand Up @@ -318,7 +317,7 @@ public GeoServerTileLayer getTileLayerById(final String layerId) {
* @see TileLayerConfiguration#getLayer(String)
*/
@Override
public GeoServerTileLayer getLayer(final String layerName) {
public Optional<TileLayer> getLayer(final String layerName) {
checkNotNull(layerName, "layer name is null");

final String layerId;
Expand All @@ -327,12 +326,12 @@ public GeoServerTileLayer getLayer(final String layerName) {
try {
layerId = getLayerId(layerName);
if (layerId == null) {
return null;
return Optional.ofNullable(null);
}
} finally {
lock.releaseReadLock();
}
return getTileLayerById(layerId);
return Optional.ofNullable(getTileLayerById(layerId));
}

/**
Expand All @@ -341,7 +340,7 @@ public GeoServerTileLayer getLayer(final String layerName) {
@Deprecated
@Override
public GeoServerTileLayer getTileLayer(final String layerName) {
return getLayer(layerName);
return getTileLayerById(layerName);
}

private String getLayerId(final String layerName) {
Expand Down Expand Up @@ -536,8 +535,7 @@ public synchronized void modifyLayer(TileLayer tl) throws NoSuchElementException
*/
@Override
public synchronized void renameLayer(String oldName, String newName) throws NoSuchElementException {
TileLayer tl = getLayer(oldName);
checkNotNull(tl, "TileLayer " + oldName+ " not found");
TileLayer tl = getLayer(oldName).orElseThrow(()-> new NullPointerException("TileLayer " + oldName+ " not found"));
checkArgument(canSave(tl), "Can't rename TileLayer of type ", tl.getClass());

GeoServerTileLayer tileLayer = (GeoServerTileLayer) tl;
Expand Down

0 comments on commit c0d3bb7

Please sign in to comment.