class RangerUsersyncConfigCalculation extends AbstractUpgradeServerAction {

  @Override
  public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException {

  String clusterName = getExecutionCommand().getClusterName();
  Cluster cluster = getClusters().getCluster(clusterName);
  String outputMsg = "";

  Config rangerUsersyncConfig = cluster.getDesiredConfigByType(RANGER_USERSYNC_CONFIG_TYPE);

  if (null == rangerUsersyncConfig) {
    return createCommandReport(0, HostRoleStatus.COMPLETED, "{}",
      MessageFormat.format("Config type {0} not found, skipping updating property in same.", RANGER_USERSYNC_CONFIG_TYPE), "");
  }

  String ldapGroupHierarchy = "0";

  if (rangerUsersyncConfig.getProperties().containsKey("ranger.usersync.ldap.grouphierarchylevels")) {
    ldapGroupHierarchy = rangerUsersyncConfig.getProperties().get("ranger.usersync.ldap.grouphierarchylevels");
  } else {
    Map<String, String> targetRangerUsersyncConfig = rangerUsersyncConfig.getProperties();
    targetRangerUsersyncConfig.put("ranger.usersync.ldap.grouphierarchylevels", ldapGroupHierarchy);
    rangerUsersyncConfig.setProperties(targetRangerUsersyncConfig);
    rangerUsersyncConfig.save();

    outputMsg = outputMsg + MessageFormat.format("Successfully updated {0} config type.\n", RANGER_USERSYNC_CONFIG_TYPE);
  }

  Config rangerEnvConfig = cluster.getDesiredConfigByType(RANGER_ENV_CONFIG_TYPE);

  if (null == rangerEnvConfig) {
    return createCommandReport(0, HostRoleStatus.COMPLETED, "{}",
      MessageFormat.format("Config type {0} not found, skipping updating property in same.", RANGER_ENV_CONFIG_TYPE), "");
  }

  String enableSyncNestedGroup = "false";

  if (!ldapGroupHierarchy.equals("0") ) {
    enableSyncNestedGroup = "true";
  }

  Map<String, String> targetRangerEnvConfig = rangerEnvConfig.getProperties();
  targetRangerEnvConfig.put("is_nested_groupsync_enabled", enableSyncNestedGroup);
  rangerEnvConfig.setProperties(targetRangerEnvConfig);
  rangerEnvConfig.save();
  agentConfigsHolder.updateData(cluster.getClusterId(), cluster.getHosts().stream().map(Host::getHostId).collect(Collectors.toList()));

  outputMsg = outputMsg + MessageFormat.format("Successfully updated {0} config type.\n", RANGER_ENV_CONFIG_TYPE);

  return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outputMsg, "");
  }

}