Search in sources :

Example 1 with DependencyMaterialRevision

use of com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision in project gocd by gocd.

the class FetchTaskTest method buildCauseWithDependencyMaterial.

private BuildCause buildCauseWithDependencyMaterial(String upstreamPipelineName, int upstreamPipelineCounter, String upstreamPipelineLabel, String upstreamStageName, int upstreamStageCounter) {
    BuildCause buildCause = BuildCause.createWithEmptyModifications();
    MaterialRevisions materialRevisions = new MaterialRevisions();
    DependencyMaterialRevision materialRevision = DependencyMaterialRevision.create(upstreamPipelineName, upstreamPipelineCounter, upstreamPipelineLabel, upstreamStageName, upstreamStageCounter);
    MaterialRevision withRevision = materialRevision.convert(new DependencyMaterial(new CaseInsensitiveString(upstreamPipelineName), new CaseInsensitiveString(upstreamStageName)), new Date());
    materialRevisions.addRevision(withRevision);
    buildCause.setMaterialRevisions(materialRevisions);
    return buildCause;
}
Also used : MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 2 with DependencyMaterialRevision

use of com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision 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);
        }
    }
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 3 with DependencyMaterialRevision

use of com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision 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 4 with DependencyMaterialRevision

use of com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision in project gocd by gocd.

the class PipelineService method populateRevisionsUsingUpstream.

private void populateRevisionsUsingUpstream(MaterialRevisions actualRevisions, MaterialRevisions newRevisions, DependencyMaterialRevision dmr, PipelineConfigDependencyGraph.PipelineConfigQueueEntry configQueueEntry) {
    if (!configQueueEntry.containsPipelineInPath(dmr.getPipelineName())) {
        return;
    }
    for (MaterialRevision materialRevision : actualRevisions) {
        Material material = materialRevision.getMaterial();
        if (currentPipelineHasMaterial(configQueueEntry, material) && !alreadyAdded(newRevisions, material)) {
            List<PipelineConfig> paths = removePathHead(configQueueEntry);
            if (!paths.isEmpty()) {
                MaterialRevision revision = getRevisionFor(paths, dmr, material);
                //revision is null when an upstream is both parent and grandparent
                if (revision != null) {
                    materialRevision.replaceModifications(revision.getModifications());
                    newRevisions.addRevision(materialRevision);
                }
            }
        }
    }
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)

Example 5 with DependencyMaterialRevision

use of com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision in project gocd by gocd.

the class FetchTaskBuilderTest method buildCauseWithDependencyMaterial.

private BuildCause buildCauseWithDependencyMaterial(String upstreamPipelineName, int upstreamPipelineCounter, String upstreamPipelineLabel, String upstreamStageName, int upstreamStageCounter) {
    BuildCause buildCause = BuildCause.createWithEmptyModifications();
    MaterialRevisions materialRevisions = new MaterialRevisions();
    DependencyMaterialRevision materialRevision = DependencyMaterialRevision.create(upstreamPipelineName, upstreamPipelineCounter, upstreamPipelineLabel, upstreamStageName, upstreamStageCounter);
    MaterialRevision withRevision = materialRevision.convert(new DependencyMaterial(new CaseInsensitiveString(upstreamPipelineName), new CaseInsensitiveString(upstreamStageName)), new Date());
    materialRevisions.addRevision(withRevision);
    buildCause.setMaterialRevisions(materialRevisions);
    return buildCause;
}
Also used : DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Aggregations

DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)17 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)7 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)6 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)5 Date (java.util.Date)4 Test (org.junit.Test)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)3 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 Materials (com.thoughtworks.go.config.materials.Materials)2 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)2 PipelineTimelineEntry (com.thoughtworks.go.domain.PipelineTimelineEntry)2 Material (com.thoughtworks.go.domain.materials.Material)2 PipelineTimeline (com.thoughtworks.go.server.domain.PipelineTimeline)2 Pair (com.thoughtworks.go.util.Pair)2 ArrayList (java.util.ArrayList)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 JobConfigs (com.thoughtworks.go.config.JobConfigs)1 PathFromAncestor (com.thoughtworks.go.config.PathFromAncestor)1 StageConfig (com.thoughtworks.go.config.StageConfig)1