Search in sources :

Example 61 with PartialConfig

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

the class PipelineConfigServiceIntegrationTest method setup.

@Before
public void setup() throws Exception {
    cachedGoPartials.clear();
    configHelper = new GoConfigFileHelper();
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    configHelper.onSetUp();
    goConfigService.forceNotifyListeners();
    user = new Username(new CaseInsensitiveString("current"));
    pipelineConfig = GoConfigMother.createPipelineConfigWithMaterialConfig(UUID.randomUUID().toString(), new GitMaterialConfig("FOO"));
    goConfigService.addPipeline(pipelineConfig, groupName);
    repoConfig1 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url"), XmlPartialConfigProvider.providerName);
    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;
        }
    });
    GoCipher goCipher = new GoCipher();
    goConfigService.updateServerConfig(new MailHost(goCipher), false, goConfigService.configFileMd5(), "artifacts", null, null, "0", null, null, "foo");
    UpdateConfigCommand command = goConfigService.modifyAdminPrivilegesCommand(asList(user.getUsername().toString()), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add));
    goConfigService.updateConfig(command);
    remoteDownstreamPipelineName = "remote-downstream";
    partialConfig = PartialConfigMother.pipelineWithDependencyMaterial(remoteDownstreamPipelineName, pipelineConfig, new RepoConfigOrigin(repoConfig1, "repo1_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfig);
    PartialConfig partialConfigFromRepo2 = PartialConfigMother.withPipeline("independent-pipeline", new RepoConfigOrigin(repoConfig2, "repo2_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, partialConfigFromRepo2);
    result = new HttpLocalizedOperationResult();
    headCommitBeforeUpdate = configRepository.getCurrentRevCommit().name();
    goConfigService.security().securityAuthConfigs().add(new SecurityAuthConfig("file", "cd.go.authentication.passwordfile"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) Before(org.junit.Before)

Example 62 with PartialConfig

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

the class PipelineConfigServiceIntegrationTest method tearDown.

@After
public void tearDown() throws Exception {
    for (PartialConfig partial : cachedGoPartials.lastValidPartials()) {
        assertThat(ErrorCollector.getAllErrors(partial).isEmpty(), is(true));
    }
    for (PartialConfig partial : cachedGoPartials.lastKnownPartials()) {
        assertThat(ErrorCollector.getAllErrors(partial).isEmpty(), is(true));
    }
    cachedGoPartials.clear();
    configHelper.onTearDown();
    dbHelper.onTearDown();
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) After(org.junit.After)

Example 63 with PartialConfig

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

the class GoPartialConfigIntegrationTest method shouldValidateAndMergeJustTheChangedPartialAlongWithAllValidPartialsIfValidationOfAllKnownPartialsFail.

@Test
public void shouldValidateAndMergeJustTheChangedPartialAlongWithAllValidPartialsIfValidationOfAllKnownPartialsFail() {
    goPartialConfig.onSuccessPartialConfig(repoConfig1, PartialConfigMother.withPipeline("p1_repo1", new RepoConfigOrigin(repoConfig1, "1")));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString("p1_repo1")), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1.getMaterialConfig().getFingerprint())).isEmpty(), is(true));
    final String invalidPipelineInPartial = "p1_repo1_invalid";
    PartialConfig invalidPartial = PartialConfigMother.invalidPartial(invalidPipelineInPartial, new RepoConfigOrigin(repoConfig1, "2"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, invalidPartial);
    assertThat(findPartial(invalidPipelineInPartial, cachedGoPartials.lastValidPartials()), is(nullValue()));
    assertThat(findPartial(invalidPipelineInPartial, cachedGoPartials.lastKnownPartials()), is(invalidPartial));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(invalidPipelineInPartial)), is(false));
    List<ServerHealthState> serverHealthStatesForRepo1 = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1));
    assertThat(serverHealthStatesForRepo1.isEmpty(), is(false));
    assertThat(serverHealthStatesForRepo1.get(0).getLogLevel(), is(HealthStateLevel.ERROR));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, PartialConfigMother.withPipeline("p2_repo2", new RepoConfigOrigin(repoConfig2, "1")));
    assertThat(findPartial(invalidPipelineInPartial, cachedGoPartials.lastValidPartials()), is(nullValue()));
    assertThat(findPartial(invalidPipelineInPartial, cachedGoPartials.lastKnownPartials()), is(invalidPartial));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString("p1_repo1")), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString("p2_repo2")), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(invalidPipelineInPartial)), is(false));
    serverHealthStatesForRepo1 = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1));
    assertThat(serverHealthStatesForRepo1.isEmpty(), is(false));
    assertThat(serverHealthStatesForRepo1.get(0).getLogLevel(), is(HealthStateLevel.ERROR));
    List<ServerHealthState> serverHealthStatesForRepo2 = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2));
    assertThat(serverHealthStatesForRepo2.isEmpty(), is(true));
}
Also used : RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.Test)

Example 64 with PartialConfig

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

the class GoPartialConfigIntegrationTest method shouldNotSaveConfigWhenANewInValidPartialGetsAdded.

@Test
public void shouldNotSaveConfigWhenANewInValidPartialGetsAdded() {
    PartialConfig invalidPartial = PartialConfigMother.invalidPartial("p1");
    invalidPartial.setOrigins(new RepoConfigOrigin(repoConfig1, "sha-2"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, invalidPartial);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString("p1")), is(false));
    List<ServerHealthState> serverHealthStates = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1));
    assertThat(serverHealthStates.isEmpty(), is(false));
    assertThat(serverHealthStates.get(0).getLogLevel(), is(HealthStateLevel.ERROR));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.Test)

Example 65 with PartialConfig

use of com.thoughtworks.go.config.remote.PartialConfig 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)

Aggregations

PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)70 Test (org.junit.Test)39 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)29 File (java.io.File)15 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)12 StringContains.containsString (org.hamcrest.core.StringContains.containsString)12 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)10 IOException (java.io.IOException)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 ExpectedException (org.junit.rules.ExpectedException)8 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)7 PipelineGroups (com.thoughtworks.go.domain.PipelineGroups)7 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)7 Cloner (com.rits.cloning.Cloner)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)6 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)5 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)4 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)3 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)3