- private void invokeSync() {
- LOG.info("Begin sending sync requests");
- for (Request request : payloads) {
- try {
- Response response = asyncHttpClient.executeRequest(request).get();
- if (response.getStatusCode() != 200 && response.getStatusCode() != 204) {
- if (response.getStatusCode() == 409) {
- LOG.warn("Request failed, status code: {} - one or more of the devices" +
- " is already configured, skipping the whole batch", response.getStatusCode());
- } else {
- LOG.warn("Status code: {}", response.getStatusCode());
- LOG.warn("url: {}", request.getUrl());
- LOG.warn(response.getResponseBody());
- }
- }
- } catch (InterruptedException | ExecutionException | IOException e) {
- LOG.warn(e.toString());
- }
- }
- LOG.info("End sending sync requests");
+ private List<HttpRequest> prepareRequests() {
+ final List<List<Integer>> batches = Lists.partition(openDevices, params.generateConfigBatchSize);
+ return batches.stream()
+ .map(b -> PayloadCreator.createStringPayload(b, params))
+ .map(this::prepareRequest)
+ .collect(Collectors.toList());