public HostRoleCommand createAmbariTask(long taskId, long requestId, long stageId,
                                          String component, String host, TaskType type, boolean skipFailure) {
    synchronized (nextTaskId) {
      if (nextTaskId.get() <= taskId) {
        nextTaskId.set(taskId + 1);
      }
    }

    HostRoleCommand task = hostRoleCommandFactory.create(
        host, Role.valueOf(component), null, RoleCommand.valueOf(type.name()), false, skipFailure);
    task.setStatus(HostRoleStatus.PENDING);
    task.setCommandDetail(String.format("Logical Task: %s component %s on host %s",
        type.name(), component, host));
    task.setTaskId(taskId);
    task.setRequestId(requestId);
    task.setStageId(stageId);

    return task;
  }
When config groups are created using Blueprints these are created when
hosts join a hostgroup and are added to the corresponding config group.
Since hosts join in parallel there might be a race condition in creating
the config group a host is to be added to. Thus we need to synchronize
the creation of config groups with the same name.
ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java