RetryingClusterControllerClientFactory extends AbstractComponent implements ClusterControllerClientFactory { @Override public ClusterControllerClient createClient(List<HostName> clusterControllers, String clusterName) { JaxRsStrategy<ClusterControllerJaxRsApi> jaxRsApi = new JaxRsStrategyFactory( new HashSet<>(clusterControllers), HARDCODED_CLUSTERCONTROLLER_PORT, jaxRsClientFactory, CLUSTERCONTROLLER_SCHEME) .apiWithRetries(ClusterControllerJaxRsApi.class, CLUSTERCONTROLLER_API_PATH) .setMaxIterations(clusterControllers.size() > 1 ? 1 : 2); return new ClusterControllerClientImpl(jaxRsApi, clusterName); } @Inject  RetryingClusterControllerClientFactory();   RetryingClusterControllerClientFactory(VespaJerseyJaxRsClientFactory jaxRsClientFactory); @Override ClusterControllerClient createClient(List<HostName> clusterControllers, String clusterName); @Override void deconstruct(); static final int HARDCODED_CLUSTERCONTROLLER_PORT; static final String CLUSTERCONTROLLER_API_PATH; static final String CLUSTERCONTROLLER_SCHEME; }
@Test public void verifyJerseyCallForSetNodeState() throws IOException { VespaJerseyJaxRsClientFactory clientFactory = mock(VespaJerseyJaxRsClientFactory.class); ClusterControllerJaxRsApi api = mock(ClusterControllerJaxRsApi.class); when(clientFactory.createClient(any())).thenReturn(api); RetryingClusterControllerClientFactory factory = new RetryingClusterControllerClientFactory(clientFactory); String clusterName = "clustername"; HostName host1 = new HostName("host1"); HostName host2 = new HostName("host2"); HostName host3 = new HostName("host3"); List<HostName> clusterControllers = Arrays.asList(host1, host2, host3); ClusterControllerClient client = factory.createClient(clusterControllers, clusterName); OrchestratorContext context = OrchestratorContext.createContextForSingleAppOp(clock); int storageNode = 2; ClusterControllerNodeState wantedState = ClusterControllerNodeState.MAINTENANCE; client.setNodeState(context, storageNode, wantedState); ArgumentCaptor<ClusterControllerStateRequest> requestCaptor = ArgumentCaptor.forClass(ClusterControllerStateRequest.class); verify(api, times(1)).setNodeState(eq(clusterName), eq(storageNode), eq(9.6f), requestCaptor.capture()); ClusterControllerStateRequest request = requestCaptor.getValue(); assertEquals(ClusterControllerStateRequest.Condition.SAFE, request.condition); Map<String, Object> expectedState = new HashMap<>(); expectedState.put("user", new ClusterControllerStateRequest.State(wantedState, "Orchestrator")); assertEquals(expectedState, request.state); }