@Test public void testOozieEnvWithMissingParam() throws Exception { String oldContent = "#!/bin/bash\n" + "\n" + "if [ -d \"/usr/lib/bigtop-tomcat\" ]; then\n" + " export OOZIE_CONFIG=${OOZIE_CONFIG:-/etc/oozie/conf}\n" + " export CATALINA_BASE=${CATALINA_BASE:-{{oozie_server_dir}}}\n" + " export CATALINA_TMPDIR=${CATALINA_TMPDIR:-/var/tmp/oozie}\n" + " export OOZIE_CATALINA_HOME=/usr/lib/bigtop-tomcat\n" + "fi\n" + "\n" + "# export OOZIE_BASE_URL=\"http: "export JAVA_LIBRARY_PATH={{hadoop_lib_home}}/native/Linux-amd64-64"; String newContent = OozieConfigCalculation.processPropertyValue(oldContent); assertTrue(newContent.endsWith("export HADOOP_OPTS=\"-Dhdp.version=$HDP_VERSION $HADOOP_OPTS\" ")); oldContent = newContent; newContent = OozieConfigCalculation.processPropertyValue(oldContent); assertEquals(newContent, oldContent); assertEquals(1, StringUtils.countMatches(newContent, "-Dhdp.version")); oldContent = "#!/bin/bash\n" + "\n" + "if [ -d \"/usr/lib/bigtop-tomcat\" ]; then\n" + " export OOZIE_CONFIG=${OOZIE_CONFIG:-/etc/oozie/conf}\n" + " export CATALINA_BASE=${CATALINA_BASE:-{{oozie_server_dir}}}\n" + " export CATALINA_TMPDIR=${CATALINA_TMPDIR:-/var/tmp/oozie}\n" + " export OOZIE_CATALINA_HOME=/usr/lib/bigtop-tomcat\n" + " export HADOOP_OPTS=-Dsome.option1 -Dsome.option1 $HADOOP_OPTS\n" + "fi\n" + "\n" + "# export OOZIE_BASE_URL=\"http: "export JAVA_LIBRARY_PATH={{hadoop_lib_home}}/native/Linux-amd64-64"; newContent = OozieConfigCalculation.processPropertyValue(oldContent); assertEquals("#!/bin/bash\n" + "\n" + "if [ -d \"/usr/lib/bigtop-tomcat\" ]; then\n" + " export OOZIE_CONFIG=${OOZIE_CONFIG:-/etc/oozie/conf}\n" + " export CATALINA_BASE=${CATALINA_BASE:-{{oozie_server_dir}}}\n" + " export CATALINA_TMPDIR=${CATALINA_TMPDIR:-/var/tmp/oozie}\n" + " export OOZIE_CATALINA_HOME=/usr/lib/bigtop-tomcat\n" + " export HADOOP_OPTS=-Dsome.option1 -Dsome.option1 $HADOOP_OPTS\n" + "fi\n" + "\n" + "# export OOZIE_BASE_URL=\"http: "export JAVA_LIBRARY_PATH={{hadoop_lib_home}}/native/Linux-amd64-64\n" + "export HADOOP_OPTS=\"-Dhdp.version=$HDP_VERSION $HADOOP_OPTS\" ", newContent); }
public static String processPropertyValue(String oldContent) { Pattern regex = Pattern.compile("^export HADOOP_OPTS=.*-Dhdp.version=.*$", Pattern.MULTILINE); Matcher regexMatcher = regex.matcher(oldContent); if (regexMatcher.find()) { return oldContent; } else { StringBuilder newContent = new StringBuilder(oldContent); newContent.append("\n").append( "export HADOOP_OPTS=\"-Dhdp.version=$HDP_VERSION $HADOOP_OPTS\" " ); return newContent.toString(); } }
OozieConfigCalculation extends AbstractServerAction { public static String processPropertyValue(String oldContent) { Pattern regex = Pattern.compile("^export HADOOP_OPTS=.*-Dhdp.version=.*$", Pattern.MULTILINE); Matcher regexMatcher = regex.matcher(oldContent); if (regexMatcher.find()) { return oldContent; } else { StringBuilder newContent = new StringBuilder(oldContent); newContent.append("\n").append( "export HADOOP_OPTS=\"-Dhdp.version=$HDP_VERSION $HADOOP_OPTS\" " ); return newContent.toString(); } } }
OozieConfigCalculation extends AbstractServerAction { public static String processPropertyValue(String oldContent) { Pattern regex = Pattern.compile("^export HADOOP_OPTS=.*-Dhdp.version=.*$", Pattern.MULTILINE); Matcher regexMatcher = regex.matcher(oldContent); if (regexMatcher.find()) { return oldContent; } else { StringBuilder newContent = new StringBuilder(oldContent); newContent.append("\n").append( "export HADOOP_OPTS=\"-Dhdp.version=$HDP_VERSION $HADOOP_OPTS\" " ); return newContent.toString(); } }  }
OozieConfigCalculation extends AbstractServerAction { public static String processPropertyValue(String oldContent) { Pattern regex = Pattern.compile("^export HADOOP_OPTS=.*-Dhdp.version=.*$", Pattern.MULTILINE); Matcher regexMatcher = regex.matcher(oldContent); if (regexMatcher.find()) { return oldContent; } else { StringBuilder newContent = new StringBuilder(oldContent); newContent.append("\n").append( "export HADOOP_OPTS=\"-Dhdp.version=$HDP_VERSION $HADOOP_OPTS\" " ); return newContent.toString(); } }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext); static String processPropertyValue(String oldContent); }
OozieConfigCalculation extends AbstractServerAction { public static String processPropertyValue(String oldContent) { Pattern regex = Pattern.compile("^export HADOOP_OPTS=.*-Dhdp.version=.*$", Pattern.MULTILINE); Matcher regexMatcher = regex.matcher(oldContent); if (regexMatcher.find()) { return oldContent; } else { StringBuilder newContent = new StringBuilder(oldContent); newContent.append("\n").append( "export HADOOP_OPTS=\"-Dhdp.version=$HDP_VERSION $HADOOP_OPTS\" " ); return newContent.toString(); } }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext); static String processPropertyValue(String oldContent);  }