@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptorForType().hashCode(); if (hasMemory()) { hash = (37 * hash) + MEMORY_FIELD_NUMBER; hash = (53 * hash) + getMemory(); } if (hasVirtualCores()) { hash = (37 * hash) + VIRTUAL_CORES_FIELD_NUMBER; hash = (53 * hash) + getVirtualCores(); } hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto)) { return super.equals(obj); } org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto other = (org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto) obj; boolean result = true; result = result && (hasMemory() == other.hasMemory()); if (hasMemory()) { result = result && (getMemory() == other.getMemory()); } result = result && (hasVirtualCores() == other.hasVirtualCores()); if (hasVirtualCores()) { result = result && (getVirtualCores() == other.getVirtualCores()); } result = result && getUnknownFields().equals(other.getUnknownFields()); return result; }
@Test public void testResource() { final long mem = 123; final int vcores = 456; final Resource r = Resource.newInstance(mem, vcores); // should be a lightweight SimpleResource which is a private inner class // so just verify it's not the heavyweight pb impl. Assert.assertFalse(r instanceof ResourcePBImpl); Assert.assertEquals(mem, r.getMemorySize()); Assert.assertEquals(vcores, r.getVirtualCores()); ResourceProto proto = ProtoUtils.convertToProtoFormat(r); Assert.assertEquals(mem, proto.getMemory()); Assert.assertEquals(vcores, proto.getVirtualCores()); Assert.assertEquals(r, ProtoUtils.convertFromProtoFormat(proto)); }
public Builder mergeFrom(org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto other) { if (other == org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto.getDefaultInstance()) return this; if (other.hasMemory()) { setMemory(other.getMemory()); } if (other.hasVirtualCores()) { setVirtualCores(other.getVirtualCores()); } this.mergeUnknownFields(other.getUnknownFields()); return this; }
public Resource getResource() { if (resource != null) { return resource; } GetResourceProfileResponseProtoOrBuilder p = viaProto ? proto : builder; if (p.hasResources()) { resource = Resource.newInstance(p.getResources().getMemory(), p.getResources().getVirtualCores()); } return resource; }