HostedVespaPolicy implements Policy { @Override public SuspensionReasons grantSuspensionRequest(OrchestratorContext context, ApplicationApi application) throws HostStateChangeDeniedException { var suspensionReasons = new SuspensionReasons(); for (ClusterApi cluster : application.getClusters()) { suspensionReasons.mergeWith(clusterPolicy.verifyGroupGoingDownIsFine(cluster)); } for (StorageNode storageNode : application.getUpStorageNodesInGroupInClusterOrder()) { storageNode.setNodeState(context, ClusterControllerNodeState.MAINTENANCE); } for (HostName hostName : application.getNodesInGroupWithStatus(HostStatus.NO_REMARKS)) { application.setHostState(context, hostName, HostStatus.ALLOWED_TO_BE_DOWN); } return suspensionReasons; } HostedVespaPolicy(HostedVespaClusterPolicy clusterPolicy,
                             ClusterControllerClientFactory clusterControllerClientFactory,
                             ApplicationApiFactory applicationApiFactory); @Override SuspensionReasons grantSuspensionRequest(OrchestratorContext context, ApplicationApi application); @Override void releaseSuspensionGrant(OrchestratorContext context, ApplicationApi application); @Override void acquirePermissionToRemove(OrchestratorContext context, ApplicationApi applicationApi); @Override void releaseSuspensionGrant(
            OrchestratorContext context,
            ApplicationInstance applicationInstance,
            HostName hostName,
            ApplicationLock lock); static final String APPLICATION_SUSPENDED_CONSTRAINT; static final String ENOUGH_SERVICES_UP_CONSTRAINT; static final String SET_NODE_STATE_CONSTRAINT; static final String CLUSTER_CONTROLLER_AVAILABLE_CONSTRAINT; static final String DEADLINE_CONSTRAINT; }
@Test public void testGrantSuspension() throws HostStateChangeDeniedException { final HostedVespaClusterPolicy clusterPolicy = mock(HostedVespaClusterPolicy.class); when(clusterPolicy.verifyGroupGoingDownIsFine(any())).thenReturn(SuspensionReasons.nothingNoteworthy()); final HostedVespaPolicy policy = new HostedVespaPolicy(clusterPolicy, clientFactory, applicationApiFactory); 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.getUpStorageNodesInGroupInClusterOrder()).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); OrchestratorContext context = mock(OrchestratorContext.class); policy.grantSuspensionRequest(context, applicationApi); order.verify(applicationApi).getClusters(); order.verify(clusterPolicy).verifyGroupGoingDownIsFine(clusterApi1); order.verify(clusterPolicy).verifyGroupGoingDownIsFine(clusterApi2); order.verify(clusterPolicy).verifyGroupGoingDownIsFine(clusterApi3); order.verify(applicationApi).getUpStorageNodesInGroupInClusterOrder(); order.verify(storageNode1).setNodeState(context, ClusterControllerNodeState.MAINTENANCE); order.verify(storageNode3).setNodeState(context, ClusterControllerNodeState.MAINTENANCE); order.verify(applicationApi).getNodesInGroupWithStatus(HostStatus.NO_REMARKS); order.verify(applicationApi).setHostState(context, hostName1, HostStatus.ALLOWED_TO_BE_DOWN); order.verify(applicationApi).setHostState(context, hostName2, HostStatus.ALLOWED_TO_BE_DOWN); order.verify(applicationApi).setHostState(context, hostName3, HostStatus.ALLOWED_TO_BE_DOWN); order.verifyNoMoreInteractions(); }