use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoConfigMigration method upgradeValidateAndVersion.
private GoConfigMigrationResult upgradeValidateAndVersion(File configFile, boolean shouldTryOlderVersion, String currentGoServerVersion) throws Exception {
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
String xmlStringBeforeUpgrade = FileUtils.readFileToString(configFile);
int currentVersion = getCurrentSchemaVersion(xmlStringBeforeUpgrade);
String reloadedXml;
if (shouldUpgrade(currentVersion)) {
backup(configFile);
reloadedXml = upgrade(xmlStringBeforeUpgrade, currentVersion);
GoConfigHolder configHolder = reloadedConfig(stream, reloadedXml);
reloadedXml = new String(stream.toByteArray());
configRepository.checkin(new GoConfigRevision(reloadedXml, CachedDigestUtils.md5Hex(reloadedXml), UPGRADE, currentGoServerVersion, timeProvider));
} else {
GoConfigHolder configHolder = reloadedConfig(stream, xmlStringBeforeUpgrade);
reloadedXml = new String(stream.toByteArray());
}
FileUtils.writeStringToFile(configFile, reloadedXml);
} catch (Exception e) {
GoConfigRevision currentConfigRevision = configRepository.getCurrentRevision();
if (shouldTryOlderVersion && ifVersionedConfig(currentConfigRevision)) {
GoConfigMigrationResult goConfigMigrationResult = revertFileToVersion(configFile, currentConfigRevision, e);
upgradeValidateAndVersion(configFile, false, currentGoServerVersion);
return goConfigMigrationResult;
} else {
log(shouldTryOlderVersion);
throw e;
}
}
return GoConfigMigrationResult.success();
}
use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoConfigMigrationTest method shouldCommitConfig_WithUsername_Upgrade.
@Test
public void shouldCommitConfig_WithUsername_Upgrade() throws Exception {
File file = tempFiles.createFile("my-config.xml");
FileUtil.writeContentToFile(OLDER_VERSION_XML, file);
final GoConfigRevision[] commitMade = new GoConfigRevision[1];
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) throws Throwable {
commitMade[0] = (GoConfigRevision) invocation.getArguments()[0];
return null;
}
}).when(configRepo).checkin(any(GoConfigRevision.class));
goConfigMigration.upgradeIfNecessary(file, null);
assertThat(commitMade[0].getUsername(), is(GoConfigMigration.UPGRADE));
}
use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoFileConfigDataSource method getMergedConfig.
private String getMergedConfig(NoOverwriteUpdateConfigCommand noOverwriteCommand, String latestMd5, List<PartialConfig> partials) throws Exception {
LOGGER.debug("[Config Save] Getting merged config");
String oldMd5 = noOverwriteCommand.unmodifiedMd5();
CruiseConfig modifiedConfig = getOldConfigAndMutateWithChanges(noOverwriteCommand, oldMd5);
modifiedConfig.setPartials(partials);
String modifiedConfigAsXml = convertMutatedConfigToXml(modifiedConfig, latestMd5);
GoConfigRevision configRevision = new GoConfigRevision(modifiedConfigAsXml, "temporary-md5-for-branch", getConfigUpdatingUser(noOverwriteCommand).getUserName(), serverVersion.version(), timeProvider);
String mergedConfigXml = configRepository.getConfigMergedWithLatestRevision(configRevision, oldMd5);
LOGGER.debug("[Config Save] -=- Done converting merged config to XML");
return mergedConfigXml;
}
use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class GoFileConfigDataSource method checkinConfigToGitRepo.
private void checkinConfigToGitRepo(List<PartialConfig> partials, CruiseConfig config, String configAsXml, String md5, String currentUser) throws Exception {
reloadStrategy.latestState(config);
LOGGER.debug("[Config Save] === Checking in the valid XML to config.git");
configRepository.checkin(new GoConfigRevision(configAsXml, md5, currentUser, serverVersion.version(), timeProvider));
LOGGER.debug("[Config Save] === Done checking in to config.git");
cachedGoPartials.markAsValid(partials);
}
use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.
the class FullConfigSaveFlow method checkinToConfigRepo.
protected void checkinToConfigRepo(String currentUser, CruiseConfig updatedConfig, String xmlString) throws Exception {
LOGGER.debug("[Config Save] Checkin updated config to git: Starting.");
configRepository.checkin(new GoConfigRevision(xmlString, updatedConfig.getMd5(), currentUser, serverVersion.version(), timeProvider));
LOGGER.debug("[Config Save] Checkin updated config to git: Done.");
}
Aggregations