use of com.yahoo.vespa.orchestrator.model.ApplicationApi in project vespa by vespa-engine.
the class HostedVespaPolicyTest method testAcquirePermissionToRemove.
@Test
public void testAcquirePermissionToRemove() throws OrchestrationException {
final HostedVespaClusterPolicy clusterPolicy = mock(HostedVespaClusterPolicy.class);
final HostedVespaPolicy policy = new HostedVespaPolicy(clusterPolicy, clientFactory);
final ApplicationApi applicationApi = mock(ApplicationApi.class);
when(applicationApi.applicationId()).thenReturn(ApplicationId.fromSerializedForm("tenant:app:default"));
ClusterApi clusterApi1 = mock(ClusterApi.class);
ClusterApi clusterApi2 = mock(ClusterApi.class);
ClusterApi clusterApi3 = mock(ClusterApi.class);
List<ClusterApi> clusterApis = Arrays.asList(clusterApi1, clusterApi2, clusterApi3);
when(applicationApi.getClusters()).thenReturn(clusterApis);
StorageNode storageNode1 = mock(StorageNode.class);
HostName hostName1 = new HostName("storage-1");
when(storageNode1.hostName()).thenReturn(hostName1);
HostName hostName2 = new HostName("host-2");
StorageNode storageNode3 = mock(StorageNode.class);
HostName hostName3 = new HostName("storage-3");
when(storageNode1.hostName()).thenReturn(hostName3);
List<StorageNode> upStorageNodes = Arrays.asList(storageNode1, storageNode3);
when(applicationApi.getStorageNodesInGroupInClusterOrder()).thenReturn(upStorageNodes);
List<HostName> noRemarksHostNames = Arrays.asList(hostName1, hostName2, hostName3);
when(applicationApi.getNodesInGroupWithStatus(HostStatus.NO_REMARKS)).thenReturn(noRemarksHostNames);
InOrder order = inOrder(applicationApi, clusterPolicy, storageNode1, storageNode3);
policy.acquirePermissionToRemove(applicationApi);
order.verify(applicationApi).getClusters();
order.verify(clusterPolicy).verifyGroupGoingDownPermanentlyIsFine(clusterApi1);
order.verify(clusterPolicy).verifyGroupGoingDownPermanentlyIsFine(clusterApi2);
order.verify(clusterPolicy).verifyGroupGoingDownPermanentlyIsFine(clusterApi3);
order.verify(applicationApi).getStorageNodesInGroupInClusterOrder();
order.verify(storageNode1).setNodeState(ClusterControllerNodeState.DOWN);
order.verify(storageNode3).setNodeState(ClusterControllerNodeState.DOWN);
order.verify(applicationApi).getNodesInGroupWithStatus(HostStatus.NO_REMARKS);
order.verify(applicationApi).setHostState(hostName1, HostStatus.ALLOWED_TO_BE_DOWN);
order.verify(applicationApi).setHostState(hostName2, HostStatus.ALLOWED_TO_BE_DOWN);
order.verify(applicationApi).setHostState(hostName3, HostStatus.ALLOWED_TO_BE_DOWN);
order.verifyNoMoreInteractions();
}
Aggregations