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(String.format("[Value Stream Map] Cyclic dependency for pipeline %s with counter %s. Graph is %s", 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 FetchTaskBuilder method resolveTargetJob.
private JobIdentifier resolveTargetJob(FetchTask task, Pipeline currentPipeline, UpstreamPipelineResolver resolver) {
PathFromAncestor pipelineNamePathFromAncestor = task.getPipelineNamePathFromAncestor();
if (pipelineNamePathFromAncestor == null || CaseInsensitiveString.isBlank(pipelineNamePathFromAncestor.getPath()) || CaseInsensitiveString.areEqual(new CaseInsensitiveString(currentPipeline.getName()), pipelineNamePathFromAncestor.getPath())) {
task.setPipelineName(new CaseInsensitiveString(currentPipeline.getName()));
String stageCounter = JobIdentifier.LATEST;
if (currentPipeline.hasStageBeenRun(CaseInsensitiveString.str(task.getStage()))) {
stageCounter = String.valueOf(currentPipeline.findStage(CaseInsensitiveString.str(task.getStage())).getCounter());
}
return new JobIdentifier(new StageIdentifier(currentPipeline.getName(), currentPipeline.getCounter(), currentPipeline.getLabel(), CaseInsensitiveString.str(task.getStage()), stageCounter), CaseInsensitiveString.str(task.getJob()));
} else {
DependencyMaterialRevision revision = null;
if (pipelineNamePathFromAncestor.isAncestor()) {
BuildCause buildCause = currentPipeline.getBuildCause();
for (CaseInsensitiveString parentPipelineName : pipelineNamePathFromAncestor.pathToAncestor()) {
DependencyMaterialRevision dependencyMaterialRevision = dmrForPipeline(parentPipelineName, buildCause);
if (dependencyMaterialRevision == null) {
throw bomb(String.format("Pipeline [%s] could not fetch artifact [%s]. Unable to resolve revision for [%s] from build cause", currentPipeline.getName(), task, parentPipelineName));
}
buildCause = resolver.buildCauseFor(dependencyMaterialRevision.getPipelineName(), dependencyMaterialRevision.getPipelineCounter());
}
revision = dmrForPipeline(pipelineNamePathFromAncestor.getAncestorName(), buildCause);
if (revision == null) {
throw bomb(String.format("Pipeline [%s] could not fetch artifact [%s]. Unable to resolve revision for [%s] from build cause", currentPipeline.getName(), task, pipelineNamePathFromAncestor.getAncestorName()));
}
} else {
revision = dmrForPipeline(pipelineNamePathFromAncestor.getPath(), currentPipeline.getBuildCause());
if (revision == null) {
throw bomb(String.format("Pipeline [%s] tries to fetch artifact from job [%s/%s/%s] " + "which is not a dependency material", currentPipeline.getName(), pipelineNamePathFromAncestor, task.getStage(), task.getJob()));
}
}
String stageCounter = JobIdentifier.LATEST;
if (task.getStage().equals(new CaseInsensitiveString(revision.getStageName()))) {
stageCounter = String.valueOf(revision.getStageCounter());
}
return new JobIdentifier(new StageIdentifier(CaseInsensitiveString.str(pipelineNamePathFromAncestor.getAncestorName()), revision.getPipelineCounter(), revision.getPipelineLabel(), CaseInsensitiveString.str(task.getStage()), stageCounter), CaseInsensitiveString.str(task.getJob()));
}
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class PipelineScheduleQueue method mostRecentScheduled.
public BuildCause mostRecentScheduled(String pipelineName) {
synchronized (mutexForPipelineName(pipelineName)) {
BuildCause buildCause = mostRecentScheduled.get(pipelineName);
if (buildCause != null) {
return buildCause;
}
mostRecentScheduled.put(pipelineName, mostRecentScheduledBuildCause(pipelineName));
return mostRecentScheduled.get(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(String.format("[Pipeline Schedule] Scheduling pipeline %s with build cause %s", pipelineName, buildCause));
long schedulingStartTime = System.currentTimeMillis();
Pipeline pipeline = schedulePipeline(pipelineName, buildCause);
long schedulingEndTime = System.currentTimeMillis();
if (pipeline != null) {
pipelineScheduledTopic.post(new PipelineScheduledMessage(pipeline.getIdentifier()));
schedulingPerformanceLogger.scheduledPipeline(pipelineName, pipelineScheduleQueue.toBeScheduled().size(), schedulingStartTime, schedulingEndTime);
}
}
} catch (Throwable e) {
LOGGER.error(String.format("[Pipeline Schedule] An exception occurred while scheduling the pipeline. %s", e));
}
}
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class ScheduleServiceTest method shouldNotifyForEveryPipelineCreated.
@Test
public void shouldNotifyForEveryPipelineCreated() throws Exception {
CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
when(cruiseConfig.getMd5()).thenReturn("md5-test");
when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
StubPipelineScheduleTopic stubTopic = new StubPipelineScheduleTopic();
service = new ScheduleService(goConfigService, null, null, schedulingChecker, stubTopic, null, null, null, null, pipelineScheduleQueue, jobInstanceService, null, null, environmentConfigService, null, serverHealthService, null, null, null, timeProvider, null, null, null, schedulingPerformanceLogger, elasticProfileService);
PipelineConfig mingleConfig = PipelineConfigMother.createPipelineConfig("mingle", "build", "unit", "functional");
PipelineConfig evolveConfig = PipelineConfigMother.createPipelineConfig("evolve", "build", "unit");
BuildCause mingleBuildCause = modifySomeFiles(mingleConfig);
BuildCause evolveBuildCause = modifySomeFiles(evolveConfig);
when(pipelineScheduleQueue.toBeScheduled()).thenReturn(m("mingle", mingleBuildCause, "evolve", evolveBuildCause));
when(goConfigService.pipelineConfigNamed(new CaseInsensitiveString("mingle"))).thenReturn(mingleConfig);
when(goConfigService.pipelineConfigNamed(new CaseInsensitiveString("evolve"))).thenReturn(evolveConfig);
when(schedulingChecker.canAutoTriggerConsumer(mingleConfig)).thenReturn(true);
when(schedulingChecker.canAutoTriggerConsumer(evolveConfig)).thenReturn(true);
when(pipelineScheduleQueue.createPipeline(mingleBuildCause, mingleConfig, new DefaultSchedulingContext(GoConstants.DEFAULT_APPROVED_BY, new Agents()), "md5-test", timeProvider)).thenReturn(PipelineMother.schedule(mingleConfig, mingleBuildCause));
when(pipelineScheduleQueue.createPipeline(evolveBuildCause, evolveConfig, new DefaultSchedulingContext(GoConstants.DEFAULT_APPROVED_BY, new Agents()), "md5-test", timeProvider)).thenReturn(PipelineMother.schedule(evolveConfig, evolveBuildCause));
service.autoSchedulePipelinesFromRequestBuffer();
assertThat(stubTopic.callCount, Matchers.is(2));
}
Aggregations