use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class CachedGoPartials method markAsValid.
public void markAsValid(List<PartialConfig> partials) {
for (PartialConfig partial : partials) {
if (partial.getOrigin() instanceof RepoConfigOrigin) {
String fingerprint = ((RepoConfigOrigin) partial.getOrigin()).getMaterial().getFingerprint();
markAsValid(fingerprint, partial);
}
}
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class BuildCause method pipelineConfigAndMaterialRevisionMatch.
public boolean pipelineConfigAndMaterialRevisionMatch(PipelineConfig pipelineConfig) {
if (!pipelineConfig.isConfigOriginSameAsOneOfMaterials()) {
return true;
}
RepoConfigOrigin repoConfigOrigin = (RepoConfigOrigin) pipelineConfig.getOrigin();
MaterialConfig configAndCodeMaterial = repoConfigOrigin.getMaterial();
// TODO if revision in any of the pipelines match
MaterialRevision revision = this.getMaterialRevisions().findRevisionForFingerPrint(configAndCodeMaterial.getFingerprint());
String revisionString = revision.getRevision().getRevision();
if (pipelineConfig.isConfigOriginFromRevision(revisionString)) {
return true;
}
return false;
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipelineWhenPartIsInvalid_AndManuallyTriggered.
@Test
public void shouldSchedulePipelineWhenPartIsInvalid_AndManuallyTriggered() throws Exception {
List<Modification> lastPush = configTestRepo.addCodeToRepositoryAndPush(fileName, "added broken config file", "bad bad config");
materialUpdateService.updateMaterial(material);
waitForMaterialNotInProgress();
assertThat(goRepoConfigDataSource.latestParseHasFailedForMaterial(material.config()), is(true));
final HashMap<String, String> revisions = new HashMap<>();
final HashMap<String, String> environmentVariables = new HashMap<>();
buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
Map<String, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(5);
assertThat(afterLoad.keySet(), hasItem(PIPELINE_NAME));
BuildCause cause = afterLoad.get(PIPELINE_NAME);
assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
String lastValidPushedRevision = this.firstRevisions.latestRevision();
assertThat("revisionOfPipelineConfigOriginShouldMatchLastValidPushedCommit", configOriginAfterSchedule.getRevision(), is(lastValidPushedRevision));
assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPush.get(0).getRevision()));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class ConfigSaveDeadlockDetectionIntegrationTest method shouldNotDeadlockWhenAllPossibleWaysOfUpdatingTheConfigAreBeingUsedAtTheSameTime.
@Test
public void shouldNotDeadlockWhenAllPossibleWaysOfUpdatingTheConfigAreBeingUsedAtTheSameTime() throws Exception {
int EXISTING_ENV_COUNT = goConfigService.cruiseConfig().getEnvironments().size();
final ArrayList<Thread> group1 = new ArrayList<>();
final ArrayList<Thread> group2 = new ArrayList<>();
final ArrayList<Thread> group3 = new ArrayList<>();
final ArrayList<Thread> group4 = new ArrayList<>();
final ArrayList<Thread> group5 = new ArrayList<>();
int count = 100;
final int pipelineCreatedThroughApiCount = count;
final int pipelineCreatedThroughUICount = count;
final int configRepoAdditionThreadCount = count;
final int configRepoDeletionThreadCount = count;
final int fullConfigSaveThreadCount = count;
for (int i = 0; i < pipelineCreatedThroughUICount; i++) {
Thread thread = configSaveThread(i);
group1.add(thread);
}
for (int i = 0; i < pipelineCreatedThroughApiCount; i++) {
Thread thread = pipelineSaveThread(i);
group2.add(thread);
}
ConfigReposConfig configRepos = new ConfigReposConfig();
for (int i = 0; i < configRepoAdditionThreadCount; i++) {
ConfigRepoConfig configRepoConfig = new ConfigRepoConfig(new GitMaterialConfig("url" + i), "plugin");
configRepos.add(configRepoConfig);
Thread thread = configRepoSaveThread(configRepoConfig, i);
group3.add(thread);
}
for (int i = 0; i < configRepoDeletionThreadCount; i++) {
ConfigRepoConfig configRepoConfig = new ConfigRepoConfig(new GitMaterialConfig("to-be-deleted-url" + i), "plugin");
cachedGoPartials.addOrUpdate(configRepoConfig.getMaterialConfig().getFingerprint(), PartialConfigMother.withPipeline("to-be-deleted" + i, new RepoConfigOrigin(configRepoConfig, "plugin")));
configRepos.add(configRepoConfig);
Thread thread = configRepoDeleteThread(configRepoConfig, i);
group4.add(thread);
}
for (int i = 0; i < fullConfigSaveThreadCount; i++) {
Thread thread = fullConfigSaveThread(i);
group5.add(thread);
}
configHelper.setConfigRepos(configRepos);
for (int i = 0; i < count; i++) {
Thread timerThread = null;
try {
timerThread = createThread(new Runnable() {
@Override
public void run() {
try {
writeConfigToFile(new File(goConfigDao.fileLocation()));
} catch (Exception e) {
e.printStackTrace();
fail("Failed with error: " + e.getMessage());
}
cachedGoConfig.forceReload();
}
}, "timer-thread");
} catch (InterruptedException e) {
fail(e.getMessage());
}
try {
group1.get(i).start();
group2.get(i).start();
group3.get(i).start();
group4.get(i).start();
group5.get(i).start();
timerThread.start();
group1.get(i).join();
group2.get(i).join();
group3.get(i).join();
group4.get(i).join();
group5.get(i).join();
timerThread.join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
assertThat(goConfigService.getAllPipelineConfigs().size(), is(pipelineCreatedThroughApiCount + pipelineCreatedThroughUICount + configRepoAdditionThreadCount));
assertThat(goConfigService.getConfigForEditing().getAllPipelineConfigs().size(), is(pipelineCreatedThroughApiCount + pipelineCreatedThroughUICount));
assertThat(goConfigService.getConfigForEditing().getEnvironments().size(), is(fullConfigSaveThreadCount + EXISTING_ENV_COUNT));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class PipelineConfigServiceIntegrationTest method shouldPerformFullValidationNotJustEntitySpecificIfMergingKnownPartialsAsOtherAspectsOfAKnownPartialMightBeInvalid.
@Test
public void shouldPerformFullValidationNotJustEntitySpecificIfMergingKnownPartialsAsOtherAspectsOfAKnownPartialMightBeInvalid() throws Exception {
PipelineConfig remoteDownstreamPipeline = partialConfig.getGroups().first().getPipelines().get(0);
assertThat(goConfigService.getCurrentConfig().getAllPipelineNames().contains(remoteDownstreamPipeline.name()), is(true));
String independentRemotePipeline = "independent-pipeline";
assertThat(goConfigService.getCurrentConfig().getAllPipelineNames().contains(new CaseInsensitiveString(independentRemotePipeline)), is(true));
// introduce an invalid change in the independent partial
PartialConfig invalidIndependentPartial = PartialConfigMother.invalidPartial(independentRemotePipeline, new RepoConfigOrigin(repoConfig2, "repo2_r2"));
goPartialConfig.onSuccessPartialConfig(repoConfig2, invalidIndependentPartial);
assertThat(((RepoConfigOrigin) cachedGoPartials.getValid(repoConfig2.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo2_r1"));
assertThat(((RepoConfigOrigin) cachedGoPartials.getKnown(repoConfig2.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo2_r2"));
assertThat(((RepoConfigOrigin) goConfigService.getCurrentConfig().getPipelineConfigByName(new CaseInsensitiveString(independentRemotePipeline)).getOrigin()).getRevision(), is("repo2_r1"));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).size(), is(1));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getMessage(), is("Invalid Merged Configuration"));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).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: url2 at repo2_r2"));
final CaseInsensitiveString upstreamStageRenamed = new CaseInsensitiveString("upstream_stage_renamed");
partialConfig = PartialConfigMother.pipelineWithDependencyMaterial("remote-downstream", new PipelineConfig(pipelineConfig.name(), pipelineConfig.materialConfigs(), new StageConfig(upstreamStageRenamed, new JobConfigs())), new RepoConfigOrigin(repoConfig1, "repo1_r2"));
goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfig);
CruiseConfig currentConfig = goConfigService.getCurrentConfig();
DependencyMaterialConfig dependencyMaterialForRemotePipelineInConfigCache = currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).materialConfigs().findDependencyMaterial(pipelineConfig.name());
assertThat(dependencyMaterialForRemotePipelineInConfigCache.getStageName(), is(new CaseInsensitiveString("stage")));
assertThat(((RepoConfigOrigin) currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).getOrigin()).getRevision(), is("repo1_r1"));
assertThat(((RepoConfigOrigin) cachedGoPartials.getValid(repoConfig1.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo1_r1"));
assertThat(((RepoConfigOrigin) cachedGoPartials.getKnown(repoConfig1.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo1_r2"));
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(String.format("1+ errors :: Stage with name 'upstream_stage_renamed' does not exist on pipeline '%s', it is being referred to from pipeline 'remote-downstream' (url at repo1_r2);; - Config-Repo: url at repo1_r2", pipelineConfig.name())));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).size(), is(1));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getMessage(), is("Invalid Merged Configuration"));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).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: url2 at repo2_r2"));
String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig);
String md5 = CachedDigestUtils.md5Hex(xml);
pipelineConfig.getFirstStageConfig().setName(new CaseInsensitiveString("upstream_stage_renamed"));
pipelineConfigService.updatePipelineConfig(user, pipelineConfig, md5, result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.message(localizer), is(String.format("Validations failed for pipeline '%s'. " + "Error(s): [Merged update operation failed on VALID 2 partials. Falling back to using LAST KNOWN 2 partials. " + "Exception message was: [Validation failed. Stage with name 'stage' does not exist on pipeline '%s', " + "it is being referred to from pipeline 'remote-downstream' (url at repo1_r1)]" + System.lineSeparator() + "Merged config update operation failed using fallback LAST KNOWN 2 partials. " + "Exception message was: 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.;; ]. Please correct and resubmit.", pipelineConfig.name(), pipelineConfig.name())));
assertThat(ErrorCollector.getAllErrors(pipelineConfig).isEmpty(), is(true));
currentConfig = goConfigService.getCurrentConfig();
assertThat(currentConfig.getAllPipelineNames().contains(remoteDownstreamPipeline.name()), is(true));
assertThat(cachedGoPartials.lastKnownPartials().equals(cachedGoPartials.lastValidPartials()), is(false));
assertThat(currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).materialConfigs().findDependencyMaterial(pipelineConfig.name()).getStageName(), is(new CaseInsensitiveString("stage")));
assertThat(currentConfig.getPipelineConfigByName(pipelineConfig.name()).getFirstStageConfig().name(), is(new CaseInsensitiveString("stage")));
assertThat(((RepoConfigOrigin) currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).getOrigin()).getRevision(), is("repo1_r1"));
assertThat(((RepoConfigOrigin) cachedGoPartials.getValid(repoConfig1.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo1_r1"));
assertThat(((RepoConfigOrigin) cachedGoPartials.getKnown(repoConfig1.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo1_r2"));
assertThat(((RepoConfigOrigin) currentConfig.getPipelineConfigByName(new CaseInsensitiveString(independentRemotePipeline)).getOrigin()).getRevision(), is("repo2_r1"));
assertThat(((RepoConfigOrigin) cachedGoPartials.getValid(repoConfig2.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo2_r1"));
assertThat(((RepoConfigOrigin) cachedGoPartials.getKnown(repoConfig2.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo2_r2"));
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(String.format("1+ errors :: Stage with name 'upstream_stage_renamed' does not exist on pipeline '%s', it is being referred to from pipeline 'remote-downstream' (url at repo1_r2);; - Config-Repo: url at repo1_r2", pipelineConfig.name())));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).size(), is(1));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getMessage(), is("Invalid Merged Configuration"));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).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: url2 at repo2_r2"));
}
Aggregations