flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tillrohrmann <...@git.apache.org>
Subject [GitHub] flink pull request #4911: [FLINK-7878] [api] make resource type extendible i...
Date Tue, 05 Dec 2017 14:49:49 GMT
Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4911#discussion_r154499917
  
    --- Diff: flink-core/src/main/java/org/apache/flink/api/common/operators/ResourceSpec.java
---
    @@ -183,17 +240,124 @@ public int hashCode() {
     		result = 31 * result + directMemoryInMB;
     		result = 31 * result + nativeMemoryInMB;
     		result = 31 * result + stateSizeInMB;
    +		result = 31 * result + extendedResources.hashCode();
     		return result;
     	}
     
     	@Override
     	public String toString() {
    +		String extend = "";
    +		for (Resource resource : extendedResources.values()) {
    +			extend += ", " + resource.name + "=" + resource.value;
    +		}
     		return "ResourceSpec{" +
     				"cpuCores=" + cpuCores +
     				", heapMemoryInMB=" + heapMemoryInMB +
     				", directMemoryInMB=" + directMemoryInMB +
     				", nativeMemoryInMB=" + nativeMemoryInMB +
    -				", stateSizeInMB=" + stateSizeInMB +
    +				", stateSizeInMB=" + stateSizeInMB + extend +
     				'}';
     	}
    +
    +	public static abstract class Resource implements Serializable {
    +		final private String name;
    +
    +		final private Double value;
    +
    +		final private ResourceAggregateType type;
    +
    +		public Resource(String name, double value, ResourceAggregateType type) {
    +			this.name = checkNotNull(name);
    +			this.value = Double.valueOf(value);
    +			this.type = checkNotNull(type);
    +		}
    +
    +		Resource merge(Resource other) {
    +			Preconditions.checkArgument(getClass() == other.getClass(), "Merge with different
resource type");
    +			Preconditions.checkArgument(this.name.equals(other.name), "Merge with different resource
name");
    +			Preconditions.checkArgument(this.type.equals(other.type), "Merge with different aggregate
type");
    +
    +			Double value = null;
    +			switch (type) {
    +				case AGGREGATE_TYPE_MAX :
    +					value = other.value.compareTo(this.value) > 0 ? other.value : this.value;
    --- End diff --
    
    `Math.max` should do the trick here.


---

Mime
View raw message