use of com.thoughtworks.go.apiv7.agents.model.AgentBulkUpdateRequest 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.apiv7.agents.model.AgentBulkUpdateRequest in project gocd by gocd.
the class AgentBulkUpdateRequestRepresenter method fromJSON.
public static AgentBulkUpdateRequest fromJSON(String requestBody) {
final JsonReader reader = GsonTransformer.getInstance().jsonReaderFrom(requestBody);
final List<String> uuids = extractToList(reader.optJsonArray("uuids"));
final String agentConfigState = reader.optString("agent_config_state").orElse(null);
if (uuids.isEmpty()) {
HaltApiResponses.haltBecauseOfReason("Must specify agent 'uuids' for bulk update.");
}
final AgentBulkUpdateRequest.Operations operations = toOperationsFromJSON(reader.optJsonObject("operations"));
return new AgentBulkUpdateRequest(uuids, operations, toTriState(agentConfigState));
}
Aggregations