Search in sources :

Example 1 with HttpException

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);
}
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 HttpException

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);
}
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 3 with HttpException

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

Aggregations

HttpException (com.thoughtworks.go.config.exceptions.HttpException)3 InvalidAgentInstructionException (com.thoughtworks.go.domain.exception.InvalidAgentInstructionException)3 IOException (java.io.IOException)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)2 AgentBulkUpdateRequest (com.thoughtworks.go.apiv7.agents.model.AgentBulkUpdateRequest)1 AgentUpdateRequest (com.thoughtworks.go.apiv7.agents.model.AgentUpdateRequest)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 TriState (com.thoughtworks.go.util.TriState)1