Search in sources :

Example 21 with GoConfigRevision

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();
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException)

Example 22 with GoConfigRevision

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));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) File(java.io.File) Test(org.junit.Test)

Example 23 with GoConfigRevision

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;
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision)

Example 24 with GoConfigRevision

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);
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision)

Example 25 with GoConfigRevision

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.");
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision)

Aggregations

GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)28 Test (org.junit.Test)22 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 GoConfigRevisions (com.thoughtworks.go.GoConfigRevisions)2 File (java.io.File)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Date (java.util.Date)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 FileOutputStream (java.io.FileOutputStream)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 DateTime (org.joda.time.DateTime)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 SecurityContext (org.springframework.security.context.SecurityContext)1