Search in sources :

Example 16 with BuildCause

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 17 with BuildCause

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()));
    }
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) PathFromAncestor(com.thoughtworks.go.config.PathFromAncestor) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 18 with BuildCause

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);
    }
}
Also used : BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 19 with BuildCause

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));
        }
    }
}
Also used : PipelineScheduledMessage(com.thoughtworks.go.server.scheduling.PipelineScheduledMessage) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 20 with BuildCause

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));
}
Also used : BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Aggregations

BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)142 Test (org.junit.Test)108 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)35 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)30 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)29 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)27 TimeProvider (com.thoughtworks.go.util.TimeProvider)22 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)20 Modification (com.thoughtworks.go.domain.materials.Modification)20 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)19 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)16 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)15 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)14 Date (java.util.Date)13 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)12 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)10 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)10 Username (com.thoughtworks.go.server.domain.Username)10