private List<String> processHeader(CSVPrinter csvPrinter, TreeNode<Resource> node) throws IOException {
    Map<String, String> header;
    List<String> fieldNameOrder;
    Object object;

    // Get the explicitly set header property for the current tree node. This may be null if no
    // header needs to be written out. The header map is expected to be a map of field names to
    // descriptive header values.
    object = node.getProperty(PROPERTY_COLUMN_MAP);
    if (object instanceof Map) {
      header = (Map<String, String>) object;
    } else {
      header = null;
    }

    // Determine the field name order.  If explicitly set, use it, else grab it from the header map
    // (if available).
    object = node.getProperty(PROPERTY_COLUMN_ORDER);
    if (object instanceof List) {
      // Use the explicitly set ordering
      fieldNameOrder = (List<String>) object;
    } else if (header != null) {
      // Use the ordering specified by the map.
      fieldNameOrder = new ArrayList<>(header.keySet());
    } else {
      fieldNameOrder = null;
    }

    if (header != null) {
      // build the header record
      List<String> headerNames = new ArrayList<>();
      for (String fieldName : fieldNameOrder) {
        headerNames.add(header.get(fieldName));
      }

      // write out the header...
      csvPrinter.printRecord(headerNames);
    }

    return fieldNameOrder;
  }
Optionally generate the CSV header record and establish the field order by processing the
csv_column_map and csv_column_order node properties.

@param csvPrinter the CSVPrinter used to create the record
@param node       a node containing header and ordering information
@return a list indicating the field order for the CSV records
@throws IOException if an error occurs creating the CSV header
ambari-server/src/main/java/org/apache/ambari/server/api/services/serializers/CsvSerializer.java