Search in sources :

Example 1 with HostStateChangeDeniedException

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

the class StorageNodeImpl method setNodeState.

@Override
public void setNodeState(ClusterControllerNodeState wantedNodeState) throws HostStateChangeDeniedException {
    // The "cluster name" used by the Cluster Controller IS the cluster ID.
    String clusterId = this.clusterId.s();
    List<HostName> clusterControllers = VespaModelUtil.getClusterControllerInstancesInOrder(applicationInstance, this.clusterId);
    ClusterControllerClient client = clusterControllerClientFactory.createClient(clusterControllers, clusterId);
    ConfigId configId = storageService.configId();
    int nodeIndex = VespaModelUtil.getStorageNodeIndex(configId);
    logger.log(LogLevel.DEBUG, () -> "Setting cluster controller state for " + "application " + applicationInstance.reference().asString() + ", host " + hostName() + ", cluster name " + clusterId + ", node index " + nodeIndex + ", node state " + wantedNodeState);
    ClusterControllerStateResponse response;
    try {
        response = client.setNodeState(nodeIndex, wantedNodeState);
    } catch (IOException e) {
        throw new HostStateChangeDeniedException(hostName(), HostedVespaPolicy.CLUSTER_CONTROLLER_AVAILABLE_CONSTRAINT, "Failed to communicate with cluster controllers " + clusterControllers + ": " + e, e);
    }
    if (!response.wasModified) {
        throw new HostStateChangeDeniedException(hostName(), HostedVespaPolicy.SET_NODE_STATE_CONSTRAINT, "Failed to set state to " + wantedNodeState + " in cluster controller: " + response.reason);
    }
}
Also used : HostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException) ClusterControllerStateResponse(com.yahoo.vespa.orchestrator.controller.ClusterControllerStateResponse) ClusterControllerClient(com.yahoo.vespa.orchestrator.controller.ClusterControllerClient) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) IOException(java.io.IOException) HostName(com.yahoo.vespa.applicationmodel.HostName)

Example 2 with HostStateChangeDeniedException

use of com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException 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)

Aggregations

HostName (com.yahoo.vespa.applicationmodel.HostName)2 HostStateChangeDeniedException (com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException)2 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)1 ClusterControllerClient (com.yahoo.vespa.orchestrator.controller.ClusterControllerClient)1 ClusterControllerStateResponse (com.yahoo.vespa.orchestrator.controller.ClusterControllerStateResponse)1 BatchHostStateChangeDeniedException (com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1