private void applyCustomCommandBackendLogic(Cluster cluster, String serviceName, String componentName, String commandName, String hostname) throws AmbariException {
    switch (commandName) {
      case "RESTART":
        ServiceComponent serviceComponent = cluster.getService(serviceName).getServiceComponent(componentName);
        ServiceComponentHost serviceComponentHost = serviceComponent.getServiceComponentHost(hostname);
        State currentDesiredState = serviceComponentHost.getDesiredState();

        if( !serviceComponent.isClientComponent()) {
          if (currentDesiredState != State.STARTED) {
            LOG.info("Updating desired state to {} on RESTART for {}/{} because it was {}",
                State.STARTED, serviceName, componentName, currentDesiredState);

            serviceComponentHost.setDesiredState(State.STARTED);
          }
        } else {
          LOG.debug("Desired state for client components should not be updated on RESTART. Service/Component {}/{}",
              serviceName, componentName);
        }

        break;
      default:
        LOG.debug("No backend operations needed for the custom command: {}", commandName);
        break;
    }
  }
Called during the start/stop/restart of services, plus custom commands during Stack Upgrade.
@param actionExecutionContext Execution Context
@param resourceFilter Resource Filter
@param stage Command stage
@param additionalCommandParams Additional command params to add the the stage
@param commandDetail String for the command detail
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java