@SuppressWarnings("unchecked")
  private void createAlertTargets(Set<Map<String, Object>> requestMaps, Map<String, String> requestInfoProps)
      throws AmbariException {
    for (Map<String, Object> requestMap : requestMaps) {
      String name = StringEscapeUtils.escapeHtml4((String) requestMap.get(ALERT_TARGET_NAME));
      String description = (String) requestMap.get(ALERT_TARGET_DESCRIPTION);
      String notificationType = (String) requestMap.get(ALERT_TARGET_NOTIFICATION_TYPE);
      Collection<String> alertStates = (Collection<String>) requestMap.get(ALERT_TARGET_STATES);
      String globalProperty = (String) requestMap.get(ALERT_TARGET_GLOBAL);
      String enabledProperty = (String) requestMap.get(ALERT_TARGET_ENABLED);

      if (StringUtils.isEmpty(name)) {
        throw new IllegalArgumentException(
            "The name of the alert target is required.");
      }

      if (StringUtils.isEmpty(notificationType)) {
        throw new IllegalArgumentException(
            "The type of the alert target is required.");
      }

      Map<String, Object> properties = extractProperties(requestMap);

      String propertiesJson = s_gson.toJson(properties);
      if (StringUtils.isEmpty(propertiesJson)) {
        throw new IllegalArgumentException(
            "Alert targets must be created with their connection properties");
      }

      String validationDirective = requestInfoProps.get(AlertTargetResourceDefinition.VALIDATE_CONFIG_DIRECTIVE);
      if (validationDirective != null
          && validationDirective.equalsIgnoreCase("true")) {
        validateTargetConfig(notificationType, properties);
      }

      boolean overwriteExisting = false;
      if (requestInfoProps.containsKey(AlertTargetResourceDefinition.OVERWRITE_DIRECTIVE)) {
        overwriteExisting = true;
      }

      // global not required
      boolean isGlobal = false;
      if (null != globalProperty) {
        isGlobal = Boolean.parseBoolean(globalProperty);
      }

      // enabled not required
      boolean isEnabled = true;
      if (null != enabledProperty) {
        isEnabled = Boolean.parseBoolean(enabledProperty);
      }

      // set the states that this alert target cares about
      final Set<AlertState> alertStateSet;
      if (null != alertStates) {
        alertStateSet = new HashSet<>(alertStates.size());
        for (String state : alertStates) {
          alertStateSet.add(AlertState.valueOf(state));
        }
      } else {
        alertStateSet = EnumSet.allOf(AlertState.class);
      }

      // if we are overwriting an existing, determine if one exists first
      AlertTargetEntity entity = s_dao.findTargetByName(name);

      if (null == entity) {
        entity = new AlertTargetEntity();
      } else {
        if( !overwriteExisting ) {
          throw new IllegalArgumentException(
              "Alert targets already exists and can't be created");
        }
      }

      // groups are not required on creation
      if (requestMap.containsKey(ALERT_TARGET_GROUPS)) {
        Collection<Long> groupIds = (Collection<Long>) requestMap.get(ALERT_TARGET_GROUPS);
        if( !groupIds.isEmpty() ){
          Set<AlertGroupEntity> groups = new HashSet<>();
          List<Long> ids = new ArrayList<>(groupIds);
          groups.addAll(s_dao.findGroupsById(ids));
          entity.setAlertGroups(groups);
        }
      }

      entity.setDescription(description);
      entity.setNotificationType(notificationType);
      entity.setProperties(propertiesJson);
      entity.setTargetName(name);
      entity.setAlertStates(alertStateSet);
      entity.setGlobal(isGlobal);
      entity.setEnabled(isEnabled);

      if (null == entity.getTargetId() || 0 == entity.getTargetId()) {
        s_dao.create(entity);
      } else {
        s_dao.merge(entity);
      }
    }
  }
Create and persist {@link AlertTargetEntity} from the map of properties.

@param requestMaps
@param requestInfoProps
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java