Search in sources :

Example 66 with Material

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

the class PipelineInstanceModelTest method shouldReturnIfAnyMaterialHasModifications.

@Test
public void shouldReturnIfAnyMaterialHasModifications() {
    final SvnMaterial svnMaterial = svnMaterial("http://svnurl");
    final HgMaterial hgMaterial = hgMaterial("http://hgurl", "hgdir");
    MaterialRevisions currentRevisions = ModificationsMother.getMaterialRevisions(new HashMap<Material, String>() {

        {
            put(svnMaterial, "1");
            put(hgMaterial, "a");
        }
    });
    MaterialRevisions latestRevisions = ModificationsMother.getMaterialRevisions(new HashMap<Material, String>() {

        {
            put(svnMaterial, "1");
            put(hgMaterial, "b");
        }
    });
    MaterialConfigs materialConfigs = new MaterialConfigs();
    materialConfigs.add(svnMaterial.config());
    materialConfigs.add(hgMaterial.config());
    StageInstanceModels stages = new StageInstanceModels();
    stages.addStage("unit1", JobHistory.withJob("test", JobState.Completed, JobResult.Passed, new Date()));
    stages.addFutureStage("unit2", false);
    PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createWithModifications(currentRevisions, ""), stages);
    model.setLatestRevisions(latestRevisions);
    model.setMaterialConfigs(materialConfigs);
    assertThat("svnMaterial hasNewRevisions", model.hasNewRevisions(svnMaterial.config()), is(false));
    assertThat("hgMaterial hasNewRevisions", model.hasNewRevisions(hgMaterial.config()), is(true));
    assertThat("all materials hasNewRevisions", model.hasNewRevisions(), is(true));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) MaterialsMother.hgMaterial(com.thoughtworks.go.helper.MaterialsMother.hgMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) MaterialsMother.svnMaterial(com.thoughtworks.go.helper.MaterialsMother.svnMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 67 with Material

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

the class ScheduledPipelineLoader method pipelineWithPasswordAwareBuildCauseByBuildId.

// TODO: Do we need to do this differently than PipelineService#fullPipeline?
public Pipeline pipelineWithPasswordAwareBuildCauseByBuildId(final long buildId) {
    Pipeline pipeline = pipelineDao.pipelineWithMaterialsAndModsByBuildId(buildId);
    MaterialRevisions scheduledRevs = pipeline.getBuildCause().getMaterialRevisions();
    MaterialConfigs knownMaterials = knownMaterials(pipeline, scheduledRevs);
    for (MaterialRevision materialRevision : scheduledRevs) {
        MaterialConfig materialConfig = materialFrom(knownMaterials, materialRevision);
        Material usedMaterial = materialRevision.getMaterial();
        if (materialConfig == null) {
            final JobInstance jobInstance = jobInstanceService.buildByIdWithTransitions(buildId);
            scheduleService.failJob(jobInstance);
            final String message = "Cannot load job '" + jobInstance.buildLocator() + "' because material " + usedMaterial.config() + " was not found in config.";
            final String description = "Job for pipeline '" + jobInstance.buildLocator() + "' has been failed as one or more material configurations were either changed or removed.";
            transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {

                @Override
                public void afterCommit() {
                    final ServerHealthState error = ServerHealthState.error(message, description, HealthStateType.general(HealthStateScope.forJob(jobInstance.getPipelineName(), jobInstance.getStageName(), jobInstance.getName())));
                    error.setTimeout(Timeout.FIVE_MINUTES);
                    serverHealthService.update(error);
                    appendToConsoleLog(jobInstance, message);
                    appendToConsoleLog(jobInstance, description);
                }
            });
            throw new StaleMaterialsOnBuildCause(message);
        }
        usedMaterial.updateFromConfig(materialConfig);
    }
    return pipeline;
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) JobInstance(com.thoughtworks.go.domain.JobInstance) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) StaleMaterialsOnBuildCause(com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) Material(com.thoughtworks.go.domain.materials.Material) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Pipeline(com.thoughtworks.go.domain.Pipeline)

Example 68 with Material

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

the class ValueStreamMapService method getValueStreamMap.

