code: private Optional<String> getPreferredRack(final List<String> rackNames) {
  
      for (final String rackName : getRackNamesOrDefault(rackNames)) {
  
        // if it does not end with the any modifier, then we should do an exact match
        if (!rackName.endsWith(Constants.ANY_RACK)) {
          if (freeNodesPerRack.containsKey(rackName) && freeNodesPerRack.get(rackName).size() > 0) {
            return Optional.of(rackName);
          }
        } else {
  
          // if ends with the any modifier, we do a prefix match
          for (final String possibleRackName : this.availableRacks) {
  
            // remove the any modifier
            final String newRackName = rackName.substring(0, rackName.length() - 1);
  
            if (possibleRackName.startsWith(newRackName) &&
                this.freeNodesPerRack.get(possibleRackName).size() > 0) {
              return Optional.of(possibleRackName);
            }
          }
        }
      }
  
      return Optional.empty();
    }
docs: Returns the rack where to allocate the container, selected from the list of
  preferred rack names. If the list is empty, and there's space in the default
  rack, then the default rack is returned. The relax locality semantic is
  enabled if the list of rack names contains '/*', otherwise relax locality
  is considered disabled.
  
  @param rackNames the list of preferred racks.
  @return the rack name where to allocate the container.