Search in sources :

Example 96 with HttpOperationResult

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

the class AgentsControllerV7 method update.

public String update(Request request, Response response) {
    String uuid = request.params("uuid");
    AgentUpdateRequest req = fromJSON(request.body());
    String hostname = req.getHostname();
    String resources = req.getResources();
    String environments = filterOutEnvsWhichAreAssociatedViaConfigRepo(uuid, req.getEnvironments());
    TriState configState = req.getAgentConfigState();
    HttpOperationResult result = new HttpOperationResult();
    AgentInstance updatedAgentInstance = null;
    try {
        updatedAgentInstance = agentService.updateAgentAttributes(uuid, hostname, resources, environments, configState);
        handleUpdateAgentResponse(updatedAgentInstance, result);
    } catch (HttpException e) {
        throw e;
    } catch (Exception e) {
        throw halt(HttpStatus.SC_INTERNAL_SERVER_ERROR, MessageJson.create(e.getMessage()));
    }
    return handleCreateOrUpdateResponse(request, response, updatedAgentInstance, result);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) HttpException(com.thoughtworks.go.config.exceptions.HttpException) AgentUpdateRequest(com.thoughtworks.go.apiv7.agents.model.AgentUpdateRequest) TriState(com.thoughtworks.go.util.TriState) HttpException(com.thoughtworks.go.config.exceptions.HttpException) InvalidAgentInstructionException(com.thoughtworks.go.domain.exception.InvalidAgentInstructionException) IOException(java.io.IOException)

Example 97 with HttpOperationResult

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

the class AgentsControllerV7 method deleteAgents.

private String deleteAgents(Request request, Response response, List<String> uuids) {
    try {
        agentService.deleteAgents(uuids);
        final HttpOperationResult result = new HttpOperationResult();
        result.ok(format("Deleted %s agent(s).", uuids == null ? 0 : uuids.size()));
        return renderHTTPOperationResult(result, request, response);
    } catch (HttpException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Shoot! This is unexpected. Something went wrong while deleting agent(s)! More details : ";
        LOG.error(msg, e);
        throw halt(HttpStatus.SC_INTERNAL_SERVER_ERROR, MessageJson.create(msg + e.getMessage()));
    }
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) HttpException(com.thoughtworks.go.config.exceptions.HttpException) HttpException(com.thoughtworks.go.config.exceptions.HttpException) InvalidAgentInstructionException(com.thoughtworks.go.domain.exception.InvalidAgentInstructionException) IOException(java.io.IOException)

Example 98 with HttpOperationResult

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

the class PipelineInstanceControllerV1 method getInstanceInfo.

String getInstanceInfo(Request request, Response response) throws IOException {
    String pipelineName = request.params("pipeline_name");
    Integer pipelineCounter = getCounterValue(request);
    HttpOperationResult result = new HttpOperationResult();
    PipelineInstanceModel pipelineInstance = pipelineHistoryService.findPipelineInstance(pipelineName, pipelineCounter, currentUsername(), result);
    if (result.canContinue()) {
        return writerForTopLevelObject(request, response, (outputWriter) -> PipelineInstanceModelRepresenter.toJSON(outputWriter, pipelineInstance));
    }
    return renderHTTPOperationResult(result, request, response);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)

Example 99 with HttpOperationResult

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

the class StageInstanceControllerV3 method instanceByCounter.

public String instanceByCounter(Request req, Response res) throws IOException {
    String pipelineName = req.params("pipeline_name");
    String pipelineCounter = req.params("pipeline_counter");
    String stageName = req.params("stage_name");
    String stageCounter = req.params("stage_counter");
    HttpOperationResult result = new HttpOperationResult();
    Stage stageModel = stageService.findStageWithIdentifier(pipelineName, Integer.parseInt(pipelineCounter), stageName, stageCounter, currentUsername().getUsername().toString(), result);
    if (result.canContinue()) {
        return writerForTopLevelObject(req, res, writer -> StageRepresenter.toJSON(writer, stageModel));
    } else {
        return renderHTTPOperationResult(result, req, res);
    }
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) NullStage(com.thoughtworks.go.domain.NullStage) Stage(com.thoughtworks.go.domain.Stage)

Example 100 with HttpOperationResult

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

the class StageInstanceControllerV3 method rerunSelectedJobs.

public String rerunSelectedJobs(Request req, Response res) throws IOException {
    HttpOperationResult result = new HttpOperationResult();
    haltIfRequestBodyDoesNotContainPropertyJobs(req);
    JsonReader requestBody = GsonTransformer.getInstance().jsonReaderFrom(req.body());
    List<String> requestedJobs = requestBody.readStringArrayIfPresent(JOB_NAMES_PROPERTY).get();
    Optional<Stage> optionalStage = getStageFromRequestParam(req, result);
    optionalStage.ifPresent(stage -> {
        HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forStage(stage.getIdentifier().getPipelineName(), stage.getName()));
        Set<String> jobsInStage = stage.getJobInstances().stream().map(JobInstance::getName).collect(Collectors.toSet());
        List<String> unknownJobs = requestedJobs.stream().filter(jobToRun -> !jobsInStage.contains(jobToRun)).collect(Collectors.toList());
        if (unknownJobs.isEmpty()) {
            scheduleService.rerunJobs(stage, requestedJobs, result);
        } else {
            String msg = String.format("Job(s) %s does not exist in stage '%s'.", unknownJobs, stage.getIdentifier().getStageLocator());
            result.notFound(msg, "", healthStateType);
        }
    });
    return renderHTTPOperationResult(result, req, res);
}
Also used : HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonReader(com.thoughtworks.go.api.representers.JsonReader) Request(spark.Request) SparkSpringController(com.thoughtworks.go.spark.spring.SparkSpringController) NullStage(com.thoughtworks.go.domain.NullStage) ApiVersion(com.thoughtworks.go.api.ApiVersion) Routes(com.thoughtworks.go.spark.Routes) Stage(com.thoughtworks.go.domain.Stage) ApiController(com.thoughtworks.go.api.ApiController) GsonTransformer(com.thoughtworks.go.api.util.GsonTransformer) StageInstancesRepresenter(com.thoughtworks.go.apiv3.stageinstance.representers.StageInstancesRepresenter) StageRepresenter(com.thoughtworks.go.apiv3.stageinstance.representers.StageRepresenter) JobInstance(com.thoughtworks.go.domain.JobInstance) PipelineRunIdInfo(com.thoughtworks.go.domain.PipelineRunIdInfo) HaltApiResponses(com.thoughtworks.go.api.util.HaltApiResponses) Set(java.util.Set) IOException(java.io.IOException) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) Collectors(java.util.stream.Collectors) ApiAuthenticationHelper(com.thoughtworks.go.api.spring.ApiAuthenticationHelper) Component(org.springframework.stereotype.Component) List(java.util.List) HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) Response(spark.Response) Optional(java.util.Optional) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ScheduleService(com.thoughtworks.go.server.service.ScheduleService) StageService(com.thoughtworks.go.server.service.StageService) Spark(spark.Spark) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) JsonReader(com.thoughtworks.go.api.representers.JsonReader) NullStage(com.thoughtworks.go.domain.NullStage) Stage(com.thoughtworks.go.domain.Stage) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType)

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