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
* default value of the <code>NodeAttributeType.STRING</code>
* </p>
*
* <p>
* Node Attribute Prefix is used as namespace to segregate the attributes.
* </p>
*/
@Public
@Unstable
public abstract class NodeAttribute {
public static final String DEFAULT_PREFIX = "";
public static NodeAttribute newInstance(String attributeName,
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.setAttributePrefix(attributePrefix);
nodeAttribute.setAttributeName(attributeName);
nodeAttribute.setAttributeType(attributeType);
nodeAttribute.setAttributeValue(attributeValue);
return nodeAttribute;
}
@Public
@Unstable
public abstract String getAttributePrefix();
@Public
@Unstable
public abstract void setAttributePrefix(String attributePrefix);
@Public
@Unstable
public abstract String getAttributeName();

View File

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

View File

@ -63,6 +63,10 @@ public String getAttributeName() {
@Override
public void setAttributeName(String attributeName) {
maybeInitBuilder();
if(attributeName == null) {
builder.clearAttributeName();
return;
}
builder.setAttributeName(attributeName);
}
@ -78,6 +82,10 @@ public String getAttributeValue() {
@Override
public void setAttributeValue(String attributeValue) {
maybeInitBuilder();
if(attributeValue == null) {
builder.clearAttributeValue();
return;
}
builder.setAttributeValue(attributeValue);
}
@ -110,12 +118,6 @@ private NodeAttributeType convertFromProtoFormat(
return NodeAttributeType.valueOf(containerState.name());
}
@Override
public String toString() {
return " name-" + getAttributeName() + ":value-" + getAttributeValue()
+ ":type-" + getAttributeType();
}
@Override
public int hashCode() {
return getProto().hashCode();
@ -152,4 +154,29 @@ private static boolean compare(Object left, Object 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
public void testNodeAttributePBImpl() throws Exception {
validatePBImplRecord(NodeAttributePBImpl.class,
NodeAttributeProto.class);
validatePBImplRecord(NodeAttributePBImpl.class, NodeAttributeProto.class);
}
@Test
public void testNodeToAttributesPBImpl() throws Exception {
validatePBImplRecord(NodeToAttributesPBImpl.class,
NodeToAttributesProto.class);
NodeToAttributesProto.class);
}
@Test
public void testNodesToAttributesMappingRequestPBImpl() throws Exception {
validatePBImplRecord(NodesToAttributesMappingRequestPBImpl.class,
NodesToAttributesMappingRequestProto.class);
NodesToAttributesMappingRequestProto.class);
}
}