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.emulators.resourceusage;
19 
20 import java.io.IOException;
21 
22 import org.apache.hadoop.mapred.gridmix.Progressive;
23 import org.apache.hadoop.util.ResourceCalculatorPlugin;
24 import org.apache.hadoop.tools.rumen.ResourceUsageMetrics;
25 import org.apache.hadoop.conf.Configuration;
26 
27 /**
28  * <p>Each resource to be emulated should have a corresponding implementation
29  * class that implements {@link ResourceUsageEmulatorPlugin}.</p>
30  * <br><br>
31  * {@link ResourceUsageEmulatorPlugin} will be configured using the
32  * {@link #initialize(Configuration, ResourceUsageMetrics,
33  *                    ResourceCalculatorPlugin, Progressive)} call.
34  * Every
35  * {@link ResourceUsageEmulatorPlugin} is also configured with a feedback module
36  * i.e a {@link ResourceCalculatorPlugin}, to monitor the current resource
37  * usage. {@link ResourceUsageMetrics} decides the final resource usage value to
38  * emulate. {@link Progressive} keeps track of the task's progress.</p>
39  *
40  * <br><br>
41  *
42  * For configuring GridMix to load and and use a resource usage emulator,
43  * see {@link ResourceUsageMatcher}.
44  */
45 public interface ResourceUsageEmulatorPlugin extends Progressive {
46   /**
47    * Initialize the plugin. This might involve
48    *   - initializing the variables
49    *   - calibrating the plugin
50    */
initialize(Configuration conf, ResourceUsageMetrics metrics, ResourceCalculatorPlugin monitor, Progressive progress)51   void initialize(Configuration conf, ResourceUsageMetrics metrics,
52                   ResourceCalculatorPlugin monitor,
53                   Progressive progress);
54 
55   /**
56    * Emulate the resource usage to match the usage target. The plugin can use
57    * the given {@link ResourceCalculatorPlugin} to query for the current
58    * resource usage.
59    * @throws IOException
60    * @throws InterruptedException
61    */
emulate()62   void emulate() throws IOException, InterruptedException;
63 }
64