YARN-6544. Add Null check RegistryDNS service while parsing registry records. Contributed by Karam Singh

This commit is contained in:
Gour Saha 2017-05-12 15:04:17 -07:00 committed by Jian He
parent 02d68c4bcf
commit a22256bd40
2 changed files with 49 additions and 11 deletions

View File

@ -1393,19 +1393,28 @@ private void op(String path, ServiceRecord record, RegistryCommand command)
throws IOException {
ServiceRecordProcessor processor;
try {
if (record.get(YarnRegistryAttributes.YARN_PERSISTENCE)
.equals(CONTAINER)) {
// container registration. the logic to identify and create the
// container entry needs to be enhanced/more accurate and associate to
// correct host
processor =
new ContainerServiceRecordProcessor(record, path, domainName, this);
String yarnPersistanceValue = record.get(
YarnRegistryAttributes.YARN_PERSISTENCE);
if (yarnPersistanceValue != null) {
if (yarnPersistanceValue.equals(CONTAINER)) {
// container registration. the logic to identify and create the
// container entry needs to be enhanced/more accurate and associate
// to correct host
processor =
new ContainerServiceRecordProcessor(record, path, domainName,
this);
} else {
LOG.debug("Creating ApplicationServiceRecordProcessor for {}",
yarnPersistanceValue);
processor =
new ApplicationServiceRecordProcessor(record, path, domainName,
this);
}
processor.manageDNSRecords(command);
} else {
processor =
new ApplicationServiceRecordProcessor(record, path, domainName,
this);
LOG.warn("Yarn Resgistry record {} does not contain {} attribute ",
record.toString(), YarnRegistryAttributes.YARN_PERSISTENCE);
}
processor.manageDNSRecords(command);
} catch (Exception e) {
throw new IOException(e);
}

View File

@ -129,6 +129,16 @@ public class TestRegistryDNS extends Assert {
+ " \"yarn:persistence\" : \"container\"\n"
+ "}\n";
private static final String CONTAINER_RECORD_YARN_PERSISTANCE_ABSENT = "{\n"
+ " \"type\" : \"JSONServiceRecord\",\n"
+ " \"description\" : \"YCLOUD\",\n"
+ " \"external\" : [ ],\n"
+ " \"internal\" : [ ],\n"
+ " \"yarn:id\" : \"container_e50_1451931954322_0016_01_000003\",\n"
+ " \"yarn:ip\" : \"172.17.0.19\",\n"
+ " \"yarn:hostname\" : \"0a134d6329bb\"\n"
+ "}\n";
@Before
public void initialize() throws Exception {
setRegistryDNS(new RegistryDNS("TestRegistry"));
@ -219,6 +229,25 @@ public void testContainerRegistration() throws Exception {
assertTrue("not an ARecord", recs[0] instanceof ARecord);
}
@Test
public void testContainerRegistrationPersistanceAbsent() throws Exception {
ServiceRecord record = marshal.fromBytes("somepath",
CONTAINER_RECORD_YARN_PERSISTANCE_ABSENT.getBytes());
registryDNS.register(
"/registry/users/root/services/org-apache-slider/test1/components/"
+ "container-e50-1451931954322-0016-01-000003",
record);
Name name =
Name.fromString("ctr-e50-1451931954322-0016-01-000002.hwx.test.");
Record question = Record.newRecord(name, Type.A, DClass.IN);
Message query = Message.newQuery(question);
byte[] responseBytes = registryDNS.generateReply(query, null);
Message response = new Message(responseBytes);
assertEquals("Excepting NXDOMAIN as Record must not have regsisterd wrong",
Rcode.NXDOMAIN, response.getRcode());
}
@Test
public void testRecordTTL() throws Exception {
ServiceRecord record = getMarshal().fromBytes("somepath",