@Override
    public int compare(Resource resource1, Resource resource2) {
      Type resourceType = resource1.getType();

      // compare based on resource type
      int compVal = resourceType.compareTo(resource2.getType());

      // compare based on requested properties
      if (compVal == 0 && sortRequest != null) {
        for (SortRequestProperty property : sortRequest.getProperties()) {
          compVal = compareValues(
            resource1.getPropertyValue(property.getPropertyId()),
            resource2.getPropertyValue(property.getPropertyId()),
            property.getOrder());

          if (compVal != 0) {
            return compVal;
          }
        }
      }

      // compare based on resource key properties
      if (compVal == 0) {
        Schema schema = getSchema(resourceType);

        for (Type type : schema.getKeyTypes()) {
          String keyPropertyId = schema.getKeyPropertyId(type);
          if (keyPropertyId != null) {
            compVal = compareValues(resource1.getPropertyValue(keyPropertyId),
                                    resource2.getPropertyValue(keyPropertyId));
            if (compVal != 0 ) {
              return compVal;
            }
          }
        }
      }

      // compare based on the resource strings
      return resource1.toString().compareTo(resource2.toString());
    }
Sort by properties.
@param sortRequest @SortRequest to sort by.
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java