Search in sources :

Example 16 with FullConfigUpdateCommand

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;
    }
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) File(java.io.File) IOException(java.io.IOException)

Example 17 with FullConfigUpdateCommand

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

Example 18 with FullConfigUpdateCommand

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");
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) TimeProvider(com.thoughtworks.go.util.TimeProvider) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) Document(org.jdom2.Document) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with FullConfigUpdateCommand

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));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) List(java.util.List) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 20 with FullConfigUpdateCommand

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");
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) Test(org.junit.jupiter.api.Test)

Aggregations

FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)28 Test (org.junit.jupiter.api.Test)23 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)11 File (java.io.File)11 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)8 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)3 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 Configuration (com.thoughtworks.go.domain.config.Configuration)2 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)2 ConfigRepository (com.thoughtworks.go.service.ConfigRepository)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 IOException (java.io.IOException)2 Arrays.asList (java.util.Arrays.asList)2 Document (org.jdom2.Document)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ContextConfiguration (org.springframework.test.context.ContextConfiguration)2 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)1 ConfigElementImplementationRegistrar (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistrar)1