UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateYarnEnv() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance( AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { Config yarnEnvConfig = cluster.getDesiredConfigByType(YARN_ENV_CONFIG); Map<String, String> yarnEnvProps = new HashMap<String, String>(); if (yarnEnvConfig != null) { String content = yarnEnvConfig.getProperties().get("content"); content = content.replaceAll("export YARN_HISTORYSERVER_HEAPSIZE=\\{\\{apptimelineserver_heapsize\\}\\}", "# export YARN_HISTORYSERVER_HEAPSIZE=\\{\\{apptimelineserver_heapsize\\}\\}"); content = content + "\n\n # Specify the max Heapsize for the timeline server using a numerical value\n" + " # in the scale of MB. For example, to specify an jvm option of -Xmx1000m, set\n" + " # the value to 1024.\n" + " # This value will be overridden by an Xmx setting specified in either YARN_OPTS\n" + " # and/or YARN_TIMELINESERVER_OPTS.\n" + " # If not specified, the default value will be picked from either YARN_HEAPMAX\n" + " # or JAVA_HEAP_MAX with YARN_HEAPMAX as the preferred option of the two.\n" + " export YARN_TIMELINESERVER_HEAPSIZE={{apptimelineserver_heapsize}}"; yarnEnvProps.put("content", content); updateConfigurationPropertiesForCluster(cluster, YARN_ENV_CONFIG, yarnEnvProps, true, true); } } } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String DESIRED_VERSION_COLUMN_NAME; static final String BLUEPRINT_SETTING_TABLE; static final String BLUEPRINT_NAME_COL; static final String SETTING_NAME_COL; static final String SETTING_DATA_COL; static final String ID; static final String BLUEPRINT_TABLE; static final String VIEWINSTANCE_TABLE; static final String SHORT_URL_COLUMN; static final String CLUSTER_HANDLE_COLUMN; static final String REQUESTSCHEDULE_TABLE; static final String AUTHENTICATED_USER_ID_COLUMN; static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD; static final String ONE_DIR_PER_PARITION_PROPERTY; static final String VIEWURL_TABLE; static final String URL_ID_COLUMN; static final String PRECISION_TABLE_TTL_PROPERTY; static final String CLUSTER_SECOND_TABLE_TTL_PROPERTY; static final String CLUSTER_TYPE_COLUMN; static final String REMOTE_AMBARI_CLUSTER_TABLE; static final String REMOTE_AMBARI_CLUSTER_SERVICE_TABLE; static final String CLUSTER_ID; static final String SERVICE_NAME; static final String CLUSTER_NAME; }
@Test public void testYarnEnvUpdateConfigs() throws Exception{ Map<String, String> oldPropertiesYarnEnv = new HashMap<String, String>() { { put("content", "export YARN_HISTORYSERVER_HEAPSIZE={{apptimelineserver_heapsize}}"); } }; Map<String, String> newPropertiesYarnEnv = new HashMap<String, String>() { { put("content", "# export YARN_HISTORYSERVER_HEAPSIZE={{apptimelineserver_heapsize}}" + "\n\n # Specify the max Heapsize for the timeline server using a numerical value\n" + " # in the scale of MB. For example, to specify an jvm option of -Xmx1000m, set\n" + " # the value to 1024.\n" + " # This value will be overridden by an Xmx setting specified in either YARN_OPTS\n" + " # and/or YARN_TIMELINESERVER_OPTS.\n" + " # If not specified, the default value will be picked from either YARN_HEAPMAX\n" + " # or JAVA_HEAP_MAX with YARN_HEAPMAX as the preferred option of the two.\n" + " export YARN_TIMELINESERVER_HEAPSIZE={{apptimelineserver_heapsize}}"); } }; EasyMockSupport easyMockSupport = new EasyMockSupport(); Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); Config mockYarnEnv = easyMockSupport.createNiceMock(Config.class); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).once(); expect(cluster.getDesiredConfigByType("yarn-env")).andReturn(mockYarnEnv).atLeastOnce(); expect(mockYarnEnv.getProperties()).andReturn(oldPropertiesYarnEnv).anyTimes(); Injector injector = easyMockSupport.createNiceMock(Injector.class); expect(injector.getInstance(Gson.class)).andReturn(null).anyTimes(); expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).anyTimes(); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)).anyTimes(); replay(injector, clusters, mockYarnEnv, cluster); AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class) .addMockedMethod("createConfiguration") .addMockedMethod("getClusters", new Class[] { }) .addMockedMethod("createConfig") .withConstructor(createNiceMock(ActionManager.class), clusters, injector) .createNiceMock(); Injector injector2 = easyMockSupport.createNiceMock(Injector.class); Capture<Map<String, String>> propertiesCapture = EasyMock.newCapture(); expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once(); replay(controller, injector2); new UpgradeCatalog240(injector2).updateYarnEnv(); easyMockSupport.verifyAll(); Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newPropertiesYarnEnv, updatedProperties).areEqual()); }