private StatusCommand createStatusCommand(String hostname, Cluster cluster,
      ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs) throws AmbariException {
    String serviceName = sch.getServiceName();
    String componentName = sch.getServiceComponentName();

    StackId stackId = sch.getDesiredStackId();

    ServiceInfo serviceInfo = ambariMetaInfo.getService(stackId.getStackName(),
        stackId.getStackVersion(), serviceName);
    ComponentInfo componentInfo = ambariMetaInfo.getComponent(
            stackId.getStackName(), stackId.getStackVersion(),
            serviceName, componentName);

    Map<String, Map<String, String>> configurations = new TreeMap<>();
    Map<String, Map<String,  Map<String, String>>> configurationAttributes = new TreeMap<>();

    // get the cluster config for type '*-env'
    // apply config group overrides
    //Config clusterConfig = cluster.getDesiredConfigByType(GLOBAL);
    Collection<Config> clusterConfigs = cluster.getAllConfigs();

    // creating list with desired config types to validate if cluster config actual
    Set<String> desiredConfigTypes = desiredConfigs.keySet();

    // Apply global properties for this host from all config groups
    Map<String, Map<String, String>> allConfigTags = configHelper
        .getEffectiveDesiredTags(cluster, hostname);

    for(Config clusterConfig: clusterConfigs) {
      String configType = clusterConfig.getType();
      if(!configType.endsWith("-env") || !desiredConfigTypes.contains(configType)) {
        continue;
      }

      // cluster config for 'global'
      Map<String, String> props = new HashMap<>(clusterConfig.getProperties());

      Map<String, Map<String, String>> configTags = new HashMap<>();

      for (Map.Entry<String, Map<String, String>> entry : allConfigTags.entrySet()) {
        if (entry.getKey().equals(clusterConfig.getType())) {
          configTags.put(clusterConfig.getType(), entry.getValue());
        }
      }

      Map<String, Map<String, String>> properties = configHelper
              .getEffectiveConfigProperties(cluster, configTags);

      if (!properties.isEmpty()) {
        for (Map<String, String> propertyMap : properties.values()) {
          props.putAll(propertyMap);
        }
      }

      configurations.put(clusterConfig.getType(), props);

      Map<String, Map<String, String>> attrs = new TreeMap<>();
      configHelper.cloneAttributesMap(clusterConfig.getPropertiesAttributes(), attrs);

      Map<String, Map<String, Map<String, String>>> attributes = configHelper
          .getEffectiveConfigAttributes(cluster, configTags);
      for (Map<String, Map<String, String>> attributesMap : attributes.values()) {
        configHelper.cloneAttributesMap(attributesMap, attrs);
      }
      configurationAttributes.put(clusterConfig.getType(), attrs);
    }

    StatusCommand statusCmd = new StatusCommand();
    statusCmd.setClusterName(cluster.getClusterName());
    statusCmd.setServiceName(serviceName);
    statusCmd.setComponentName(componentName);
    statusCmd.setConfigurations(configurations);
    statusCmd.setConfigurationAttributes(configurationAttributes);
    statusCmd.setHostname(hostname);

    // If Agent wants the command and the States differ
    statusCmd.setDesiredState(sch.getDesiredState());
    statusCmd.setHasStaleConfigs(configHelper.isStaleConfigs(sch, desiredConfigs));
    if (getAgentRequests().shouldSendExecutionDetails(hostname, componentName)) {
      LOG.info(componentName + " is at " + sch.getState() + " adding more payload per agent ask");
      statusCmd.setPayloadLevel(StatusCommand.StatusCommandPayload.EXECUTION_COMMAND);
    }

    // Fill command params
    Map<String, String> commandParams = statusCmd.getCommandParams();

    String commandTimeout = configuration.getDefaultAgentTaskTimeout(false);
    CommandScriptDefinition script = componentInfo.getCommandScript();
    if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
      if (script != null) {
        commandParams.put(SCRIPT, script.getScript());
        commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
        if (script.getTimeout() > 0) {
          commandTimeout = String.valueOf(script.getTimeout());
        }
      } else {
        String message = String.format("Component %s of service %s has not " +
                "command script defined", componentName, serviceName);
        throw new AmbariException(message);
      }
    }
    commandParams.put(COMMAND_TIMEOUT, commandTimeout);
    commandParams.put(SERVICE_PACKAGE_FOLDER,
       serviceInfo.getServicePackageFolder());
    commandParams.put(HOOKS_FOLDER, configuration.getProperty(Configuration.HOOKS_FOLDER));
    // Fill host level params
    Map<String, String> hostLevelParams = statusCmd.getHostLevelParams();
    hostLevelParams.put(JDK_LOCATION, ambariManagementController.getJdkResourceUrl());
    hostLevelParams.put(STACK_NAME, stackId.getStackName());
    hostLevelParams.put(STACK_VERSION, stackId.getStackVersion());

    if (statusCmd.getPayloadLevel() == StatusCommand.StatusCommandPayload.EXECUTION_COMMAND) {
      ExecutionCommand ec = ambariManagementController.getExecutionCommand(cluster, sch, RoleCommand.START);
      statusCmd.setExecutionCommand(ec);
      LOG.debug("{} has more payload for execution command", componentName);
    }

    return statusCmd;
  }
Generates status command and fills all appropriate fields.
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java