throws ConfigurationException, StorageException { final String id = config.getName(); final boolean enabled = config.isEnabled(); LiveStore defaultStore = stores.getOrDefault(CompositeBlobStore.DEFAULT_STORE_DEFAULT_ID, null); store = config.createInstance(layers, lockProvider); stores.put(config.getName(), liveStore); if (config.isDefault()) { if (defaultStore == null || defaultStore.config.getName().equals(config.getName())) { if (!enabled) { throw new ConfigurationException( "The default blob store can't be disabled: " + config.getName()); throw new ConfigurationException( "Duplicate default blob store: " + defaultStore.config.getName() + " and " + config.getName());
/** @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(); }
@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; } }
@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()); }
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()); } }
/** * @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(); }
@Test public void testBlobStoreConfigIsLoaded() throws Exception { // get the blobstores from the config (from test resource geowebcache_190.xml) final List<BlobStoreInfo> blobStores = config.getBlobStores(); assertEquals( "Unexpected number of BlobStoreInfo elements configured", 1, blobStores.size()); // get the 1 configured BlobStoreInfo BlobStoreInfo info = blobStores.get(0); assertFalse("Unexpected BlobStoreInfo default setting", info.isDefault()); assertFalse("Unexpected BlobStoreInfo enabled setting", info.isEnabled()); assertTrue( "Unexpected BlobeStoreInfo class type", FileBlobStoreInfo.class.isAssignableFrom(info.getClass())); // cast the info to a FileBlobStoreInfo final FileBlobStoreInfo fileInfo = FileBlobStoreInfo.class.cast(info); assertEquals( "Unexpected FileBlobStoreInfo filesystem block size", 4096, fileInfo.getFileSystemBlockSize()); assertEquals( "Unexpected FileBlobStoreInfo location value", "/tmp/defaultCache", fileInfo.getBaseDirectory()); }
if (null != oldDefaultStore.config.getName()) { oldDefaultStore.config.setDefault(false); blobStoreConfigs.modifyBlobStore(oldDefaultStore.config); oldDefaultStore.config.setDefault(true); throw e;
if (bStore instanceof CompositeBlobStore) { for (BlobStoreInfo bsConfig : blobStoreAggregator.getBlobStores()) { blobStoreLocations.put(bsConfig.getName(), bsConfig.getLocation());
while (infos.hasNext() && foundInfo == null) { final BlobStoreInfo info = infos.next(); if (info.getName().equals(oldName)) { blobStoreInfoToRename.setName(newName); blobStoreInfos.add(blobStoreInfoToRename); while (infos.hasNext() && blobStoreInfoToRevert == null) { final BlobStoreInfo info = infos.next(); if (info.getName().equals(newName)) { blobStoreInfoToRevert.setName(oldName); blobStoreInfos.add(blobStoreInfoToRevert); throw new ConfigurationPersistenceException(
@Override public void handleAddBlobStore(BlobStoreInfo newBlobStore) throws ConfigurationException, StorageException { if (newBlobStore.isDefault()) { loadBlobStoreOverwritingDefault(blobStores, newBlobStore); } else { loadBlobStore(blobStores, newBlobStore); } }
private void createFromSavedConfig(BlobStoreConfiguration configLoad) throws StorageException { List<BlobStoreInfo> blobStores2 = configLoad.getBlobStores(); for (BlobStoreInfo blobStoreConfig : blobStores2) { LockProvider lockProvider = new NoOpLockProvider(); blobStoreConfig.createInstance(dispatch, lockProvider); } }
public LiveStore(BlobStoreInfo config, @Nullable BlobStore store) { Preconditions.checkArgument(config.isEnabled() == (store != null)); this.config = config; this.liveInstance = store; } }
@Override public boolean matches(Object item) { return expected.equals(item); } };
/** @see BlobStoreConfiguration#getBlobStores() */ @Override public List<BlobStoreInfo> getBlobStores() { // need to return an unmodifiable list of unmodifiable BlobStoreInfos return Collections.unmodifiableList( getGwcConfig() .getBlobStores() .stream() .map( (info) -> { return (BlobStoreInfo) info.clone(); }) .collect(Collectors.toList())); }
/** Helper method that finds a GWC store by is id. */ private MbtilesInfo findStore(String storeId) { List<BlobStoreInfo> configurations = GWC.get().getBlobStores(); for (BlobStoreInfo candidateConfiguration : configurations) { if (candidateConfiguration instanceof MbtilesInfo && candidateConfiguration.getId().equals(storeId)) { return (MbtilesInfo) candidateConfiguration; } } return null; } }
@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()); } }