use of com.thoughtworks.go.config.exceptions.HttpException in project gocd by gocd.
the class AgentsControllerV7 method bulkUpdate.
public String bulkUpdate(Request request, Response response) throws IOException {
final AgentBulkUpdateRequest req = AgentBulkUpdateRequestRepresenter.fromJSON(request.body());
final HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
try {
agentService.bulkUpdateAgentAttributes(req.getUuids(), req.getOperations().getResources().toAdd(), req.getOperations().getResources().toRemove(), req.getOperations().getEnvironments().toAdd(), req.getOperations().getEnvironments().toRemove(), req.getAgentConfigState(), environmentConfigService);
result.setMessage("Updated agent(s) with uuid(s): [" + join(req.getUuids(), ", ") + "].");
} catch (HttpException e) {
throw e;
} catch (Exception e) {
throw halt(HttpStatus.SC_INTERNAL_SERVER_ERROR, MessageJson.create(e.getMessage()));
}
return renderHTTPOperationResult(result, request, response);
}
use of com.thoughtworks.go.config.exceptions.HttpException 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.config.exceptions.HttpException 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()));
}
}
Aggregations