YARN-8445. Improved error message for duplicated service and component names.

Contributed by Chandni Singh
This commit is contained in:
Eric Yang 2018-06-21 11:18:14 -04:00
parent 43541a1890
commit 9f15483c5d
3 changed files with 25 additions and 0 deletions

View File

@ -28,6 +28,8 @@ public interface RestApiErrorMessages {
"than 63 characters";
String ERROR_COMPONENT_NAME_INVALID =
"Component name must be no more than %s characters: %s";
String ERROR_COMPONENT_NAME_CONFLICTS_WITH_SERVICE_NAME =
"Component name %s must not be same as service name %s";
String ERROR_USER_NAME_INVALID =
"User name must be no more than 63 characters";

View File

@ -143,6 +143,11 @@ public static void validateAndResolveService(Service service,
throw new IllegalArgumentException(String.format(RestApiErrorMessages
.ERROR_COMPONENT_NAME_INVALID, maxCompLength, comp.getName()));
}
if (service.getName().equals(comp.getName())) {
throw new IllegalArgumentException(String.format(RestApiErrorMessages
.ERROR_COMPONENT_NAME_CONFLICTS_WITH_SERVICE_NAME,
comp.getName(), service.getName()));
}
if (componentNames.contains(comp.getName())) {
throw new IllegalArgumentException("Component name collision: " +
comp.getName());

View File

@ -333,6 +333,24 @@ public void testDuplicateComponents() throws IOException {
}
}
@Test
public void testComponentNameSameAsServiceName() throws IOException {
SliderFileSystem sfs = ServiceTestUtils.initMockFs();
Service app = new Service();
app.setName("test");
app.setVersion("v1");
app.addComponent(createValidComponent("test"));
//component name same as service name
try {
ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED);
Assert.fail(EXCEPTION_PREFIX + "component name matches service name");
} catch (IllegalArgumentException e) {
assertEquals("Component name test must not be same as service name test",
e.getMessage());
}
}
@Test
public void testExternalDuplicateComponent() throws IOException {
Service ext = createValidApplication("comp1");