Search in sources :

Example 91 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldRemoveCorrespondingRemotePipelinesFromCachedGoConfigIfTheConfigRepoIsDeleted.

@Test
public void shouldRemoveCorrespondingRemotePipelinesFromCachedGoConfigIfTheConfigRepoIsDeleted() {
    final ConfigRepoConfig repoConfig1 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url1"), XmlPartialConfigProvider.providerName);
    final ConfigRepoConfig repoConfig2 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url2"), XmlPartialConfigProvider.providerName);
    goConfigService.updateConfig(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getConfigRepos().add(repoConfig1);
            cruiseConfig.getConfigRepos().add(repoConfig2);
            return cruiseConfig;
        }
    });
    PartialConfig partialConfigInRepo1 = PartialConfigMother.withPipeline("pipeline_in_repo1", new RepoConfigOrigin(repoConfig1, "repo1_r1"));
    PartialConfig partialConfigInRepo2 = PartialConfigMother.withPipeline("pipeline_in_repo2", new RepoConfigOrigin(repoConfig2, "repo2_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfigInRepo1);
    goPartialConfig.onSuccessPartialConfig(repoConfig2, partialConfigInRepo2);
    // introduce an invalid change in repo1 so that there is a server health message corresponding to it
    PartialConfig invalidPartialInRepo1Revision2 = PartialConfigMother.invalidPartial("pipeline_in_repo1", new RepoConfigOrigin(repoConfig1, "repo1_r2"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, invalidPartialInRepo1Revision2);
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).size(), is(1));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).get(0).getMessage(), is("Invalid Merged Configuration"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).get(0).getDescription(), is("1+ errors :: Invalid stage name ''. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters.;;  -  Config-Repo: url1 at repo1_r2"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(true));
    int countBeforeDeletion = cachedGoConfig.currentConfig().getConfigRepos().size();
    ConfigSaveState configSaveState = cachedGoConfig.writeWithLock(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getConfigRepos().remove(repoConfig1);
            return cruiseConfig;
        }
    });
    assertThat(configSaveState, is(ConfigSaveState.UPDATED));
    assertThat(cachedGoConfig.currentConfig().getConfigRepos().size(), is(countBeforeDeletion - 1));
    assertThat(cachedGoConfig.currentConfig().getConfigRepos().contains(repoConfig2), is(true));
    assertThat(cachedGoConfig.currentConfig().getAllPipelineNames().contains(new CaseInsensitiveString("pipeline_in_repo1")), is(false));
    assertThat(cachedGoConfig.currentConfig().getAllPipelineNames().contains(new CaseInsensitiveString("pipeline_in_repo2")), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(1));
    assertThat(((RepoConfigOrigin) cachedGoPartials.lastKnownPartials().get(0).getOrigin()).getMaterial().getFingerprint().equals(repoConfig2.getMaterialConfig().getFingerprint()), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().stream().filter(new Predicate<PartialConfig>() {

        @Override
        public boolean test(PartialConfig item) {
            return ((RepoConfigOrigin) item.getOrigin()).getMaterial().getFingerprint().equals(repoConfig1.getMaterialConfig().getFingerprint());
        }
    }).findFirst().orElse(null), is(nullValue()));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(1));
    assertThat(((RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin()).getMaterial().getFingerprint().equals(repoConfig2.getMaterialConfig().getFingerprint()), is(true));
    assertThat(cachedGoPartials.lastValidPartials().stream().filter(new Predicate<PartialConfig>() {

        @Override
        public boolean test(PartialConfig item) {
            return ((RepoConfigOrigin) item.getOrigin()).getMaterial().getFingerprint().equals(repoConfig1.getMaterialConfig().getFingerprint());
        }
    }).findFirst().orElse(null), is(nullValue()));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(true));
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Predicate(java.util.function.Predicate)

Example 92 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldUpdateConfigWhenPartialsAreConfigured.

