YARN-8445. Improved error message for duplicated service and component names.
Contributed by Chandni Singh
This commit is contained in:
parent
43541a1890
commit
9f15483c5d
|
@ -28,6 +28,8 @@ public interface RestApiErrorMessages {
|
||||||
"than 63 characters";
|
"than 63 characters";
|
||||||
String ERROR_COMPONENT_NAME_INVALID =
|
String ERROR_COMPONENT_NAME_INVALID =
|
||||||
"Component name must be no more than %s characters: %s";
|
"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 =
|
String ERROR_USER_NAME_INVALID =
|
||||||
"User name must be no more than 63 characters";
|
"User name must be no more than 63 characters";
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,11 @@ public class ServiceApiUtil {
|
||||||
throw new IllegalArgumentException(String.format(RestApiErrorMessages
|
throw new IllegalArgumentException(String.format(RestApiErrorMessages
|
||||||
.ERROR_COMPONENT_NAME_INVALID, maxCompLength, comp.getName()));
|
.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())) {
|
if (componentNames.contains(comp.getName())) {
|
||||||
throw new IllegalArgumentException("Component name collision: " +
|
throw new IllegalArgumentException("Component name collision: " +
|
||||||
comp.getName());
|
comp.getName());
|
||||||
|
|
|
@ -333,6 +333,24 @@ public class TestServiceApiUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testExternalDuplicateComponent() throws IOException {
|
public void testExternalDuplicateComponent() throws IOException {
|
||||||
Service ext = createValidApplication("comp1");
|
Service ext = createValidApplication("comp1");
|
||||||
|
|
Loading…
Reference in New Issue