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