synchronized GoConfigHolder forceLoad(File configFile) throws Exception { LOGGER.debug("Reloading config file: {}", configFile.getAbsolutePath()); GoConfigHolder holder; try { try { List<PartialConfig> lastKnownPartials = cloner.deepClone(cachedGoPartials.lastKnownPartials()); holder = internalLoad(FileUtils.readFileToString(configFile, UTF_8), new ConfigModifyingUser(FILESYSTEM), lastKnownPartials); } catch (GoConfigInvalidException e) { if (!canUpdateConfigWithLastValidPartials()) { throw e; } else { List<PartialConfig> lastValidPartials = cloner.deepClone(cachedGoPartials.lastValidPartials()); holder = internalLoad(FileUtils.readFileToString(configFile, UTF_8), new ConfigModifyingUser(FILESYSTEM), lastValidPartials); } } return holder; } catch (Exception e) { LOGGER.error("Unable to load config file: {} {}", configFile.getAbsolutePath(), e.getMessage(), e); if (configFile.exists()) { LOGGER.warn("--- {} ---", configFile.getAbsolutePath()); LOGGER.warn(FileUtils.readFileToString(configFile, StandardCharsets.UTF_8)); LOGGER.warn("------"); } LOGGER.debug("", e); throw e; } }
synchronized GoConfigHolder forceLoad() throws Exception { File configFile = goConfigFileReader.fileLocation(); CruiseConfig cruiseConfig = this.magicalGoConfigXmlLoader.deserializeConfig(goConfigFileReader.configXml()); LOGGER.debug("Reloading config file: {}", configFile.getAbsolutePath()); GoConfigHolder goConfigHolder; try { try { goConfigHolder = fullConfigSaveNormalFlow.execute(new FullConfigUpdateCommand(cruiseConfig, null), cachedGoPartials.lastKnownPartials(), FILESYSTEM); } catch (GoConfigInvalidException e) { if (!canUpdateConfigWithLastValidPartials()) throw e; goConfigHolder = fullConfigSaveNormalFlow.execute(new FullConfigUpdateCommand(cruiseConfig, null), cachedGoPartials.lastValidPartials(), FILESYSTEM); } reloadStrategy.latestState(goConfigHolder.config); return goConfigHolder; } catch (Exception e) { LOGGER.error("Unable to load config file: {} {}", configFile.getAbsolutePath(), e.getMessage(), e); if (configFile.exists()) { LOGGER.warn("--- {} ---", configFile.getAbsolutePath()); LOGGER.warn(FileUtils.readFileToString(configFile, StandardCharsets.UTF_8)); LOGGER.warn("------"); } LOGGER.debug("", e); throw e; } }
public synchronized GoConfigSaveResult writeFullConfigWithLock(FullConfigUpdateCommand updatingCommand, GoConfigHolder configHolder) { try { GoConfigHolder validatedConfigHolder; try { validatedConfigHolder = trySavingConfigWithLastKnownPartials(updatingCommand, configHolder); } catch (Exception e) { if (!canUpdateConfigWithLastValidPartials()) throw e; LOGGER.warn("Merged config update operation failed on LATEST {} partials. Falling back to using LAST VALID {} partials. Exception message was: {}", cachedGoPartials.lastKnownPartials().size(), cachedGoPartials.lastValidPartials().size(), e.getMessage(), e); validatedConfigHolder = trySavingConfigWithLastValidPartials(updatingCommand, configHolder); } ConfigSaveState configSaveState = shouldMergeConfig(updatingCommand, configHolder) ? ConfigSaveState.MERGED : ConfigSaveState.UPDATED; return new GoConfigSaveResult(validatedConfigHolder, configSaveState); } catch (ConfigFileHasChangedException e) { LOGGER.warn("Configuration file could not be merged successfully after a concurrent edit: {}", e.getMessage(), e); throw e; } catch (GoConfigInvalidException e) { LOGGER.warn("Configuration file is invalid: {}", e.getMessage(), e); throw bomb(e.getMessage(), e); } catch (Exception e) { LOGGER.error("Configuration file is not valid: {}", e.getMessage(), e); throw bomb(e.getMessage(), e); } finally { LOGGER.debug("[Config Save] Done writing with lock"); } }