YARN-8618. Added detection for non-upgradable service.
Contributed by Chandni Singh
This commit is contained in:
parent
be1cffb085
commit
66f059ed1d
@ -238,7 +238,22 @@ private ApplicationReport upgradePrecheck(Service service)
|
||||
LOG.error(message);
|
||||
throw new YarnException(message);
|
||||
}
|
||||
|
||||
boolean foundNotNeverComp = false;
|
||||
for (Component comp : persistedService.getComponents()) {
|
||||
// If restart policy of any component is not NEVER then upgrade is
|
||||
// allowed.
|
||||
if (!comp.getRestartPolicy().equals(Component.RestartPolicyEnum.NEVER)) {
|
||||
foundNotNeverComp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundNotNeverComp) {
|
||||
String message = "All the components of the service " + service.getName()
|
||||
+ " have " + Component.RestartPolicyEnum.NEVER + " restart policy, " +
|
||||
"so it cannot be upgraded.";
|
||||
LOG.error(message);
|
||||
throw new YarnException(message);
|
||||
}
|
||||
Service liveService = getStatus(service.getName());
|
||||
if (!liveService.getState().equals(ServiceState.STABLE)) {
|
||||
String message = service.getName() + " is at " + liveService.getState()
|
||||
|
@ -149,6 +149,29 @@ public void testGetCompInstances() throws Exception {
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpgradeDisabledWhenAllCompsHaveNeverRestartPolicy()
|
||||
throws Exception {
|
||||
Service service = createService();
|
||||
service.getComponents().forEach(comp ->
|
||||
comp.setRestartPolicy(Component.RestartPolicyEnum.NEVER));
|
||||
|
||||
ServiceClient client = MockServiceClient.create(rule, service, true);
|
||||
|
||||
//upgrade the service
|
||||
service.setVersion("v2");
|
||||
try {
|
||||
client.initiateUpgrade(service);
|
||||
} catch (YarnException ex) {
|
||||
Assert.assertEquals("All the components of the service " +
|
||||
service.getName() + " have " + Component.RestartPolicyEnum.NEVER
|
||||
+ " restart policy, so it cannot be upgraded.",
|
||||
ex.getMessage());
|
||||
return;
|
||||
}
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
private Service createService() throws IOException,
|
||||
YarnException {
|
||||
Service service = ServiceTestUtils.createExampleApplication();
|
||||
|
Loading…
Reference in New Issue
Block a user