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));
}
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;
}
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;
}
}
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];
}
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);
}
Aggregations