@Override
  public State getState(String clusterName, String serviceName) {
      try {
        Cluster cluster = getCluster(clusterName);
        if (cluster != null && managementControllerProvider != null) {
          Service service = cluster.getService(serviceName);
          AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo();
          StackId stackId = service.getDesiredStackId();

          ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName,
            serviceName, null, null, null);

          Set<ServiceComponentHostResponse> hostComponentResponses =
            managementControllerProvider.get().getHostComponents(Collections.singleton(request), true);

          State   masterState = null;
          State   clientState = null;
          State   otherState = null;
          State   maxMMState = null; // The worst state among components in MM

          boolean hasDisabled  = false;
          boolean hasMaster    = false;
          boolean hasOther     = false;
          boolean hasClient    = false;
          boolean hasMM        = false;

          for (ServiceComponentHostResponse hostComponentResponse : hostComponentResponses ) {
            try {
              ComponentInfo componentInfo = ambariMetaInfo.getComponent(stackId.getStackName(),
                stackId.getStackVersion(), hostComponentResponse.getServiceName(),
                hostComponentResponse.getComponentName());

              State state = getHostComponentState(hostComponentResponse);
              // Components in MM should not affect service status,
              // so we tend to ignore them
              boolean isInMaintenance = ! MaintenanceState.OFF.toString().
                equals(hostComponentResponse.getMaintenanceState());

              if (state.equals(State.DISABLED)) {
                hasDisabled = true;
              }

              if (isInMaintenance && !componentInfo.isClient()) {
                hasMM = true;
                if ( maxMMState == null || state.ordinal() > maxMMState.ordinal()) {
                  maxMMState = state;
                }
              }

              if (componentInfo.isMaster()) {
                if (state.equals(State.STARTED) || ! isInMaintenance) {
                  // We rely on master's state to determine service state
                  hasMaster = true;
                }

                if (! state.equals(State.STARTED) &&
                  ! isInMaintenance &&  // Ignore status of MM component
                  ( masterState == null || state.ordinal() > masterState.ordinal())) {
                  masterState = state;
                }
              } else if (componentInfo.isClient()) {
                hasClient = true;
                if (!state.equals(State.INSTALLED) &&
                  (clientState == null || state.ordinal() > clientState.ordinal())) {
                  clientState = state;
                }
              } else {
                if (state.equals(State.STARTED) || ! isInMaintenance) {
                  // We rely on slaves's state to determine service state
                  hasOther = true;
                }
                if (! state.equals(State.STARTED) &&
                  ! isInMaintenance && // Ignore status of MM component
                  ( otherState == null || state.ordinal() > otherState.ordinal())) {
                  otherState = state;
                }
              }
            } catch (ObjectNotFoundException e) {
              // component doesn't exist, nothing to do
            }
          }

          return hasMaster   ? masterState == null ? State.STARTED : masterState :
            hasOther    ? otherState == null ? State.STARTED : otherState :
              hasClient   ? clientState == null ? State.INSTALLED : clientState :
                hasDisabled ? State.DISABLED :
                  hasMM       ? maxMMState : State.UNKNOWN;
        }
      } catch (AmbariException e) {
        LOG.error("Can't determine service state.", e);
      }
    return State.UNKNOWN;
  }
Default calculator of service state.
The following rules should apply :
For services that have all components DISABLED, the service state should be DISABLED.
For services that have any master components, the service state should
be STARTED if all master components are STARTED.
For services that have all client components, the service state should
be INSTALLED if all of the components are INSTALLED.
For all other cases the state of the service should match the highest state of all
of its component states or UNKNOWN if the component states can not be determined.
ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java