public ValueStreamMapPresentationModel getValueStreamMap(String materialFingerprint, String revision, Username username, LocalizedOperationResult result) {
    try {
        MaterialConfig materialConfig = null;
        boolean hasViewPermissionForMaterial = false;
        List<PipelineConfig> downstreamPipelines = new ArrayList<>();
        for (PipelineConfigs pipelineGroup : goConfigService.groups()) {
            boolean hasViewPermissionForGroup = securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), pipelineGroup.getGroup());
            for (PipelineConfig pipelineConfig : pipelineGroup) {
                for (MaterialConfig currentMaterialConfig : pipelineConfig.materialConfigs()) {
                    if (currentMaterialConfig.getFingerprint().equals(materialFingerprint)) {
                        materialConfig = currentMaterialConfig;
                        if (hasViewPermissionForGroup) {
                            hasViewPermissionForMaterial = true;
                        }
                        downstreamPipelines.add(pipelineConfig);
                    }
                }
            }
        }
        if (materialConfig == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_CONFIG_WITH_FINGERPRINT_NOT_FOUND", materialFingerprint), HealthStateType.general(HealthStateScope.GLOBAL));
            return null;
        }
        if (!hasViewPermissionForMaterial) {
            result.unauthorized(LocalizedMessage.cannotViewMaterial(materialFingerprint), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        MaterialInstance materialInstance = materialRepository.findMaterialInstance(materialConfig);
        if (materialInstance == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_INSTANCE_WITH_FINGERPRINT_NOT_FOUND", materialFingerprint), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        Material material = new MaterialConfigConverter().toMaterial(materialConfig);
        Modification modification = materialRepository.findModificationWithRevision(material, revision);
        if (modification == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_MODIFICATION_NOT_FOUND", materialFingerprint, revision), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        ValueStreamMap valueStreamMap = buildValueStreamMap(material, materialInstance, modification, downstreamPipelines, username);
        if (valueStreamMap == null) {
            return null;
        }
        return valueStreamMap.presentationModel();
    } catch (Exception e) {
        result.internalServerError(LocalizedMessage.string("VSM_INTERNAL_SERVER_ERROR_FOR_MATERIAL", materialFingerprint, revision));
        LOGGER.error("[Value Stream Map] Material {} with revision {} could not be rendered.", materialFingerprint, revision, e);
        return null;
    }
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ArrayList(java.util.ArrayList) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

Example 69 with Material

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

the class PipelineService method getRevisionsBasedOnDependenciesForDebug.

// This is for debugging purposes
public String getRevisionsBasedOnDependenciesForDebug(CaseInsensitiveString pipelineName, final Integer targetIterationCount) {
    CruiseConfig cruiseConfig = goConfigService.getCurrentConfig();
    FanInGraph fanInGraph = new FanInGraph(cruiseConfig, pipelineName, materialRepository, pipelineDao, systemEnvironment, materialConfigConverter);
    final String[] iterationData = { null };
    fanInGraph.setFanInEventListener(new FanInEventListener() {

        @Override
        public void iterationComplete(int iterationCount, List<DependencyFanInNode> dependencyFanInNodes) {
            if (iterationCount == targetIterationCount) {
                iterationData[0] = new GsonBuilder().setExclusionStrategies(getGsonExclusionStrategy()).create().toJson(dependencyFanInNodes);
            }
        }
    });
    PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(pipelineName);
    Materials materials = materialConfigConverter.toMaterials(pipelineConfig.materialConfigs());
    MaterialRevisions actualRevisions = new MaterialRevisions();
    for (Material material : materials) {
        actualRevisions.addAll(materialRepository.findLatestModification(material));
    }
    MaterialRevisions materialRevisions = fanInGraph.computeRevisions(actualRevisions, pipelineTimeline);
    if (iterationData[0] == null) {
        iterationData[0] = new GsonBuilder().setExclusionStrategies(getGsonExclusionStrategy()).create().toJson(materialRevisions);
    }
    return iterationData[0];
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GsonBuilder(com.google.gson.GsonBuilder) Materials(com.thoughtworks.go.config.materials.Materials) FanInGraph(com.thoughtworks.go.server.service.dd.FanInGraph) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) DependencyFanInNode(com.thoughtworks.go.server.service.dd.DependencyFanInNode) FanInEventListener(com.thoughtworks.go.server.service.dd.FanInEventListener)

Example 70 with Material

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

the class SvnMaterialTest method shouldNotBeEqualWhenTypeDifferent.

@Test
public void shouldNotBeEqualWhenTypeDifferent() throws Exception {
    final Material hgMaterial = MaterialsMother.hgMaterials("url1", "hgdir").get(0);
    final Material nonHgMaterial = MaterialsMother.defaultSvnMaterialsWithUrl("url1").get(0);
    assertComplementaryEquals(hgMaterial, nonHgMaterial, false);
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Test(org.junit.Test)

Aggregations

Material (com.thoughtworks.go.domain.materials.Material)95 Test (org.junit.Test)59 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)39 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)39 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)23 Modification (com.thoughtworks.go.domain.materials.Modification)20 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)18 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)16 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)14 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)14 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)14 Materials (com.thoughtworks.go.config.materials.Materials)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)10 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)9 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)9 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)8 Date (java.util.Date)8 HashSet (java.util.HashSet)8 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)7 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)7