Search in sources :

Example 1 with StaleMaterialsOnBuildCause

use of com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause in project gocd by gocd.

the class BuildAssignmentService method createWork.

private Work createWork(final AgentInstance agent, final JobPlan job) {
    try {
        return (Work) transactionTemplate.transactionSurrounding(new TransactionTemplate.TransactionSurrounding<RuntimeException>() {

            public Object surrounding() {
                final String agentUuid = agent.getUuid();
                //TODO: Use fullPipeline and get the Stage from it?
                final Pipeline pipeline;
                try {
                    pipeline = scheduledPipelineLoader.pipelineWithPasswordAwareBuildCauseByBuildId(job.getJobId());
                } catch (StaleMaterialsOnBuildCause e) {
                    return NO_WORK;
                }
                List<Task> tasks = goConfigService.tasksForJob(pipeline.getName(), job.getIdentifier().getStageName(), job.getName());
                final List<Builder> builders = builderFactory.buildersForTasks(pipeline, tasks, resolver);
                return transactionTemplate.execute(new TransactionCallback() {

                    public Object doInTransaction(TransactionStatus status) {
                        if (scheduleService.updateAssignedInfo(agentUuid, job)) {
                            return NO_WORK;
                        }
                        BuildAssignment buildAssignment = BuildAssignment.create(job, pipeline.getBuildCause(), builders, pipeline.defaultWorkingFolder());
                        environmentConfigService.enhanceEnvironmentVariables(buildAssignment);
                        return new BuildWork(buildAssignment);
                    }
                });
            }
        });
    } catch (PipelineNotFoundException e) {
        removeJobIfNotPresentInCruiseConfig(goConfigService.getCurrentConfig(), job);
        throw e;
    }
}
Also used : StaleMaterialsOnBuildCause(com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause) Builder(com.thoughtworks.go.domain.builder.Builder) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallback(org.springframework.transaction.support.TransactionCallback)

Example 2 with StaleMaterialsOnBuildCause

use of com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause 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)

Aggregations

StaleMaterialsOnBuildCause (com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 Builder (com.thoughtworks.go.domain.builder.Builder)1 Material (com.thoughtworks.go.domain.materials.Material)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)1 ServerHealthState (com.thoughtworks.go.serverhealth.ServerHealthState)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1 TransactionSynchronizationAdapter (org.springframework.transaction.support.TransactionSynchronizationAdapter)1