Search in sources :

Example 31 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class PipelineOperationsControllerV1 method schedule.

public String schedule(Request req, Response res) throws IOException {
    HttpOperationResult result = new HttpOperationResult();
    String pipelineName = req.params("pipeline_name");
    pipelineTriggerService.schedule(pipelineName, getScheduleOptions(req), currentUsername(), result);
    return renderHTTPOperationResult(result, req, res);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult)

Example 32 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class PipelineOperationsControllerV1 method unlock.

public String unlock(Request req, Response res) throws IOException {
    HttpOperationResult result = new HttpOperationResult();
    String pipelineName = req.params("pipeline_name");
    pipelineUnlockApiService.unlock(pipelineName, currentUsername(), result);
    return renderHTTPOperationResult(result, req, res);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult)

Example 33 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class PipelineOperationsControllerV1 method getStatusInfo.

String getStatusInfo(Request request, Response response) throws IOException {
    String pipelineName = request.params("pipeline_name");
    HttpOperationResult result = new HttpOperationResult();
    PipelineStatusModel pipelineStatus = pipelineHistoryService.getPipelineStatus(pipelineName, currentUsernameString(), result);
    if (result.canContinue()) {
        return writerForTopLevelObject(request, response, (outputWriter) -> PipelineStatusModelRepresenter.toJSON(outputWriter, pipelineStatus));
    }
    return renderHTTPOperationResult(result, request, response);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineStatusModel(com.thoughtworks.go.presentation.PipelineStatusModel)

Example 34 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class ArtifactsDiskCleanerTest method shouldTriggerCleanupWhenLimitReached.

@Test
@Timeout(20)
public void shouldTriggerCleanupWhenLimitReached() throws InterruptedException {
    serverConfig.setPurgeLimits(20.0, 30.0);
    final boolean[] artifactsDeletionTriggered = { false };
    final Thread[] artifactDeleterThread = { null };
    final Semaphore sem = new Semaphore(1);
    sem.acquire();
    artifactsDiskCleaner = new ArtifactsDiskCleaner(sysEnv, goConfigService, diskSpaceChecker, artifactService, stageService, configDbStateRepository) {

        @Override
        void deleteOldArtifacts() {
            artifactDeleterThread[0] = Thread.currentThread();
            artifactsDeletionTriggered[0] = true;
            sem.release();
        }
    };
    Thread cleaner = (Thread) ReflectionUtil.getField(artifactsDiskCleaner, "cleaner");
    while (!cleaner.getState().equals(Thread.State.WAITING)) {
        Thread.sleep(5);
    }
    artifactsDiskCleaner.createFailure(new HttpOperationResult(), 10, 100);
    sem.acquire();
    assertThat(artifactsDeletionTriggered[0], is(true));
    assertThat(artifactDeleterThread[0], not(sameInstance(Thread.currentThread())));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 35 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class JobRerunScheduleServiceTest method shouldMarkResultIfScheduleFailsForUnexpectedReason.

@Test
void shouldMarkResultIfScheduleFailsForUnexpectedReason() {
    PipelineConfig mingleConfig = PipelineConfigMother.createPipelineConfig("mingle", "build", "unit", "functional");
    Pipeline pipeline = PipelineMother.passedPipelineInstance("mingle", "build", "unit");
    Stage firstStage = pipeline.getFirstStage();
    stub(mingleConfig, pipeline, firstStage);
    // leads to null pointer exception
    schedulingChecker = mock(SchedulingCheckerService.class);
    doThrow(new NullPointerException("The whole world is a big null.")).when(schedulingChecker).canSchedule(any(OperationResult.class));
    service = new ScheduleService(goConfigService, pipelineService, stageService, schedulingChecker, mock(PipelineDao.class), mock(StageDao.class), mock(StageOrderService.class), securityService, pipelineScheduleQueue, jobInstanceService, mock(JobInstanceDao.class), mock(AgentAssignment.class), environmentConfigService, lockService, serverHealthService, txnTemplate, mock(AgentService.class), null, null, null, null, null, schedulingPerformanceLogger, null, null);
    HttpOperationResult result = new HttpOperationResult();
    try (LogFixture logFixture = logFixtureFor(ScheduleService.class, Level.DEBUG)) {
        Stage stage = service.rerunJobs(firstStage, a("unit"), result);
        assertThat(logFixture.contains(Level.ERROR, "Job rerun request for job(s) [unit] could not be completed because of unexpected failure. Cause: The whole world is a big null.")).isTrue();
        assertThat(stage).isNull();
        assertThat(result.httpCode()).isEqualTo(500);
        assertThat(result.message()).isEqualTo("Job rerun request for job(s) [unit] could not be completed because of unexpected failure. Cause: The whole world is a big null.");
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) OperationResult(com.thoughtworks.go.server.service.result.OperationResult) Test(org.junit.jupiter.api.Test)

Aggregations

HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)146 Test (org.junit.jupiter.api.Test)64 Test (org.junit.Test)53 Username (com.thoughtworks.go.server.domain.Username)34 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)23 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)12 Pagination (com.thoughtworks.go.server.util.Pagination)7 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)6 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)6 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)6 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)5 AgentInstance (com.thoughtworks.go.domain.AgentInstance)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 NullStage (com.thoughtworks.go.domain.NullStage)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 PipelineStatusModel (com.thoughtworks.go.presentation.PipelineStatusModel)4 Stage (com.thoughtworks.go.domain.Stage)3