• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tradefed.config;
18 
19 import com.android.tradefed.build.IBuildProvider;
20 import com.android.tradefed.command.ICommandOptions;
21 import com.android.tradefed.config.ConfigurationDef.OptionDef;
22 import com.android.tradefed.device.IDeviceRecovery;
23 import com.android.tradefed.device.IDeviceSelection;
24 import com.android.tradefed.device.TestDeviceOptions;
25 import com.android.tradefed.device.metric.IMetricCollector;
26 import com.android.tradefed.device.metric.target.DeviceSideCollectorSpecification;
27 import com.android.tradefed.log.ILeveledLogOutput;
28 import com.android.tradefed.postprocessor.IPostProcessor;
29 import com.android.tradefed.result.ILogSaver;
30 import com.android.tradefed.result.ITestInvocationListener;
31 import com.android.tradefed.suite.checker.ISystemStatusChecker;
32 import com.android.tradefed.targetprep.ITargetPreparer;
33 import com.android.tradefed.targetprep.multi.IMultiTargetPreparer;
34 import com.android.tradefed.testtype.IRemoteTest;
35 import com.android.tradefed.util.keystore.IKeyStoreClient;
36 
37 import org.json.JSONArray;
38 import org.json.JSONException;
39 
40 import java.io.IOException;
41 import java.io.PrintStream;
42 import java.io.PrintWriter;
43 import java.util.Collection;
44 import java.util.List;
45 
46 /**
47  * Configuration information for a TradeFederation invocation.
48  *
49  * Each TradeFederation invocation has a single {@link IConfiguration}. An {@link IConfiguration}
50  * stores all the delegate objects that should be used during the invocation, and their associated
51  * {@link Option}'s
52  */
53 public interface IConfiguration {
54 
55     /** Returns the name of the configuration. */
getName()56     public String getName();
57 
58     /**
59      * Gets the {@link IBuildProvider} from the configuration.
60      *
61      * @return the {@link IBuildProvider} provided in the configuration
62      */
getBuildProvider()63     public IBuildProvider getBuildProvider();
64 
65     /**
66      * Gets the {@link ITargetPreparer}s from the configuration.
67      *
68      * @return the {@link ITargetPreparer}s provided in order in the configuration
69      */
getTargetPreparers()70     public List<ITargetPreparer> getTargetPreparers();
71 
72     /**
73      * Gets the {@link IRemoteTest}s to run from the configuration.
74      *
75      * @return the tests provided in the configuration
76      */
getTests()77     public List<IRemoteTest> getTests();
78 
79     /**
80      * Gets the {@link ITestInvocationListener}s to use from the configuration.
81      *
82      * @return the {@link ITestInvocationListener}s provided in the configuration.
83      */
getTestInvocationListeners()84     public List<ITestInvocationListener> getTestInvocationListeners();
85 
86     /**
87      * Gets the {@link IDeviceRecovery} to use from the configuration.
88      *
89      * @return the {@link IDeviceRecovery} provided in the configuration.
90      */
getDeviceRecovery()91     public IDeviceRecovery getDeviceRecovery();
92 
93     /**
94      * Gets the {@link TestDeviceOptions} to use from the configuration.
95      *
96      * @return the {@link TestDeviceOptions} provided in the configuration.
97      */
getDeviceOptions()98     public TestDeviceOptions getDeviceOptions();
99 
100     /**
101      * Gets the {@link ILeveledLogOutput} to use from the configuration.
102      *
103      * @return the {@link ILeveledLogOutput} provided in the configuration.
104      */
getLogOutput()105     public ILeveledLogOutput getLogOutput();
106 
107     /**
108      * Gets the {@link ILogSaver} to use from the configuration.
109      *
110      * @return the {@link ILogSaver} provided in the configuration.
111      */
getLogSaver()112     public ILogSaver getLogSaver();
113 
114     /**
115      * Gets the {@link IMultiTargetPreparer}s from the configuration.
116      *
117      * @return the {@link IMultiTargetPreparer}s provided in order in the configuration
118      */
getMultiTargetPreparers()119     public List<IMultiTargetPreparer> getMultiTargetPreparers();
120 
121     /**
122      * Gets the {@link IMultiTargetPreparer}s from the configuration that should be executed before
123      * any of the devices target_preparers.
124      *
125      * @return the {@link IMultiTargetPreparer}s provided in order in the configuration
126      */
getMultiPreTargetPreparers()127     public List<IMultiTargetPreparer> getMultiPreTargetPreparers();
128 
129     /**
130      * Gets the {@link ISystemStatusChecker}s from the configuration.
131      *
132      * @return the {@link ISystemStatusChecker}s provided in order in the configuration
133      */
getSystemStatusCheckers()134     public List<ISystemStatusChecker> getSystemStatusCheckers();
135 
136     /** Gets the {@link IMetricCollector}s from the configuration. */
getMetricCollectors()137     public List<IMetricCollector> getMetricCollectors();
138 
139     /** Gets the {@link IPostProcessor}s from the configuration. */
getPostProcessors()140     public List<IPostProcessor> getPostProcessors();
141 
142     /**
143      * Gets the {@link DeviceSideCollectorSpecification} driving the device/target-side
144      * specification of the collectors and their options.
145      */
getDeviceSideCollectorsSpec()146     public DeviceSideCollectorSpecification getDeviceSideCollectorsSpec();
147 
148     /**
149      * Gets the {@link ICommandOptions} to use from the configuration.
150      *
151      * @return the {@link ICommandOptions} provided in the configuration.
152      */
getCommandOptions()153     public ICommandOptions getCommandOptions();
154 
155     /** Returns the {@link ConfigurationDescriptor} provided in the configuration. */
getConfigurationDescription()156     public ConfigurationDescriptor getConfigurationDescription();
157 
158     /**
159      * Gets the {@link IDeviceSelection} to use from the configuration.
160      *
161      * @return the {@link IDeviceSelection} provided in the configuration.
162      */
getDeviceRequirements()163     public IDeviceSelection getDeviceRequirements();
164 
165     /**
166      * Generic interface to get the configuration object with the given type name.
167      *
168      * @param typeName the unique type of the configuration object
169      *
170      * @return the configuration object or <code>null</code> if the object type with given name
171      * does not exist.
172      */
getConfigurationObject(String typeName)173     public Object getConfigurationObject(String typeName);
174 
175     /**
176      * Generic interface to get all the object of one given type name across devices.
177      *
178      * @param typeName the unique type of the configuration object
179      * @return The list of configuration objects of the given type.
180      */
getAllConfigurationObjectsOfType(String typeName)181     public Collection<Object> getAllConfigurationObjectsOfType(String typeName);
182 
183     /**
184      * Similar to {@link #getConfigurationObject(String)}, but for configuration
185      * object types that support multiple objects.
186      *
187      * @param typeName the unique type name of the configuration object
188      *
189      * @return the list of configuration objects or <code>null</code> if the object type with
190      * given name does not exist.
191      */
getConfigurationObjectList(String typeName)192     public List<?> getConfigurationObjectList(String typeName);
193 
194     /**
195      * Gets the {@link IDeviceConfiguration}s from the configuration.
196      *
197      * @return the {@link IDeviceConfiguration}s provided in order in the configuration
198      */
getDeviceConfig()199     public List<IDeviceConfiguration> getDeviceConfig();
200 
201     /**
202      * Return the {@link IDeviceConfiguration} associated to the name provided, null if not found.
203      */
getDeviceConfigByName(String nameDevice)204     public IDeviceConfiguration getDeviceConfigByName(String nameDevice);
205 
206     /**
207      * Inject a option value into the set of configuration objects.
208      * <p/>
209      * Useful to provide values for options that are generated dynamically.
210      *
211      * @param optionName the option name
212      * @param optionValue the option value
213      * @throws ConfigurationException if failed to set the option's value
214      */
injectOptionValue(String optionName, String optionValue)215     public void injectOptionValue(String optionName, String optionValue)
216             throws ConfigurationException;
217 
218     /**
219      * Inject a option value into the set of configuration objects.
220      * <p/>
221      * Useful to provide values for options that are generated dynamically.
222      *
223      * @param optionName the option name
224      * @param optionKey the optional key for map options, or null
225      * @param optionValue the map option value
226      * @throws ConfigurationException if failed to set the option's value
227      */
injectOptionValue(String optionName, String optionKey, String optionValue)228     public void injectOptionValue(String optionName, String optionKey, String optionValue)
229             throws ConfigurationException;
230 
231     /**
232      * Inject a option value into the set of configuration objects.
233      * <p/>
234      * Useful to provide values for options that are generated dynamically.
235      *
236      * @param optionName the option name
237      * @param optionKey the optional key for map options, or null
238      * @param optionValue the map option value
239      * @param optionSource the source config that provided this option value
240      * @throws ConfigurationException if failed to set the option's value
241      */
injectOptionValueWithSource(String optionName, String optionKey, String optionValue, String optionSource)242     public void injectOptionValueWithSource(String optionName, String optionKey, String optionValue,
243             String optionSource) throws ConfigurationException;
244 
245     /**
246      * Inject multiple option values into the set of configuration objects.
247      * <p/>
248      * Useful to inject many option values at once after creating a new object.
249      *
250      * @param optionDefs a list of option defs to inject
251      * @throws ConfigurationException if failed to set option values
252      */
injectOptionValues(List<OptionDef> optionDefs)253     public void injectOptionValues(List<OptionDef> optionDefs) throws ConfigurationException;
254 
255     /**
256      * Create a shallow copy of this object.
257      *
258      * @return a {link IConfiguration} copy
259      */
clone()260     public IConfiguration clone();
261 
262     /**
263      * Replace the current {@link IBuildProvider} in the configuration.
264      *
265      * @param provider the new {@link IBuildProvider}
266      */
setBuildProvider(IBuildProvider provider)267     public void setBuildProvider(IBuildProvider provider);
268 
269     /**
270      * Set the {@link ILeveledLogOutput}, replacing any existing value.
271      *
272      * @param logger
273      */
setLogOutput(ILeveledLogOutput logger)274     public void setLogOutput(ILeveledLogOutput logger);
275 
276     /**
277      * Set the {@link ILogSaver}, replacing any existing value.
278      *
279      * @param logSaver
280      */
setLogSaver(ILogSaver logSaver)281     public void setLogSaver(ILogSaver logSaver);
282 
283     /**
284      * Set the {@link IDeviceRecovery}, replacing any existing value.
285      *
286      * @param recovery
287      */
setDeviceRecovery(IDeviceRecovery recovery)288     public void setDeviceRecovery(IDeviceRecovery recovery);
289 
290     /**
291      * Set the {@link ITargetPreparer}, replacing any existing value.
292      *
293      * @param preparer
294      */
setTargetPreparer(ITargetPreparer preparer)295     public void setTargetPreparer(ITargetPreparer preparer);
296 
297     /**
298      * Set the list of {@link ITargetPreparer}s, replacing any existing value.
299      *
300      * @param preparers
301      */
setTargetPreparers(List<ITargetPreparer> preparers)302     public void setTargetPreparers(List<ITargetPreparer> preparers);
303 
304     /**
305      * Set a {@link IDeviceConfiguration}, replacing any existing value.
306      *
307      * @param deviceConfig
308      */
setDeviceConfig(IDeviceConfiguration deviceConfig)309     public void setDeviceConfig(IDeviceConfiguration deviceConfig);
310 
311     /**
312      * Set the {@link IDeviceConfiguration}s, replacing any existing value.
313      *
314      * @param deviceConfigs
315      */
setDeviceConfigList(List<IDeviceConfiguration> deviceConfigs)316     public void setDeviceConfigList(List<IDeviceConfiguration> deviceConfigs);
317 
318     /**
319      * Convenience method to set a single {@link IRemoteTest} in this configuration, replacing any
320      * existing values
321      *
322      * @param test
323      */
setTest(IRemoteTest test)324     public void setTest(IRemoteTest test);
325 
326     /**
327      * Set the list of {@link IRemoteTest}s in this configuration, replacing any
328      * existing values
329      *
330      * @param tests
331      */
setTests(List<IRemoteTest> tests)332     public void setTests(List<IRemoteTest> tests);
333 
334     /**
335      * Set the list of {@link IMultiTargetPreparer}s in this configuration, replacing any
336      * existing values
337      *
338      * @param multiTargPreps
339      */
setMultiTargetPreparers(List<IMultiTargetPreparer> multiTargPreps)340     public void setMultiTargetPreparers(List<IMultiTargetPreparer> multiTargPreps);
341 
342     /**
343      * Convenience method to set a single {@link IMultiTargetPreparer} in this configuration,
344      * replacing any existing values
345      *
346      * @param multiTargPrep
347      */
setMultiTargetPreparer(IMultiTargetPreparer multiTargPrep)348     public void setMultiTargetPreparer(IMultiTargetPreparer multiTargPrep);
349 
350     /**
351      * Set the list of {@link IMultiTargetPreparer}s in this configuration that should be executed
352      * before any of the devices target_preparers, replacing any existing values
353      *
354      * @param multiPreTargPreps
355      */
setMultiPreTargetPreparers(List<IMultiTargetPreparer> multiPreTargPreps)356     public void setMultiPreTargetPreparers(List<IMultiTargetPreparer> multiPreTargPreps);
357 
358     /**
359      * Convenience method to set a single {@link IMultiTargetPreparer} in this configuration that
360      * should be executed before any of the devices target_preparers, replacing any existing values
361      *
362      * @param multiPreTargPreps
363      */
setMultiPreTargetPreparer(IMultiTargetPreparer multiPreTargPreps)364     public void setMultiPreTargetPreparer(IMultiTargetPreparer multiPreTargPreps);
365 
366     /**
367      * Set the list of {@link ISystemStatusChecker}s in this configuration, replacing any
368      * existing values
369      *
370      * @param systemCheckers
371      */
setSystemStatusCheckers(List<ISystemStatusChecker> systemCheckers)372     public void setSystemStatusCheckers(List<ISystemStatusChecker> systemCheckers);
373 
374     /**
375      * Convenience method to set a single {@link ISystemStatusChecker} in this configuration,
376      * replacing any existing values
377      *
378      * @param systemChecker
379      */
setSystemStatusChecker(ISystemStatusChecker systemChecker)380     public void setSystemStatusChecker(ISystemStatusChecker systemChecker);
381 
382     /**
383      * Set the list of {@link ITestInvocationListener}s, replacing any existing values
384      *
385      * @param listeners
386      */
setTestInvocationListeners(List<ITestInvocationListener> listeners)387     public void setTestInvocationListeners(List<ITestInvocationListener> listeners);
388 
389     /**
390      * Convenience method to set a single {@link ITestInvocationListener}
391      *
392      * @param listener
393      */
setTestInvocationListener(ITestInvocationListener listener)394     public void setTestInvocationListener(ITestInvocationListener listener);
395 
396     /** Set the list of {@link IMetricCollector}s, replacing any existing values. */
setDeviceMetricCollectors(List<IMetricCollector> collectors)397     public void setDeviceMetricCollectors(List<IMetricCollector> collectors);
398 
399     /** Set the {@link DeviceSideCollectorSpecification}, replacing any existing values. */
setDeviceSideCollectorSpec(DeviceSideCollectorSpecification deviceCollectorSpec)400     public void setDeviceSideCollectorSpec(DeviceSideCollectorSpecification deviceCollectorSpec);
401 
402     /** Set the list of {@link IPostProcessor}s, replacing any existing values. */
setPostProcessors(List<IPostProcessor> processors)403     public void setPostProcessors(List<IPostProcessor> processors);
404 
405     /**
406      * Set the {@link ICommandOptions}, replacing any existing values
407      *
408      * @param cmdOptions
409      */
setCommandOptions(ICommandOptions cmdOptions)410     public void setCommandOptions(ICommandOptions cmdOptions);
411 
412     /**
413      * Set the {@link IDeviceSelection}, replacing any existing values
414      *
415      * @param deviceSelection
416      */
setDeviceRequirements(IDeviceSelection deviceSelection)417     public void setDeviceRequirements(IDeviceSelection deviceSelection);
418 
419     /**
420      * Set the {@link TestDeviceOptions}, replacing any existing values
421      */
setDeviceOptions(TestDeviceOptions deviceOptions)422     public void setDeviceOptions(TestDeviceOptions deviceOptions);
423 
424     /**
425      * Generic method to set the config object with the given name, replacing any existing value.
426      *
427      * @param name the unique name of the config object type.
428      * @param configObject the config object
429      * @throws ConfigurationException if the configObject was not the correct type
430      */
setConfigurationObject(String name, Object configObject)431     public void setConfigurationObject(String name, Object configObject)
432             throws ConfigurationException;
433 
434     /**
435      * Generic method to set the config object list for the given name, replacing any existing
436      * value.
437      *
438      * @param name the unique name of the config object type.
439      * @param configList the config object list
440      * @throws ConfigurationException if any objects in the list are not the correct type
441      */
setConfigurationObjectList(String name, List<?> configList)442     public void setConfigurationObjectList(String name, List<?> configList)
443             throws ConfigurationException;
444 
445     /** Returns whether or not a configured device is tagged isFake=true or not. */
isDeviceConfiguredFake(String deviceName)446     public boolean isDeviceConfiguredFake(String deviceName);
447 
448     /**
449      * Set the config {@link Option} fields with given set of command line arguments
450      * <p/>
451      * {@link ArgsOptionParser} for expected format
452      *
453      * @param listArgs the command line arguments
454      * @return the unconsumed arguments
455      */
setOptionsFromCommandLineArgs(List<String> listArgs)456     public List<String> setOptionsFromCommandLineArgs(List<String> listArgs)
457             throws ConfigurationException;
458 
459     /**
460      * Set the config {@link Option} fields with given set of command line arguments
461      * <p/>
462      * See {@link ArgsOptionParser} for expected format
463      *
464      * @param listArgs the command line arguments
465      * @param keyStoreClient {@link IKeyStoreClient} to use.
466      * @return the unconsumed arguments
467      */
setOptionsFromCommandLineArgs(List<String> listArgs, IKeyStoreClient keyStoreClient)468     public List<String> setOptionsFromCommandLineArgs(List<String> listArgs,
469             IKeyStoreClient keyStoreClient)
470             throws ConfigurationException;
471 
472     /**
473      * Outputs a command line usage help text for this configuration to given printStream.
474      *
475      * @param importantOnly if <code>true</code> only print help for the important options
476      * @param out the {@link PrintStream} to use.
477      * @throws ConfigurationException
478      */
printCommandUsage(boolean importantOnly, PrintStream out)479     public void printCommandUsage(boolean importantOnly, PrintStream out)
480             throws ConfigurationException;
481 
482     /**
483      * Returns a JSON representation of this configuration.
484      * <p/>
485      * The return value is a JSONArray containing JSONObjects to represent each configuration
486      * object. Each configuration object entry has the following structure:
487      * <pre>
488      * {@code
489      *   &#123;
490      *     "alias": "device-unavail-email",
491      *     "name": "result_reporter",
492      *     "class": "com.android.tradefed.result.DeviceUnavailEmailResultReporter",
493      *     "options": [ ... ]
494      *   &#125;
495      * }
496      * </pre>
497      * The "options" entry is a JSONArray containing JSONObjects to represent each @Option annotated
498      * field. Each option entry has the following structure:
499      * <pre>
500      * {@code
501      *   &#123;
502      *     "updateRule": "LAST",
503      *     "isTimeVal": false,
504      *     "source": "google\/template\/reporters\/asit",
505      *     "importance": "IF_UNSET",
506      *     "description": "The envelope-sender address to use for the messages.",
507      *     "mandatory": false,
508      *     "name": "sender",
509      *     "javaClass": "java.lang.String",
510      *     "value": "tffail@google.com"
511      *   &#125;
512      * }
513      * </pre>
514      * Most of the values come from the @Option annotation. 'javaClass' is the name of the
515      * underlying java class for this option. 'value' is a JSON representation of the field's
516      * current value. 'source' is the set of config names which set the field's value. For regular
517      * objects or Collections, 'source' is a JSONArray containing each contributing config's name.
518      * For map fields, sources for each key are tracked individually and stored in a JSONObject.
519      * Each key / value pair in the JSONObject corresponds to a key in the map and an array of its
520      * source configurations.
521      *
522      * @throws JSONException
523      */
getJsonCommandUsage()524     public JSONArray getJsonCommandUsage() throws JSONException;
525 
526     /**
527      * Validate option values.
528      * <p/>
529      * Currently this will just validate that all mandatory options have been set
530      *
531      * @throws ConfigurationException if config is not valid
532      */
validateOptions()533     public void validateOptions() throws ConfigurationException;
534 
535     /**
536      * Validate option values.
537      *
538      * <p>Currently this will just validate that all mandatory options have been set
539      *
540      * @param download Whether or not to download the files associated to a remote path
541      * @throws ConfigurationException if config is not valid
542      */
validateOptions(boolean download)543     public void validateOptions(boolean download) throws ConfigurationException;
544 
545     /** Delete any files that was downloaded to resolved Option fields of remote files. */
cleanDynamicOptionFiles()546     public void cleanDynamicOptionFiles();
547 
548     /**
549      * Sets the command line used to create this {@link IConfiguration}.
550      * This stores the whole command line, including the configuration name,
551      * unlike setOptionsFromCommandLineArgs.
552      *
553      * @param arrayArgs the command line
554      */
setCommandLine(String[] arrayArgs)555     public void setCommandLine(String[] arrayArgs);
556 
557     /**
558      * Gets the command line used to create this {@link IConfiguration}.
559      *
560      * @return the command line used to create this {@link IConfiguration}.
561      */
getCommandLine()562     public String getCommandLine();
563 
564     /**
565      * Gets the expanded XML file for the config with all options shown for this
566      * {@link IConfiguration} as a {@link String}.
567      *
568      * @param output the writer to print the xml to.
569      * @throws IOException
570      */
dumpXml(PrintWriter output)571     public void dumpXml(PrintWriter output) throws IOException;
572 
573     /**
574      * Gets the expanded XML file for the config with all options shown for this {@link
575      * IConfiguration} minus the objects filters by their key name.
576      *
577      * <p>Filter example: {@link Configuration#TARGET_PREPARER_TYPE_NAME}.
578      *
579      * @param output the writer to print the xml to.
580      * @param excludeFilters the list of object type that should not be dumped.
581      * @throws IOException
582      */
dumpXml(PrintWriter output, List<String> excludeFilters)583     public void dumpXml(PrintWriter output, List<String> excludeFilters) throws IOException;
584 
585     /**
586      * Gets the expanded XML file for the config with all options shown for this {@link
587      * IConfiguration} minus the objects filters by their key name.
588      *
589      * <p>Filter example: {@link Configuration#TARGET_PREPARER_TYPE_NAME}.
590      *
591      * @param output the writer to print the xml to.
592      * @param excludeFilters the list of object type that should not be dumped.
593      * @param printDeprecatedOptions Whether or not to print options marked as deprecated
594      * @throws IOException
595      */
dumpXml( PrintWriter output, List<String> excludeFilters, boolean printDeprecatedOptions)596     public void dumpXml(
597             PrintWriter output, List<String> excludeFilters, boolean printDeprecatedOptions)
598             throws IOException;
599 }
600