Search in sources :

Example 1 with PatchHostResponse

use of com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse in project vespa by vespa-engine.

the class HostResourceTest method patch_works.

@Test
public void patch_works() throws OrchestrationException {
    Orchestrator orchestrator = mock(Orchestrator.class);
    HostResource hostResource = new HostResource(orchestrator, uriInfo);
    String hostNameString = "hostname";
    PatchHostRequest request = new PatchHostRequest();
    request.state = "NO_REMARKS";
    PatchHostResponse response = hostResource.patch(hostNameString, request);
    assertEquals(response.description, "ok");
    verify(orchestrator, times(1)).setNodeStatus(new HostName(hostNameString), HostStatus.NO_REMARKS);
}
Also used : PatchHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse) PatchHostRequest(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostRequest) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Example 2 with PatchHostResponse

use of com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse in project vespa by vespa-engine.

the class HostResource method patch.

@Override
public PatchHostResponse patch(String hostNameString, PatchHostRequest request) {
    HostName hostName = new HostName(hostNameString);
    if (request.state != null) {
        HostStatus state;
        try {
            state = HostStatus.valueOf(request.state);
        } catch (IllegalArgumentException dummy) {
            throw new BadRequestException("Bad state in request: '" + request.state + "'");
        }
        try {
            orchestrator.setNodeStatus(hostName, state);
        } catch (HostNameNotFoundException e) {
            log.log(LogLevel.INFO, "Host not found: " + hostName);
            throw new NotFoundException(e);
        } catch (OrchestrationException e) {
            String message = "Failed to set " + hostName + " to " + state + ": " + e.getMessage();
            log.log(LogLevel.INFO, message, e);
            throw new InternalServerErrorException(message);
        }
    }
    PatchHostResponse response = new PatchHostResponse();
    response.description = "ok";
    return response;
}
Also used : PatchHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse) OrchestrationException(com.yahoo.vespa.orchestrator.OrchestrationException) BadRequestException(javax.ws.rs.BadRequestException) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) HostStatus(com.yahoo.vespa.orchestrator.status.HostStatus) HostName(com.yahoo.vespa.applicationmodel.HostName) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException)

Aggregations

HostName (com.yahoo.vespa.applicationmodel.HostName)2 PatchHostResponse (com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse)2 HostNameNotFoundException (com.yahoo.vespa.orchestrator.HostNameNotFoundException)1 OrchestrationException (com.yahoo.vespa.orchestrator.OrchestrationException)1 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)1 PatchHostRequest (com.yahoo.vespa.orchestrator.restapi.wire.PatchHostRequest)1 HostStatus (com.yahoo.vespa.orchestrator.status.HostStatus)1 BadRequestException (javax.ws.rs.BadRequestException)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 NotFoundException (javax.ws.rs.NotFoundException)1 Test (org.junit.Test)1