Search in sources :

Example 11 with DependencyMaterialRevision

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

the class ChangesetService method revisionsBetween.

public List<MaterialRevision> revisionsBetween(List<PipelineRevisionRange> pipelineRevisionRanges, Username username, HttpLocalizedOperationResult result) {
    ArrayList<MaterialRevision> revisions = new ArrayList<>();
    for (PipelineRevisionRange pipelineRevisionRange : pipelineRevisionRanges) {
        DependencyMaterialRevision fromDmr = DependencyMaterialRevision.create(pipelineRevisionRange.getFromRevision(), null);
        DependencyMaterialRevision toDmr = DependencyMaterialRevision.create(pipelineRevisionRange.getToRevision(), null);
        revisions.addAll(revisionsBetween(pipelineRevisionRange.getPipelineName(), fromDmr.getPipelineCounter(), toDmr.getPipelineCounter(), username, result, true, false));
    }
    return deduplicateMaterialRevisionsForCommonMaterials(revisions);
}
Also used : PipelineRevisionRange(com.thoughtworks.go.server.web.PipelineRevisionRange) ArrayList(java.util.ArrayList) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)

Example 12 with DependencyMaterialRevision

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

the class FetchTaskBuilder method resolveTargetJob.

private JobIdentifier resolveTargetJob(AbstractFetchTask 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(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(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(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 : DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 13 with DependencyMaterialRevision

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

the class DependencyFanInNode method getRevisionNthFor.

private Pair<StageIdentifier, List<FaninScmMaterial>> getRevisionNthFor(int n, FanInGraphContext context) {
    List<FaninScmMaterial> scmMaterials = new ArrayList<>();
    PipelineTimeline pipelineTimeline = context.pipelineTimeline;
    Queue<PipelineTimelineEntry.Revision> revisionQueue = new ConcurrentLinkedQueue<>();
    DependencyMaterialConfig dependencyMaterial = (DependencyMaterialConfig) materialConfig;
    PipelineTimelineEntry entry = pipelineTimeline.instanceFor(dependencyMaterial.getPipelineName(), totalInstanceCount - n);
    Set<CaseInsensitiveString> visitedNodes = new HashSet<>();
    StageIdentifier dependentStageIdentifier = dependentStageIdentifier(context, entry, CaseInsensitiveString.str(dependencyMaterial.getStageName()));
    if (!StageIdentifier.NULL.equals(dependentStageIdentifier)) {
        addToRevisionQueue(entry, revisionQueue, scmMaterials, context, visitedNodes);
    } else {
        return null;
    }
    while (!revisionQueue.isEmpty()) {
        PipelineTimelineEntry.Revision revision = revisionQueue.poll();
        DependencyMaterialRevision dmr = DependencyMaterialRevision.create(revision.revision, null);
        PipelineTimelineEntry pte = pipelineTimeline.getEntryFor(new CaseInsensitiveString(dmr.getPipelineName()), dmr.getPipelineCounter());
        addToRevisionQueue(pte, revisionQueue, scmMaterials, context, visitedNodes);
    }
    return new Pair<>(dependentStageIdentifier, scmMaterials);
}
Also used : DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) PipelineTimeline(com.thoughtworks.go.server.domain.PipelineTimeline) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Pair(com.thoughtworks.go.util.Pair)

Example 14 with DependencyMaterialRevision

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

the class ReportingDependencyFanInNode method getRevisionNthFor.

private Pair<StageIdentifier, List<ReportingFaninScmMaterial>> getRevisionNthFor(int n, ReportingFanInGraphContext context) {
    List<ReportingFaninScmMaterial> scmMaterials = new ArrayList<>();
    PipelineTimeline pipelineTimeline = context.pipelineTimeline;
    Queue<PipelineTimelineEntry.Revision> revisionQueue = new ConcurrentLinkedQueue<>();
    DependencyMaterialConfig dependencyMaterial = (DependencyMaterialConfig) materialConfig;
    PipelineTimelineEntry entry = pipelineTimeline.instanceFor(dependencyMaterial.getPipelineName(), totalInstanceCount - n);
    StageIdentifier dependentStageIdentifier = dependentStageIdentifier(context, entry, CaseInsensitiveString.str(dependencyMaterial.getStageName()));
    if (!StageIdentifier.NULL.equals(dependentStageIdentifier)) {
        addToRevisionQueue(entry, revisionQueue, scmMaterials, context);
    } else {
        return null;
    }
    while (!revisionQueue.isEmpty()) {
        PipelineTimelineEntry.Revision revision = revisionQueue.poll();
        DependencyMaterialRevision dmr = DependencyMaterialRevision.create(revision.revision, null);
        PipelineTimelineEntry pte = pipelineTimeline.getEntryFor(new CaseInsensitiveString(dmr.getPipelineName()), dmr.getPipelineCounter());
        addToRevisionQueue(pte, revisionQueue, scmMaterials, context);
    }
    return new Pair<>(dependentStageIdentifier, scmMaterials);
}
Also used : ArrayList(java.util.ArrayList) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) PipelineTimeline(com.thoughtworks.go.server.domain.PipelineTimeline) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Pair(com.thoughtworks.go.util.Pair)

Example 15 with DependencyMaterialRevision

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

the class PipelineSqlMapDao method invalidateCacheConditionallyForPipelineInstancesTriggeredWithDependencyMaterial.

private void invalidateCacheConditionallyForPipelineInstancesTriggeredWithDependencyMaterial(Pipeline pipeline) {
    BuildCause buildCause = pipeline.getBuildCause();
    for (MaterialRevision materialRevision : buildCause.getMaterialRevisions()) {
        if (DependencyMaterial.TYPE.equals(materialRevision.getMaterial().getType())) {
            DependencyMaterialRevision dependencyMaterialRevision = (DependencyMaterialRevision) materialRevision.getRevision();
            goCache.remove(cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial(pipeline.getName(), dependencyMaterialRevision.getPipelineName(), dependencyMaterialRevision.getPipelineCounter()));
        } else {
            goCache.remove(cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial(pipeline.getName(), materialRevision.getMaterial().getFingerprint(), materialRevision.getRevision().getRevision()));
        }
    }
}
Also used : DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Aggregations

DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)20 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)7 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)6 Test (org.junit.Test)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)5 Date (java.util.Date)4 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 Materials (com.thoughtworks.go.config.materials.Materials)2 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)2 PipelineTimelineEntry (com.thoughtworks.go.domain.PipelineTimelineEntry)2 FetchArtifactBuilder (com.thoughtworks.go.domain.builder.FetchArtifactBuilder)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