HADOOP-14400. Fix warnings from spotbugs in hadoop-tools. Contributed by Weiwei Yang.

This commit is contained in:
Akira Ajisaka 2017-05-10 05:57:12 -05:00
parent a5fa954684
commit 2ba9903932
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
9 changed files with 58 additions and 49 deletions

View File

@ -2451,8 +2451,6 @@ public boolean mkdirs(Path f, FsPermission permission, boolean noUmask) throws I
ArrayList<String> keysToCreateAsFolder = new ArrayList<String>(); ArrayList<String> keysToCreateAsFolder = new ArrayList<String>();
ArrayList<String> keysToUpdateAsFolder = new ArrayList<String>();
boolean childCreated = false;
// Check that there is no file in the parent chain of the given path. // Check that there is no file in the parent chain of the given path.
for (Path current = absolutePath, parent = current.getParent(); for (Path current = absolutePath, parent = current.getParent();
parent != null; // Stop when you get to the root parent != null; // Stop when you get to the root
@ -2464,14 +2462,6 @@ public boolean mkdirs(Path f, FsPermission permission, boolean noUmask) throws I
+ current + " is an existing file."); + current + " is an existing file.");
} else if (currentMetadata == null) { } else if (currentMetadata == null) {
keysToCreateAsFolder.add(currentKey); keysToCreateAsFolder.add(currentKey);
childCreated = true;
} else {
// The directory already exists. Its last modified time need to be
// updated if there is a child directory created under it.
if (childCreated) {
keysToUpdateAsFolder.add(currentKey);
}
childCreated = false;
} }
} }

View File

@ -131,9 +131,7 @@ private long[] toLongArray(final ArrayList<Long> sigh) {
static final Comparator<Entry<String,Double>> hostRank = static final Comparator<Entry<String,Double>> hostRank =
new Comparator<Entry<String,Double>>() { new Comparator<Entry<String,Double>>() {
public int compare(Entry<String,Double> a, Entry<String,Double> b) { public int compare(Entry<String,Double> a, Entry<String,Double> b) {
final double va = a.getValue(); return Double.compare(a.getValue(), b.getValue());
final double vb = b.getValue(); }
return va > vb ? -1 : va < vb ? 1 : 0;
}
}; };
} }

View File

