1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package org.apache.hadoop.mapred.gridmix;
19 
20 import org.apache.hadoop.conf.Configuration;
21 import org.apache.hadoop.fs.Path;
22 import org.apache.hadoop.tools.rumen.JobStory;
23 
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.concurrent.CountDownLatch;
27 
28 
29 /**
30  * Component generating random job traces for testing on a single node.
31  */
32 public class DebugJobFactory {
33 
34   interface Debuggable {
getSubmitted()35     ArrayList<JobStory> getSubmitted();
36   }
37 
getFactory( JobSubmitter submitter, Path scratch, int numJobs, Configuration conf, CountDownLatch startFlag, UserResolver resolver)38   public static JobFactory<?> getFactory(
39     JobSubmitter submitter, Path scratch, int numJobs, Configuration conf,
40     CountDownLatch startFlag, UserResolver resolver) throws IOException {
41     GridmixJobSubmissionPolicy policy = GridmixJobSubmissionPolicy.getPolicy(
42       conf, GridmixJobSubmissionPolicy.STRESS);
43     if (policy == GridmixJobSubmissionPolicy.REPLAY) {
44       return new DebugReplayJobFactory(
45         submitter, scratch, numJobs, conf, startFlag, resolver);
46     } else if (policy == GridmixJobSubmissionPolicy.STRESS) {
47       return new DebugStressJobFactory(
48         submitter, scratch, numJobs, conf, startFlag, resolver);
49     } else if (policy == GridmixJobSubmissionPolicy.SERIAL) {
50       return new DebugSerialJobFactory(
51         submitter, scratch, numJobs, conf, startFlag, resolver);
52 
53     }
54     return null;
55   }
56 
57   static class DebugReplayJobFactory extends ReplayJobFactory
58     implements Debuggable {
DebugReplayJobFactory( JobSubmitter submitter, Path scratch, int numJobs, Configuration conf, CountDownLatch startFlag, UserResolver resolver)59     public DebugReplayJobFactory(
60       JobSubmitter submitter, Path scratch, int numJobs, Configuration conf,
61       CountDownLatch startFlag, UserResolver resolver) throws IOException {
62       super(
63         submitter, new DebugJobProducer(numJobs, conf), scratch, conf,
64         startFlag, resolver);
65     }
66 
67     @Override
getSubmitted()68     public ArrayList<JobStory> getSubmitted() {
69       return ((DebugJobProducer) jobProducer).submitted;
70     }
71 
72   }
73 
74   static class DebugSerialJobFactory extends SerialJobFactory
75     implements Debuggable {
DebugSerialJobFactory( JobSubmitter submitter, Path scratch, int numJobs, Configuration conf, CountDownLatch startFlag, UserResolver resolver)76     public DebugSerialJobFactory(
77       JobSubmitter submitter, Path scratch, int numJobs, Configuration conf,
78       CountDownLatch startFlag, UserResolver resolver) throws IOException {
79       super(
80         submitter, new DebugJobProducer(numJobs, conf), scratch, conf,
81         startFlag, resolver);
82     }
83 
84     @Override
getSubmitted()85     public ArrayList<JobStory> getSubmitted() {
86       return ((DebugJobProducer) jobProducer).submitted;
87     }
88   }
89 
90   static class DebugStressJobFactory extends StressJobFactory
91     implements Debuggable {
DebugStressJobFactory( JobSubmitter submitter, Path scratch, int numJobs, Configuration conf, CountDownLatch startFlag, UserResolver resolver)92     public DebugStressJobFactory(
93       JobSubmitter submitter, Path scratch, int numJobs, Configuration conf,
94       CountDownLatch startFlag, UserResolver resolver) throws IOException {
95       super(
96         submitter, new DebugJobProducer(numJobs, conf), scratch, conf,
97         startFlag, resolver);
98     }
99 
100     @Override
getSubmitted()101     public ArrayList<JobStory> getSubmitted() {
102       return ((DebugJobProducer) jobProducer).submitted;
103     }
104   }
105 
106 }
107