Repository: oozie Updated Branches: refs/heads/master f638381da -> d5b9e3690
OOZIE-2955 [oozie-client] Fix Findbugs warnings (Jan Hentschel, kmarton via andras.piros) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/d5b9e369 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/d5b9e369 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/d5b9e369 Branch: refs/heads/master Commit: d5b9e3690de783df389818fa920cdc7d11dabe4d Parents: f638381 Author: Andras Piros <[email protected]> Authored: Mon Jul 2 12:07:03 2018 +0200 Committer: Andras Piros <[email protected]> Committed: Mon Jul 2 12:07:03 2018 +0200 ---------------------------------------------------------------------- .../java/org/apache/oozie/cli/CLIParser.java | 21 +-- .../java/org/apache/oozie/cli/OozieCLI.java | 143 +++++++++---------- .../apache/oozie/client/AuthOozieClient.java | 28 ++-- .../org/apache/oozie/client/OozieClient.java | 132 ++++++++--------- .../org/apache/oozie/client/XOozieClient.java | 44 +++--- release-log.txt | 1 + 6 files changed, 174 insertions(+), 195 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/d5b9e369/client/src/main/java/org/apache/oozie/cli/CLIParser.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/oozie/cli/CLIParser.java b/client/src/main/java/org/apache/oozie/cli/CLIParser.java index bbdb803..f6b49b5 100644 --- a/client/src/main/java/org/apache/oozie/cli/CLIParser.java +++ b/client/src/main/java/org/apache/oozie/cli/CLIParser.java @@ -18,14 +18,17 @@ package org.apache.oozie.cli; +import com.google.common.base.Charsets; import org.apache.commons.cli.MissingOptionException; import org.apache.commons.cli.Options; import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.UnrecognizedOptionException; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; import java.util.Arrays; import java.util.Map; import java.util.LinkedHashMap; @@ -42,9 +45,9 @@ public class CLIParser { private String cliName; private String[] cliHelp; - private Map<String, Options> commands = new LinkedHashMap<String, Options>(); - private Map<String, Boolean> commandWithArgs = new LinkedHashMap<String, Boolean>(); - private Map<String, String> commandsHelp = new LinkedHashMap<String, String>(); + private Map<String, Options> commands = new LinkedHashMap<>(); + private Map<String, Boolean> commandWithArgs = new LinkedHashMap<>(); + private Map<String, String> commandsHelp = new LinkedHashMap<>(); /** * Create a parser. @@ -165,7 +168,8 @@ public class CLIParser { * @param commandLine the command line */ public void showHelp(CommandLine commandLine) { - PrintWriter pw = new PrintWriter(System.out); + Writer writer = new OutputStreamWriter(System.out, Charsets.UTF_8); + PrintWriter pw = new PrintWriter(writer); pw.println("usage: "); for (String s : cliHelp) { pw.println(LEFT_PADDING + s); @@ -175,7 +179,7 @@ public class CLIParser { Set<String> commandsToPrint = commands.keySet(); String[] args = commandLine.getArgs(); if (args.length > 0 && commandsToPrint.contains(args[0])) { - commandsToPrint = new HashSet<String>(); + commandsToPrint = new HashSet<>(); commandsToPrint.add(args[0]); } for (String comm : commandsToPrint) { @@ -202,10 +206,7 @@ public class CLIParser { @Override protected void checkRequiredOptions() throws MissingOptionException { - if (ignoreMissingOption) { - return; - } - else { + if (!ignoreMissingOption) { super.checkRequiredOptions(); } } http://git-wip-us.apache.org/repos/asf/oozie/blob/d5b9e369/client/src/main/java/org/apache/oozie/cli/OozieCLI.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/oozie/cli/OozieCLI.java b/client/src/main/java/org/apache/oozie/cli/OozieCLI.java index bc234e3..c289971 100644 --- a/client/src/main/java/org/apache/oozie/cli/OozieCLI.java +++ b/client/src/main/java/org/apache/oozie/cli/OozieCLI.java @@ -19,6 +19,7 @@ package org.apache.oozie.cli; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Charsets; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; @@ -61,9 +62,9 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.FileInputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; @@ -713,41 +714,42 @@ public class OozieCLI { } public void processCommand(CLIParser parser, CLIParser.Command command) throws Exception { - if (command.getName().equals(HELP_CMD)) { - parser.showHelp(command.getCommandLine()); - } - else if (command.getName().equals(JOB_CMD)) { - jobCommand(command.getCommandLine()); - } - else if (command.getName().equals(JOBS_CMD)) { - jobsCommand(command.getCommandLine()); - } - else if (command.getName().equals(ADMIN_CMD)) { - adminCommand(command.getCommandLine()); - } - else if (command.getName().equals(VERSION_CMD)) { - versionCommand(); - } - else if (command.getName().equals(VALIDATE_CMD)) { - validateCommand(command.getCommandLine()); - } - else if (command.getName().equals(SLA_CMD)) { - slaCommand(command.getCommandLine()); - } - else if (command.getName().equals(PIG_CMD)) { - scriptLanguageCommand(command.getCommandLine(), PIG_CMD); - } - else if (command.getName().equals(HIVE_CMD)) { - scriptLanguageCommand(command.getCommandLine(), HIVE_CMD); - } - else if (command.getName().equals(SQOOP_CMD)) { - sqoopCommand(command.getCommandLine()); - } - else if (command.getName().equals(INFO_CMD)) { - infoCommand(command.getCommandLine()); - } - else if (command.getName().equals(MR_CMD)){ - mrCommand(command.getCommandLine()); + switch (command.getName()) { + case JOB_CMD: + jobCommand(command.getCommandLine()); + break; + case JOBS_CMD: + jobsCommand(command.getCommandLine()); + break; + case ADMIN_CMD: + adminCommand(command.getCommandLine()); + break; + case VERSION_CMD: + versionCommand(); + break; + case VALIDATE_CMD: + validateCommand(command.getCommandLine()); + break; + case SLA_CMD: + slaCommand(command.getCommandLine()); + break; + case PIG_CMD: + scriptLanguageCommand(command.getCommandLine(), PIG_CMD); + break; + case HIVE_CMD: + scriptLanguageCommand(command.getCommandLine(), HIVE_CMD); + break; + case SQOOP_CMD: + sqoopCommand(command.getCommandLine()); + break; + case INFO_CMD: + infoCommand(command.getCommandLine()); + break; + case MR_CMD: + mrCommand(command.getCommandLine()); + break; + default: + parser.showHelp(command.getCommandLine()); } } protected String getOozieUrl(CommandLine commandLine) { @@ -792,10 +794,7 @@ public class OozieCLI { Document doc = builder.parse(is); return parseDocument(doc, conf); } - catch (SAXException e) { - throw new IOException(e); - } - catch (ParserConfigurationException e) { + catch (SAXException | ParserConfigurationException e) { throw new IOException(e); } } @@ -857,7 +856,7 @@ public class OozieCLI { throw new IOException("configuration file [" + configFile + "] not found"); } if (configFile.endsWith(".properties")) { - conf.load(new FileReader(file)); + conf.load(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8)); } else if (configFile.endsWith(".xml")) { parse(new FileInputStream(configFile), conf); @@ -881,7 +880,7 @@ public class OozieCLI { * @throws IOException */ private boolean isConfigurationSpecified(OozieClient wc, CommandLine commandLine) throws IOException { - boolean isConf = false; + boolean isConf; String configFile = commandLine.getOptionValue(CONFIG_OPTION); if (configFile == null) { isConf = false; @@ -1005,7 +1004,7 @@ public class OozieCLI { private void jobCommand(CommandLine commandLine) throws IOException, OozieCLIException { XOozieClient wc = createXOozieClient(commandLine); - List<String> options = new ArrayList<String>(); + List<String> options = new ArrayList<>(); for (Option option : commandLine.getOptions()) { options.add(option.getOpt()); } @@ -1058,8 +1057,8 @@ public class OozieCLI { if (commandLine.getOptionValue(KILL_OPTION).contains("-C") && (options.contains(DATE_OPTION) || options.contains(ACTION_OPTION))) { String coordJobId = commandLine.getOptionValue(KILL_OPTION); - String scope = null; - String rangeType = null; + String scope; + String rangeType; if (options.contains(DATE_OPTION) && options.contains(ACTION_OPTION)) { throw new OozieCLIException("Invalid options provided for rerun: either" + DATE_OPTION + " or " + ACTION_OPTION + " expected. Don't use both at the same time."); @@ -1133,8 +1132,8 @@ public class OozieCLI { } else { String coordJobId = commandLine.getOptionValue(RERUN_OPTION); - String scope = null; - String rerunType = null; + String scope; + String rerunType; boolean refresh = false; boolean noCleanup = false; boolean failed = false; @@ -1266,22 +1265,14 @@ public class OozieCLI { } } else if (options.contains(ERROR_LOG_OPTION)) { - PrintStream ps = System.out; - try { + try (PrintStream ps = System.out) { wc.getJobErrorLog(commandLine.getOptionValue(ERROR_LOG_OPTION), ps); } - finally { - ps.close(); - } } else if (options.contains(AUDIT_LOG_OPTION)) { - PrintStream ps = System.out; - try { + try (PrintStream ps = System.out) { wc.getJobAuditLog(commandLine.getOptionValue(AUDIT_LOG_OPTION), ps); } - finally { - ps.close(); - } } else if (options.contains(DEFINITION_OPTION)) { System.out.println(wc.getJobDefinition(commandLine.getOptionValue(DEFINITION_OPTION))); @@ -1728,7 +1719,7 @@ public class OozieCLI { private void jobsCommand(CommandLine commandLine) throws IOException, OozieCLIException { XOozieClient wc = createXOozieClient(commandLine); - List<String> options = new ArrayList<String>(); + List<String> options = new ArrayList<>(); for (Option option : commandLine.getOptions()) { options.add(option.getOpt()); } @@ -1970,13 +1961,13 @@ public class OozieCLI { private void adminCommand(CommandLine commandLine) throws OozieCLIException { XOozieClient wc = createXOozieClient(commandLine); - List<String> options = new ArrayList<String>(); + List<String> options = new ArrayList<>(); for (Option option : commandLine.getOptions()) { options.add(option.getOpt()); } try { - SYSTEM_MODE status = SYSTEM_MODE.NORMAL; + SYSTEM_MODE status; if (options.contains(VERSION_OPTION)) { System.out.println("Oozie server build version: " + wc.getServerBuildVersion()); } @@ -2023,22 +2014,22 @@ public class OozieCLI { } } else if (options.contains(AVAILABLE_SERVERS_OPTION)) { - Map<String, String> availableOozieServers = new TreeMap<String, String>(wc.getAvailableOozieServers()); + Map<String, String> availableOozieServers = new TreeMap<>(wc.getAvailableOozieServers()); for (Map.Entry<String, String> ent : availableOozieServers.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } } else if (options.contains(SERVER_CONFIGURATION_OPTION)) { - Map<String, String> serverConfig = new TreeMap<String, String>(wc.getServerConfiguration()); + Map<String, String> serverConfig = new TreeMap<>(wc.getServerConfiguration()); for (Map.Entry<String, String> ent : serverConfig.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } } else if (options.contains(SERVER_OS_ENV_OPTION)) { - Map<String, String> osEnv = new TreeMap<String, String>(wc.getOSEnv()); + Map<String, String> osEnv = new TreeMap<>(wc.getOSEnv()); for (Map.Entry<String, String> ent : osEnv.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } } else if (options.contains(SERVER_JAVA_SYSTEM_PROPERTIES_OPTION)) { - Map<String, String> javaSysProps = new TreeMap<String, String>(wc.getJavaSystemProperties()); + Map<String, String> javaSysProps = new TreeMap<>(wc.getJavaSystemProperties()); for (Map.Entry<String, String> ent : javaSysProps.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } @@ -2153,7 +2144,7 @@ public class OozieCLI { return "-"; } - SimpleDateFormat dateFormater = null; + SimpleDateFormat dateFormater; if (verbose) { dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz", Locale.US); } @@ -2181,7 +2172,7 @@ public class OozieCLI { } try { XOozieClient wc = createXOozieClient(commandLine); - String result = wc.validateXML(args[0].toString()); + String result = wc.validateXML(args[0]); if (result == null) { return; } @@ -2213,7 +2204,7 @@ public class OozieCLI { XOozieClient wc = createXOozieClient(commandLine); Properties conf = getConfiguration(wc, commandLine); String script = commandLine.getOptionValue(SCRIPTFILE_OPTION); - List<String> paramsList = new ArrayList<String>(); + List<String> paramsList = new ArrayList<>(); if (commandLine.hasOption("P")) { Properties params = commandLine.getOptionProperties("P"); for (String key : params.stringPropertyNames()) { @@ -2366,27 +2357,26 @@ public class OozieCLI { private void printMetrics(OozieClient.Metrics metrics) { System.out.println("COUNTERS"); System.out.println("--------"); - Map<String, Long> counters = new TreeMap<String, Long>(metrics.getCounters()); + Map<String, Long> counters = new TreeMap<>(metrics.getCounters()); for (Map.Entry<String, Long> ent : counters.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } System.out.println("\nGAUGES"); System.out.println("------"); - Map<String, Object> gauges = new TreeMap<String, Object>(metrics.getGauges()); + Map<String, Object> gauges = new TreeMap<>(metrics.getGauges()); for (Map.Entry<String, Object> ent : gauges.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } System.out.println("\nTIMERS"); System.out.println("------"); - Map<String, OozieClient.Metrics.Timer> timers = new TreeMap<String, OozieClient.Metrics.Timer>(metrics.getTimers()); + Map<String, OozieClient.Metrics.Timer> timers = new TreeMap<>(metrics.getTimers()); for (Map.Entry<String, OozieClient.Metrics.Timer> ent : timers.entrySet()) { System.out.println(ent.getKey()); System.out.println(ent.getValue()); } System.out.println("\nHISTOGRAMS"); System.out.println("----------"); - Map<String, OozieClient.Metrics.Histogram> histograms = - new TreeMap<String, OozieClient.Metrics.Histogram>(metrics.getHistograms()); + Map<String, OozieClient.Metrics.Histogram> histograms = new TreeMap<>(metrics.getHistograms()); for (Map.Entry<String, OozieClient.Metrics.Histogram> ent : histograms.entrySet()) { System.out.println(ent.getKey()); System.out.println(ent.getValue()); @@ -2396,26 +2386,25 @@ public class OozieCLI { private void printInstrumentation(OozieClient.Instrumentation instrumentation) { System.out.println("COUNTERS"); System.out.println("--------"); - Map<String, Long> counters = new TreeMap<String, Long>(instrumentation.getCounters()); + Map<String, Long> counters = new TreeMap<>(instrumentation.getCounters()); for (Map.Entry<String, Long> ent : counters.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } System.out.println("\nVARIABLES"); System.out.println("---------"); - Map<String, Object> variables = new TreeMap<String, Object>(instrumentation.getVariables()); + Map<String, Object> variables = new TreeMap<>(instrumentation.getVariables()); for (Map.Entry<String, Object> ent : variables.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } System.out.println("\nSAMPLERS"); System.out.println("---------"); - Map<String, Double> samplers = new TreeMap<String, Double>(instrumentation.getSamplers()); + Map<String, Double> samplers = new TreeMap<>(instrumentation.getSamplers()); for (Map.Entry<String, Double> ent : samplers.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } System.out.println("\nTIMERS"); System.out.println("---------"); - Map<String, OozieClient.Instrumentation.Timer> timers = - new TreeMap<String, OozieClient.Instrumentation.Timer>(instrumentation.getTimers()); + Map<String, OozieClient.Instrumentation.Timer> timers = new TreeMap<>(instrumentation.getTimers()); for (Map.Entry<String, OozieClient.Instrumentation.Timer> ent : timers.entrySet()) { System.out.println(ent.getKey()); System.out.println(ent.getValue()); http://git-wip-us.apache.org/repos/asf/oozie/blob/d5b9e369/client/src/main/java/org/apache/oozie/client/AuthOozieClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/oozie/client/AuthOozieClient.java b/client/src/main/java/org/apache/oozie/client/AuthOozieClient.java index 98f421f..3a8b5ab 100644 --- a/client/src/main/java/org/apache/oozie/client/AuthOozieClient.java +++ b/client/src/main/java/org/apache/oozie/client/AuthOozieClient.java @@ -20,9 +20,11 @@ package org.apache.oozie.client; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.Writer; import java.lang.management.ManagementFactory; import java.net.HttpURLConnection; @@ -32,6 +34,7 @@ import java.nio.file.StandardCopyOption; import java.util.HashMap; import java.util.Map; +import com.google.common.base.Charsets; import org.apache.hadoop.security.authentication.client.AuthenticatedURL; import org.apache.hadoop.security.authentication.client.AuthenticationException; import org.apache.hadoop.security.authentication.client.Authenticator; @@ -61,7 +64,7 @@ public class AuthOozieClient extends XOozieClient { */ public static final File AUTH_TOKEN_CACHE_FILE = new File(System.getProperty("user.home"), ".oozie-auth-token"); - public static enum AuthType { + public enum AuthType { KERBEROS, SIMPLE } @@ -107,7 +110,7 @@ public class AuthOozieClient extends XOozieClient { protected HttpURLConnection createConnection(URL url, String method) throws IOException, OozieClientException { boolean useAuthFile = System.getProperty(USE_AUTH_TOKEN_CACHE_SYS_PROP, "false").equalsIgnoreCase("true"); AuthenticatedURL.Token readToken = null; - AuthenticatedURL.Token currentToken = null; + AuthenticatedURL.Token currentToken; // Read the token in from the file if (useAuthFile) { @@ -215,7 +218,8 @@ public class AuthOozieClient extends XOozieClient { AuthenticatedURL.Token authToken = null; if (AUTH_TOKEN_CACHE_FILE.exists()) { try { - BufferedReader reader = new BufferedReader(new FileReader(AUTH_TOKEN_CACHE_FILE)); + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(AUTH_TOKEN_CACHE_FILE), + Charsets.UTF_8)); String line = reader.readLine(); reader.close(); if (line != null) { @@ -245,7 +249,7 @@ public class AuthOozieClient extends XOozieClient { new File(System.getProperty("user.home"))); // just to be safe, if something goes wrong delete tmp file eventually tmpTokenFile.deleteOnExit(); - Writer writer = new FileWriter(tmpTokenFile); + Writer writer = new OutputStreamWriter(new FileOutputStream(tmpTokenFile), Charsets.UTF_8); writer.write(authToken.toString()); writer.close(); Files.move(tmpTokenFile.toPath(), AUTH_TOKEN_CACHE_FILE.toPath(), StandardCopyOption.ATOMIC_MOVE); @@ -292,12 +296,7 @@ public class AuthOozieClient extends XOozieClient { "Invalid options provided for auth: " + authOption + ", (" + AuthType.KERBEROS + " or " + AuthType.SIMPLE + " expected.)"); } - catch (InstantiationException ex) { - throw new OozieClientException(OozieClientException.AUTHENTICATION, - "Could not instantiate Authenticator for option [" + authOption + "], " + - ex.getMessage(), ex); - } - catch (IllegalAccessException ex) { + catch (InstantiationException | IllegalAccessException ex) { throw new OozieClientException(OozieClientException.AUTHENTICATION, "Could not instantiate Authenticator for option [" + authOption + "], " + ex.getMessage(), ex); @@ -309,7 +308,7 @@ public class AuthOozieClient extends XOozieClient { if (className != null) { try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); - Class<? extends Object> klass = (cl != null) ? cl.loadClass(className) : + Class<?> klass = (cl != null) ? cl.loadClass(className) : getClass().getClassLoader().loadClass(className); if (klass == null) { throw new OozieClientException(OozieClientException.AUTHENTICATION, @@ -339,7 +338,7 @@ public class AuthOozieClient extends XOozieClient { * @return the map for classes of Authenticator */ protected Map<String, Class<? extends Authenticator>> getAuthenticators() { - Map<String, Class<? extends Authenticator>> authClasses = new HashMap<String, Class<? extends Authenticator>>(); + Map<String, Class<? extends Authenticator>> authClasses = new HashMap<>(); authClasses.put(AuthType.KERBEROS.toString(), KerberosAuthenticator.class); authClasses.put(AuthType.SIMPLE.toString(), PseudoAuthenticator.class); authClasses.put(null, KerberosAuthenticator.class); @@ -354,5 +353,4 @@ public class AuthOozieClient extends XOozieClient { public String getAuthOption() { return authOption; } - } http://git-wip-us.apache.org/repos/asf/oozie/blob/d5b9e369/client/src/main/java/org/apache/oozie/client/OozieClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/oozie/client/OozieClient.java b/client/src/main/java/org/apache/oozie/client/OozieClient.java index 2cc1692..949b453 100644 --- a/client/src/main/java/org/apache/oozie/client/OozieClient.java +++ b/client/src/main/java/org/apache/oozie/client/OozieClient.java @@ -20,10 +20,9 @@ package org.apache.oozie.client; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Charsets; import com.google.common.base.Strings; import com.google.common.collect.Lists; -import org.apache.commons.io.IOUtils; -import com.google.common.collect.Lists; import org.apache.oozie.BuildInfo; import org.apache.oozie.cli.ValidationUtil; import org.apache.oozie.client.rest.JsonTags; @@ -54,7 +53,6 @@ import java.io.Reader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -213,7 +211,7 @@ public class OozieClient { } } - public static enum SYSTEM_MODE { + public enum SYSTEM_MODE { NORMAL, NOWEBSERVICE, SAFEMODE } @@ -244,7 +242,6 @@ public class OozieClient { private int retryCount = 4; - private String baseUrl; private String protocolUrl; private boolean validatedVersion = false; @@ -414,7 +411,7 @@ public class OozieClient { HttpURLConnection conn = createRetryableConnection(url, "GET"); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { - versions = (JSONArray) JSONValue.parse(new InputStreamReader(conn.getInputStream())); + versions = (JSONArray) JSONValue.parse(new InputStreamReader(conn.getInputStream(), Charsets.UTF_8)); } else { handleError(conn); @@ -498,8 +495,8 @@ public class OozieClient { String separator = "?"; for (Map.Entry<String, String> param : parameters.entrySet()) { if (param.getValue() != null) { - sb.append(separator).append(URLEncoder.encode(param.getKey(), "UTF-8")).append("=").append( - URLEncoder.encode(param.getValue(), "UTF-8")); + sb.append(separator).append(URLEncoder.encode(param.getKey(), Charsets.UTF_8.name())).append("=").append( + URLEncoder.encode(param.getValue(), Charsets.UTF_8.name())); separator = "&"; } } @@ -529,8 +526,7 @@ public class OozieClient { return (HttpURLConnection) new ConnectionRetriableClient(getRetryCount()) { @Override public Object doExecute(URL url, String method) throws IOException, OozieClientException { - HttpURLConnection conn = createConnection(url, method); - return conn; + return createConnection(url, method); } }.execute(url, method); } @@ -608,7 +604,7 @@ public class OozieClient { @Override protected Map<String, String> call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); Map<String, String> map = new HashMap<>(); for (Object key : json.keySet()) { @@ -731,7 +727,7 @@ public class OozieClient { writeToXml(conf, conn.getOutputStream()); if (conn.getResponseCode() == HttpURLConnection.HTTP_CREATED) { - JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); + JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream(), Charsets.UTF_8)); return (String) json.get(JsonTags.JOB_ID); } @@ -792,9 +788,8 @@ public class OozieClient { protected JSONObject call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); - JSONObject json = (JSONObject) JSONValue.parse(reader); - return json; + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); + return (JSONObject) JSONValue.parse(reader); } else { handleError(conn); @@ -853,7 +848,7 @@ public class OozieClient { writeToXml(conf, conn.getOutputStream()); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { - JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); + JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream(), Charsets.UTF_8)); JSONObject update = (JSONObject) json.get(JsonTags.COORD_UPDATE); if (update != null) { return (String) update.get(JsonTags.COORD_UPDATE_DIFF); @@ -1012,7 +1007,7 @@ public class OozieClient { @Override protected WorkflowJob call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return JsonToBean.createWorkflowJob(json); } @@ -1031,7 +1026,7 @@ public class OozieClient { protected JMSConnectionInfo call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return JsonToBean.createJMSConnectionInfo(json); } @@ -1051,7 +1046,7 @@ public class OozieClient { @Override protected WorkflowAction call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return JsonToBean.createWorkflowAction(json); } @@ -1072,7 +1067,7 @@ public class OozieClient { protected List<Map<String, String>> call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return new ObjectMapper().readValue(json.get(JsonTags.WORKFLOW_ACTION_RETRIES).toString(), new TypeReference<List<Map<String, String>>>() { @@ -1244,7 +1239,7 @@ public class OozieClient { protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.JMS_TOPIC_NAME); } @@ -1308,7 +1303,7 @@ public class OozieClient { @SuppressWarnings("unchecked") protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); if (json != null) { JSONArray inputDependencies = (JSONArray) json.get(JsonTags.COORD_ACTION_MISSING_DEPENDENCIES); @@ -1338,9 +1333,8 @@ public class OozieClient { printStream.println("Pending Dependencies : "); if (inputDependenciesList != null) { - Iterator<String> iterator = inputDependenciesList.iterator(); - while (iterator.hasNext()) { - printStream.println("\t " + iterator.next()); + for (String anInputDependenciesList : (Iterable<String>) inputDependenciesList) { + printStream.println("\t " + anInputDependenciesList); } } printStream.println(); @@ -1394,18 +1388,13 @@ public class OozieClient { String returnVal = null; if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { InputStream is = conn.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - try { + try (InputStreamReader isr = new InputStreamReader(is, Charsets.UTF_8)) { if (printStream != null) { sendToOutputStream(isr, -1, printStream); - } - else { + } else { returnVal = getReaderAsString(isr, -1); } } - finally { - isr.close(); - } } else { handleError(conn); @@ -1482,7 +1471,7 @@ public class OozieClient { @Override protected CoordinatorJob call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return JsonToBean.createCoordinatorJob(json); } @@ -1503,7 +1492,7 @@ public class OozieClient { @Override protected List<WorkflowJob> call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); JSONArray workflows = (JSONArray) json.get(JsonTags.WORKFLOWS_JOBS); if (workflows == null) { @@ -1529,7 +1518,7 @@ public class OozieClient { @Override protected BundleJob call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return JsonToBean.createBundleJob(json); } @@ -1549,7 +1538,7 @@ public class OozieClient { @Override protected CoordinatorAction call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return JsonToBean.createCoordinatorAction(json); } @@ -1640,7 +1629,7 @@ public class OozieClient { protected List<WorkflowJob> call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); JSONArray workflows = (JSONArray) json.get(JsonTags.WORKFLOWS_JOBS); if (workflows == null) { @@ -1667,7 +1656,7 @@ public class OozieClient { protected List<CoordinatorJob> call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); JSONArray jobs = (JSONArray) json.get(JsonTags.COORDINATOR_JOBS); if (jobs == null) { @@ -1694,7 +1683,7 @@ public class OozieClient { protected List<BundleJob> call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); JSONArray jobs = (JSONArray) json.get(JsonTags.BUNDLE_JOBS); if (jobs == null) { @@ -1720,7 +1709,7 @@ public class OozieClient { protected List<BulkResponse> call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); JSONArray results = (JSONArray) json.get(JsonTags.BULK_RESPONSES); if (results == null) { @@ -1747,7 +1736,7 @@ public class OozieClient { protected List<CoordinatorAction> call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); JSONArray coordActions = (JSONArray) json.get(JsonTags.COORDINATOR_ACTIONS); return JsonToBean.createCoordinatorActionList(coordActions); @@ -1770,7 +1759,7 @@ public class OozieClient { protected List<CoordinatorAction> call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); if(json != null) { JSONArray coordActions = (JSONArray) json.get(JsonTags.COORDINATOR_ACTIONS); @@ -1800,7 +1789,7 @@ public class OozieClient { protected List<CoordinatorAction> call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); JSONArray coordActions = (JSONArray) json.get(JsonTags.COORDINATOR_ACTIONS); return JsonToBean.createCoordinatorActionList(coordActions); @@ -2015,9 +2004,7 @@ public class OozieClient { */ protected String mapToString(Map<String, String> map) { StringBuilder sb = new StringBuilder(); - Iterator<Entry<String, String>> it = map.entrySet().iterator(); - while (it.hasNext()) { - Entry<String, String> e = (Entry<String, String>) it.next(); + for (Entry<String, String> e : map.entrySet()) { sb.append(e.getKey()).append("=").append(e.getValue()).append(";"); } return sb.toString(); @@ -2074,8 +2061,8 @@ public class OozieClient { protected Void call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); - String line = null; + BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charsets.UTF_8)); + String line; while ((line = br.readLine()) != null) { System.out.println(line); } @@ -2097,7 +2084,7 @@ public class OozieClient { @Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.JOB_ID); } @@ -2157,7 +2144,7 @@ public class OozieClient { @Override protected SYSTEM_MODE call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return SYSTEM_MODE.valueOf((String) json.get(JsonTags.OOZIE_SYSTEM_MODE)); } @@ -2199,7 +2186,7 @@ public class OozieClient { @Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return json.get(JsonTags.BUILD_INFO).toString(); } @@ -2226,13 +2213,13 @@ public class OozieClient { if (file.startsWith("/")) { FileInputStream fi = new FileInputStream(new File(file)); byte[] buffer = new byte[1024]; - int n = 0; + int n; while (-1 != (n = fi.read(buffer))) { conn.getOutputStream().write(buffer, 0, n); } } if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.VALIDATE); } @@ -2273,8 +2260,8 @@ public class OozieClient { protected String call(HttpURLConnection conn) throws IOException, OozieClientException { StringBuffer bf = new StringBuffer(); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); - Object sharelib = (Object) JSONValue.parse(reader); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); + Object sharelib = JSONValue.parse(reader); bf.append("[ShareLib update status]").append(System.getProperty("line.separator")); if (sharelib instanceof JSONArray) { for (Object o : ((JSONArray) sharelib)) { @@ -2315,7 +2302,7 @@ public class OozieClient { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { StringBuffer bf = new StringBuffer(); - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); Object sharelib = json.get(JsonTags.SHARELIB_LIB); bf.append("[Available ShareLib]").append(System.getProperty("line.separator")); @@ -2398,7 +2385,7 @@ public class OozieClient { @Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { - Reader reader = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject jsonObject = (JSONObject) JSONValue.parse(reader); Object msg = jsonObject.get(JsonTags.PURGE); return msg.toString(); @@ -2559,7 +2546,7 @@ public class OozieClient { @Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.STATUS); } @@ -2582,7 +2569,7 @@ public class OozieClient { return null; } - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); List<String> queueDumpMessages = Lists.newArrayList(); @@ -2724,10 +2711,9 @@ public class OozieClient { @Override protected Metrics call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); - Metrics metrics = new Metrics(json); - return metrics; + return new Metrics(json); } else if ((conn.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE)) { // Use Instrumentation endpoint @@ -2749,28 +2735,28 @@ public class OozieClient { @SuppressWarnings("unchecked") public Metrics(JSONObject json) { JSONObject jCounters = (JSONObject) json.get("counters"); - counters = new HashMap<String, Long>(jCounters.size()); + counters = new HashMap<>(jCounters.size()); for (Object entO : jCounters.entrySet()) { Entry<String, JSONObject> ent = (Entry<String, JSONObject>) entO; counters.put(ent.getKey(), (Long)ent.getValue().get("count")); } JSONObject jGuages = (JSONObject) json.get("gauges"); - gauges = new HashMap<String, Object>(jGuages.size()); + gauges = new HashMap<>(jGuages.size()); for (Object entO : jGuages.entrySet()) { Entry<String, JSONObject> ent = (Entry<String, JSONObject>) entO; gauges.put(ent.getKey(), ent.getValue().get("value")); } JSONObject jTimers = (JSONObject) json.get("timers"); - timers = new HashMap<String, Timer>(jTimers.size()); + timers = new HashMap<>(jTimers.size()); for (Object entO : jTimers.entrySet()) { Entry<String, JSONObject> ent = (Entry<String, JSONObject>) entO; timers.put(ent.getKey(), new Timer(ent.getValue())); } JSONObject jHistograms = (JSONObject) json.get("histograms"); - histograms = new HashMap<String, Histogram>(jHistograms.size()); + histograms = new HashMap<>(jHistograms.size()); for (Object entO : jHistograms.entrySet()) { Entry<String, JSONObject> ent = (Entry<String, JSONObject>) entO; histograms.put(ent.getKey(), new Histogram(ent.getValue())); @@ -2957,10 +2943,9 @@ public class OozieClient { @Override protected Instrumentation call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { - Reader reader = new InputStreamReader(conn.getInputStream()); + Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); - Instrumentation instrumentation = new Instrumentation(json); - return instrumentation; + return new Instrumentation(json); } else if ((conn.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE)) { // Use Metrics endpoint @@ -2981,7 +2966,7 @@ public class OozieClient { public Instrumentation(JSONObject json) { JSONArray jCounters = (JSONArray) json.get("counters"); - counters = new HashMap<String, Long>(jCounters.size()); + counters = new HashMap<>(jCounters.size()); for (Object groupO : jCounters) { JSONObject group = (JSONObject) groupO; String groupName = group.get("group").toString() + "."; @@ -2993,7 +2978,7 @@ public class OozieClient { } JSONArray jVariables = (JSONArray) json.get("variables"); - variables = new HashMap<String, Object>(jVariables.size()); + variables = new HashMap<>(jVariables.size()); for (Object groupO : jVariables) { JSONObject group = (JSONObject) groupO; String groupName = group.get("group").toString() + "."; @@ -3005,7 +2990,7 @@ public class OozieClient { } JSONArray jSamplers = (JSONArray) json.get("samplers"); - samplers = new HashMap<String, Double>(jSamplers.size()); + samplers = new HashMap<>(jSamplers.size()); for (Object groupO : jSamplers) { JSONObject group = (JSONObject) groupO; String groupName = group.get("group").toString() + "."; @@ -3017,7 +3002,7 @@ public class OozieClient { } JSONArray jTimers = (JSONArray) json.get("timers"); - timers = new HashMap<String, Timer>(jTimers.size()); + timers = new HashMap<>(jTimers.size()); for (Object groupO : jTimers) { JSONObject group = (JSONObject) groupO; String groupName = group.get("group").toString() + "."; @@ -3162,5 +3147,4 @@ public class OozieClient { } return obj; } - } http://git-wip-us.apache.org/repos/asf/oozie/blob/d5b9e369/client/src/main/java/org/apache/oozie/client/XOozieClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/oozie/client/XOozieClient.java b/client/src/main/java/org/apache/oozie/client/XOozieClient.java index ba60f8e..7761d11 100644 --- a/client/src/main/java/org/apache/oozie/client/XOozieClient.java +++ b/client/src/main/java/org/apache/oozie/client/XOozieClient.java @@ -20,12 +20,15 @@ package org.apache.oozie.client; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.util.Properties; +import com.google.common.base.Charsets; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.apache.commons.io.FilenameUtils; import org.apache.oozie.cli.OozieCLI; import org.apache.oozie.client.rest.JsonTags; import org.apache.oozie.client.rest.RestConstants; @@ -71,6 +74,7 @@ public class XOozieClient extends OozieClient { super(oozieUrl); } + @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "FilenameUtils is used to filter user input. JDK8+ is used.") private String readScript(String script) throws IOException { if (!new File(script).exists()) { throw new IOException("Error: script file [" + script + "] does not exist"); @@ -78,7 +82,8 @@ public class XOozieClient extends OozieClient { BufferedReader br = null; try { - br = new BufferedReader(new FileReader(script)); + br = new BufferedReader(new InputStreamReader(new FileInputStream( + FilenameUtils.getFullPath(script) + FilenameUtils.getName(script)), Charsets.UTF_8)); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { @@ -200,22 +205,23 @@ public class XOozieClient extends OozieClient { OozieClient.notNull(scriptFile, "scriptFile"); validateHttpSubmitConf(conf); - String script = ""; - String options = ""; - String scriptParams = ""; - - if (jobType.equals(OozieCLI.HIVE_CMD)) { - script = XOozieClient.HIVE_SCRIPT; - options = XOozieClient.HIVE_OPTIONS; - scriptParams = XOozieClient.HIVE_SCRIPT_PARAMS; - } - else if (jobType.equals(OozieCLI.PIG_CMD)) { - script = XOozieClient.PIG_SCRIPT; - options = XOozieClient.PIG_OPTIONS; - scriptParams = XOozieClient.PIG_SCRIPT_PARAMS; - } - else { - throw new IllegalArgumentException("jobType must be either pig or hive"); + String script; + String options; + String scriptParams; + + switch (jobType) { + case OozieCLI.HIVE_CMD: + script = XOozieClient.HIVE_SCRIPT; + options = XOozieClient.HIVE_OPTIONS; + scriptParams = XOozieClient.HIVE_SCRIPT_PARAMS; + break; + case OozieCLI.PIG_CMD: + script = XOozieClient.PIG_SCRIPT; + options = XOozieClient.PIG_OPTIONS; + scriptParams = XOozieClient.PIG_SCRIPT_PARAMS; + break; + default: + throw new IllegalArgumentException("jobType must be either pig or hive"); } conf.setProperty(script, readScript(scriptFile)); @@ -273,7 +279,7 @@ public class XOozieClient extends OozieClient { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); writeToXml(conf, conn.getOutputStream()); if (conn.getResponseCode() == HttpURLConnection.HTTP_CREATED) { - JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); + JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream(), Charsets.UTF_8)); return (String) json.get(JsonTags.JOB_ID); } if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { http://git-wip-us.apache.org/repos/asf/oozie/blob/d5b9e369/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 53bcd24..5afa261 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 5.1.0 release (trunk - unreleased) +OOZIE-2955 [oozie-client] Fix Findbugs warnings (Jan Hentschel, kmarton via andras.piros) OOZIE-3109 [log-streaming] Escape HTML-specific characters (dionusos via andras.piros) OOZIE-2956 Fix Findbugs warnings related to reliance on default encoding in oozie-core (Jan Hentschel, kmarton via andras.piros) OOZIE-3295 Flaky test TestSLACalculatorMemory#testAddMultipleRestartRemoveMultipleInstrumentedCorrectly (pbacsko via andras.piros)
