Skip to content

Commit

Permalink
Update GWC with BlobStore configuration changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Merkle <emerkle@boundlessgeo.com>
  • Loading branch information
Erik Merkle committed Jan 29, 2018
1 parent 971c669 commit 55ebbe6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
42 changes: 21 additions & 21 deletions src/gwc/src/main/java/org/geoserver/gwc/GWC.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
import org.geowebcache.GeoWebCacheException;
import org.geowebcache.GeoWebCacheExtensions;
import org.geowebcache.config.BaseConfiguration;
import org.geowebcache.config.BlobStoreConfig;
import org.geowebcache.config.BlobStoreConfigurationCatalog;
import org.geowebcache.config.BlobStoreConfiguration;
import org.geowebcache.config.BlobStoreInfo;
import org.geowebcache.config.ConfigurationException;
import org.geowebcache.config.TileLayerConfiguration;
import org.geowebcache.config.XMLConfiguration;
Expand Down Expand Up @@ -2334,20 +2334,20 @@ static Set<String> getAdvertisedCachedFormats(final PublishedType type, final It
/**
* @return the list of configured blobstores
*/
public List<BlobStoreConfig> getBlobStores() {
BlobStoreConfigurationCatalog xmlConfig = getXmlConfiguration();
public List<BlobStoreInfo> getBlobStores() {
BlobStoreConfiguration xmlConfig = getXmlConfiguration();

return new ArrayList<BlobStoreConfig>(xmlConfig.getBlobStores());
return new ArrayList<BlobStoreInfo>(xmlConfig.getBlobStores());
}

/**
* @return the {@link BlobStoreConfig#isDefault() default} blobstore, or {@code null} if there's
* @return the {@link BlobStoreInfo#isDefault() default} blobstore, or {@code null} if there's
* no default
*/
public BlobStoreConfig getDefaultBlobStore() {
BlobStoreConfigurationCatalog xmlConfig = getXmlConfiguration();
public BlobStoreInfo getDefaultBlobStore() {
BlobStoreConfiguration xmlConfig = getXmlConfiguration();

for (BlobStoreConfig config : xmlConfig.getBlobStores()) {
for (BlobStoreInfo config : xmlConfig.getBlobStores()) {
if (config.isDefault()) {
return config;
}
Expand All @@ -2359,12 +2359,12 @@ public BlobStoreConfig getDefaultBlobStore() {
* Convenience method to add a new blob store, calling {@link #setBlobStores} the extra
* {@code config}
*/
public void addBlobStore(BlobStoreConfig config) throws ConfigurationException {
public void addBlobStore(BlobStoreInfo config) throws ConfigurationException {
checkNotNull(config);

List<BlobStoreConfig> stores = new ArrayList<>(getXmlConfiguration().getBlobStores());
List<BlobStoreInfo> stores = new ArrayList<>(getXmlConfiguration().getBlobStores());
if (config.isDefault()) {
for (BlobStoreConfig c : stores) {
for (BlobStoreInfo c : stores) {
c.setDefault(false);
}
}
Expand All @@ -2377,14 +2377,14 @@ public void addBlobStore(BlobStoreConfig config) throws ConfigurationException {
* Convenience method to modify a blobstore; calling {@link #setBlobStores(List)} with the
* config identified by {@code oldId} repplaced by {@code config}
*/
public void modifyBlobStore(String oldId, BlobStoreConfig config) throws ConfigurationException {
public void modifyBlobStore(String oldId, BlobStoreInfo config) throws ConfigurationException {
checkNotNull(oldId);
checkNotNull(config);

List<BlobStoreConfig> stores = new ArrayList<>(getXmlConfiguration().getBlobStores());
List<BlobStoreInfo> stores = new ArrayList<>(getXmlConfiguration().getBlobStores());
int index = -1;
for (int i = 0; i < stores.size(); i++) {
BlobStoreConfig c = stores.get(i);
BlobStoreInfo c = stores.get(i);
if (oldId.equals(c.getId())) {
index = i;
break;
Expand All @@ -2408,14 +2408,14 @@ public void modifyBlobStore(String oldId, BlobStoreConfig config) throws Configu
public void removeBlobStores(Iterable<String> blobStoreIds) throws ConfigurationException {
checkNotNull(blobStoreIds);

Map<String, BlobStoreConfig> stores = Maps.uniqueIndex(new ArrayList<>(
getXmlConfiguration().getBlobStores()), new Function<BlobStoreConfig, String>() {
Map<String, BlobStoreInfo> stores = Maps.uniqueIndex(new ArrayList<>(
getXmlConfiguration().getBlobStores()), new Function<BlobStoreInfo, String>() {
@Override
public String apply(BlobStoreConfig c) {
public String apply(BlobStoreInfo c) {
return c.getId();
}
});
Map<String, BlobStoreConfig> filtered = Maps.filterKeys(stores,
Map<String, BlobStoreInfo> filtered = Maps.filterKeys(stores,
Predicates.not(Predicates.in(ImmutableList.copyOf(blobStoreIds))));

if (!filtered.equals(stores)) {
Expand All @@ -2437,14 +2437,14 @@ public String apply(BlobStoreConfig c) {
* ones or the configuration can't be saved
* @see {@link CompositeBlobStore#setBlobStores}
*/
void setBlobStores(List<BlobStoreConfig> stores) throws ConfigurationException {
void setBlobStores(List<BlobStoreInfo> stores) throws ConfigurationException {
Preconditions.checkNotNull(stores, "stores is null");

XMLConfiguration xmlConfig = getXmlConfiguration();

CompositeBlobStore compositeBlobStore = getCompositeBlobStore();

List<BlobStoreConfig> oldStores = new ArrayList<BlobStoreConfig>(xmlConfig.getBlobStores());
List<BlobStoreInfo> oldStores = new ArrayList<BlobStoreInfo>(xmlConfig.getBlobStores());

try {
compositeBlobStore.setBlobStores(stores);
Expand Down
24 changes: 12 additions & 12 deletions src/gwc/src/test/java/org/geoserver/gwc/GWCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ public void testSetBlobStoresNull() throws ConfigurationException {

@Test
public void testSetBlobStoresWrapsStorageException() throws Exception {
when(xmlConfig.getBlobStores()).thenReturn(ImmutableList.<BlobStoreConfig> of());
when(xmlConfig.getBlobStores()).thenReturn(ImmutableList.<BlobStoreInfo> of());
CompositeBlobStore composite = mock(CompositeBlobStore.class);
doReturn(composite).when(mediator).getCompositeBlobStore();

Expand All @@ -1395,21 +1395,21 @@ public void testSetBlobStoresWrapsStorageException() throws Exception {

expected.expect(ConfigurationException.class);
expected.expectMessage("Error connecting to BlobStore");
mediator.setBlobStores(ImmutableList.<BlobStoreConfig> of());
mediator.setBlobStores(ImmutableList.<BlobStoreInfo> of());
}

@Test
public void testSetBlobStoresSavesConfig() throws Exception {
when(xmlConfig.getBlobStores()).thenReturn(ImmutableList.<BlobStoreConfig> of());
when(xmlConfig.getBlobStores()).thenReturn(ImmutableList.<BlobStoreInfo> of());
CompositeBlobStore composite = mock(CompositeBlobStore.class);
doReturn(composite).when(mediator).getCompositeBlobStore();

List<BlobStoreConfig> configList = Lists.newArrayList(mock(BlobStoreConfig.class),
mock(BlobStoreConfig.class));
List<BlobStoreInfo> configList = Lists.newArrayList(mock(BlobStoreInfo.class),
mock(BlobStoreInfo.class));
when(xmlConfig.getBlobStores()).thenReturn(configList);

BlobStoreConfig config = new FileBlobStoreConfig();
List<BlobStoreConfig> newStores = ImmutableList.<BlobStoreConfig> of(config);
BlobStoreInfo config = new FileBlobStoreInfo();
List<BlobStoreInfo> newStores = ImmutableList.<BlobStoreInfo> of(config);
mediator.setBlobStores(newStores);

verify(composite, times(1)).setBlobStores(same(newStores));
Expand All @@ -1419,18 +1419,18 @@ public void testSetBlobStoresSavesConfig() throws Exception {

@Test
public void testSetBlobStoresRestoresRuntimeStoresOnSaveFailure() throws Exception {
when(xmlConfig.getBlobStores()).thenReturn(ImmutableList.<BlobStoreConfig> of());
when(xmlConfig.getBlobStores()).thenReturn(ImmutableList.<BlobStoreInfo> of());
CompositeBlobStore composite = mock(CompositeBlobStore.class);
doReturn(composite).when(mediator).getCompositeBlobStore();

doThrow(new IOException("expected")).when(xmlConfig).save();

List<BlobStoreConfig> oldStores = Lists.newArrayList(mock(BlobStoreConfig.class),
mock(BlobStoreConfig.class));
List<BlobStoreInfo> oldStores = Lists.newArrayList(mock(BlobStoreInfo.class),
mock(BlobStoreInfo.class));
when(xmlConfig.getBlobStores()).thenReturn(oldStores);

BlobStoreConfig config = new FileBlobStoreConfig();
List<BlobStoreConfig> newStores = ImmutableList.<BlobStoreConfig> of(config);
BlobStoreInfo config = new FileBlobStoreInfo();
List<BlobStoreInfo> newStores = ImmutableList.<BlobStoreInfo> of(config);
try {
mediator.setBlobStores(newStores);
fail("Expected ConfigurationException");
Expand Down

0 comments on commit 55ebbe6

Please sign in to comment.