Search in sources :

Example 1 with AgentBulkUpdateRequest

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);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) AgentBulkUpdateRequest(com.thoughtworks.go.apiv7.agents.model.AgentBulkUpdateRequest) 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 2 with AgentBulkUpdateRequest

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));
}
Also used : JsonReader(com.thoughtworks.go.api.representers.JsonReader) AgentBulkUpdateRequest(com.thoughtworks.go.apiv7.agents.model.AgentBulkUpdateRequest)

Aggregations

AgentBulkUpdateRequest (com.thoughtworks.go.apiv7.agents.model.AgentBulkUpdateRequest)2 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 HttpException (com.thoughtworks.go.config.exceptions.HttpException)1 InvalidAgentInstructionException (com.thoughtworks.go.domain.exception.InvalidAgentInstructionException)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 IOException (java.io.IOException)1