use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class StageServiceIntegrationTest method setup2DependentInstances.
private PipelineConfig setup2DependentInstances(MingleConfig upstreamMingle, MingleConfig downstreamMingle) {
Username loser = new Username(new CaseInsensitiveString("loser"));
ManualBuild build = new ManualBuild(loser);
Date checkinTime = new Date();
GitMaterial git = MaterialsMother.gitMaterial("http://google.com", null, "master");
git.setFolder("git");
HgMaterial hg = MaterialsMother.hgMaterial();
hg.setFolder("hg");
PipelineConfig upstreamWithMingle = PipelineConfigMother.createPipelineConfig("upstream-with-mingle", "stage", "build");
upstreamWithMingle.setMaterialConfigs(new MaterialConfigs(git.config(), hg.config()));
upstreamWithMingle.setMingleConfig(upstreamMingle);
configFileHelper.addPipelineToGroup(upstreamWithMingle, "upstream-with-mingle");
P4Material p4 = MaterialsMother.p4Material("loser:007", "loser", "boozer", "through-the-window", true);
PipelineConfig upstreamWithoutMingle = PipelineConfigMother.createPipelineConfig("upstream-without-mingle", "stage", "build");
upstreamWithoutMingle.setMaterialConfigs(new MaterialConfigs(p4.config()));
configFileHelper.addPipelineToGroup(upstreamWithoutMingle, "upstream-without-mingle");
DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial(upstreamWithMingle.name().toString(), upstreamWithMingle.get(0).name().toString());
SvnMaterial svn = MaterialsMother.svnMaterial("http://svn.com");
DependencyMaterial dependencyMaterialViaP4 = MaterialsMother.dependencyMaterial(upstreamWithoutMingle.name().toString(), upstreamWithoutMingle.get(0).name().toString());
PipelineConfig downstream = PipelineConfigMother.createPipelineConfig("downstream", "down-stage", "job");
downstream.setMaterialConfigs(new MaterialConfigs(dependencyMaterial.config(), svn.config(), dependencyMaterialViaP4.config()));
downstream.setMingleConfig(downstreamMingle);
configFileHelper.addPipelineToGroup(downstream, "downstream");
// mingle card nos.
// svn: 1xx
// p4: 2xx
// hg: 3xx
// git: 4xx
Modification svnCommit1 = checkin(svn, "888", "svn commit #101 1", "svn 1 guy", "svn.1@gmail.com", checkinTime);
Modification hgCommit1 = checkin(hg, "abcd", "hg commit 1 #301", "hg 1 guy", "hg.1@gmail.com", checkinTime);
Modification gitCommit1 = checkin(git, "1234", "#401 - git commit 1", "git 1 guy", "git.1@gmail.com", checkinTime);
// used in a later instance
Modification gitCommit2 = checkin(git, "2355", "git #402 commit 2", "git 2&3 guy", "git.2.and.3@gmail.com", checkinTime);
Modification hgCommit2 = checkin(hg, "abc", "hg commit #302 2", "hg 2 guy", null, checkinTime);
Pipeline pipelineOne = dbHelper.checkinRevisionsToBuild(build, upstreamWithMingle, new MaterialRevision(git, gitCommit1), new MaterialRevision(hg, hgCommit2, hgCommit1));
Modification hgCommit3 = checkin(hg, "bcde", "hg commit 3 #303", "hg 3 guy", "hg.3@gmail.com", checkinTime);
Modification gitCommit3 = checkin(git, "567", "git #403 commit 3", "git 2&3 guy", "git.2.and.3@gmail.com", checkinTime);
Pipeline pipelineTwo = dbHelper.checkinRevisionsToBuild(build, upstreamWithMingle, new MaterialRevision(git, gitCommit3, gitCommit2), new MaterialRevision(hg, hgCommit3));
Modification p4Commit1 = checkin(p4, "777", "#201 - p4 commit 1", "p4 1 guy", "p4.1@gmail.com", checkinTime);
Pipeline pipelineP4 = dbHelper.checkinRevisionsToBuild(build, upstreamWithoutMingle, new MaterialRevision(p4, p4Commit1));
ArrayList<MaterialRevision> materialRevisionsFor1 = new ArrayList<>();
dbHelper.addDependencyRevisionModification(materialRevisionsFor1, dependencyMaterial, pipelineOne);
dbHelper.addDependencyRevisionModification(materialRevisionsFor1, dependencyMaterialViaP4, pipelineP4);
Modification svnCommit2 = checkin(svn, "999", "svn #102 commit 2", "svn 2 guy", "svn.2@gmail.com", checkinTime);
materialRevisionsFor1.add(new MaterialRevision(svn, svnCommit2, svnCommit1));
// save downstream pipeline 1
dbHelper.passPipeline(dbHelper.checkinRevisionsToBuild(build, downstream, materialRevisionsFor1));
Modification p4Commit2 = checkin(p4, "007", "#202 - p4 commit 2", "p4 2 guy", "p4.2@gmail.com", checkinTime);
Pipeline pipeline2P4 = dbHelper.checkinRevisionsToBuild(build, upstreamWithoutMingle, new MaterialRevision(p4, p4Commit2));
ArrayList<MaterialRevision> materialRevisionsFor2 = new ArrayList<>();
dbHelper.addDependencyRevisionModification(materialRevisionsFor2, dependencyMaterial, pipelineTwo);
dbHelper.addDependencyRevisionModification(materialRevisionsFor2, dependencyMaterialViaP4, pipeline2P4);
Modification svnCommit3 = checkin(svn, "1000", "svn commit #103 3", "svn 3 guy", "svn.3@gmail.com", checkinTime);
materialRevisionsFor2.add(new MaterialRevision(svn, svnCommit3));
// save downstream pipeline 2
dbHelper.passPipeline(dbHelper.checkinRevisionsToBuild(build, downstream, materialRevisionsFor2));
return downstream;
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldCreateWork_withAncestorFetchArtifactCalls_resolvedToRelevantStage.
/**
* (uppest/2/uppest-stage/1)
* |------------------> upper-peer -------
* | ...................................|...............................................
* | . | .
* [ uppest-stage ............................|...................... {bar.zip uppest/upper-peer/downer}
* V .
* uppest uppest-stage-2 ------> upper ------> downer ------> downest {foo.zip uppest/upper/downer}
* (uppest/1/uppest-stage-2/1)
* uppest-stage-3 ]
* <p/>
* .... :: fetch artifact call
* ---> :: material dependency
*/
@Test
public void shouldCreateWork_withAncestorFetchArtifactCalls_resolvedToRelevantStage() throws Exception {
configHelper.addPipeline("uppest", "uppest-stage");
configHelper.addStageToPipeline("uppest", "uppest-stage-2");
PipelineConfig uppest = configHelper.addStageToPipeline("uppest", "uppest-stage-3");
configHelper.addPipeline("upper", "upper-stage");
DependencyMaterial upper_sMaterial = new DependencyMaterial(new CaseInsensitiveString("uppest"), new CaseInsensitiveString("uppest-stage-2"));
PipelineConfig upper = configHelper.setMaterialConfigForPipeline("upper", upper_sMaterial.config());
configHelper.addPipeline("upper-peer", "upper-peer-stage");
DependencyMaterial upperPeer_sMaterial = new DependencyMaterial(new CaseInsensitiveString("uppest"), new CaseInsensitiveString("uppest-stage"));
PipelineConfig upperPeer = configHelper.setMaterialConfigForPipeline("upper-peer", upperPeer_sMaterial.config());
configHelper.addPipeline("downer", "downer-stage");
DependencyMaterial downer_sUpperMaterial = new DependencyMaterial(new CaseInsensitiveString("upper"), new CaseInsensitiveString("upper-stage"));
configHelper.setMaterialConfigForPipeline("downer", downer_sUpperMaterial.config());
DependencyMaterial downer_sUpperPeerMaterial = new DependencyMaterial(new CaseInsensitiveString("upper-peer"), new CaseInsensitiveString("upper-peer-stage"));
PipelineConfig downer = configHelper.addMaterialToPipeline("downer", downer_sUpperPeerMaterial.config());
configHelper.addPipeline("downest", "downest-stage");
DependencyMaterial downest_sMaterial = new DependencyMaterial(new CaseInsensitiveString("downer"), new CaseInsensitiveString("downer-stage"));
configHelper.setMaterialConfigForPipeline("downest", downest_sMaterial.config());
Tasks allFetchTasks = new Tasks();
allFetchTasks.add(new FetchTask(new CaseInsensitiveString("uppest/upper/downer"), new CaseInsensitiveString("uppest-stage"), new CaseInsensitiveString("unit"), "foo.zip", "bar"));
allFetchTasks.add(new FetchTask(new CaseInsensitiveString("uppest/upper-peer/downer"), new CaseInsensitiveString("uppest-stage"), new CaseInsensitiveString("unit"), "bar.zip", "baz"));
configHelper.replaceAllJobsInStage("downest", "downest-stage", new JobConfig(new CaseInsensitiveString("fetcher"), new ResourceConfigs("fetcher"), new ArtifactConfigs(), allFetchTasks));
PipelineConfig downest = goConfigService.getCurrentConfig().pipelineConfigByName(new CaseInsensitiveString("downest"));
DefaultSchedulingContext defaultSchedulingCtx = new DefaultSchedulingContext(DEFAULT_APPROVED_BY);
Pipeline uppestInstanceForUpper = instanceFactory.createPipelineInstance(uppest, modifySomeFiles(uppest), defaultSchedulingCtx, md5, new TimeProvider());
dbHelper.savePipelineWithStagesAndMaterials(uppestInstanceForUpper);
dbHelper.passStage(uppestInstanceForUpper.findStage("uppest-stage"));
Stage upper_sMaterialStage = dbHelper.scheduleStage(uppestInstanceForUpper, uppest.getStage(new CaseInsensitiveString("uppest-stage-2")));
dbHelper.passStage(upper_sMaterialStage);
Pipeline uppestInstanceForUpperPeer = instanceFactory.createPipelineInstance(uppest, modifySomeFiles(uppest), new DefaultSchedulingContext("super-hero"), md5, new TimeProvider());
dbHelper.savePipelineWithStagesAndMaterials(uppestInstanceForUpperPeer);
Stage upperPeer_sMaterialStage = uppestInstanceForUpperPeer.findStage("uppest-stage");
dbHelper.passStage(upperPeer_sMaterialStage);
Pipeline upperInstance = instanceFactory.createPipelineInstance(upper, buildCauseForDependency(upper_sMaterial, upper_sMaterialStage), defaultSchedulingCtx, md5, new TimeProvider());
dbHelper.savePipelineWithStagesAndMaterials(upperInstance);
Stage downer_sUpperMaterialStage = upperInstance.findStage("upper-stage");
dbHelper.passStage(downer_sUpperMaterialStage);
Pipeline upperPeerInstance = instanceFactory.createPipelineInstance(upperPeer, buildCauseForDependency(upperPeer_sMaterial, upperPeer_sMaterialStage), defaultSchedulingCtx, md5, new TimeProvider());
dbHelper.savePipelineWithStagesAndMaterials(upperPeerInstance);
Stage downer_sUpperPeerMaterialStage = upperPeerInstance.findStage("upper-peer-stage");
dbHelper.passStage(downer_sUpperPeerMaterialStage);
MaterialRevisions downer_sMaterialRevisions = new MaterialRevisions(materialRevisionForDownstream(downer_sUpperMaterial, downer_sUpperMaterialStage), materialRevisionForDownstream(downer_sUpperPeerMaterial, downer_sUpperPeerMaterialStage));
Pipeline downerInstance = instanceFactory.createPipelineInstance(downer, BuildCause.createManualForced(downer_sMaterialRevisions, loserUser), defaultSchedulingCtx, md5, new TimeProvider());
dbHelper.savePipelineWithStagesAndMaterials(downerInstance);
Stage downest_sMaterialStage = downerInstance.findStage("downer-stage");
dbHelper.passStage(downest_sMaterialStage);
Pipeline downestInstance = instanceFactory.createPipelineInstance(downest, buildCauseForDependency(downest_sMaterial, downest_sMaterialStage), defaultSchedulingCtx, md5, new TimeProvider());
dbHelper.savePipelineWithStagesAndMaterials(downestInstance);
buildAssignmentService.onTimer();
AgentConfig agentConfig = AgentMother.localAgent();
agentConfig.addResourceConfig(new ResourceConfig("fetcher"));
BuildWork work = (BuildWork) buildAssignmentService.assignWorkToAgent(agent(agentConfig));
List<Builder> builders = work.getAssignment().getBuilders();
FetchArtifactBuilder fooZipFetch = (FetchArtifactBuilder) builders.get(0);
assertThat(fooZipFetch.artifactLocator(), is("uppest/1/uppest-stage/latest/unit/foo.zip"));
FetchArtifactBuilder barZipFetch = (FetchArtifactBuilder) builders.get(1);
assertThat(barZipFetch.artifactLocator(), is("uppest/2/uppest-stage/1/unit/bar.zip"));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class ChangesetServiceIntegrationTest method shouldFilterOutMaterialRevisionsAtThePointInTheDependencyIfTrackingToolDoesNotMatchWithParent.
@Test
public void shouldFilterOutMaterialRevisionsAtThePointInTheDependencyIfTrackingToolDoesNotMatchWithParent() throws Exception {
Username user = new Username(new CaseInsensitiveString("user"));
SvnMaterial svn = MaterialsMother.svnMaterial("http://svn");
PipelineConfig grandFatherPipeline = configHelper.addPipelineWithGroup("unauthorizedGroup", "granpa", new MaterialConfigs(svn.config()), new TrackingTool("http://jira/${ID}", "some-regex"), "stage", "job");
configHelper.setViewPermissionForGroup("unauthorizedGroup", CaseInsensitiveString.str(user.getUsername()));
DependencyMaterial parentDependencyMaterial = MaterialsMother.dependencyMaterial("granpa", "stage");
PipelineConfig upstreamPipeline = configHelper.addPipeline("upstream", "stage", new MaterialConfigs(git.config(), parentDependencyMaterial.config()), "job");
DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial("upstream", "stage");
PipelineConfig downstream = configHelper.addPipeline("downstream", "stage", dependencyMaterial.config(), new TrackingTool("http://mingle/${ID}", "another-regex"), "job");
// Schedule grandfather
List<MaterialRevision> revisionsForGrandfather1 = new ArrayList<>();
addRevisionWith2Mods(revisionsForGrandfather1, svn);
Pipeline grandFatherOne = dbHelper.checkinRevisionsToBuild(new ManualBuild(user), grandFatherPipeline, revisionsForGrandfather1);
// Schedule upstream
List<MaterialRevision> revisionsForUpstream1 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream1, git);
dbHelper.addDependencyRevisionModification(revisionsForUpstream1, parentDependencyMaterial, grandFatherOne);
Pipeline upstreamOne = dbHelper.checkinRevisionsToBuild(new ManualBuild(user), upstreamPipeline, revisionsForUpstream1);
// Schedule downstream
List<MaterialRevision> revisionsForDownstream = new ArrayList<>();
dbHelper.addDependencyRevisionModification(revisionsForDownstream, dependencyMaterial, upstreamOne);
Pipeline pipelineDownstream = dbHelper.checkinRevisionsToBuild(new ManualBuild(user), downstream, revisionsForDownstream);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
List<MaterialRevision> actual = changesetService.revisionsBetween(pipelineDownstream.getName(), pipelineDownstream.getCounter(), pipelineDownstream.getCounter(), user, result, true, false);
List<MaterialRevision> expectedRevisions = groupByMaterial(revisionsForUpstream1, revisionsForDownstream);
assertMaterialRevisions(expectedRevisions, actual);
assertThat(result.isSuccessful(), is(true));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class ChangesetServiceIntegrationTest method shouldPopulateActualFromRevisionId.
@Test
public void shouldPopulateActualFromRevisionId() {
PipelineConfig upstreamPipeline = configHelper.addPipeline("upstream", "stage", git.config(), "job");
DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial("upstream", "stage");
PipelineConfig downstreamConfig = configHelper.addPipeline("downstream", "stage", dependencyMaterial.config(), "build");
Username username = new Username(new CaseInsensitiveString("user1"));
// By default the pmr's actualFromRevisionId should be the fromRevisionId
List<MaterialRevision> revisionsForUpstream1 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream1, git);
Pipeline upstream1 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream1);
assertPipelineMaterialRevisions(upstream1);
// First downstream pipeline's actualFromRevisionId should also be it's fromRevisionId
List<MaterialRevision> revisionsForDownstream1 = new ArrayList<>();
dbHelper.addDependencyRevisionModification(revisionsForDownstream1, dependencyMaterial, upstream1);
Pipeline downstream1 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), downstreamConfig, revisionsForDownstream1);
assertPipelineMaterialRevisions(downstream1);
// When downstream is triggered with a range of upstream modifications it's actualFromRevisionId should be 1 more than the last one that was built
List<MaterialRevision> revisionsForUpstream2 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream2, git);
Pipeline upstream2 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream2);
assertPipelineMaterialRevisions(upstream2);
List<MaterialRevision> revisionsForUpstream3 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream3, git);
Pipeline upstream3 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream3);
assertPipelineMaterialRevisions(upstream3);
List<MaterialRevision> revisionsForUpstream4 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream4, git);
Pipeline upstream4 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream4);
assertPipelineMaterialRevisions(upstream4);
List<MaterialRevision> depMaterialRevision = new ArrayList<>();
dbHelper.addDependencyRevisionModification(depMaterialRevision, dependencyMaterial, upstream2);
Modification expectedMod = depMaterialRevision.get(0).getLatestModification();
MaterialInstance dep = materialRepository.findOrCreateFrom(dependencyMaterial);
saveRev(expectedMod, dep);
dbHelper.addDependencyRevisionModification(depMaterialRevision, dependencyMaterial, upstream3);
saveRev(depMaterialRevision.get(0).getLatestModification(), dep);
List<MaterialRevision> revisionsForDownstream2 = new ArrayList<>();
dbHelper.addDependencyRevisionModification(revisionsForDownstream2, dependencyMaterial, upstream4);
Pipeline downstream2 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), downstreamConfig, revisionsForDownstream2);
List<PipelineMaterialRevision> pmrs = materialRepository.findPipelineMaterialRevisions(downstream2.getId());
assertThat(pmrs.size(), is(1));
assertThat(pmrs.get(0).getActualFromRevisionId(), is(expectedMod.getId()));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class ChangesetServiceIntegrationTest method shouldReturn_SCMMods_AcrossParentStageFailures.
@Test
public void shouldReturn_SCMMods_AcrossParentStageFailures() {
PipelineConfig upstreamPipeline = configHelper.addPipeline("upstream", "stage", git.config(), "job");
DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial("upstream", "stage");
pipelineConfigWithTwoMaterials.addMaterialConfig(dependencyMaterial.config());
pipelineConfigWithTwoMaterials.removeMaterialConfig(git.config());
Username username = new Username(new CaseInsensitiveString("user1"));
// Schedule first of upstream
List<MaterialRevision> revisionsForUpstream1 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream1, git);
Pipeline upstreamOne = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream1);
// Schedule downstream
List<MaterialRevision> revisionsForDownstream1 = new ArrayList<>();
addRevisionWith2Mods(revisionsForDownstream1, hg);
dbHelper.addDependencyRevisionModification(revisionsForDownstream1, dependencyMaterial, upstreamOne);
Pipeline downstreamOne = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), pipelineConfigWithTwoMaterials, revisionsForDownstream1);
// Schedule second upstream
List<MaterialRevision> revisionsForUpstream2 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream2, git);
Pipeline upstreamTwo = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream2);
// Schedule second downstream
List<MaterialRevision> revisionsForDownstream2 = new ArrayList<>();
addRevisionWith2Mods(revisionsForDownstream2, hg);
dbHelper.addDependencyRevisionModification(revisionsForDownstream2, dependencyMaterial, upstreamTwo);
Pipeline downstreamTwo = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), pipelineConfigWithTwoMaterials, revisionsForDownstream2);
// Schedule multiple upstream, but no corresponding downstream, because upstream stage failed(may be?)
List<MaterialRevision> revisionsForUpstream3 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream3, git);
Pipeline upstreamThree = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream3);
List<MaterialRevision> revisionsForUpstream4 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream4, git);
Pipeline upstreamFour = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream4);
// Schedule upstream again(upstream stage starts passing once again)
List<MaterialRevision> revisionsForUpstream5 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream5, git);
Pipeline upstreamFive = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream5);
// Schedule downstream for comparision
List<MaterialRevision> revisionsForDownstream3 = new ArrayList<>();
addRevisionWith2Mods(revisionsForDownstream3, hg);
dbHelper.addDependencyRevisionModification(revisionsForDownstream3, dependencyMaterial, upstreamFive);
Pipeline downstreamThree = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), pipelineConfigWithTwoMaterials, revisionsForDownstream3);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
List<MaterialRevision> actual = changesetService.revisionsBetween(CaseInsensitiveString.str(pipelineConfigWithTwoMaterials.name()), downstreamOne.getCounter(), downstreamThree.getCounter(), username, result, true, false);
List<MaterialRevision> expectedRevisions = groupByMaterial(revisionsForUpstream2, revisionsForUpstream3, revisionsForUpstream4, revisionsForUpstream5, revisionsForDownstream2, revisionsForDownstream3);
assertMaterialRevisions(expectedRevisions, actual);
assertThat(result.isSuccessful(), is(true));
}
Aggregations