use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class GoFileConfigDataSource method forceLoad.
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;
}
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class GoConfigMigrator method upgradeConfigFile.
private GoConfigHolder upgradeConfigFile() throws Exception {
String upgradedXml = this.goConfigMigration.upgradeIfNecessary(this.goConfigFileReader.configXml());
LOGGER.info("[Config Save] Starting Config Save post upgrade using FullConfigSaveNormalFlow");
CruiseConfig cruiseConfig = this.loader.deserializeConfig(upgradedXml);
return fullConfigSaveNormalFlow.execute(new FullConfigUpdateCommand(cruiseConfig, null), new ArrayList<>(), "Upgrade");
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class FullConfigSaveMergeFlowTest method setup.
@BeforeEach
public void setup() throws Exception {
configForEdit = mock(CruiseConfig.class);
updateConfigCommand = new FullConfigUpdateCommand(configForEdit, "md5");
loader = mock(MagicalGoConfigXmlLoader.class);
writer = mock(MagicalGoConfigXmlWriter.class);
document = mock(Document.class);
fileWriter = mock(GoConfigFileWriter.class);
timeProvider = mock(TimeProvider.class);
configRepository = mock(ConfigRepository.class);
cachedGoPartials = mock(CachedGoPartials.class);
configElementImplementationRegistry = mock(ConfigElementImplementationRegistry.class);
partials = new ArrayList<>();
flow = new FullConfigSaveMergeFlow(loader, writer, configElementImplementationRegistry, timeProvider, configRepository, cachedGoPartials, fileWriter);
when(writer.documentFrom(configForEdit)).thenReturn(document);
when(writer.toString(document)).thenReturn("cruise_config");
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class GoConfigMigratorTest method shouldUpgradeConfigUsingLatestConfigRevisionInRepoIfUpgradingConfigFileFails.
@Test
public void shouldUpgradeConfigUsingLatestConfigRevisionInRepoIfUpgradingConfigFileFails() throws Exception {
String configInFile = "cruise_config_in_file";
String versionedConfig = "versioned_cruise_config";
CruiseConfig cruiseConfig = mock(CruiseConfig.class);
ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
when(systemEnvironment.getCruiseConfigFile()).thenReturn("");
when(reader.configXml()).thenReturn(configInFile).thenReturn(versionedConfig);
when(configRepository.getCurrentRevision()).thenReturn(mock(GoConfigRevision.class));
when(goConfigMigration.upgradeIfNecessary(configInFile)).thenThrow(new RuntimeException());
when(goConfigMigration.upgradeIfNecessary(versionedConfig)).thenReturn(versionedConfig);
when(loader.deserializeConfig(versionedConfig)).thenReturn(cruiseConfig);
when(goConfigMigration.revertFileToVersion(any(File.class), any(GoConfigRevision.class))).thenReturn(new File("path_to_backup_file"));
when(fullConfigSaveNormalFlow.execute(commandArgumentCaptor.capture(), listArgumentCaptor.capture(), stringArgumentCaptor.capture())).thenReturn(mock(GoConfigHolder.class));
goConfigMigrator.migrate();
assertThat(stringArgumentCaptor.getValue(), is("Upgrade"));
assertThat(commandArgumentCaptor.getValue().configForEdit(), is(cruiseConfig));
assertThat(listArgumentCaptor.getValue().size(), is(0));
verify(goConfigMigration).revertFileToVersion(any(File.class), any(GoConfigRevision.class));
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldUpdateConfigWithLastKnownPartials_OnWriteFullConfigWithLock.
@Test
public void shouldUpdateConfigWithLastKnownPartials_OnWriteFullConfigWithLock() throws Exception {
com.thoughtworks.go.server.newsecurity.SessionUtilsHelper.loginAs("loser_boozer");
BasicCruiseConfig configForEdit = new BasicCruiseConfig();
MagicalGoConfigXmlLoader.setMd5(configForEdit, "md5");
FullConfigUpdateCommand updatingCommand = new FullConfigUpdateCommand(new BasicCruiseConfig(), "md5");
GoConfigHolder configHolder = new GoConfigHolder(new BasicCruiseConfig(), configForEdit);
List<PartialConfig> lastKnownPartials = mock(List.class);
when(cachedGoPartials.lastKnownPartials()).thenReturn(lastKnownPartials);
when(fullConfigSaveNormalFlow.execute(any(FullConfigUpdateCommand.class), anyList(), any(String.class))).thenReturn(new GoConfigHolder(new BasicCruiseConfig(), new BasicCruiseConfig()));
dataSource.writeFullConfigWithLock(updatingCommand, configHolder);
verify(fullConfigSaveNormalFlow).execute(updatingCommand, lastKnownPartials, "loser_boozer");
}
Aggregations