Search in sources :

Example 6 with Material

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

the class ConfigMaterialUpdater method onMessage.

@Override
public void onMessage(MaterialUpdateCompletedMessage message) {
    Material material = message.getMaterial();
    // MDU is done using the checkout, it has done db update and stored latest changes
    // but MUS is still waiting for material updated message on MaterialUpdateCompletedTopic
    LOGGER.debug("[Config Material Update] Config material update completed for material {}. Starting parse process", material);
    try {
        if (message instanceof MaterialUpdateFailedMessage) {
            MaterialUpdateFailedMessage failure = (MaterialUpdateFailedMessage) message;
            LOGGER.warn("[Config Material Update] Cannot update configuration part because material update has failed. Reason: {}", failure.getReason());
        } else {
            File folder = materialRepository.folderFor(material);
            MaterialRevisions latestModification = materialRepository.findLatestModification(material);
            Revision revision = latestModification.firstModifiedMaterialRevision().getRevision();
            MaterialRevision lastParseRevision = getMaterialRevisionAtLastParseAttempt(message);
            if (lastParseRevision == null) {
                // never parsed
                updateConfigurationFromCheckout(folder, revision, material);
            } else if (latestModification.findRevisionFor(material.config()).hasChangedSince(lastParseRevision)) {
                // revision has changed. the config files might have been updated
                updateConfigurationFromCheckout(folder, revision, material);
            } else {
            // revision is the same as last time, no need to parse again
            }
        }
    } finally {
        // always post the original message further
        // this will remove material from inProgress in MUS
        topic.post(message);
    }
}
Also used : MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Revision(com.thoughtworks.go.domain.materials.Revision) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) File(java.io.File)

Example 7 with Material

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

the class MaterialUpdateService method updateGitMaterial.

public boolean updateGitMaterial(String branchName, Collection<String> possibleUrls) {
    final CruiseConfig cruiseConfig = goConfigService.currentCruiseConfig();
    Set<Material> allUniquePostCommitSchedulableMaterials = materialConfigConverter.toMaterials(cruiseConfig.getAllUniquePostCommitSchedulableMaterials());
    Predicate<Material> predicate = new MaterialPredicate(branchName, possibleUrls);
    Set<Material> allGitMaterials = allUniquePostCommitSchedulableMaterials.stream().filter(predicate).collect(Collectors.toSet());
    allGitMaterials.forEach(new Consumer<Material>() {

        @Override
        public void accept(Material material) {
            MaterialUpdateService.this.updateMaterial(material);
        }
    });
    return !allGitMaterials.isEmpty();
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) CruiseConfig(com.thoughtworks.go.config.CruiseConfig)

Example 8 with Material

use of com.thoughtworks.go.domain.materials.Material 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 9 with Material

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

the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.

@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
    String pipelineName = "pipeline";
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
    Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
    config.materialConfigs().clear();
    config.addMaterialConfig(svnMaterial.config());
    config.addMaterialConfig(dependencyMaterial.config());
    lenient().when(pipelineService.getRevisionsBasedOnDependencies(any(MaterialRevisions.class), any(BasicCruiseConfig.class), any(CaseInsensitiveString.class))).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
    when(pipelineScheduleQueue.mostRecentScheduled(new CaseInsensitiveString(pipelineName))).thenReturn(BuildCause.createNeverRun());
    Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
    when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
    when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
    when(specificMaterialRevisionFactory.create(any(String.class), anyMap())).thenReturn(MaterialRevisions.EMPTY);
    MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
    Materials materials = new Materials(svnMaterial, dependencyMaterial);
    when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
    when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
    when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null);
    ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
    assertThat(serverHealthState.isSuccess(), is(true));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) Test(org.junit.jupiter.api.Test)

Example 10 with Material

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

the class BuildAssignmentServiceIntegrationTest method shouldCancelAScheduledJobInCaseStageHasBeenRenamed.

@Test
public void shouldCancelAScheduledJobInCaseStageHasBeenRenamed() throws Exception {
    Material hgMaterial = new HgMaterial("url", "folder");
    String[] hgRevs = new String[] { "h1" };
    u.checkinInOrder(hgMaterial, hgRevs);
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("PIPELINE_WHICH_WILL_EVENTUALLY_CHANGE_CASE", u.m(hgMaterial));
    BuildCause buildCause = BuildCause.createWithModifications(u.mrs(u.mr(u.m(hgMaterial).material, true, hgRevs)), "user");
    Pipeline originalPipelineRun = scheduleService.schedulePipeline(p1.config.name(), buildCause);
    ScheduleTestUtil.AddedPipeline renamedPipeline = u.renamePipelineAndFirstStage(p1, "pipeline_which_will_eventually_change_case", "NEW_RANDOM_STAGE_NAME" + UUID.randomUUID());
    CruiseConfig cruiseConfig = configHelper.load();
    // To Reload Job Plans
    buildAssignmentService.onTimer();
    buildAssignmentService.onConfigChange(cruiseConfig);
    Stages allStages = stageDao.findAllStagesFor(originalPipelineRun.getName(), originalPipelineRun.getCounter());
    assertThat(allStages.byName(CaseInsensitiveString.str(p1.config.first().name())).getState(), is(StageState.Cancelled));
    u.checkinInOrder(hgMaterial, "h2");
    BuildCause buildCauseForRenamedPipeline = BuildCause.createWithModifications(u.mrs(u.mr(u.m(hgMaterial).material, true, "h2")), "user");
    Pipeline p1_2 = scheduleService.schedulePipeline(renamedPipeline.config.name(), buildCauseForRenamedPipeline);
    Stages allStagesForRenamedPipeline = stageDao.findAllStagesFor(p1_2.getName(), p1_2.getCounter());
    assertThat(allStagesForRenamedPipeline.byName(p1_2.getFirstStage().getName()).getState(), is(StageState.Building));
}
Also used : PipelineWithTwoStages(com.thoughtworks.go.fixture.PipelineWithTwoStages) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.jupiter.api.Test)

Aggregations

Material (com.thoughtworks.go.domain.materials.Material)122 Test (org.junit.jupiter.api.Test)72 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)49 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)47 Modification (com.thoughtworks.go.domain.materials.Modification)29 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)28 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)24 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)19 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)19 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)19 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)18 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)18 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)16 Materials (com.thoughtworks.go.config.materials.Materials)14 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)13 File (java.io.File)13 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)12 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)12 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)12 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)8