class RangerWebAlertConfigAction extends AbstractUpgradeServerAction {

  @Override
  public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext)
      throws AmbariException, InterruptedException {
    String clusterName = getExecutionCommand().getClusterName();
    Cluster cluster = getClusters().getCluster(clusterName);

    String ranger_admin_process = "ranger_admin_process";

    try {

      AlertDefinitionEntity rangerAlertDefinitionEntity = alertDefinitionDAO.findByName(cluster.getClusterId(), ranger_admin_process);
      if (rangerAlertDefinitionEntity != null) {

        logger.info("Updating the alert definition for ranger_admin_process.");

        String rangerAlertCurrentDefinitionSource = rangerAlertDefinitionEntity.getSource();
        JsonObject rangerAlertsCurrentDefinitionJSON = new JsonParser().parse(rangerAlertCurrentDefinitionSource).getAsJsonObject();

        //updating the alert definition
        rangerAlertsCurrentDefinitionJSON.remove("uri");

        JsonObject rangerUpdatedURLConfig = new JsonObject();
        rangerUpdatedURLConfig.addProperty("http", "{{admin-properties/policymgr_external_url}}/login.jsp");
        rangerUpdatedURLConfig.addProperty("https", "{{admin-properties/policymgr_external_url}}/login.jsp");
        rangerUpdatedURLConfig.addProperty("kerberos_keytab", "{{cluster-env/smokeuser_keytab}}");
        rangerUpdatedURLConfig.addProperty("kerberos_principal", "{{cluster-env/smokeuser_principal_name}}");
        rangerUpdatedURLConfig.addProperty("https_property", "{{ranger-admin-site/ranger.service.https.attrib.ssl.enabled}}");
        rangerUpdatedURLConfig.addProperty("https_property_value", "true");
        rangerUpdatedURLConfig.addProperty("connection_timeout", 5.0);

        rangerAlertsCurrentDefinitionJSON.add("uri", rangerUpdatedURLConfig);

        rangerAlertDefinitionEntity.setHash(UUID.randomUUID().toString());
        rangerAlertDefinitionEntity.setSource(rangerAlertsCurrentDefinitionJSON.toString());

        alertDefinitionDAO.merge(rangerAlertDefinitionEntity);

        // invalidating alert and publishing the updated definition
        Set<String> invalidatedHosts = alertDefinitionHash.invalidateHosts(rangerAlertDefinitionEntity);
        AlertHashInvalidationEvent alertInvalidationEvent = new AlertHashInvalidationEvent(
            rangerAlertDefinitionEntity.getClusterId(), invalidatedHosts);

        eventPublisher.publish(alertInvalidationEvent);

        return createCommandReport(0, HostRoleStatus.COMPLETED, "{}",
            "Ranger service alert check configuration has been updated successfully.", "");

      } else {
        return createCommandReport(0, HostRoleStatus.COMPLETED, "{}",
            String.format(
                "The %s configuration type was not found; unable to update Ranger Alert properties.",
                ranger_admin_process), "");
      }
    } catch (Exception e) {
      logger.error("RangerWebAlertConfigAction.execute : There was an error in updating Ranger alerts.", e);
    }
    return null;
  }

}