@ -19,6 +19,8 @@
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapred.gridmix.Progressive; import org.apache.hadoop.mapred.gridmix.Progressive;
import org.apache.hadoop.tools.rumen.ResourceUsageMetrics; import org.apache.hadoop.tools.rumen.ResourceUsageMetrics;
@ -129,7 +131,7 @@ public void initialize(ResourceCalculatorPlugin monitor,
public static class DefaultHeapUsageEmulator public static class DefaultHeapUsageEmulator
implements HeapUsageEmulatorCore { implements HeapUsageEmulatorCore {
// store the unit loads in a list // store the unit loads in a list
protected static final ArrayList<Object> heapSpace = private static final ArrayList<Object> heapSpace =
new ArrayList<Object>(); new ArrayList<Object>();
/** /**
@ -142,7 +144,17 @@ public void load(long sizeInMB) {
heapSpace.add((Object)new byte[ONE_MB]); heapSpace.add((Object)new byte[ONE_MB]);
} }
} }
/**
* Gets the total number of 1mb objects stored in the emulator.
*
* @return total number of 1mb objects.
*/
@VisibleForTesting
public int getHeapSpaceSize() {
return heapSpace.size();
}
/** /**
* This will initialize the core and check if the core can emulate the * This will initialize the core and check if the core can emulate the
* desired target on the underlying hardware. * desired target on the underlying hardware.

View File

@ -58,7 +58,7 @@ int getNumCalls() {
// Get the total number of 1mb objects stored within // Get the total number of 1mb objects stored within
long getHeapUsageInMB() { long getHeapUsageInMB() {
return heapSpace.size(); return getHeapSpaceSize();
} }
@Override @Override

View File

@ -130,7 +130,7 @@ public DataType<?> parseJobProperty(String key, String value) {
/** /**
* Extracts the -Xmx heap option from the specified string. * Extracts the -Xmx heap option from the specified string.
*/ */
public static void extractMaxHeapOpts(String javaOptions, public static void extractMaxHeapOpts(final String javaOptions,
List<String> heapOpts, List<String> heapOpts,
List<String> others) { List<String> others) {
for (String opt : javaOptions.split(" ")) { for (String opt : javaOptions.split(" ")) {
@ -160,6 +160,7 @@ public static void extractMinHeapOpts(String javaOptions,
// Maps the value of the specified key. // Maps the value of the specified key.
private DataType<?> fromString(String key, String value) { private DataType<?> fromString(String key, String value) {
DefaultDataType defaultValue = new DefaultDataType(value);
if (value != null) { if (value != null) {
// check known configs // check known configs
// job-name // job-name
@ -190,14 +191,13 @@ private DataType<?> fromString(String key, String value) {
// check if the config parameter represents a number // check if the config parameter represents a number
try { try {
format.parse(value); format.parse(value);
return new DefaultDataType(value); return defaultValue;
} catch (ParseException pe) {} } catch (ParseException pe) {}
// check if the config parameters represents a boolean // check if the config parameters represents a boolean
// avoiding exceptions // avoiding exceptions
if ("true".equals(value) || "false".equals(value)) { if ("true".equals(value) || "false".equals(value)) {
Boolean.parseBoolean(value); return defaultValue;
return new DefaultDataType(value);
} }
// check if the config parameter represents a class // check if the config parameter represents a class
@ -208,7 +208,7 @@ private DataType<?> fromString(String key, String value) {
// handle distributed cache sizes and timestamps // handle distributed cache sizes and timestamps
if (latestKey.endsWith("sizes") if (latestKey.endsWith("sizes")
|| latestKey.endsWith(".timestamps")) { || latestKey.endsWith(".timestamps")) {
new DefaultDataType(value); return defaultValue;
} }
// check if the config parameter represents a file-system path // check if the config parameter represents a file-system path

View File

@ -32,6 +32,7 @@
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonFactory;
@ -113,7 +114,8 @@ public class SLSRunner extends Configured implements Tool {
// other simulation information // other simulation information
private int numNMs, numRacks, numAMs, numTasks; private int numNMs, numRacks, numAMs, numTasks;
private long maxRuntime; private long maxRuntime;
public final static Map<String, Object> simulateInfoMap =
private final static Map<String, Object> simulateInfoMap =
new HashMap<String, Object>(); new HashMap<String, Object>();
// logger // logger
@ -165,6 +167,13 @@ private void init(Configuration tempConf) throws ClassNotFoundException {
} }
} }
/**
* @return an unmodifiable view of the simulated info map.
*/
public static Map<String, Object> getSimulateInfoMap() {
return Collections.unmodifiableMap(simulateInfoMap);
}
public void setSimulationParams(TraceType inType, String[] inTraces, public void setSimulationParams(TraceType inType, String[] inTraces,
String nodes, String outDir, Set<String> trackApps, String nodes, String outDir, Set<String> trackApps,
boolean printsimulation) throws IOException, ClassNotFoundException { boolean printsimulation) throws IOException, ClassNotFoundException {

View File

@ -180,16 +180,16 @@ public void trackQueue(String queueName) {
new Gauge<Long>() { new Gauge<Long>() {
@Override @Override
public Long getValue() { public Long getValue() {
if (! maxReset && if (! maxReset
SLSRunner.simulateInfoMap.containsKey("Number of nodes") && && SLSRunner.getSimulateInfoMap().containsKey("Number of nodes")
SLSRunner.simulateInfoMap.containsKey("Node memory (MB)") && && SLSRunner.getSimulateInfoMap().containsKey("Node memory (MB)")
SLSRunner.simulateInfoMap.containsKey("Node VCores")) { && SLSRunner.getSimulateInfoMap().containsKey("Node VCores")) {
int numNMs = Integer.parseInt( int numNMs = Integer.parseInt(SLSRunner.getSimulateInfoMap()
SLSRunner.simulateInfoMap.get("Number of nodes").toString()); .get("Number of nodes").toString());
int numMemoryMB = Integer.parseInt( int numMemoryMB = Integer.parseInt(SLSRunner.getSimulateInfoMap()
SLSRunner.simulateInfoMap.get("Node memory (MB)").toString()); .get("Node memory (MB)").toString());
int numVCores = Integer.parseInt( int numVCores = Integer.parseInt(SLSRunner.getSimulateInfoMap()
SLSRunner.simulateInfoMap.get("Node VCores").toString()); .get("Node VCores").toString());
totalMemoryMB = numNMs * numMemoryMB; totalMemoryMB = numNMs * numMemoryMB;
totalVCores = numNMs * numVCores; totalVCores = numNMs * numVCores;

View File

@ -187,14 +187,14 @@ private void printPageIndex(HttpServletRequest request,
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
String simulateInfo; String simulateInfo;
if (SLSRunner.simulateInfoMap.isEmpty()) { if (SLSRunner.getSimulateInfoMap().isEmpty()) {
String empty = "<tr><td colspan='2' align='center'>" + String empty = "<tr><td colspan='2' align='center'>" +
"No information available</td></tr>"; "No information available</td></tr>";
simulateInfo = MessageFormat.format(simulateInfoTemplate, empty); simulateInfo = MessageFormat.format(simulateInfoTemplate, empty);
} else { } else {
StringBuilder info = new StringBuilder(); StringBuilder info = new StringBuilder();
for (Map.Entry<String, Object> entry : for (Map.Entry<String, Object> entry :
SLSRunner.simulateInfoMap.entrySet()) { SLSRunner.getSimulateInfoMap().entrySet()) {
info.append("<tr>"); info.append("<tr>");
info.append("<td class='td1'>").append(entry.getKey()).append("</td>"); info.append("<td class='td1'>").append(entry.getKey()).append("</td>");
info.append("<td class='td2'>").append(entry.getValue()) info.append("<td class='td2'>").append(entry.getValue())

View File

@ -20,7 +20,6 @@
import org.junit.Assert; import org.junit.Assert;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.hadoop.yarn.sls.SLSRunner;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@ -28,6 +27,7 @@
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.HashMap;
public class TestSLSWebApp { public class TestSLSWebApp {
@ -36,20 +36,21 @@ public void testSimulateInfoPageHtmlTemplate() throws Exception {
String simulateInfoTemplate = FileUtils.readFileToString( String simulateInfoTemplate = FileUtils.readFileToString(
new File("src/main/html/simulate.info.html.template")); new File("src/main/html/simulate.info.html.template"));
SLSRunner.simulateInfoMap.put("Number of racks", 10); Map<String, Object> simulateInfoMap = new HashMap<>();
SLSRunner.simulateInfoMap.put("Number of nodes", 100); simulateInfoMap.put("Number of racks", 10);
SLSRunner.simulateInfoMap.put("Node memory (MB)", 1024); simulateInfoMap.put("Number of nodes", 100);
SLSRunner.simulateInfoMap.put("Node VCores", 1); simulateInfoMap.put("Node memory (MB)", 1024);
SLSRunner.simulateInfoMap.put("Number of applications", 100); simulateInfoMap.put("Node VCores", 1);
SLSRunner.simulateInfoMap.put("Number of tasks", 1000); simulateInfoMap.put("Number of applications", 100);
SLSRunner.simulateInfoMap.put("Average tasks per applicaion", 10); simulateInfoMap.put("Number of tasks", 1000);
SLSRunner.simulateInfoMap.put("Number of queues", 4); simulateInfoMap.put("Average tasks per applicaion", 10);
SLSRunner.simulateInfoMap.put("Average applications per queue", 25); simulateInfoMap.put("Number of queues", 4);
SLSRunner.simulateInfoMap.put("Estimated simulate time (s)", 10000); simulateInfoMap.put("Average applications per queue", 25);
simulateInfoMap.put("Estimated simulate time (s)", 10000);
StringBuilder info = new StringBuilder(); StringBuilder info = new StringBuilder();
for (Map.Entry<String, Object> entry : for (Map.Entry<String, Object> entry :
SLSRunner.simulateInfoMap.entrySet()) { simulateInfoMap.entrySet()) {
info.append("<tr>"); info.append("<tr>");
info.append("<td class='td1'>" + entry.getKey() + "</td>"); info.append("<td class='td1'>" + entry.getKey() + "</td>");
info.append("<td class='td2'>" + entry.getValue() + "</td>"); info.append("<td class='td2'>" + entry.getValue() + "</td>");
@ -60,8 +61,7 @@ public void testSimulateInfoPageHtmlTemplate() throws Exception {
MessageFormat.format(simulateInfoTemplate, info.toString()); MessageFormat.format(simulateInfoTemplate, info.toString());
Assert.assertTrue("The simulate info html page should not be empty", Assert.assertTrue("The simulate info html page should not be empty",
simulateInfo.length() > 0); simulateInfo.length() > 0);
for (Map.Entry<String, Object> entry : for (Map.Entry<String, Object> entry : simulateInfoMap.entrySet()) {
SLSRunner.simulateInfoMap.entrySet()) {
Assert.assertTrue("The simulate info html page should have information " Assert.assertTrue("The simulate info html page should have information "
+ "of " + entry.getKey(), simulateInfo.contains("<td class='td1'>" + "of " + entry.getKey(), simulateInfo.contains("<td class='td1'>"
+ entry.getKey() + "</td><td class='td2'>" + entry.getKey() + "</td><td class='td2'>"