From 91c916e20915c264cdc26dbdc82db9104a15b60a Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Thu, 18 Oct 2018 19:59:11 -0400 Subject: [PATCH] YARN-8618. Added detection for non-upgradable service. Contributed by Chandni Singh (cherry picked from commit 66f059ed1db93c0a86e86c64636013001169a677) --- .../yarn/service/client/ServiceClient.java | 17 +++++++++++++- .../service/client/TestServiceClient.java | 23 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java index 23db57efad6..c71ed0306df 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java @@ -238,7 +238,22 @@ public class ServiceClient extends AppAdminClient implements SliderExitCodes, 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() diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java index 700655ce5de..beb3339a052 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java @@ -149,6 +149,29 @@ public class TestServiceClient { 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();