Source:
<code><START> public void rotateHostCertificates() throws CloudbreakException { <END> Cluster cluster = stack.getCluster(); String user = cluster.getCloudbreakAmbariUser(); String password = cluster.getCloudbreakAmbariPassword(); try { ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig); HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client); BatchResourceApi batchResourceApi = clouderaManagerApiFactory.getBatchResourceApi(client); ApiHostList hostList = hostsResourceApi.readHosts(null, null, "SUMMARY"); List<ApiBatchRequestElement> batchRequestElements = hostList.getItems().stream() .filter(host -> host.getClusterRef() != null) .map(host -> new ApiBatchRequestElement() .method(HTTPMethod.POST) .url(ClouderaManagerApiClientProvider.API_V_31 + "/hosts/" + host.getHostId() + "/commands/generateHostCerts") .body("{}") .acceptType("application/json") .contentType("application/json")) .collect(Collectors.toList()); ApiBatchRequest batchRequest = new ApiBatchRequest().items(batchRequestElements); ApiBatchResponse apiBatchResponse = batchResourceApi.execute(batchRequest); if (apiBatchResponse.getSuccess()) { List<BigDecimal> ids = apiBatchResponse.getItems().stream() .map(bre -> new Json((String) bre.getResponse()).getSilent(ApiCommand.class).getId()) .collect(Collectors.toList()); PollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCommandList(stack, client, ids, "Rotate host certificates"); if (PollingResult.isExited(pollingResult)) { throw new CancellationException("Cluster was terminated during rotation of host certificates"); } else if (PollingResult.isTimeout(pollingResult)) { throw new ClouderaManagerOperationFailedException("Timeout while Cloudera Manager rotates the host certificates."); } } else { throw new ClouderaManagerOperationFailedException("Host certificates rotation batch operation failed: " + apiBatchResponse); } } catch (ApiException | ClouderaManagerClientInitException e) { throw new CloudbreakException("Can't rotate the host certificates due to: " + e.getMessage()); } }</code><technical_language>refactor this smaller parts move logic a separate class</technical_language>

Target:
public void rotateHostCertificates() throws CloudbreakException { Cluster cluster = stack.getCluster(); String user = cluster.getCloudbreakAmbariUser(); String password = cluster.getCloudbreakAmbariPassword(); try { ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig); HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client); BatchResourceApi batchResourceApi = clouderaManagerApiFactory.getBatchResourceApi(client); ApiHostList hostList = hostsResourceApi.readHosts(null, null, "SUMMARY"); ApiBatchRequest batchRequest = createHostCertsBatchRequest(hostList); ApiBatchResponse apiBatchResponse = batchResourceApi.execute(batchRequest); processHostCertsBatchResponse(client, apiBatchResponse); } catch (ApiException | ClouderaManagerClientInitException e) { LOGGER.warn("Can't rotate the host certificates", e); throw new CloudbreakException("Can't rotate the host certificates due to: " + e.getMessage()); } }