@Test
public void shouldUpdateConfigWhenPartialsAreConfigured() throws GitAPIException, IOException {
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    PartialConfig validPartial = PartialConfigMother.withPipeline("remote_pipeline", new RepoConfigOrigin(configRepo, "revision1"));
    goPartialConfig.onSuccessPartialConfig(configRepo, validPartial);
    assertThat(cachedGoPartials.lastValidPartials().contains(validPartial), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().contains(validPartial), is(true));
    CruiseConfig config = new Cloner().deepClone(cachedGoConfig.loadForEditing());
    config.addEnvironment(UUID.randomUUID().toString());
    ConfigSaveState state = cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(config, goConfigService.configFileMd5()));
    String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
    String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
    assertThat(state, is(ConfigSaveState.UPDATED));
    assertThat(cachedGoConfig.loadForEditing(), is(config));
    assertNotEquals(gitShaBeforeSave, gitShaAfterSave);
    assertThat(cachedGoConfig.loadForEditing().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
    assertThat(cachedGoConfig.currentConfig().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
    assertThat(configXmlFromConfigFolder, is(configRepository.getCurrentRevision().getContent()));
    assertThat(cachedGoPartials.lastValidPartials().contains(validPartial), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().contains(validPartial), is(true));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) StringContains.containsString(org.hamcrest.core.StringContains.containsString) File(java.io.File) Cloner(com.rits.cloning.Cloner)

Example 93 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldMarkAPartialAsValidIfItBecomesValidBecauseOfNewerChangesInMainXml_GitMergeWorkflow.

@Test
public void shouldMarkAPartialAsValidIfItBecomesValidBecauseOfNewerChangesInMainXml_GitMergeWorkflow() {
    final String upstream = UUID.randomUUID().toString();
    String remoteDownstream = "remote-downstream";
    setupExternalConfigRepoWithDependencyMaterialOnPipelineInMainXml(upstream, remoteDownstream);
    PartialConfig partialWithStageRenamed = new Cloner().deepClone(goPartialConfig.lastPartials().get(0));
    PipelineConfig pipelineInRemoteConfigRepo = partialWithStageRenamed.getGroups().get(0).getPipelines().get(0);
    pipelineInRemoteConfigRepo.materialConfigs().getDependencyMaterial().setStageName(new CaseInsensitiveString("new_name"));
    partialWithStageRenamed.setOrigin(new RepoConfigOrigin(configRepo, "r2"));
    goPartialConfig.onSuccessPartialConfig(configRepo, partialWithStageRenamed);
    final String md5 = cachedGoConfig.currentConfig().getMd5();
    // some random unrelated change to force a git merge workflow
    cachedGoConfig.writeWithLock(new NoOverwriteUpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.server().setCommandRepositoryLocation("new_location");
            return cruiseConfig;
        }

        @Override
        public String unmodifiedMd5() {
            return md5;
        }
    });
    ConfigSaveState saveState = cachedGoConfig.writeWithLock(new NoOverwriteUpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().setName(new CaseInsensitiveString("new_name"));
            return cruiseConfig;
        }

        @Override
        public String unmodifiedMd5() {
            return md5;
        }
    });
    assertThat(saveState, is(ConfigSaveState.MERGED));
    assertThat(cachedGoPartials.lastValidPartials().get(0).getGroups().first().get(0).materialConfigs().getDependencyMaterial().getStageName(), is(new CaseInsensitiveString("new_name")));
    assertThat(goConfigService.getConfigForEditing().getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().name(), is(new CaseInsensitiveString("new_name")));
    assertThat(goConfigService.getCurrentConfig().getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().name(), is(new CaseInsensitiveString("new_name")));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Cloner(com.rits.cloning.Cloner)

Example 94 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldAllowFallbackMergeAndSaveWhenKnownPartialHasAnInvalidEnvironmentThatRefersToAnUnknownPipeline.

@Test
public void shouldAllowFallbackMergeAndSaveWhenKnownPartialHasAnInvalidEnvironmentThatRefersToAnUnknownPipeline() throws Exception {
    cachedGoPartials.clear();
    PartialConfig partialConfigWithInvalidEnvironment = PartialConfigMother.withEnvironment("env", new RepoConfigOrigin(configRepo, "revision1"));
    goPartialConfig.onSuccessPartialConfig(configRepo, partialConfigWithInvalidEnvironment);
    ConfigSaveState state = cachedGoConfig.writeWithLock(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.server().setCommandRepositoryLocation("newlocation");
            return cruiseConfig;
        }
    });
    assertThat(state, is(ConfigSaveState.UPDATED));
    assertThat(goConfigService.getCurrentConfig().server().getCommandRepositoryLocation(), is("newlocation"));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException)

Example 95 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials.

@Test
public void shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials() throws GitAPIException, IOException {
    setupExternalConfigRepoWithDependencyMaterialOnPipelineInMainXml("upstream", "downstream");
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    CruiseConfig originalConfig = cachedGoConfig.loadForEditing();
    CruiseConfig editedConfig = new Cloner().deepClone(originalConfig);
    editedConfig.getGroups().remove(editedConfig.findGroup("default"));
    try {
        cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(editedConfig, goConfigService.configFileMd5()));
        fail("Expected the test to fail");
    } catch (Exception e) {
        String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
        String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
        assertThat(cachedGoConfig.loadForEditing(), is(originalConfig));
        assertEquals(gitShaBeforeSave, gitShaAfterSave);
        assertThat(cachedGoConfig.loadForEditing().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
        assertThat(cachedGoConfig.currentConfig().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
        assertThat(configXmlFromConfigFolder, is(configRepository.getCurrentRevision().getContent()));
        RepoConfigOrigin origin = (RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin();
        assertThat(origin.getRevision(), is("r1"));
    }
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) StringContains.containsString(org.hamcrest.core.StringContains.containsString) File(java.io.File) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Cloner(com.rits.cloning.Cloner)

Aggregations

RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)97 Test (org.junit.Test)74 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)34 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)29 FileConfigOrigin (com.thoughtworks.go.config.remote.FileConfigOrigin)23 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)15 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)13 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)11 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)11 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)11 StringContains.containsString (org.hamcrest.core.StringContains.containsString)11 File (java.io.File)9 IOException (java.io.IOException)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 ExpectedException (org.junit.rules.ExpectedException)8 Cloner (com.rits.cloning.Cloner)7 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)6 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)6