From 14b47990af39de71b0a09d995208f45ea3b79c23 Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Fri, 27 Apr 2018 12:23:56 -0400 Subject: [PATCH] YARN-8204. Added a flag to disable YARN service upgrade. Contributed by Chandni Singh --- .../yarn/service/client/ServiceClient.java | 7 +++++ .../yarn/service/conf/YarnServiceConf.java | 7 +++++ .../yarn/service/exceptions/ErrorStrings.java | 2 ++ .../yarn/service/TestYarnNativeServices.java | 1 + .../service/client/TestServiceClient.java | 28 ++++++++++++++++--- 5 files changed, 41 insertions(+), 4 deletions(-) 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 52cd369c235..8dd534209a0 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 @@ -74,6 +74,7 @@ import org.apache.hadoop.yarn.service.containerlaunch.ClasspathConstructor; import org.apache.hadoop.yarn.service.containerlaunch.JavaCommandLineBuilder; import org.apache.hadoop.yarn.service.exceptions.BadClusterStateException; import org.apache.hadoop.yarn.service.exceptions.BadConfigException; +import org.apache.hadoop.yarn.service.exceptions.ErrorStrings; import org.apache.hadoop.yarn.service.exceptions.SliderException; import org.apache.hadoop.yarn.service.provider.AbstractClientProvider; import org.apache.hadoop.yarn.service.provider.ProviderUtils; @@ -224,6 +225,12 @@ public class ServiceClient extends AppAdminClient implements SliderExitCodes, public int initiateUpgrade(Service service) throws YarnException, IOException { + boolean upgradeEnabled = getConfig().getBoolean( + YARN_SERVICE_UPGRADE_ENABLED, + YARN_SERVICE_UPGRADE_ENABLED_DEFAULT); + if (!upgradeEnabled) { + throw new YarnException(ErrorStrings.SERVICE_UPGRADE_DISABLED); + } Service persistedService = ServiceApiUtil.loadService(fs, service.getName()); if (!StringUtils.isEmpty(persistedService.getId())) { 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/conf/YarnServiceConf.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/conf/YarnServiceConf.java index 55a3d7002a1..13ed1aaca97 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/conf/YarnServiceConf.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/conf/YarnServiceConf.java @@ -127,6 +127,13 @@ public class YarnServiceConf { public static final String YARN_SERVICE_CONTAINER_HEALTH_THRESHOLD_PREFIX = YARN_SERVICE_PREFIX + "container-health-threshold."; + /** + * Upgrade feature enabled for services. + */ + public static final String YARN_SERVICE_UPGRADE_ENABLED = + "yarn.service.upgrade.enabled"; + public static final boolean YARN_SERVICE_UPGRADE_ENABLED_DEFAULT = false; + /** * The container health threshold percent when explicitly set for a specific * component or globally for all components, will schedule a health check 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/exceptions/ErrorStrings.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/exceptions/ErrorStrings.java index 83658c89ea2..6ae124faedd 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/exceptions/ErrorStrings.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/exceptions/ErrorStrings.java @@ -39,4 +39,6 @@ public interface ErrorStrings { "Too many arguments"; String ERROR_DUPLICATE_ENTRY = "Duplicate entry for "; + String SERVICE_UPGRADE_DISABLED = "Service upgrade is disabled."; + } 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/TestYarnNativeServices.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/TestYarnNativeServices.java index ab7cb62fb47..5b608e3e589 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/TestYarnNativeServices.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/TestYarnNativeServices.java @@ -375,6 +375,7 @@ public class TestYarnNativeServices extends ServiceTestUtils { @Test(timeout = 200000) public void testUpgrade() throws Exception { setupInternal(NUM_NMS); + getConf().setBoolean(YARN_SERVICE_UPGRADE_ENABLED, true); ServiceClient client = createClient(getConf()); Service service = createExampleApplication(); 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 3e3280be66d..d3664ea1dc3 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 @@ -39,6 +39,8 @@ import org.apache.hadoop.yarn.service.api.records.Component; import org.apache.hadoop.yarn.service.api.records.Container; import org.apache.hadoop.yarn.service.api.records.Service; import org.apache.hadoop.yarn.service.api.records.ServiceState; +import org.apache.hadoop.yarn.service.conf.YarnServiceConf; +import org.apache.hadoop.yarn.service.exceptions.ErrorStrings; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; import org.junit.Assert; import org.junit.Rule; @@ -66,10 +68,27 @@ public class TestServiceClient { public ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); + @Test + public void testUpgradeDisabledByDefault() throws Exception { + Service service = createService(); + ServiceClient client = MockServiceClient.create(rule, service, false); + + //upgrade the service + service.setVersion("v2"); + try { + client.initiateUpgrade(service); + } catch (YarnException ex) { + Assert.assertEquals(ErrorStrings.SERVICE_UPGRADE_DISABLED, + ex.getMessage()); + return; + } + Assert.fail(); + } + @Test public void testActionServiceUpgrade() throws Exception { Service service = createService(); - ServiceClient client = MockServiceClient.create(rule, service); + ServiceClient client = MockServiceClient.create(rule, service, true); //upgrade the service service.setVersion("v2"); @@ -85,7 +104,7 @@ public class TestServiceClient { @Test public void testActionCompInstanceUpgrade() throws Exception { Service service = createService(); - MockServiceClient client = MockServiceClient.create(rule, service); + MockServiceClient client = MockServiceClient.create(rule, service, true); //upgrade the service service.setVersion("v2"); @@ -127,7 +146,7 @@ public class TestServiceClient { } static MockServiceClient create(ServiceTestUtils.ServiceFSWatcher rule, - Service service) + Service service, boolean enableUpgrade) throws IOException, YarnException { MockServiceClient client = new MockServiceClient(); @@ -163,7 +182,8 @@ public class TestServiceClient { client.setFileSystem(rule.getFs()); client.setYarnClient(yarnClient); client.service = service; - + rule.getConf().setBoolean(YarnServiceConf.YARN_SERVICE_UPGRADE_ENABLED, + enableUpgrade); client.init(rule.getConf()); client.start(); client.actionCreate(service);