class RangerKmsProxyConfig 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 rangerEnv = cluster.getDesiredConfigByType(RANGER_ENV_CONFIG_TYPE);

    if (null == rangerEnv) {
      return createCommandReport(0, HostRoleStatus.COMPLETED, "{}",
        MessageFormat.format("Config source type {0} not found, skipping adding properties to {1}.", RANGER_ENV_CONFIG_TYPE, RANGER_KMS_SITE_CONFIG_TYPE), "");
    }

    String rangerUserProp = "ranger_user";
    String rangerUser = rangerEnv.getProperties().get(rangerUserProp);

    if (null == rangerUser) {
      return createCommandReport(0, HostRoleStatus.COMPLETED, "{}",
        MessageFormat.format("Required user service user value from {0}/{1} not found, skipping adding properties to {2}.", RANGER_ENV_CONFIG_TYPE, rangerUserProp, RANGER_KMS_SITE_CONFIG_TYPE), "");
    }

    Config kmsSite = cluster.getDesiredConfigByType(RANGER_KMS_SITE_CONFIG_TYPE);

    if (null == kmsSite) {
      return createCommandReport(0, HostRoleStatus.COMPLETED, "{}",
        MessageFormat.format("Config type {0} not found, skipping adding properties to it.", RANGER_KMS_SITE_CONFIG_TYPE), "");
    }

    Map<String, String> targetValues = kmsSite.getProperties();
    if (cluster.getSecurityType() == SecurityType.KERBEROS) {
      String userProp = "hadoop.kms.proxyuser." + rangerUser + ".users";
      String groupProp = "hadoop.kms.proxyuser." + rangerUser + ".groups";
      String hostProp = "hadoop.kms.proxyuser." + rangerUser + ".hosts";
      targetValues.put(userProp, "*");
      targetValues.put(groupProp, "*");
      targetValues.put(hostProp, "*");
      kmsSite.setProperties(targetValues);
      kmsSite.save();
      agentConfigsHolder.updateData(cluster.getClusterId(), cluster.getHosts().stream()
          .map(Host::getHostId).collect(Collectors.toList()));
      outputMsg = outputMsg + MessageFormat.format("Successfully added properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE);
    } else {
      outputMsg = outputMsg +  MessageFormat.format("Kerberos not enable, not setting proxy properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE);
    }

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

  }

}