use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class InstanceFactoryTest method shouldSchedulePipelineWithFirstStage.
@Test
public void shouldSchedulePipelineWithFirstStage() {
StageConfig stageOneConfig = StageConfigMother.stageConfig("dev", BuildPlanMother.withBuildPlans("functional", "unit"));
StageConfig stageTwoConfig = StageConfigMother.stageConfig("qa", BuildPlanMother.withBuildPlans("suiteOne", "suiteTwo"));
MaterialConfigs materialConfigs = MaterialConfigsMother.defaultMaterialConfigs();
PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("mingle"), materialConfigs, stageOneConfig, stageTwoConfig);
BuildCause buildCause = BuildCause.createManualForced(modifyOneFile(pipelineConfig), Username.ANONYMOUS);
Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, buildCause, new DefaultSchedulingContext("test"), "some-md5", new TimeProvider());
assertThat(pipeline.getName(), is("mingle"));
assertThat(pipeline.getStages().size(), is(1));
assertThat(pipeline.getStages().get(0).getName(), is("dev"));
assertThat(pipeline.getStages().get(0).getJobInstances().get(0).getName(), is("functional"));
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class MessageTest method encodeAndDecodeAssignWorkWithDifferentBuilders.
@Test
public void encodeAndDecodeAssignWorkWithDifferentBuilders() throws Exception {
File workingDir = new File(CruiseConfig.WORKING_BASE_DIR + "pipelineName");
Materials materials = MaterialsMother.defaultMaterials();
MaterialRevisions revisions = ModificationsMother.modifyOneFile(materials, ModificationsMother.nextRevision());
BuildCause buildCause = BuildCause.createWithModifications(revisions, "");
List<Builder> builder = new ArrayList<>();
builder.add(new CommandBuilder("command", "args", workingDir, new RunIfConfigs(), new NullBuilder(), "desc"));
builder.add(new BuilderForKillAllChildTask());
builder.add(new CommandBuilderWithArgList("command", new String[] { "arg1", "arg2" }, workingDir, new RunIfConfigs(), new NullBuilder(), "desc"));
builder.add(new FetchArtifactBuilder(new RunIfConfigs(), new NullBuilder(), "desc", jobPlan().getIdentifier(), "srcdir", "dest", new FileHandler(workingDir, "src"), new ChecksumFileHandler(workingDir)));
BuildAssignment assignment = BuildAssignment.create(jobPlan(), buildCause, builder, workingDir, new EnvironmentVariableContext(), new ArtifactStores());
BuildWork work = new BuildWork(assignment, "utf-8");
byte[] msg = MessageEncoding.encodeMessage(new Message(Action.assignWork, MessageEncoding.encodeWork(work)));
Message decodedMsg = MessageEncoding.decodeMessage(new ByteArrayInputStream(msg));
BuildWork decodedWork = (BuildWork) MessageEncoding.decodeWork(decodedMsg.getData());
assertThat(decodedWork.getAssignment().getJobIdentifier().getPipelineName(), is("pipelineName"));
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class ScheduleService method autoSchedulePipelinesFromRequestBuffer.
// Note: This is called from a Spring timer
public void autoSchedulePipelinesFromRequestBuffer() {
synchronized (autoScheduleMutex) {
try {
for (Entry<String, BuildCause> entry : pipelineScheduleQueue.toBeScheduled().entrySet()) {
String pipelineName = entry.getKey();
BuildCause buildCause = entry.getValue();
LOGGER.info("[Pipeline Schedule] Scheduling pipeline {} with build cause {}", pipelineName, buildCause);
long schedulingStartTime = System.currentTimeMillis();
Pipeline pipeline = schedulePipeline(pipelineName, buildCause);
long schedulingEndTime = System.currentTimeMillis();
if (pipeline != null) {
schedulingPerformanceLogger.scheduledPipeline(pipelineName, pipelineScheduleQueue.toBeScheduled().size(), schedulingStartTime, schedulingEndTime);
}
}
} catch (Throwable e) {
LOGGER.error("[Pipeline Schedule] An exception occurred while scheduling the pipeline. {}", e);
}
}
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class ValueStreamMapService method buildValueStreamMap.
private ValueStreamMap buildValueStreamMap(String pipelineName, int counter, Username username, LocalizedOperationResult result) {
CruiseConfig cruiseConfig = goConfigService.currentCruiseConfig();
BuildCause buildCauseForPipeline;
try {
pipelineName = pipelineNameWithSameCaseAsConfig(pipelineName, cruiseConfig);
buildCauseForPipeline = pipelineService.buildCauseFor(pipelineName, counter);
} catch (PipelineNotFoundException e) {
result.notFound(LocalizedMessage.string("PIPELINE_WITH_COUNTER_NOT_FOUND", pipelineName, counter), HealthStateType.general(HealthStateScope.forPipeline(pipelineName)));
return null;
}
String label = pipelineService.findPipelineByCounterOrLabel(pipelineName, String.valueOf(counter)).getLabel();
ValueStreamMap valueStreamMap = new ValueStreamMap(pipelineName, new PipelineRevision(pipelineName, counter, label));
Map<String, List<PipelineConfig>> pipelineToDownstreamMap = cruiseConfig.generatePipelineVsDownstreamMap();
traverseDownstream(pipelineName, pipelineToDownstreamMap, valueStreamMap, new ArrayList<>());
traverseUpstream(pipelineName, buildCauseForPipeline, valueStreamMap, new ArrayList<>());
if (valueStreamMap.hasCycle()) {
result.notImplemented(LocalizedMessage.string("VSM_CYCLIC_DEPENDENCY", pipelineName, counter));
LOGGER.error("[Value Stream Map] Cyclic dependency for pipeline {} with counter {}. Graph is {}", pipelineName, counter, valueStreamMap);
return null;
}
addInstanceInformationToTheGraph(valueStreamMap);
removeRevisionsBasedOnPermissionAndCurrentConfig(valueStreamMap, username);
valueStreamMap.addWarningIfBuiltFromInCompatibleRevisions();
return valueStreamMap;
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class ValueStreamMapService method traverseUpstream.
private void traverseUpstream(String pipelineName, BuildCause buildCause, ValueStreamMap graph, List<MaterialRevision> visitedNodes) {
for (MaterialRevision materialRevision : buildCause.getMaterialRevisions()) {
Material material = materialRevision.getMaterial();
if (material instanceof DependencyMaterial) {
String upstreamPipeline = ((DependencyMaterial) material).getPipelineName().toString();
DependencyMaterialRevision revision = (DependencyMaterialRevision) materialRevision.getRevision();
graph.addUpstreamNode(new PipelineDependencyNode(upstreamPipeline, upstreamPipeline), new PipelineRevision(revision.getPipelineName(), revision.getPipelineCounter(), revision.getPipelineLabel()), pipelineName);
if (visitedNodes.contains(materialRevision)) {
continue;
}
visitedNodes.add(materialRevision);
DependencyMaterialRevision dmrOfUpstreamPipeline = buildCause.getMaterialRevisions().findDependencyMaterialRevision(upstreamPipeline);
BuildCause buildCauseForUpstreamPipeline = pipelineService.buildCauseFor(dmrOfUpstreamPipeline.getPipelineName(), dmrOfUpstreamPipeline.getPipelineCounter());
traverseUpstream(upstreamPipeline, buildCauseForUpstreamPipeline, graph, visitedNodes);
} else {
graph.addUpstreamMaterialNode(new SCMDependencyNode(material.getFingerprint(), material.getUriForDisplay(), materialRevision.getMaterialType()), material.getName(), pipelineName, materialRevision);
}
}
}
Aggregations