YARN-7840. Update PB for prefix support of node attributes. Contributed by Naganarasimha G R.

This commit is contained in:
bibinchundatt 2018-02-02 10:31:00 +05:30 committed by Sunil G
parent d9d93e3925
commit 4458b2772f
4 changed files with 61 additions and 14 deletions

View File

@ -37,21 +37,41 @@
* Its not compulsory for all the attributes to have value, empty string is the * Its not compulsory for all the attributes to have value, empty string is the
* default value of the <code>NodeAttributeType.STRING</code> * default value of the <code>NodeAttributeType.STRING</code>
* </p> * </p>
* * <p>
* Node Attribute Prefix is used as namespace to segregate the attributes.
* </p>
*/ */
@Public @Public
@Unstable @Unstable
public abstract class NodeAttribute { public abstract class NodeAttribute {
public static final String DEFAULT_PREFIX = "";
public static NodeAttribute newInstance(String attributeName, public static NodeAttribute newInstance(String attributeName,
NodeAttributeType attributeType, String attributeValue) { NodeAttributeType attributeType, String attributeValue) {
return newInstance(DEFAULT_PREFIX, attributeName, attributeType,
attributeValue);
}
public static NodeAttribute newInstance(String attributePrefix,
String attributeName, NodeAttributeType attributeType,
String attributeValue) {
NodeAttribute nodeAttribute = Records.newRecord(NodeAttribute.class); NodeAttribute nodeAttribute = Records.newRecord(NodeAttribute.class);
nodeAttribute.setAttributePrefix(attributePrefix);
nodeAttribute.setAttributeName(attributeName); nodeAttribute.setAttributeName(attributeName);
nodeAttribute.setAttributeType(attributeType); nodeAttribute.setAttributeType(attributeType);
nodeAttribute.setAttributeValue(attributeValue); nodeAttribute.setAttributeValue(attributeValue);
return nodeAttribute; return nodeAttribute;
} }
@Public
@Unstable
public abstract String getAttributePrefix();
@Public
@Unstable
public abstract void setAttributePrefix(String attributePrefix);
@Public @Public
@Unstable @Unstable
public abstract String getAttributeName(); public abstract String getAttributeName();

View File

@ -377,9 +377,10 @@ enum NodeAttributeTypeProto {
} }
message NodeAttributeProto { message NodeAttributeProto {
optional string attributeName = 1; optional string attributePrefix = 1;
optional NodeAttributeTypeProto attributeType = 2; required string attributeName = 2;
optional string attributeValue = 3; optional NodeAttributeTypeProto attributeType = 3 [default = STRING];
optional string attributeValue = 4 [default=""];
} }

View File

@ -63,6 +63,10 @@ public String getAttributeName() {
@Override @Override
public void setAttributeName(String attributeName) { public void setAttributeName(String attributeName) {
maybeInitBuilder(); maybeInitBuilder();
if(attributeName == null) {
builder.clearAttributeName();
return;
}
builder.setAttributeName(attributeName); builder.setAttributeName(attributeName);
} }
@ -78,6 +82,10 @@ public String getAttributeValue() {
@Override @Override
public void setAttributeValue(String attributeValue) { public void setAttributeValue(String attributeValue) {
maybeInitBuilder(); maybeInitBuilder();
if(attributeValue == null) {
builder.clearAttributeValue();
return;
}
builder.setAttributeValue(attributeValue); builder.setAttributeValue(attributeValue);
} }
@ -110,12 +118,6 @@ private NodeAttributeType convertFromProtoFormat(
return NodeAttributeType.valueOf(containerState.name()); return NodeAttributeType.valueOf(containerState.name());
} }
@Override
public String toString() {
return " name-" + getAttributeName() + ":value-" + getAttributeValue()
+ ":type-" + getAttributeType();
}
@Override @Override
public int hashCode() { public int hashCode() {
return getProto().hashCode(); return getProto().hashCode();
@ -152,4 +154,29 @@ private static boolean compare(Object left, Object right) {
return left.equals(right); return left.equals(right);
} }
} }
@Override
public String getAttributePrefix() {
NodeAttributeProtoOrBuilder p = viaProto ? proto : builder;
if (!p.hasAttributePrefix()) {
return null;
}
return p.getAttributePrefix();
}
@Override
public void setAttributePrefix(String attributePrefix) {
maybeInitBuilder();
if(attributePrefix == null) {
builder.clearAttributePrefix();
return;
}
builder.setAttributePrefix(attributePrefix);
}
@Override
public String toString() {
return "Prefix-" + getAttributePrefix() + " :Name-" + getAttributeName()
+ ":Value-" + getAttributeValue() + ":Type-" + getAttributeType();
}
} }

View File

@ -1245,19 +1245,18 @@ public void testGetAllResourceTypesInfoResponsePBImpl() throws Exception {
@Test @Test
public void testNodeAttributePBImpl() throws Exception { public void testNodeAttributePBImpl() throws Exception {
validatePBImplRecord(NodeAttributePBImpl.class, validatePBImplRecord(NodeAttributePBImpl.class, NodeAttributeProto.class);
NodeAttributeProto.class);
} }
@Test @Test
public void testNodeToAttributesPBImpl() throws Exception { public void testNodeToAttributesPBImpl() throws Exception {
validatePBImplRecord(NodeToAttributesPBImpl.class, validatePBImplRecord(NodeToAttributesPBImpl.class,
NodeToAttributesProto.class); NodeToAttributesProto.class);
} }
@Test @Test
public void testNodesToAttributesMappingRequestPBImpl() throws Exception { public void testNodesToAttributesMappingRequestPBImpl() throws Exception {
validatePBImplRecord(NodesToAttributesMappingRequestPBImpl.class, validatePBImplRecord(NodesToAttributesMappingRequestPBImpl.class,
NodesToAttributesMappingRequestProto.class); NodesToAttributesMappingRequestProto.class);
} }
} }