Search in sources :

Example 71 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class ConsoleActivityMonitorTest method shouldClearServerHealthMessageForAnyJobCancelledExternally.

@Test
public void shouldClearServerHealthMessageForAnyJobCancelledExternally() {
    DateTime now = new DateTime();
    when(timeProvider.currentTimeMillis()).thenReturn(now.getMillis());
    JobIdentifier unresponsiveJob = new JobIdentifier("foo", 12, "foo-10", "stage", "2", "job", 20l);
    JobInstance job = buildingInstance(unresponsiveJob);
    listener.jobStatusChanged(job);
    job.cancel();
    listener.jobStatusChanged(job);
    verify(serverHealthService).removeByScope(HealthStateScope.forJob("foo", "stage", "job"));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 72 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class BuildRepositoryService method isCancelledOrRescheduled.

public boolean isCancelledOrRescheduled(Long buildInstanceId) {
    JobInstance instance = jobInstanceService.buildByIdWithTransitions(buildInstanceId);
    if (instance.isNull()) {
        return false;
    }
    boolean cancelled = instance.getResult() == JobResult.Cancelled;
    boolean rescheduled = instance.getState() == JobState.Rescheduled;
    return cancelled || rescheduled;
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance)

Example 73 with JobInstance

use of com.thoughtworks.go.domain.JobInstance 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 74 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobPresentationService method jobInstanceModelFor.

public List<JobInstanceModel> jobInstanceModelFor(JobInstances jobInstances) {
    ArrayList<JobInstanceModel> models = new ArrayList<>();
    for (JobInstance jobInstance : jobInstances) {
        AgentInstance agentInstance = jobInstance.isAssignedToAgent() ? agentService.findAgentAndRefreshStatus(jobInstance.getAgentUuid()) : null;
        JobInstanceModel model;
        if (null != agentInstance && !agentInstance.isNullAgent()) {
            model = new JobInstanceModel(jobInstance, jobDurationStrategy, agentInstance);
        } else if (jobInstance.getAgentUuid() != null) {
            Agent agent = agentService.findAgentObjectByUuid(jobInstance.getAgentUuid());
            model = new JobInstanceModel(jobInstance, jobDurationStrategy, agent);
        } else {
            model = new JobInstanceModel(jobInstance, jobDurationStrategy);
        }
        models.add(model);
    }
    sort(models, JobInstanceModel.JOB_MODEL_COMPARATOR);
    return models;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Agent(com.thoughtworks.go.server.domain.Agent) JobInstance(com.thoughtworks.go.domain.JobInstance) ArrayList(java.util.ArrayList) JobInstanceModel(com.thoughtworks.go.server.ui.JobInstanceModel)

Example 75 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsRescheduled.

@Test
public void shouldSendCancelMessageIfJobIsRescheduled() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    configHelper.addAgent(agentConfig);
    fixture.createPipelineWithFirstStageScheduled();
    AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
    info.setCookie("cookie");
    agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    buildAssignmentService.onTimer();
    assertThat(agent.messages.size(), is(1));
    assertThat(MessageEncoding.decodeWork(agent.messages.get(0).getData()), instanceOf(BuildWork.class));
    BuildWork work = (BuildWork) MessageEncoding.decodeWork(agent.messages.get(0).getData());
    BuildAssignment assignment = work.getAssignment();
    final JobInstance instance = jobInstanceService.buildByIdWithTransitions(assignment.getJobIdentifier().getBuildId());
    scheduleService.rescheduleJob(instance);
    assertThat(agent.messages.size(), is(2));
    assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Message(com.thoughtworks.go.websocket.Message) JobInstance(com.thoughtworks.go.domain.JobInstance) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) BuildWork(com.thoughtworks.go.remote.work.BuildWork)

Aggregations

JobInstance (com.thoughtworks.go.domain.JobInstance)82 Test (org.junit.Test)56 Stage (com.thoughtworks.go.domain.Stage)16 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)15 Pipeline (com.thoughtworks.go.domain.Pipeline)15 JobInstances (com.thoughtworks.go.domain.JobInstances)12 JobConfigIdentifier (com.thoughtworks.go.domain.JobConfigIdentifier)7 Agent (com.thoughtworks.go.server.domain.Agent)6 Gson (com.google.gson.Gson)5 Stages (com.thoughtworks.go.domain.Stages)5 Map (java.util.Map)5 DurationBean (com.thoughtworks.go.dto.DurationBean)4 DateTime (org.joda.time.DateTime)4 ArtifactPropertiesGenerator (com.thoughtworks.go.config.ArtifactPropertiesGenerator)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 Resource (com.thoughtworks.go.config.Resource)3 DirectoryEntries (com.thoughtworks.go.domain.DirectoryEntries)3 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)3 JobInstanceModel (com.thoughtworks.go.server.ui.JobInstanceModel)3