UpgradeCatalog220 extends AbstractUpgradeCatalog { protected String updateHiveEnvContent(String hiveEnvContent) { if(hiveEnvContent == null) { return null; } String exportHadoopClientOpts = "(?s).*export\\s*HADOOP_CLIENT_OPTS.*"; if (hiveEnvContent.matches(exportHadoopClientOpts)) { String oldHeapSizeRegex = "export\\s*HADOOP_CLIENT_OPTS=\"-Xmx\\$\\{HADOOP_HEAPSIZE\\}m\\s*\\$HADOOP_CLIENT_OPTS\""; String newHeapSizeRegex = "export HADOOP_CLIENT_OPTS=\"$HADOOP_CLIENT_OPTS -Xmx${HADOOP_HEAPSIZE}m\""; return hiveEnvContent.replaceAll(oldHeapSizeRegex, Matcher.quoteReplacement(newHeapSizeRegex)); } else { String oldHeapSizeRegex = "export\\s*HADOOP_HEAPSIZE\\s*=\\s*\"\\{\\{hive_heapsize\\}\\}\"\\.*\\n\\s*fi\\s*\\n"; String newHeapSizeRegex = "export HADOOP_HEAPSIZE={{hive_heapsize}} # Setting for HiveServer2 and Client\n" + "fi\n" + "\n" + "export HADOOP_CLIENT_OPTS=\"$HADOOP_CLIENT_OPTS -Xmx${HADOOP_HEAPSIZE}m\"\n"; return hiveEnvContent.replaceAll(oldHeapSizeRegex, Matcher.quoteReplacement(newHeapSizeRegex)); } } @Inject  UpgradeCatalog220(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); @Transactional void bootstrapRepoVersionForHDP21(); static final String UPGRADE_PACKAGE_COL; static final String UPGRADE_TYPE_COL; static final String REPO_VERSION_TABLE; }
@Test public void testUpdateHiveEnvContent() throws Exception { UpgradeCatalog220 upgradeCatalog220 = new UpgradeCatalog220(injector); String testContent = "# The heap size of the jvm stared by hive shell script can be controlled via:\n" + "\n" + "if [ \"$SERVICE\" = \"metastore\" ]; then\n" + " export HADOOP_HEAPSIZE=\"{{hive_metastore_heapsize}}\"\n" + "else\n" + " export HADOOP_HEAPSIZE=\"{{hive_heapsize}}\"\n" + "fi\n" + "\n" + "export HADOOP_CLIENT_OPTS=\"-Xmx${HADOOP_HEAPSIZE}m $HADOOP_CLIENT_OPTS\"\n" + "\n" + "# Larger heap size may be required when running queries over large number of files or partitions.\n"; String expectedResult = "# The heap size of the jvm stared by hive shell script can be controlled via:\n" + "\n" + "if [ \"$SERVICE\" = \"metastore\" ]; then\n" + " export HADOOP_HEAPSIZE=\"{{hive_metastore_heapsize}}\"\n" + "else\n" + " export HADOOP_HEAPSIZE=\"{{hive_heapsize}}\"\n" + "fi\n" + "\n" + "export HADOOP_CLIENT_OPTS=\"$HADOOP_CLIENT_OPTS -Xmx${HADOOP_HEAPSIZE}m\"\n" + "\n" + "# Larger heap size may be required when running queries over large number of files or partitions.\n"; Assert.assertEquals(expectedResult, upgradeCatalog220.updateHiveEnvContent(testContent)); testContent = "# The heap size of the jvm stared by hive shell script can be controlled via:\n" + "export SERVICE=$SERVICE\n" + "if [ \"$SERVICE\" = \"metastore\" ]; then\n" + " export HADOOP_HEAPSIZE=\"{{hive_metastore_heapsize}}\"\n" + "else\n" + " export HADOOP_HEAPSIZE=\"{{hive_heapsize}}\"\n" + "fi\n" + "\n" + "# Larger heap size may be required when running queries over large number of files or partitions.\n"; expectedResult = "# The heap size of the jvm stared by hive shell script can be controlled via:\n" + "export SERVICE=$SERVICE\n" + "if [ \"$SERVICE\" = \"metastore\" ]; then\n" + " export HADOOP_HEAPSIZE=\"{{hive_metastore_heapsize}}\"\n" + "else\n" + " export HADOOP_HEAPSIZE={{hive_heapsize}} # Setting for HiveServer2 and Client\n" + "fi\n" + "\n" + "export HADOOP_CLIENT_OPTS=\"$HADOOP_CLIENT_OPTS -Xmx${HADOOP_HEAPSIZE}m\"\n" + "# Larger heap size may be required when running queries over large number of files or partitions.\n"; Assert.assertEquals(expectedResult, upgradeCatalog220.updateHiveEnvContent(testContent)); }