@Override
    public boolean isQuiescent(ApplicationId id) {
        try {
            ApplicationInstance application = serviceMonitor.getApplication(OrchestratorUtil.toApplicationInstanceReference(id, serviceMonitor))
                                                            .orElseThrow(ApplicationIdNotFoundException::new);

            List<ServiceCluster> contentClusters = application.serviceClusters().stream()
                                                              .filter(VespaModelUtil::isContent)
                                                              .toList();

            // For all content clusters, probe whether maintenance is OK.
            OrchestratorContext context = OrchestratorContext.createContextForBatchProbe(clock);
            for (ServiceCluster cluster : contentClusters) {
                List<HostName> clusterControllers = VespaModelUtil.getClusterControllerInstancesInOrder(application, cluster.clusterId());
                ClusterControllerClient client = clusterControllerClientFactory.createClient(clusterControllers, cluster.clusterId().s());
                for (ServiceInstance service : cluster.serviceInstances()) {
                    try {
                        if ( ! client.trySetNodeState(context, service.hostName(), VespaModelUtil.getStorageNodeIndex(service.configId()), MAINTENANCE, ContentService.STORAGE_NODE, false))
                            return false;
                    }
                    catch (Exception e) {
                        log.log(Level.INFO, "Failed probing for permission to set " + service + " in MAINTENANCE: " + Exceptions.toMessageString(e));
                        return false;
                    }
                }
            }
            return true;
        }
        catch (ApplicationIdNotFoundException ignored) {
            return false;
        }
    }
@Test
    public void testIsQuiescent() {
        StatusService statusService = new ZkStatusService(new MockCurator(),
                                                          mock(Metric.class),
                                                          new TestTimer(),
                                                          new DummyAntiServiceMonitor());

        HostName hostName = new HostName("my.host");
        HostName ccHost = new HostName("cc.host");
        TenantId tenantId = new TenantId("tenant");
        ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId("app:env:region:instance");
        ApplicationInstanceReference reference = new ApplicationInstanceReference(tenantId, applicationInstanceId);
        ApplicationId id = ApplicationId.from("tenant", "app", "instance");

        ApplicationInstance applicationInstance =
                new ApplicationInstance(tenantId,
                                        applicationInstanceId,
                                        Set.of(new ServiceCluster(new ClusterId("foo"),
                                                                  ServiceType.STORAGE,
                                                                  Set.of(new ServiceInstance(new ConfigId("foo/storage/1"),
                                                                                             hostName,
                                                                                             ServiceStatus.UP),
                                                                         new ServiceInstance(new ConfigId("foo/storage/2"),
                                                                                             hostName,
                                                                                             ServiceStatus.UP))),
                                               new ServiceCluster(new ClusterId("bar"),
                                                                  ServiceType.SEARCH,
                                                                  Set.of(new ServiceInstance(new ConfigId("bar/storage/0"),
                                                                                             hostName,
                                                                                             ServiceStatus.UP),
                                                                         new ServiceInstance(new ConfigId("bar/storage/3"),
                                                                                             hostName,
                                                                                             ServiceStatus.UP))),
                                               new ServiceCluster(new ClusterId("cluster-controllers"),
                                                                  ServiceType.CLUSTER_CONTROLLER,
                                                                  Set.of(new ServiceInstance(new ConfigId("what/standalone/cluster-controllers/0"),
                                                                                             ccHost,
                                                                                             ServiceStatus.UP)))));

        ServiceMonitor serviceMonitor = () -> new ServiceModel(Map.of(reference, applicationInstance));

        ClusterControllerClientFactory clusterControllerClientFactory = mock(ClusterControllerClientFactory.class);
        ClusterControllerClient fooClient = mock(ClusterControllerClient.class);
        ClusterControllerClient barClient = mock(ClusterControllerClient.class);
        when(clusterControllerClientFactory.createClient(List.of(ccHost), "foo")).thenReturn(fooClient);
        when(clusterControllerClientFactory.createClient(List.of(ccHost), "bar")).thenReturn(barClient);

        orchestrator = new OrchestratorImpl(new HostedVespaPolicy(new HostedVespaClusterPolicy(flagSource, zone),
                                                                  clusterControllerClientFactory,
                                                                  applicationApiFactory,
                                                                  flagSource),
                                            clusterControllerClientFactory,
                                            statusService,
                                            serviceMonitor,
                                            0,
                                            new ManualClock(),
                                            applicationApiFactory,
                                            flagSource);

        when(fooClient.trySetNodeState(any(), any(), eq(1), eq(ClusterControllerNodeState.MAINTENANCE), eq(ContentService.STORAGE_NODE), eq(false))).thenReturn(true);
        when(fooClient.trySetNodeState(any(), any(), eq(2), eq(ClusterControllerNodeState.MAINTENANCE), eq(ContentService.STORAGE_NODE), eq(false))).thenReturn(true);
        when(barClient.trySetNodeState(any(), any(), eq(0), eq(ClusterControllerNodeState.MAINTENANCE), eq(ContentService.STORAGE_NODE), eq(false))).thenReturn(true);
        when(barClient.trySetNodeState(any(), any(), eq(3), eq(ClusterControllerNodeState.MAINTENANCE), eq(ContentService.STORAGE_NODE), eq(false))).thenReturn(true);
        assertTrue(orchestrator.isQuiescent(id));

        when(fooClient.trySetNodeState(any(), any(), eq(2), eq(ClusterControllerNodeState.MAINTENANCE), eq(ContentService.STORAGE_NODE), eq(false))).thenReturn(false);
        assertFalse(orchestrator.isQuiescent(id));

        when(fooClient.trySetNodeState(any(), any(), eq(2), eq(ClusterControllerNodeState.MAINTENANCE), eq(ContentService.STORAGE_NODE), eq(false))).thenThrow(new RuntimeException());
        assertFalse(orchestrator.isQuiescent(id));
    }