Search in sources :

Example 1 with BatchHostStateChangeDeniedException

use of com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException in project vespa by vespa-engine.

the class OrchestratorImplTest method whenSuspendAllFails.

@Test
public void whenSuspendAllFails() throws Exception {
    // A spy is preferential because suspendAll() relies on delegating the hard work to suspend() and resume().
    OrchestratorImpl orchestrator = spy(this.orchestrator);
    Throwable supensionFailure = new HostStateChangeDeniedException(DummyInstanceLookupService.TEST6_HOST_NAME, "some-constraint", "error message");
    doThrow(supensionFailure).when(orchestrator).suspendGroup(DummyInstanceLookupService.TEST6_NODE_GROUP);
    try {
        orchestrator.suspendAll(new HostName("parentHostname"), Arrays.asList(DummyInstanceLookupService.TEST1_HOST_NAME, DummyInstanceLookupService.TEST3_HOST_NAME, DummyInstanceLookupService.TEST6_HOST_NAME));
        fail();
    } catch (BatchHostStateChangeDeniedException e) {
        assertEquals("Failed to suspend NodeGroup{application=tenant-id-3:application-instance-3:prod:utopia-1:default, " + "hostNames=[test6.hostname.tld]} with parent host parentHostname: " + "Changing the state of test6.hostname.tld would violate " + "some-constraint: error message", e.getMessage());
    }
    InOrder order = inOrder(orchestrator);
    order.verify(orchestrator).suspendGroup(DummyInstanceLookupService.TEST3_NODE_GROUP);
    order.verify(orchestrator).suspendGroup(DummyInstanceLookupService.TEST6_NODE_GROUP);
    order.verifyNoMoreInteractions();
}
Also used : BatchHostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException) HostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException) InOrder(org.mockito.InOrder) BatchHostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Example 2 with BatchHostStateChangeDeniedException

use of com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException in project vespa by vespa-engine.

the class HostSuspensionResource method suspendAll.

@Override
public BatchOperationResult suspendAll(String parentHostnameString, List<String> hostnamesAsStrings) {
    HostName parentHostname = new HostName(parentHostnameString);
    List<HostName> hostnames = hostnamesAsStrings.stream().map(HostName::new).collect(Collectors.toList());
    try {
        orchestrator.suspendAll(parentHostname, hostnames);
    } catch (BatchHostStateChangeDeniedException e) {
        log.log(LogLevel.DEBUG, "Failed to suspend nodes " + hostnames + " with parent host " + parentHostname, e);
        throw createWebApplicationException(e.getMessage(), Response.Status.CONFLICT);
    } catch (BatchHostNameNotFoundException e) {
        log.log(LogLevel.DEBUG, "Failed to suspend nodes " + hostnames + " with parent host " + parentHostname, e);
        // by the URL path was found. It's one of the hostnames in the request it failed to find.
        throw createWebApplicationException(e.getMessage(), Response.Status.BAD_REQUEST);
    } catch (BatchInternalErrorException e) {
        log.log(LogLevel.DEBUG, "Failed to suspend nodes " + hostnames + " with parent host " + parentHostname, e);
        throw createWebApplicationException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
    }
    log.log(LogLevel.DEBUG, "Suspended " + hostnames + " with parent " + parentHostname);
    return BatchOperationResult.successResult();
}
Also used : BatchHostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException) BatchHostNameNotFoundException(com.yahoo.vespa.orchestrator.BatchHostNameNotFoundException) HostName(com.yahoo.vespa.applicationmodel.HostName) BatchInternalErrorException(com.yahoo.vespa.orchestrator.BatchInternalErrorException)

Aggregations

HostName (com.yahoo.vespa.applicationmodel.HostName)2 BatchHostStateChangeDeniedException (com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException)2 BatchHostNameNotFoundException (com.yahoo.vespa.orchestrator.BatchHostNameNotFoundException)1 BatchInternalErrorException (com.yahoo.vespa.orchestrator.BatchInternalErrorException)1 HostStateChangeDeniedException (com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1