public GWCConfig getConfig() { return gwcConfigPersister.getConfig(); }
public void saveConfig(GWCConfig gwcConfig) throws IOException { gwcConfigPersister.save(gwcConfig); }
public GWCConfig getConfig() { if (config == null) { try { loadConfig(); } catch (IOException e) { throw new RuntimeException(e); } } return config; }
/** * @see org.geoserver.config.GeoServerInitializer#initialize(org.geoserver.config.GeoServer) */ public void initialize(final GeoServer geoServer) throws Exception { LOGGER.info("Initializing GeoServer specific GWC configuration from " + GWCConfigPersister.GWC_CONFIG_FILE); final Version currentVersion = new Version("1.0.0"); final File configFile = configPersister.findConfigFile(); if (configFile == null) { LOGGER.fine("GWC's GeoServer specific configuration not found, creating with old defaults"); GWCConfig oldDefaults = GWCConfig.getOldDefaults(); oldDefaults.setVersion(currentVersion.toString()); upgradeWMSIntegrationConfig(geoServer, oldDefaults); createDefaultTileLayerInfos(oldDefaults); configPersister.save(oldDefaults); } final GWCConfig config = configPersister.getConfig(); final Version version = new Version(config.getVersion()); if (currentVersion.compareTo(version) > 0) { // got the global config file, so old defaults are already in place if need be. Now // check whether we need to migrate the configuration from the Layer/GroupInfo metadata // maps to the tile layer catalog store moveTileLayerInfosToTileLayerCatalog(); config.setVersion(currentVersion.toString()); configPersister.save(config); } final GWCConfig gwcConfig = configPersister.getConfig(); checkNotNull(gwcConfig); }
config.setDirectWMSIntegrationEnabled(true); persister.save(config); assertSame(config, persister.getConfig()); persister = new GWCConfigPersister(new XStreamPersisterFactory(), resourceLoader); assertEquals(config, persister.getConfig()); persister = new GWCConfigPersister(new XStreamPersisterFactory(), resourceLoader); GWCConfig actual = persister.getConfig(); assertEquals(expected, actual);
public void testUpgradeDirectWMSIntegrationFlag() throws Exception { // no gwc-gs.xml exists, so that initialization runs when(configPersister.findConfigFile()).thenReturn(null); // no catalog layers for this test List<LayerInfo> layers = ImmutableList.of(); List<LayerGroupInfo> groups = ImmutableList.of(); when(rawCatalog.getLayers()).thenReturn(layers); when(rawCatalog.getLayerGroups()).thenReturn(groups); WMSInfoImpl wmsInfo = new WMSInfoImpl(); // initialize wmsInfo with a value for the old direct wms integration flag wmsInfo.getMetadata().put(GWCInitializer.WMS_INTEGRATION_ENABLED_KEY, Boolean.TRUE); // make sure WMSInfo exists when(geoServer.getService(eq(WMSInfo.class))).thenReturn(wmsInfo); ArgumentCaptor<GWCConfig> captor = ArgumentCaptor.forClass(GWCConfig.class); // run layer initialization initializer.initialize(geoServer); verify(configPersister, times(2)).save(captor.capture()); assertTrue(captor.getAllValues().get(0).isDirectWMSIntegrationEnabled()); assertFalse(wmsInfo.getMetadata().containsKey(GWCInitializer.WMS_INTEGRATION_ENABLED_KEY)); verify(geoServer).save(same(wmsInfo)); }
public void testUpgradeFromTileLayerInfosToTileLayerCatalog() throws Exception { when(configPersister.findConfigFile()).thenReturn(fakeConfig); when(configPersister.getConfig()).thenReturn(defaults);
private synchronized void loadConfig() throws IOException { File configFile = findConfigFile(); checkNotNull(configFile, "gwc config file does not exist: ", GWC_CONFIG_FILE); XStreamPersister xmlPersister = this.persisterFactory.createXMLPersister(); configureXstream(xmlPersister.getXStream()); try { InputStream in = new FileInputStream(configFile); try { this.config = xmlPersister.load(in, GWCConfig.class); } finally { in.close(); } LOGGER.fine("GWC GeoServer specific configuration loaded from " + GWC_CONFIG_FILE); } catch (Exception e) { LOGGER.log( Level.WARNING, "Error loading GWC GeoServer specific " + "configuration from " + configFile.getAbsolutePath() + ". Applying defaults.", e); this.config = new GWCConfig(); } }
/** * Saves and applies the integrated GWC's GeoServer specific configuration to the * {@code <data dir>/gwc-gs.xml} file. * * @param config * * @throws IOException */ public void save(final GWCConfig config) throws IOException { LOGGER.finer("Saving integrated GWC configuration"); File tmp = new File(getConfigRoot(), GWC_CONFIG_FILE + ".tmp"); XStreamPersister xmlPersister = this.persisterFactory.createXMLPersister(); configureXstream(xmlPersister.getXStream()); OutputStream out = new FileOutputStream(tmp); try { xmlPersister.save(config, out); } finally { out.close(); } File configFile = new File(getConfigRoot(), GWC_CONFIG_FILE); IOUtils.rename(tmp, configFile); this.config = config; LOGGER.finer("Integrated GWC configuration saved to " + configFile.getAbsolutePath()); }
public void testInitializeLayersToOldDefaults() throws Exception { // no gwc-gs.xml exists when(configPersister.findConfigFile()).thenReturn(null); // ignore the upgrade of the direct wms integration flag on this test when(geoServer.getService(eq(WMSInfo.class))).thenReturn(null); // let the catalog have something to initialize LayerInfo layer = mockLayer("testLayer", new String[]{}, LayerInfo.Type.RASTER); LayerGroupInfo group = mockGroup("testGroup", layer); when(rawCatalog.getLayers()).thenReturn(Lists.newArrayList(layer)); when(rawCatalog.getLayerGroups()).thenReturn(Lists.newArrayList(group)); // run layer initialization initializer.initialize(geoServer); // make sure default tile layers were created GWCConfig oldDefaults = GWCConfig.getOldDefaults(); GeoServerTileLayerInfo tileLayer = TileLayerInfoUtil.loadOrCreate(layer, oldDefaults); GeoServerTileLayerInfo tileLayerGroup = TileLayerInfoUtil.loadOrCreate(group, oldDefaults); verify(tileLayerCatalog, times(1)).save(eq(tileLayer)); verify(tileLayerCatalog, times(1)).save(eq(tileLayerGroup)); }
@Override protected void setUp() throws Exception { resourceLoader = mock(GeoServerResourceLoader.class); persister = new GWCConfigPersister(new XStreamPersisterFactory(), resourceLoader); }
final Resource configFile = configPersister.findConfigFile(); if (configFile == null || configFile.getType() != Type.RESOURCE) { LOGGER.fine( upgradeWMSIntegrationConfig(geoServer, oldDefaults); createDefaultTileLayerInfos(oldDefaults); configPersister.save(oldDefaults); final GWCConfig config = configPersister.getConfig(); final Version version = new Version(config.getVersion()); configPersister.save(config); configPersister.save(config); final GWCConfig gwcConfig = configPersister.getConfig(); checkNotNull(gwcConfig); || gwcConfig.getCacheProviderClass().isEmpty()) { gwcConfig.setCacheProviderClass(GuavaCacheProvider.class.toString()); configPersister.save(gwcConfig); map.put(GuavaCacheProvider.class.toString(), new CacheConfiguration()); gwcConfig.setCacheConfigurations(map); configPersister.save(gwcConfig); } else { if (LOGGER.isLoggable(Level.FINEST)) { if (!blobStore.getCacheProviders().containsKey(cacheProviderClass)) {
private synchronized void loadConfig() throws IOException { Resource configFile = findConfigFile(); checkNotNull(configFile, "gwc config file does not exist: ", GWC_CONFIG_FILE); XStreamPersister xmlPersister = this.persisterFactory.createXMLPersister(); configureXstream(xmlPersister.getXStream()); try { try (InputStream in = configFile.in()) { this.config = xmlPersister.load(in, GWCConfig.class); } LOGGER.fine("GWC GeoServer specific configuration loaded from " + GWC_CONFIG_FILE); } catch (Exception e) { LOGGER.log( Level.WARNING, "Error loading GWC GeoServer specific " + "configuration from " + configFile.path() + ". Applying defaults.", e); this.config = new GWCConfig(); } }
/** * Saves and applies the integrated GWC's GeoServer specific configuration to the {@code <data * dir>/gwc-gs.xml} file. * * @param config * @throws IOException */ public void save(final GWCConfig config) throws IOException { LOGGER.finer("Saving integrated GWC configuration"); Resource tmp = getConfigRoot().get(GWC_CONFIG_FILE + ".tmp"); XStreamPersister xmlPersister = this.persisterFactory.createXMLPersister(); configureXstream(xmlPersister.getXStream()); OutputStream out = tmp.out(); try { xmlPersister.save(config, out); } finally { out.close(); } Resource configFile = getConfigRoot().get(GWC_CONFIG_FILE); tmp.renameTo(configFile); this.config = config; LOGGER.finer("Integrated GWC configuration saved to " + configFile.path()); }
public GWCConfig getConfig() { return gwcConfigPersister.getConfig(); }
public void saveConfig(GWCConfig gwcConfig) throws IOException { gwcConfigPersister.save(gwcConfig); // make sure we switch to the lock provider just configured updateLockProvider(gwcConfig.getLockProviderName()); }
public GWCConfig getConfig() { if (config == null) { try { loadConfig(); } catch (IOException e) { throw new RuntimeException(e); } } return config; }
@Override protected void setUp() throws Exception { configPersister = mock(GWCConfigPersister.class); when(configPersister.getConfig()).thenReturn(GWCConfig.getOldDefaults()); rawCatalog = mock(Catalog.class); tileLayerCatalog = mock(TileLayerCatalog.class); initializer = new GWCInitializer(configPersister, rawCatalog, tileLayerCatalog); geoServer = mock(GeoServer.class); }
public void testPrecondition() throws Exception { // gwc-gs.xml shall exists, it's GWCInitializer responsibility when(resourceLoader.find(eq(GWCConfigPersister.GWC_CONFIG_FILE))).thenReturn(null); try { persister.getConfig(); fail("Expected assertion error"); } catch (RuntimeException e) { assertTrue(e.getMessage().contains(GWCConfigPersister.GWC_CONFIG_FILE)); } }
@Override protected void setUp() throws Exception { catalog = mock(Catalog.class); layer = mockLayer("testLayer", new String[]{"style1", "style2"}, LayerInfo.Type.RASTER); layerGroup = mockGroup("testGroup", layer); mockCatalog(); defaults = GWCConfig.getOldDefaults(); gwcConfigPersister = mock(GWCConfigPersister.class); when(gwcConfigPersister.getConfig()).thenReturn(defaults); storageBroker = mock(StorageBroker.class); gridSetBroker = new GridSetBroker(true, true); tileLayerInfo = TileLayerInfoUtil.loadOrCreate(layer, defaults); tileLayerGroupInfo = TileLayerInfoUtil.loadOrCreate(layerGroup, defaults); tileLayer = new GeoServerTileLayer(layer, gridSetBroker, tileLayerInfo); tileLayerGroup = new GeoServerTileLayer(layerGroup, gridSetBroker, tileLayerGroupInfo); tld = mock(TileLayerDispatcher.class); mockTileLayerDispatcher(); config = mock(Configuration.class); tileBreeder = mock(TileBreeder.class); quotaStore = mock(QuotaStore.class); diskQuotaMonitor = mock(DiskQuotaMonitor.class); owsDispatcher = mock(Dispatcher.class); mediator = new GWC(gwcConfigPersister, storageBroker, tld, gridSetBroker, tileBreeder, quotaStore, diskQuotaMonitor, owsDispatcher, catalog); GWC.set(mediator); }