1818
1919package org .apache .hadoop .yarn .logaggregation .filecontroller ;
2020
21- import static org .apache .hadoop .yarn .conf .YarnConfiguration .LOG_AGGREGATION_FILE_CONTROLLER_FMT ;
22- import static org .apache .hadoop .yarn .conf .YarnConfiguration .LOG_AGGREGATION_REMOTE_APP_LOG_DIR_FMT ;
23- import static org .apache .hadoop .yarn .conf .YarnConfiguration .LOG_AGGREGATION_REMOTE_APP_LOG_DIR_SUFFIX_FMT ;
24- import static org .junit .Assert .assertEquals ;
25- import static org .junit .Assert .assertTrue ;
26- import static org .junit .Assert .fail ;
27-
28- import java .io .File ;
29- import java .io .FileWriter ;
30- import java .io .IOException ;
31- import java .io .OutputStream ;
32- import java .io .Writer ;
33- import java .util .Arrays ;
34- import java .util .Collections ;
35- import java .util .List ;
36- import java .util .Map ;
37-
38- import org .apache .commons .lang3 .StringUtils ;
3921import org .apache .hadoop .conf .Configuration ;
4022import org .apache .hadoop .conf .Configured ;
4123import org .apache .hadoop .fs .FileSystem ;
5638import org .slf4j .Logger ;
5739import org .slf4j .LoggerFactory ;
5840
41+ import java .io .File ;
42+ import java .io .FileWriter ;
43+ import java .io .IOException ;
44+ import java .io .OutputStream ;
45+ import java .io .Writer ;
46+ import java .util .Arrays ;
47+ import java .util .Collections ;
48+ import java .util .List ;
49+ import java .util .Map ;
50+
51+ import static org .apache .hadoop .yarn .conf .YarnConfiguration .LOG_AGGREGATION_FILE_FORMATS ;
52+ import static org .apache .hadoop .yarn .logaggregation .LogAggregationTestUtils .REMOTE_LOG_ROOT ;
53+ import static org .apache .hadoop .yarn .logaggregation .LogAggregationTestUtils .enableFileControllers ;
54+ import static org .junit .Assert .*;
55+
5956/**
6057 * Test LogAggregationFileControllerFactory.
6158 */
6259public class TestLogAggregationFileControllerFactory extends Configured {
6360 private static final Logger LOG = LoggerFactory .getLogger (
6461 TestLogAggregationFileControllerFactory .class );
6562
66- private static final String REMOTE_LOG_ROOT = "target/app-logs/" ;
6763 private static final String REMOTE_DEFAULT_DIR = "default/" ;
6864 private static final String APP_OWNER = "test" ;
6965
@@ -87,8 +83,7 @@ public class TestLogAggregationFileControllerFactory extends Configured {
8783 public void setup () throws IOException {
8884 Configuration conf = new YarnConfiguration ();
8985 conf .setBoolean (YarnConfiguration .LOG_AGGREGATION_ENABLED , true );
90- conf .set (YarnConfiguration .NM_REMOTE_APP_LOG_DIR , REMOTE_LOG_ROOT +
91- REMOTE_DEFAULT_DIR );
86+ conf .set (YarnConfiguration .NM_REMOTE_APP_LOG_DIR , REMOTE_LOG_ROOT + REMOTE_DEFAULT_DIR );
9287 conf .set (YarnConfiguration .NM_REMOTE_APP_LOG_DIR_SUFFIX , "log" );
9388 setConf (conf );
9489 }
@@ -143,36 +138,15 @@ public void testDefaultLogAggregationFileControllerFactory()
143138 @ Test (expected = Exception .class )
144139 public void testLogAggregationFileControllerFactoryClassNotSet () {
145140 Configuration conf = getConf ();
146- conf .set (YarnConfiguration .LOG_AGGREGATION_FILE_FORMATS ,
147- "TestLogAggregationFileController" );
141+ conf .set (LOG_AGGREGATION_FILE_FORMATS , "TestLogAggregationFileController" );
148142 new LogAggregationFileControllerFactory (conf );
149143 fail ("TestLogAggregationFileController's class was not set, " +
150144 "but the factory creation did not fail." );
151145 }
152146
153- private void enableFileControllers (
154- List <Class <? extends LogAggregationFileController >> fileControllers ,
155- List <String > fileControllerNames ) {
156- Configuration conf = getConf ();
157- conf .set (YarnConfiguration .LOG_AGGREGATION_FILE_FORMATS ,
158- StringUtils .join (fileControllerNames , "," ));
159- for (int i = 0 ; i < fileControllers .size (); i ++) {
160- Class <? extends LogAggregationFileController > fileController =
161- fileControllers .get (i );
162- String controllerName = fileControllerNames .get (i );
163-
164- conf .setClass (String .format (LOG_AGGREGATION_FILE_CONTROLLER_FMT ,
165- controllerName ), fileController , LogAggregationFileController .class );
166- conf .set (String .format (LOG_AGGREGATION_REMOTE_APP_LOG_DIR_FMT ,
167- controllerName ), REMOTE_LOG_ROOT + controllerName + "/" );
168- conf .set (String .format (LOG_AGGREGATION_REMOTE_APP_LOG_DIR_SUFFIX_FMT ,
169- controllerName ), controllerName );
170- }
171- }
172-
173147 @ Test
174148 public void testLogAggregationFileControllerFactory () throws Exception {
175- enableFileControllers (ALL_FILE_CONTROLLERS , ALL_FILE_CONTROLLER_NAMES );
149+ enableFileControllers (getConf (), ALL_FILE_CONTROLLERS , ALL_FILE_CONTROLLER_NAMES );
176150 LogAggregationFileControllerFactory factory =
177151 new LogAggregationFileControllerFactory (getConf ());
178152 List <LogAggregationFileController > list =
@@ -199,8 +173,7 @@ public void testLogAggregationFileControllerFactory() throws Exception {
199173
200174 @ Test
201175 public void testClassConfUsed () {
202- enableFileControllers (Collections .singletonList (
203- LogAggregationTFileController .class ),
176+ enableFileControllers (getConf (), Collections .singletonList (LogAggregationTFileController .class ),
204177 Collections .singletonList ("TFile" ));
205178 LogAggregationFileControllerFactory factory =
206179 new LogAggregationFileControllerFactory (getConf ());
@@ -215,7 +188,7 @@ public void testClassConfUsed() {
215188 @ Test
216189 public void testNodemanagerConfigurationIsUsed () {
217190 Configuration conf = getConf ();
218- conf .set (YarnConfiguration . LOG_AGGREGATION_FILE_FORMATS , "TFile" );
191+ conf .set (LOG_AGGREGATION_FILE_FORMATS , "TFile" );
219192 LogAggregationFileControllerFactory factory =
220193 new LogAggregationFileControllerFactory (conf );
221194 LogAggregationFileController fc = factory .getFileControllerForWrite ();
@@ -231,7 +204,7 @@ public void testDefaultConfUsed() {
231204 Configuration conf = getConf ();
232205 conf .unset (YarnConfiguration .NM_REMOTE_APP_LOG_DIR );
233206 conf .unset (YarnConfiguration .NM_REMOTE_APP_LOG_DIR_SUFFIX );
234- conf .set (YarnConfiguration . LOG_AGGREGATION_FILE_FORMATS , "TFile" );
207+ conf .set (LOG_AGGREGATION_FILE_FORMATS , "TFile" );
235208
236209 LogAggregationFileControllerFactory factory =
237210 new LogAggregationFileControllerFactory (getConf ());
@@ -268,20 +241,19 @@ public void postWrite(LogAggregationFileControllerContext record)
268241 }
269242
270243 @ Override
271- public void initializeWriter (LogAggregationFileControllerContext context )
272- throws IOException {
244+ public void initializeWriter (LogAggregationFileControllerContext context ) {
273245 // Do Nothing
274246 }
275247
276248 @ Override
277249 public boolean readAggregatedLogs (ContainerLogsRequest logRequest ,
278- OutputStream os ) throws IOException {
250+ OutputStream os ) {
279251 return false ;
280252 }
281253
282254 @ Override
283255 public List <ContainerLogMeta > readAggregatedLogsMeta (
284- ContainerLogsRequest logRequest ) throws IOException {
256+ ContainerLogsRequest logRequest ) {
285257 return null ;
286258 }
287259
0 commit comments