/** * @return the unique identifier for the blob store; which {@link TileLayer#getBlobStoreId()} * refers to. * @deprecated Please use {@link #getName()} to retrieve the unique name. * @see #getName() */ @Deprecated public String getId() { return getName(); }
@Override public void handleRemoveBlobStore(BlobStoreInfo removedBlobStore) throws ConfigurationException, StorageException { if (removedBlobStore .getName() .equals(blobStores.get(DEFAULT_STORE_DEFAULT_ID).config.getName())) { throw new ConfigurationException( "The default blob store can't be removed: " + removedBlobStore.getName()); } blobStores.remove(removedBlobStore.getName()); }
/** * Returns the BlobStoreConfiguration for the given BlobStoreInfo, if found in list of blob * store configurations. * * @param bs BlobStoreInfo for this configuration * @return The BlobStoreConfiguration for BlobStoreInfo * @throws IllegalArgumentException */ public BlobStoreConfiguration getConfiguration(BlobStoreInfo bs) throws IllegalArgumentException { Assert.notNull(bs, "blobStore is null"); return getConfiguration(bs.getName()); }
@Override public void handleModifyBlobStore(BlobStoreInfo modifiedBlobStore) throws ConfigurationException, StorageException { LiveStore removedStore = blobStores.remove(modifiedBlobStore.getName()); try { if (modifiedBlobStore.isDefault() && !modifiedBlobStore .getName() .equals(blobStores.get(DEFAULT_STORE_DEFAULT_ID).config.getName())) { loadBlobStoreOverwritingDefault(blobStores, modifiedBlobStore); } else { loadBlobStore(blobStores, modifiedBlobStore); } } catch (StorageException | ConfigurationException e) { blobStores.put(modifiedBlobStore.getName(), removedStore); throw e; } }
/** @see BlobStoreConfiguration#getBlobStoreNames() */ @Override public Set<String> getBlobStoreNames() { return getGwcConfig() .getBlobStores() .stream() .map( (info) -> { return info.getName(); }) .collect(Collectors.toSet()); }
private void destroy(Map<String, LiveStore> blobStores) { for (LiveStore bs : blobStores.values()) { try { if (bs.config.isEnabled()) { bs.liveInstance.destroy(); } } catch (Exception e) { log.error("Error disposing BlobStore " + bs.config.getName(), e); } } blobStores.clear(); }
/** @see BlobStoreConfiguration#getBlobStore(java.lang.String) */ @Override public Optional<BlobStoreInfo> getBlobStore(String name) { for (BlobStoreInfo info : getGwcConfig().getBlobStores()) { if (info.getName().equals(name)) { return Optional.of((BlobStoreInfo) info.clone()); } } return Optional.empty(); }
/** * 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, BlobStoreInfo config) throws ConfigurationException { checkNotNull(oldId); checkNotNull(config); BlobStoreAggregator agg = getBlobStoreAggregator(); if (config.getName().equals(oldId)) { agg.modifyBlobStore(config); } else { synchronized (agg) { agg.renameBlobStore(oldId, config.getName()); agg.modifyBlobStore(config); } } }
BlobStoreInfo oldConfig = blobStores.get(DEFAULT_STORE_DEFAULT_ID).config; if (oldName.equals(oldConfig.getName()) || modifiedBlobStore.equals(oldConfig)) {
if (info.getName() == null) { throw new IllegalArgumentException( "Failed to add BlobStoreInfo. A BlobStoreInfo name cannot be null"); if (getBlobStoreNames().contains(info.getName())) { throw new IllegalArgumentException( String.format( "Failed to add BlobStoreInfo. A BlobStoreInfo with name \"%s\" already exists", info.getName()));
private void assertBlobStoreConfiguration(BlobStoreConfiguration config) { List<BlobStoreInfo> blobStores = config.getBlobStores(); List<String> blobStoreNames = Arrays.asList(BLOBSTORES); for (BlobStoreInfo blobStoreConfig : blobStores) { assertTrue(blobStoreNames.contains(blobStoreConfig.getName())); } assertEquals(BLOBSTORES.length, blobStores.size()); } }
private BlobStore store(String layerId) throws StorageException { LiveStore store; try { store = forLayer(layerId); } catch (GeoWebCacheException e) { throw new StorageException(e.getMessage(), e); } if (!store.config.isEnabled()) { throw new StorageException( "Attempted to use a blob store that's disabled: " + store.config.getName()); } return store.liveInstance; }
@Test public void testSuitabilityOnAdd() throws Exception { final BlobStoreInfo info = mock(BlobStoreInfo.class); when(info.getName()).thenReturn("testStore"); when(info.isEnabled()).thenReturn(true); BlobStore subStore = mock(BlobStore.class); when(info.createInstance(Mockito.any(), Mockito.any())) .thenAnswer( invocation -> { assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EXISTING)); return subStore; }); store = create(); store.handleAddBlobStore(info); verify(info).createInstance(Mockito.any(), Mockito.any()); }
@Test public void testNonDefaultSuitabilityOnAdd() throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); final BlobStoreInfo info = mock(BlobStoreInfo.class); when(info.getName()).thenReturn("testStore"); when(info.isEnabled()).thenReturn(true); BlobStore subStore = mock(BlobStore.class); when(info.createInstance(Mockito.any(), Mockito.any())) .thenAnswer( invocation -> { assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EMPTY)); return subStore; }); store = create(); store.handleAddBlobStore(info); verify(info).createInstance(Mockito.any(), Mockito.any()); }
private SqliteBlobStore getBlobStoreForLayer(String layerName) throws Exception { // let's find layer associated store String blobStoreId = tileLayerDispatcher.getTileLayer(layerName).getBlobStoreId(); BlobStoreInfo blobStoreConfig = null; for (BlobStoreInfo candidateBlobStoreConfig : blobConfiguration.getBlobStores()) { if (blobStoreId == null) { // we need to find the default configuration if (candidateBlobStoreConfig.isDefault()) { // this is the default configuration, we are done blobStoreConfig = candidateBlobStoreConfig; break; } } if (candidateBlobStoreConfig.getName().equals(blobStoreId)) { // we need to find a specific store by is id blobStoreConfig = candidateBlobStoreConfig; break; } } if (blobStoreConfig == null || !(blobStoreConfig instanceof SqliteInfo)) { // no store found or the store is not an sqlite store return null; } // returning an instance of found store return (SqliteBlobStore) blobStoreConfig.createInstance( tileLayerDispatcher, gwcConfiguration.getLockProvider()); } }
private SqliteBlobStore getBlobStoreForLayer(String layerName) throws Exception { // let's find layer associated store String blobStoreId = tileLayerDispatcher.getTileLayer(layerName).getBlobStoreId(); BlobStoreInfo blobStoreConfig = null; for (BlobStoreInfo candidateBlobStoreConfig : blobConfiguration.getBlobStores()) { if (blobStoreId == null) { // we need to find the default configuration if (candidateBlobStoreConfig.isDefault()) { // this is the default configuration, we are done blobStoreConfig = candidateBlobStoreConfig; break; } } if (candidateBlobStoreConfig.getName().equals(blobStoreId)) { // we need to find a specific store by is id blobStoreConfig = candidateBlobStoreConfig; break; } } if (blobStoreConfig == null || !(blobStoreConfig instanceof SqliteInfo)) { // no store found or the store is not an sqlite store return null; } // returning an instance of found store return (SqliteBlobStore) blobStoreConfig.createInstance( tileLayerDispatcher, gwcConfiguration.getLockProvider()); } }
@Test public void testSuitabilityOnStartup() throws Exception { // Default to EXISTING assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EXISTING)); final BlobStoreInfo info = mock(BlobStoreInfo.class); when(info.getName()).thenReturn("testStore"); when(info.isEnabled()).thenReturn(true); BlobStore subStore = mock(BlobStore.class); when(info.createInstance(Mockito.any(), Mockito.any())) .thenAnswer( invocation -> { // When this gets called we should be skipping suitability checks assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.NONE)); return subStore; }); configs.add(info); store = create(); verify(info).createInstance(Mockito.any(), Mockito.any()); // Should be back to default after startup. assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EXISTING)); }
@Test public void testNonDefaultSuitabilityOnStartup() throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EMPTY)); final BlobStoreInfo info = mock(BlobStoreInfo.class); when(info.getName()).thenReturn("testStore"); when(info.isEnabled()).thenReturn(true); BlobStore subStore = mock(BlobStore.class); when(info.createInstance(Mockito.any(), Mockito.any())) .thenAnswer( invocation -> { // When this gets called we should be skipping suitability checks assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.NONE)); return subStore; }); configs.add(info); store = create(); verify(info).createInstance(Mockito.any(), Mockito.any()); // Should be back to default after startup. assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EMPTY)); }
@Test public void testRenameBlobStoreChangesLayer() throws GeoWebCacheException { TileLayer layer = tileLayerDispatcher.getLayerList().iterator().next(); BlobStoreInfo blobStore = blobStoreAggregator.getBlobStore(layer.getBlobStoreId()); assertNotNull(blobStore); blobStoreAggregator.renameBlobStore(blobStore.getName(), "foobarbaz"); layer = tileLayerDispatcher.getLayerList().iterator().next(); assertEquals("foobarbaz", layer.getBlobStoreId()); } }