Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add config for timezone of job history server #214

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app-conf/FetcherConf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
files, but also increase the risk of OutOfMemory error. The default heap size of Dr. Elephant
is 1024MB. To increase this, e.g. to 2048MB, run this before start.sh:
export OPTS="-mem 2048"

To work properly, this fetcher should use the same timezone with the job history server.
If not set, the local timezone will be used.
-->
<!--
<fetcher>
Expand All @@ -53,6 +56,7 @@
<params>
<sampling_enabled>false</sampling_enabled>
<history_log_size_limit_in_mb>500</history_log_size_limit_in_mb>
<history_server_time_zone>PST</history_server_time_zone>
</params>
</fetcher>
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;

/**
* This class implements the Fetcher for MapReduce Applications on Hadoop2
Expand All @@ -57,6 +58,7 @@ public class MapReduceFSFetcherHadoop2 extends MapReduceFetcher {
private static final Logger logger = Logger.getLogger(MapReduceFSFetcherHadoop2.class);

private static final String LOG_SIZE_XML_FIELD = "history_log_size_limit_in_mb";
private static final String HISTORY_SERVER_TIME_ZONE_XML_FIELD = "history_server_time_zone";
private static final String TIMESTAMP_DIR_FORMAT = "%04d" + File.separator + "%02d" + File.separator + "%02d";
private static final int SERIAL_NUMBER_DIRECTORY_DIGITS = 6;
protected static final double DEFALUT_MAX_LOG_SIZE_IN_MB = 500;
Expand All @@ -65,6 +67,7 @@ public class MapReduceFSFetcherHadoop2 extends MapReduceFetcher {
private String _historyLocation;
private String _intermediateHistoryLocation;
private double _maxLogSizeInMB;
private TimeZone _timeZone;

public MapReduceFSFetcherHadoop2(FetcherConfigurationData fetcherConfData) throws IOException {
super(fetcherConfData);
Expand All @@ -78,6 +81,10 @@ public MapReduceFSFetcherHadoop2(FetcherConfigurationData fetcherConfData) throw
}
logger.info("The history log limit of MapReduce application is set to " + _maxLogSizeInMB + " MB");

String timeZoneStr = fetcherConfData.getParamMap().get(HISTORY_SERVER_TIME_ZONE_XML_FIELD);
_timeZone = timeZoneStr == null ? TimeZone.getDefault() : TimeZone.getTimeZone(timeZoneStr);
logger.info("Using timezone: " + _timeZone.getID());

Configuration conf = new Configuration();
this._fs = FileSystem.get(conf);
this._historyLocation = conf.get("mapreduce.jobhistory.done-dir");
Expand All @@ -94,6 +101,10 @@ public double getMaxLogSizeInMB() {
return _maxLogSizeInMB;
}

public TimeZone getTimeZone() {
return _timeZone;
}

/**
* The location of a job history file is in format: {done-dir}/yyyy/mm/dd/{serialPart}.
* yyyy/mm/dd is the year, month and date of the finish time.
Expand All @@ -112,7 +123,7 @@ public double getMaxLogSizeInMB() {
*/
protected String getHistoryDir(AnalyticJob job) {
// generate the date part
Calendar timestamp = Calendar.getInstance();
Calendar timestamp = Calendar.getInstance(_timeZone);
timestamp.setTimeInMillis(job.getFinishTime());
String datePart = String.format(TIMESTAMP_DIR_FORMAT,
timestamp.get(Calendar.YEAR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.TimeZone;

public class MapReduceFSFetcherHadoop2Test {

Expand Down Expand Up @@ -77,6 +78,7 @@ public void testFetcherDefaultConfig() {
fetcherConf.getFetchersConfigurationData().get(0));
Assert.assertFalse("Sampling should be disabled in default", fetcher.isSamplingEnabled());
Assert.assertEquals(fetcher.DEFALUT_MAX_LOG_SIZE_IN_MB, fetcher.getMaxLogSizeInMB(), 0.0001);
Assert.assertEquals(TimeZone.getDefault(), fetcher.getTimeZone());

List<Object> list = new ArrayList<Object>();
int listLen = fetcher.MAX_SAMPLE_SIZE * 2;
Expand All @@ -98,6 +100,7 @@ public void testFetcherConfig() {
fetcherConf.getFetchersConfigurationData().get(0));
Assert.assertTrue("Failed to enable sampling", fetcher.isSamplingEnabled());
Assert.assertEquals(200d, fetcher.getMaxLogSizeInMB(), 0.0001);
Assert.assertEquals(TimeZone.getTimeZone("PST"), fetcher.getTimeZone());

List<Object> list = new ArrayList<Object>();
int listLen = fetcher.MAX_SAMPLE_SIZE * 2;
Expand All @@ -119,6 +122,7 @@ public void testFetcherEmptyConf() {
fetcherConf.getFetchersConfigurationData().get(0));
Assert.assertFalse("Sampling should be disabled in default", fetcher.isSamplingEnabled());
Assert.assertEquals(fetcher.DEFALUT_MAX_LOG_SIZE_IN_MB, fetcher.getMaxLogSizeInMB(), 0.0001);
Assert.assertEquals(TimeZone.getDefault(), fetcher.getTimeZone());

List<Object> list = new ArrayList<Object>();
int listLen = fetcher.MAX_SAMPLE_SIZE * 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<params>
<sampling_enabled>true</sampling_enabled>
<history_log_size_limit_in_mb>200</history_log_size_limit_in_mb>
<history_server_time_zone>PST</history_server_time_zone>
</params>
</fetcher>
</fetchers>