public MaintenanceState getEffectiveState(long clusterId, Alert alert) throws AmbariException {
    String serviceName = alert.getService();
    String componentName = alert.getComponent();
    String hostName = alert.getHostName();

    if (null == serviceName && null == hostName) {
      LOG.warn("Unable to determine maintenance state for an alert without a service or host");
      return MaintenanceState.OFF;
    }

    // always start with the host first; we always have a host unless this is an
    // aggregate alert (service-level alert)
    if (StringUtils.isNotBlank(hostName)) {
      Host host = clusters.getHost(hostName);
      if (host.getMaintenanceState(clusterId) != MaintenanceState.OFF) {
        return MaintenanceState.ON;
      }
    }

    // the AMBARI service is not a real service; it's never in MM
    if( StringUtils.equals(RootService.AMBARI.name(), serviceName)){
      return MaintenanceState.OFF;
    }

    // the host is not in MM, move onto the service
    Cluster cluster = clusters.getClusterById(clusterId);
    Service service = cluster.getService(serviceName);
    if( service.getMaintenanceState() != MaintenanceState.OFF ){
      return MaintenanceState.ON;
    }

    if( StringUtils.isNotBlank(componentName)){
      ServiceComponent serviceComponent = service.getServiceComponent(componentName);
      ServiceComponentHost serviceComponentHost = serviceComponent.getServiceComponentHost(hostName);

      if (serviceComponentHost.getMaintenanceState() != MaintenanceState.OFF) {
        return MaintenanceState.ON;
      }
    }

    // MM is off at the host, service, and component level; return OFF
    return MaintenanceState.OFF;
  }
Gets the effective maintenance state for a given alert. This will determine
whether the alert needs to report that it is in maintenance mode.

@param clusterId
         the ID of the cluster for the alert.
@param alert
         the alert (not {@code null}).
@return {@link MaintenanceState#OFF} if the host/service/component all
        report they are not in maintenance mode;
        {@link MaintenanceState#ON} otherwise.
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java