HADOOP-15013. Fix ResourceEstimator findbugs issues. (asuresh)
This commit is contained in:
parent
e6ec02001f
commit
53c0fb7efe
@ -65,51 +65,49 @@
|
|||||||
@Singleton @Path("/resourceestimator") public class ResourceEstimatorService {
|
@Singleton @Path("/resourceestimator") public class ResourceEstimatorService {
|
||||||
private static final Logger LOGGER =
|
private static final Logger LOGGER =
|
||||||
LoggerFactory.getLogger(ResourceEstimatorService.class);
|
LoggerFactory.getLogger(ResourceEstimatorService.class);
|
||||||
private static SkylineStore skylineStore;
|
private final SkylineStore skylineStore;
|
||||||
private static Solver solver;
|
private final Solver solver;
|
||||||
private static LogParser logParser;
|
private final LogParser logParser;
|
||||||
private static LogParserUtil logParserUtil = new LogParserUtil();
|
private final LogParserUtil logParserUtil = new LogParserUtil();
|
||||||
private static Configuration config;
|
private final Configuration config;
|
||||||
private static Gson gson;
|
private final Gson gson;
|
||||||
private static Type rleType;
|
private final Type rleType;
|
||||||
private static Type skylineStoreType;
|
private final Type skylineStoreType;
|
||||||
|
|
||||||
public ResourceEstimatorService() throws ResourceEstimatorException {
|
public ResourceEstimatorService() throws ResourceEstimatorException {
|
||||||
if (skylineStore == null) {
|
try {
|
||||||
try {
|
config = new Configuration();
|
||||||
config = new Configuration();
|
config.addResource(ResourceEstimatorConfiguration.CONFIG_FILE);
|
||||||
config.addResource(ResourceEstimatorConfiguration.CONFIG_FILE);
|
skylineStore = ResourceEstimatorUtil.createProviderInstance(config,
|
||||||
skylineStore = ResourceEstimatorUtil.createProviderInstance(config,
|
ResourceEstimatorConfiguration.SKYLINESTORE_PROVIDER,
|
||||||
ResourceEstimatorConfiguration.SKYLINESTORE_PROVIDER,
|
ResourceEstimatorConfiguration.DEFAULT_SKYLINESTORE_PROVIDER,
|
||||||
ResourceEstimatorConfiguration.DEFAULT_SKYLINESTORE_PROVIDER,
|
SkylineStore.class);
|
||||||
SkylineStore.class);
|
logParser = ResourceEstimatorUtil.createProviderInstance(config,
|
||||||
logParser = ResourceEstimatorUtil.createProviderInstance(config,
|
ResourceEstimatorConfiguration.TRANSLATOR_PROVIDER,
|
||||||
ResourceEstimatorConfiguration.TRANSLATOR_PROVIDER,
|
ResourceEstimatorConfiguration.DEFAULT_TRANSLATOR_PROVIDER,
|
||||||
ResourceEstimatorConfiguration.DEFAULT_TRANSLATOR_PROVIDER,
|
LogParser.class);
|
||||||
LogParser.class);
|
logParser.init(config, skylineStore);
|
||||||
logParser.init(config, skylineStore);
|
logParserUtil.setLogParser(logParser);
|
||||||
logParserUtil.setLogParser(logParser);
|
solver = ResourceEstimatorUtil.createProviderInstance(config,
|
||||||
solver = ResourceEstimatorUtil.createProviderInstance(config,
|
ResourceEstimatorConfiguration.SOLVER_PROVIDER,
|
||||||
ResourceEstimatorConfiguration.SOLVER_PROVIDER,
|
ResourceEstimatorConfiguration.DEFAULT_SOLVER_PROVIDER,
|
||||||
ResourceEstimatorConfiguration.DEFAULT_SOLVER_PROVIDER,
|
Solver.class);
|
||||||
Solver.class);
|
solver.init(config, skylineStore);
|
||||||
solver.init(config, skylineStore);
|
} catch (Exception ex) {
|
||||||
} catch (Exception ex) {
|
LOGGER
|
||||||
LOGGER
|
.error("Server initialization failed due to: {}", ex.getMessage());
|
||||||
.error("Server initialization failed due to: {}", ex.getMessage());
|
throw new ResourceEstimatorException(ex.getMessage(), ex);
|
||||||
throw new ResourceEstimatorException(ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
gson = new GsonBuilder()
|
|
||||||
.registerTypeAdapter(Resource.class, new ResourceSerDe())
|
|
||||||
.registerTypeAdapter(RLESparseResourceAllocation.class,
|
|
||||||
new RLESparseResourceAllocationSerDe())
|
|
||||||
.enableComplexMapKeySerialization().create();
|
|
||||||
rleType = new TypeToken<RLESparseResourceAllocation>() {
|
|
||||||
}.getType();
|
|
||||||
skylineStoreType =
|
|
||||||
new TypeToken<Map<RecurrenceId, List<ResourceSkyline>>>() {
|
|
||||||
}.getType();
|
|
||||||
}
|
}
|
||||||
|
gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Resource.class, new ResourceSerDe())
|
||||||
|
.registerTypeAdapter(RLESparseResourceAllocation.class,
|
||||||
|
new RLESparseResourceAllocationSerDe())
|
||||||
|
.enableComplexMapKeySerialization().create();
|
||||||
|
rleType = new TypeToken<RLESparseResourceAllocation>() {
|
||||||
|
}.getType();
|
||||||
|
skylineStoreType =
|
||||||
|
new TypeToken<Map<RecurrenceId, List<ResourceSkyline>>>() {
|
||||||
|
}.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,9 +190,6 @@ public String getHistoryResourceSkyline(
|
|||||||
LOGGER
|
LOGGER
|
||||||
.debug("Query the skyline store for recurrenceId: {}." + recurrenceId);
|
.debug("Query the skyline store for recurrenceId: {}." + recurrenceId);
|
||||||
|
|
||||||
recurrenceId = new RecurrenceId("*", "*");
|
|
||||||
jobHistory = skylineStore.getHistory(recurrenceId);
|
|
||||||
|
|
||||||
return skyline;
|
return skyline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,11 +24,13 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.CharSet;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.resourceestimator.common.api.RecurrenceId;
|
import org.apache.hadoop.resourceestimator.common.api.RecurrenceId;
|
||||||
import org.apache.hadoop.resourceestimator.common.api.ResourceSkyline;
|
import org.apache.hadoop.resourceestimator.common.api.ResourceSkyline;
|
||||||
@ -101,7 +103,8 @@ public void parseLine(final String logLine,
|
|||||||
new HashMap<>();
|
new HashMap<>();
|
||||||
final Map<String, JobMetaData> jobMetas =
|
final Map<String, JobMetaData> jobMetas =
|
||||||
new HashMap<String, JobMetaData>();
|
new HashMap<String, JobMetaData>();
|
||||||
final BufferedReader bf = new BufferedReader(new InputStreamReader(logs));
|
final BufferedReader bf = new BufferedReader(
|
||||||
|
new InputStreamReader(logs, StandardCharsets.UTF_8));
|
||||||
String line = null;
|
String line = null;
|
||||||
while ((line = bf.readLine()) != null) {
|
while ((line = bf.readLine()) != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -91,7 +91,14 @@ public final void parseLog(final String logFile)
|
|||||||
throw new ResourceEstimatorException("The log parser is not initialized,"
|
throw new ResourceEstimatorException("The log parser is not initialized,"
|
||||||
+ " please try again after initializing.");
|
+ " please try again after initializing.");
|
||||||
}
|
}
|
||||||
InputStream inputStream = new FileInputStream(logFile);
|
InputStream inputStream = null;
|
||||||
logParser.parseStream(inputStream);
|
try {
|
||||||
|
inputStream = new FileInputStream(logFile);
|
||||||
|
logParser.parseStream(inputStream);
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,6 @@
|
|||||||
* Test ResourceEstimatorService.
|
* Test ResourceEstimatorService.
|
||||||
*/
|
*/
|
||||||
public class TestResourceEstimatorService extends JerseyTest {
|
public class TestResourceEstimatorService extends JerseyTest {
|
||||||
private static final Logger LOGGER =
|
|
||||||
LoggerFactory.getLogger(TestResourceEstimatorService.class);
|
|
||||||
private final String parseLogCommand = "resourceestimator/translator/"
|
private final String parseLogCommand = "resourceestimator/translator/"
|
||||||
+ "src/test/resources/resourceEstimatorService.txt";
|
+ "src/test/resources/resourceEstimatorService.txt";
|
||||||
private final String getHistorySkylineCommand =
|
private final String getHistorySkylineCommand =
|
||||||
|
Loading…
Reference in New Issue
Block a user