class HostUpdateHelper {

  void updateHostsInConfigurations() throws AmbariException {
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
    Clusters clusters = ambariManagementController.getClusters();

    if (clusters != null) {

      // going through all clusters with host pairs from file
      for (Map.Entry<String, Map<String,String>> clusterHosts : hostChangesFileMap.entrySet()) {
        boolean hostConfigsUpdated = false;
        String clusterName = clusterHosts.getKey();
        ClusterEntity clusterEntity = clusterDAO.findByName(clusterName);
        Cluster cluster = clusters.getCluster(clusterName);
        Map<String, String> hostMapping = clusterHosts.getValue();
        List<String> currentHostNames = new ArrayList<>();
        String updatedPropertyValue;

        for (Map.Entry<String, String> hostPair : hostMapping.entrySet()) {
          currentHostNames.add(hostPair.getKey());
        }

        //******************************

        if (clusterEntity != null) {
          Collection<ClusterConfigEntity> clusterConfigEntities = clusterEntity.getClusterConfigEntities();
          boolean configUpdated;

          // going through all cluster configs and update property values
          ConfigFactory configFactory = injector.getInstance(ConfigFactory.class);
          for (ClusterConfigEntity clusterConfigEntity : clusterConfigEntities) {
            Config config = configFactory.createExisting(cluster, clusterConfigEntity);
            configUpdated = false;

            for (Map.Entry<String,String> property : config.getProperties().entrySet()) {
              updatedPropertyValue = replaceHosts(property.getValue(), currentHostNames, hostMapping);

              if (updatedPropertyValue != null) {
                Map<String,String> propertiesWithUpdates = config.getProperties();
                propertiesWithUpdates.put(property.getKey(), updatedPropertyValue);
                config.setProperties(propertiesWithUpdates);
                configUpdated = true;
              }
            }

            if (configUpdated) {
              hostConfigsUpdated = true;
              config.save();
            }
          }
        }
        if (hostConfigsUpdated) {
          AgentConfigsHolder agentConfigsHolder = injector.getInstance(AgentConfigsHolder.class);
          agentConfigsHolder.updateData(cluster.getClusterId(), currentHostNames.stream()
              .map(hm -> cluster.getHost(hm).getHostId()).collect(Collectors.toList()));
        }

        //******************************
      }
    }
  }

  @Inject public  HostUpdateHelper(PersistService persistService,
                          Configuration configuration,
                          Injector injector);

}