private void createHostAction(Cluster cluster,
                                Stage stage,
                                ServiceComponentHost scHost,
                                RoleCommand roleCommand,
                                Map<String, String> commandParamsInp,
                                ServiceComponentHostEvent event,
                                boolean skipFailure,
                                RepositoryVersionEntity repoVersion,
                                boolean isUpgradeSuspended,
                                DatabaseType databaseType,
                                Map<String, DesiredConfig> clusterDesiredConfigs,
                                boolean useLatestConfigs)
                                throws AmbariException {

    String serviceName = scHost.getServiceName();

    stage.addHostRoleExecutionCommand(scHost.getHost(),
        Role.valueOf(scHost.getServiceComponentName()), roleCommand, event, cluster, serviceName, false, skipFailure);

    String componentName = scHost.getServiceComponentName();
    String hostname = scHost.getHostName();
    Host host = clusters.getHost(hostname);
    HostEntity hostEntity = host.getHostEntity();
    Map<String, String> hostAttributes = gson.fromJson(hostEntity.getHostAttributes(), hostAttributesType);
    String osFamily = host.getOSFamilyFromHostAttributes(hostAttributes);

    StackId stackId = scHost.getServiceComponent().getDesiredStackId();

    ServiceInfo serviceInfo = ambariMetaInfo.getService(stackId.getStackName(),
        stackId.getStackVersion(), serviceName);
    ComponentInfo componentInfo = ambariMetaInfo.getComponent(
      stackId.getStackName(), stackId.getStackVersion(),
      serviceName, componentName);
    StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(),
        stackId.getStackVersion());
    Map<String, ServiceInfo> servicesMap = ambariMetaInfo.getServices(stackInfo.getName(), stackInfo.getVersion());

    ExecutionCommandWrapper execCmdWrapper = stage.getExecutionCommandWrapper(hostname, componentName);
    ExecutionCommand execCmd = execCmdWrapper.getExecutionCommand();

    execCmd.setConfigurations(new TreeMap<>());

    // Get the value of credential store enabled from the DB
    Service clusterService = cluster.getService(serviceName);
    execCmd.setCredentialStoreEnabled(String.valueOf(clusterService.isCredentialStoreEnabled()));

    ServiceComponent component = clusterService.getServiceComponent(componentName);

    // Get the map of service config type to password properties for the service
    Map<String, Map<String, String>> configCredentials;
    configCredentials = configCredentialsForService.get(clusterService.getName());
    if (configCredentials == null) {
      configCredentials = configHelper.getCredentialStoreEnabledProperties(stackId, clusterService);
      configCredentialsForService.put(clusterService.getName(), configCredentials);
    }

    execCmd.setConfigurationCredentials(configCredentials);

    // Create a local copy for each command
    Map<String, String> commandParams = new TreeMap<>();
    if (commandParamsInp != null) { // if not defined
      commandParams.putAll(commandParamsInp);
    }

    boolean isInstallCommand = roleCommand.equals(RoleCommand.INSTALL);
    String agentDefaultCommandTimeout = configs.getDefaultAgentTaskTimeout(isInstallCommand);
    String scriptCommandTimeout = "";
    /*
     * This script is only used for
     * default commands like INSTALL/STOP/START
     */
    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());

        boolean retryEnabled = false;
        Integer retryMaxTime = 0;
        if (commandParams.containsKey(CLUSTER_PHASE_PROPERTY) &&
            (commandParams.get(CLUSTER_PHASE_PROPERTY).equals(CLUSTER_PHASE_INITIAL_INSTALL) ||
            commandParams.get(CLUSTER_PHASE_PROPERTY).equals(CLUSTER_PHASE_INITIAL_START))) {
          String retryEnabledStr =
              configHelper.getValueFromDesiredConfigurations(cluster, ConfigHelper.CLUSTER_ENV,
                                                             ConfigHelper.CLUSTER_ENV_RETRY_ENABLED);
          String commandsStr =
              configHelper.getValueFromDesiredConfigurations(cluster, ConfigHelper.CLUSTER_ENV,
                                                             ConfigHelper.CLUSTER_ENV_RETRY_COMMANDS);
          String retryMaxTimeStr =
              configHelper.getValueFromDesiredConfigurations(cluster,
                                                             ConfigHelper.CLUSTER_ENV,
                                                             ConfigHelper.CLUSTER_ENV_RETRY_MAX_TIME_IN_SEC);
          if (StringUtils.isNotEmpty(retryEnabledStr)) {
            retryEnabled = Boolean.TRUE.toString().equals(retryEnabledStr);
          }

          if (retryEnabled) {
            retryMaxTime = NumberUtils.toInt(retryMaxTimeStr, 0);
            if (retryMaxTime < 0) {
              retryMaxTime = 0;
            }

            if (StringUtils.isNotEmpty(commandsStr)) {
              boolean commandMayBeRetried = false;
              String[] commands = commandsStr.split(",");
              for (String command : commands) {
                if (roleCommand.toString().equals(command.trim())) {
                  commandMayBeRetried = true;
                }
              }
              retryEnabled = commandMayBeRetried;
            }
          }
          LOG.info("Auto retry setting for {}-{} on {} is retryEnabled={} and retryMaxTime={}", serviceName, componentName, scHost.getHostName(), retryEnabled, retryMaxTime);
        }
        commandParams.put(MAX_DURATION_OF_RETRIES, Integer.toString(retryMaxTime));
        commandParams.put(COMMAND_RETRY_ENABLED, Boolean.toString(retryEnabled));

        if (script.getTimeout() > 0) {
          scriptCommandTimeout = String.valueOf(script.getTimeout());
        }
      } else {
        String message = String.format("Component %s of service %s has no " +
          "command script defined", componentName, serviceName);
        throw new AmbariException(message);
      }
    }

    String actualTimeout = (!scriptCommandTimeout.equals("") ? scriptCommandTimeout : agentDefaultCommandTimeout);

    // Because the INSTALL command can take much longer than typical commands, set the timeout to be the max
    // between the script's service component timeout and the agent default timeout.
    if (roleCommand.equals(RoleCommand.INSTALL) && !agentDefaultCommandTimeout.equals("") &&
        Integer.parseInt(actualTimeout) < Integer.parseInt(agentDefaultCommandTimeout)) {
      actualTimeout = agentDefaultCommandTimeout;
    }

    commandParams.put(COMMAND_TIMEOUT, actualTimeout);

    String customCacheDirectory = componentInfo.getCustomFolder();
    if (customCacheDirectory != null) {
      File customCache = new File(configs.getResourceDirPath(), customCacheDirectory);
      if (customCache.exists() && customCache.isDirectory()) {
        commandParams.put(CUSTOM_FOLDER, customCacheDirectory);
      }
    }

    String clusterName = cluster.getClusterName();
    if (customCommandExecutionHelper.isTopologyRefreshRequired(roleCommand.name(), clusterName, serviceName)) {
      commandParams.put(ExecutionCommand.KeyNames.REFRESH_TOPOLOGY, "True");
    }
    StageUtils.useAmbariJdkInCommandParams(commandParams, configs);

    String repoInfo;
    try {
      repoInfo = repoVersionHelper.getRepoInfoString(cluster, component, host);
    } catch (SystemException e) {
      throw new RuntimeException(e);
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Sending repo information to agent, hostname={}, clusterName={}, stackInfo={}, repoInfo={}",
        scHost.getHostName(), clusterName, stackId.getStackId(), repoInfo);
    }

    Map<String, String> hostParams = new TreeMap<>();

    if (roleCommand.equals(RoleCommand.INSTALL)) {
      List<ServiceOsSpecific.Package> packages =
          getPackagesForServiceHost(serviceInfo, hostParams, osFamily);
      String packageList = gson.toJson(packages);
      commandParams.put(PACKAGE_LIST, packageList);
    }

    Set<PropertyInfo> stackProperties = ambariMetaInfo.getStackProperties(stackInfo.getName(), stackInfo.getVersion());

    Set<String> userSet = configHelper.getPropertyValuesWithPropertyType(PropertyType.USER, cluster, clusterDesiredConfigs, servicesMap, stackProperties);
    String userList = gson.toJson(userSet);
    hostParams.put(USER_LIST, userList);

    //Create a user_group mapping and send it as part of the hostLevelParams
    Map<String, Set<String>> userGroupsMap = configHelper.createUserGroupsMap(
      cluster, clusterDesiredConfigs, servicesMap, stackProperties);
    String userGroups = gson.toJson(userGroupsMap);
    hostParams.put(USER_GROUPS, userGroups);

    Set<String> groupSet = configHelper.getPropertyValuesWithPropertyType(PropertyType.GROUP, cluster, clusterDesiredConfigs, servicesMap, stackProperties);
    String groupList = gson.toJson(groupSet);
    hostParams.put(GROUP_LIST, groupList);

    Map<PropertyInfo, String> notManagedHdfsPathMap = configHelper.getPropertiesWithPropertyType(PropertyType.NOT_MANAGED_HDFS_PATH, cluster, clusterDesiredConfigs, servicesMap, stackProperties);
    Set<String> notManagedHdfsPathSet = configHelper.filterInvalidPropertyValues(notManagedHdfsPathMap, NOT_MANAGED_HDFS_PATH_LIST);
    String notManagedHdfsPathList = gson.toJson(notManagedHdfsPathSet);
    hostParams.put(NOT_MANAGED_HDFS_PATH_LIST, notManagedHdfsPathList);

    if (databaseType == DatabaseType.ORACLE) {
      hostParams.put(DB_DRIVER_FILENAME, configs.getOjdbcJarName());
    } else if (databaseType == DatabaseType.MYSQL) {
      hostParams.put(DB_DRIVER_FILENAME, configs.getMySQLJarName());
    }

    hostParams.put(CLIENTS_TO_UPDATE_CONFIGS, getClientsToUpdateConfigs(componentInfo));

    execCmd.setHostLevelParams(hostParams);

    Map<String, String> roleParams = new TreeMap<>();

    // !!! consistent with where custom commands put variables
    // !!! after-INSTALL hook checks this such that the stack selection tool won't
    // select-all to a version that is not being upgraded, breaking RU
    if (isUpgradeSuspended) {
      cluster.addSuspendedUpgradeParameters(commandParams, roleParams);
    }

    execCmd.setRoleParams(roleParams);
    execCmd.setCommandParams(commandParams);

    CommandRepository commandRepository;
    try {
      commandRepository = repoVersionHelper.getCommandRepository(cluster, component, host);
    } catch (SystemException e) {
      throw new RuntimeException(e);
    }
    execCmd.setRepositoryFile(commandRepository);
    execCmdWrapper.setVersions(cluster, null);

    if (useLatestConfigs) {
      execCmd.setUseLatestConfigs(useLatestConfigs);
    }
  }
Creates and populates an EXECUTION_COMMAND for host
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java