命令調度程序
public class CommandScheduler
extends Object
implements ICommandScheduler
java.lang.Object | |
↳ | com.android.tradefed.command.CommandScheduler |
用於在所有可用設備上運行 TradeFederation 命令的調度程序。
將嘗試根據執行時間的總運行計數來確定要運行的命令的優先級。例如,不頻繁或快速運行的命令將優先於長時間運行的命令。
永遠在後台運行,直到關機。
概括
公共構造函數 | |
---|---|
CommandScheduler () 創建一個 |
公共方法 | |
---|---|
Pair <Boolean, Integer> | addCommand (String[] args) 向調度程序添加命令。 |
void | addCommandFile (String cmdFilePath, extraArgs) addCommandFile (String cmdFilePath, extraArgs) 將給定文件中的所有命令添加到調度程序 |
void | await () 等待調度程序開始運行,包括等待舊 TF 的切換完成(如果適用)。 |
static TradefedDelegator | checkDelegation (String[] args) 基於命令行創建一個delegator,看看我們是否需要委託運行。 |
static | createReleaseMap ( IInvocationContext context, Throwable e) 創建設備狀態圖,以便可以適當地發布它們。 |
ISandbox | createSandbox () 創建調用將用於運行的 |
void | displayCommandQueue (PrintWriter printWriter) 輸出有關命令執行隊列狀態的詳細調試信息。 |
void | displayCommandsInfo (PrintWriter printWriter, String regex) 輸出當前命令的列表。 |
void | displayInvocationsInfo (PrintWriter printWriter) 顯示當前調用的列表。 |
void | dumpCommandsXml (PrintWriter printWriter, String regex) 轉儲命令的擴展 xml 文件,其中包含為所有當前命令指定的所有 |
long | execCommand ( ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) execCommand ( ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) 直接在已經分配的設備上執行命令。 |
long | execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, String[] args) 直接分配設備並執行命令,而不使用已存在的 |
long | execCommand ( ICommandScheduler.IScheduledInvocationListener listener, String[] args) 直接分配設備並執行命令,而不將其添加到命令隊列中。 |
CommandFileWatcher | getCommandFileWatcher () 為此調度程序獲取適當的 |
int | getExecutingCommandCount () 返回處於執行狀態的命令數。 |
CommandScheduler.HostState | getHostState () |
String | getInvocationInfo (int invocationId) 返回有關指定調用 ID 的調用的信息。 |
CommandRunner.ExitCode | getLastInvocationExitCode () 返回最後一次運行的調用的錯誤代碼。 |
Throwable | getLastInvocationThrowable () 從最後一次運行的調用中返回 |
int | getReadyCommandCount () 返回隊列中處於就緒狀態的命令數。 |
long | getShutdownTimeout () |
boolean | isDeviceInInvocationThread ( ITestDevice device) 如果設備由活動調用線程使用,則返回 true。 |
boolean | isShuttingDown () |
void | notifyFileChanged (File cmdFile, extraArgs) notifyFileChanged (File cmdFile, extraArgs) |
void | removeAllCommands () 從調度程序中刪除所有命令 |
void | run () 該線程的主要執行塊。 |
void | setClearcutClient (ClearcutClient client) 設置客戶端上報線束數據 |
boolean | shouldShutdownOnCmdfileError () 如果我們需要在命令錯誤時關閉調度程序,則返回 true |
void | shutdown (boolean notifyStop) 嘗試正常關閉命令調度程序。 |
void | shutdownHard (boolean killAdb) 嘗試強制關閉命令調度程序。 |
void | shutdownHard () 嘗試強制關閉命令調度程序。 |
void | shutdownOnEmpty () 類似於 |
void | start () 啟動調度程序,包括設置日誌記錄、初始化 |
boolean | stopInvocation ( ITestInvocation invocation) 停止正在運行的調用。 |
boolean | stopInvocation (int invocationId, String cause) 通過指定它的 id 來停止正在運行的調用。 |
受保護的方法 | |
---|---|
void | cleanUp () 在我們退出之前關閉日誌並進行任何其他必要的清理。 |
IConfiguration | createConfiguration (String[] args) |
IInvocationContext | createInvocationContext () |
long | execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) |
IConfigurationFactory | getConfigFactory () 用於獲取對 |
DeviceManagementGrpcServer | getDeviceManagementServer () |
IDeviceManager | getDeviceManager () 獲取對 |
TradefedFeatureServer | getFeatureServer () |
IHostOptions | getHostOptions () |
IKeyStoreClient | getKeyStoreClient () 使用在 |
TestInvocationManagementServer | getTestInvocationManagementServer () |
void | initLogging () 初始化 ddmlib 日誌。 |
boolean | isShutdown () |
void | processReadyCommands ( IDeviceManager manager) |
公共構造函數
公共方法
添加命令
public Pair<Boolean, Integer> addCommand (String[] args)
向調度程序添加命令。
命令本質上是要運行的配置及其相關參數的實例。
如果指定了“--help”參數,配置的幫助文本將輸出到標準輸出。否則,配置將被添加到隊列中以運行。
參數 | |
---|---|
args | String :配置參數。 |
退貨 | |
---|---|
Pair <Boolean, Integer> | 一對值,如果成功添加命令,第一個值為布爾值true 。第二個值是已知的命令跟踪器id(非負值)如果命令添加成功,則為所有設備添加命令時返回0,否則返回-1。 |
投擲 | |
---|---|
ConfigurationException |
添加命令文件
public void addCommandFile (String cmdFilePath,extraArgs)
將給定文件中的所有命令添加到調度程序
參數 | |
---|---|
cmdFilePath | String : 命令文件的文件系統路徑 |
extraArgs | ERROR(/List) 的ERROR(/String) 參數附加到從文件解析的每個命令。可以為空但不應為空。 |
投擲 | |
---|---|
ConfigurationException |
等待
public void await ()
等待調度程序開始運行,包括等待舊 TF 的切換完成(如果適用)。
檢查委派
public static TradefedDelegator checkDelegation (String[] args)
基於命令行創建一個delegator,看看我們是否需要委託運行。
參數 | |
---|---|
args | String |
退貨 | |
---|---|
TradefedDelegator |
投擲 | |
---|---|
| com.android.tradefed.config.ConfigurationException |
ConfigurationException |
創建ReleaseMap
public staticcreateReleaseMap (IInvocationContext context, Throwable e)
創建設備狀態圖,以便可以適當地發布它們。
參數 | |
---|---|
context | IInvocationContext |
e | Throwable |
退貨 | |
---|---|
顯示命令隊列
public void displayCommandQueue (PrintWriter printWriter)
輸出有關命令執行隊列狀態的詳細調試信息。
顯示命令信息
public void displayCommandsInfo (PrintWriter printWriter, String regex)
輸出當前命令的列表。
參數 | |
---|---|
printWriter | PrintWriter :要輸出到的ERROR(/PrintWriter) 。 |
regex | String :為了打印命令應該匹配的正則表達式。如果為空,則將打印所有命令。 |
顯示調用信息
public void displayInvocationsInfo (PrintWriter printWriter)
顯示當前調用的列表。
參數 | |
---|---|
printWriter | PrintWriter :要輸出到的ERROR(/PrintWriter) 。 |
dumpCommandsXml
public void dumpCommandsXml (PrintWriter printWriter, String regex)
轉儲命令的擴展 xml 文件,其中包含為所有當前命令指定的所有Option
值。
參數 | |
---|---|
printWriter | PrintWriter :將狀態輸出到的ERROR(/PrintWriter) 。 |
regex | String :為了轉儲 xml 文件,命令應與其匹配的正則表達式。如果為空,則將轉儲所有命令。 |
執行命令
public long execCommand (ICommandScheduler.IScheduledInvocationListener listener,reservedDevices, String[] args)
直接在已經分配的設備上執行命令。
參數 | |
---|---|
listener | ICommandScheduler.IScheduledInvocationListener :要通知的ICommandScheduler.IScheduledInvocationListener |
reservedDevices | ERROR(/List ) ERROR(/List ) 使用 |
args | String :命令參數 |
退貨 | |
---|---|
long | 計劃命令的調用 ID。 |
投擲 | |
---|---|
ConfigurationException |
執行命令
public long execCommand (IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, String[] args)
直接分配設備並執行命令,而不使用已存在的IInvocationContext
將其添加到命令隊列。
參數 | |
---|---|
context | IInvocationContext :一個現有的IInvocationContext 。 |
listener | ICommandScheduler.IScheduledInvocationListener :要通知的ICommandScheduler.IScheduledInvocationListener |
args | String :命令參數 |
退貨 | |
---|---|
long |
投擲 | |
---|---|
ConfigurationException | |
NoDeviceException |
執行命令
public long execCommand (ICommandScheduler.IScheduledInvocationListener listener, String[] args)
直接分配設備並執行命令,而不將其添加到命令隊列中。
參數 | |
---|---|
listener | ICommandScheduler.IScheduledInvocationListener :要通知的ICommandScheduler.IScheduledInvocationListener |
args | String :命令參數 |
退貨 | |
---|---|
long | 計劃命令的調用 ID。 |
投擲 | |
---|---|
ConfigurationException | |
NoDeviceException |
getCommandFileWatcher
public CommandFileWatcher getCommandFileWatcher ()
為此調度程序獲取適當的CommandFileWatcher
退貨 | |
---|---|
CommandFileWatcher |
getExecutingCommandCount
public int getExecutingCommandCount ()
返回處於執行狀態的命令數。
退貨 | |
---|---|
int |
獲取調用信息
public String getInvocationInfo (int invocationId)
返回有關指定調用 ID 的調用的信息。
參數 | |
---|---|
invocationId | int :調用的跟踪 ID。 |
退貨 | |
---|---|
String | 包含有關調用的信息的ERROR(/String) 。 |
getLastInvocationExitCode
public CommandRunner.ExitCode getLastInvocationExitCode ()
返回最後一次運行的調用的錯誤代碼。如果尚未運行任何調用,則返回 0(無錯誤)。
退貨 | |
---|---|
CommandRunner.ExitCode |
getLastInvocationThrowable
public Throwable getLastInvocationThrowable ()
從最後一次運行的調用中返回ERROR(/Throwable)
。如果沒有可用的 throwable,則返回 null。
退貨 | |
---|---|
Throwable |
getReadyCommandCount
public int getReadyCommandCount ()
返回隊列中處於就緒狀態的命令數。
退貨 | |
---|---|
int |
獲取關機超時
public long getShutdownTimeout ()
退貨 | |
---|---|
long |
isDeviceInInvocationThread
public boolean isDeviceInInvocationThread (ITestDevice device)
如果設備由活動調用線程使用,則返回 true。
參數 | |
---|---|
device | ITestDevice |
退貨 | |
---|---|
boolean |
正在關機
public boolean isShuttingDown ()
退貨 | |
---|---|
boolean |
通知文件已更改
public void notifyFileChanged (File cmdFile,extraArgs)
參數 | |
---|---|
cmdFile | File |
extraArgs |
刪除所有命令
public void removeAllCommands ()
從調度程序中刪除所有命令
跑步
public void run ()
該線程的主要執行塊。
設置清除客戶端
public void setClearcutClient (ClearcutClient client)
設置客戶端上報線束數據
參數 | |
---|---|
client | ClearcutClient |
shouldShutdownOnCmdfileError
public boolean shouldShutdownOnCmdfileError ()
如果我們需要在命令錯誤時關閉調度程序,則返回 true
退貨 | |
---|---|
boolean |
關閉
public void shutdown (boolean notifyStop)
嘗試正常關閉命令調度程序。
參數 | |
---|---|
notifyStop | boolean :如果為真,則通知調用 TF 關閉。 |
硬關機
public void shutdownHard (boolean killAdb)
嘗試強制關閉命令調度程序。
類似於shutdown()
,但也可以選擇終止 adb 連接,以試圖“激發”正在進行的調用以更快地完成。
參數 | |
---|---|
killAdb | boolean |
硬關機
public void shutdownHard ()
嘗試強制關閉命令調度程序。與 shutdownHard(true) 相同。
停止調用
public boolean stopInvocation (ITestInvocation invocation)
停止正在運行的調用。
參數 | |
---|---|
invocation | ITestInvocation |
退貨 | |
---|---|
boolean | 如果調用已停止,則為 true,否則為 false |
停止調用
public boolean stopInvocation (int invocationId, String cause)
通過指定它的 id 來停止正在運行的調用。
參數 | |
---|---|
invocationId | int :調用的跟踪 ID。 |
cause | String :停止調用的原因。 |
退貨 | |
---|---|
boolean | 如果調用已停止,則為 true,否則為 false |
受保護的方法
清理
protected void cleanUp ()
在我們退出之前關閉日誌並進行任何其他必要的清理。
公開以便單元測試可以模擬。
創建配置
protected IConfiguration createConfiguration (String[] args)
參數 | |
---|---|
args | String |
退貨 | |
---|---|
IConfiguration |
投擲 | |
---|---|
ConfigurationException |
執行命令
protected long execCommand (IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener,reservedDevices, String[] args)
參數 | |
---|---|
context | IInvocationContext |
listener | ICommandScheduler.IScheduledInvocationListener |
reservedDevices | |
args | String |
退貨 | |
---|---|
long |
投擲 | |
---|---|
ConfigurationException |
獲取配置工廠
protected IConfigurationFactory getConfigFactory ()
用於獲取對IConfigurationFactory
引用的工廠方法
退貨 | |
---|---|
IConfigurationFactory | 要使用的IConfigurationFactory |
獲取設備管理服務器
protected DeviceManagementGrpcServer getDeviceManagementServer ()
退貨 | |
---|---|
DeviceManagementGrpcServer |
獲取設備管理器
protected IDeviceManager getDeviceManager ()
獲取對IDeviceManager
引用的工廠方法
退貨 | |
---|---|
IDeviceManager | 要使用的IDeviceManager |
獲取KeyStoreClient
protected IKeyStoreClient getKeyStoreClient ()
使用在IGlobalConfiguration
中聲明的IKeyStoreFactory
獲取IKeyStoreClient
,如果未定義則為 null。
退貨 | |
---|---|
IKeyStoreClient | IKeyStoreClient |
getTestInvocationManagementServer
protected TestInvocationManagementServer getTestInvocationManagementServer ()
退貨 | |
---|---|
TestInvocationManagementServer |
初始化記錄
protected void initLogging ()
初始化 ddmlib 日誌。
公開以便單元測試可以模擬。
是關機
protected boolean isShutdown ()
退貨 | |
---|---|
boolean |
processReadyCommands
protected void processReadyCommands (IDeviceManager manager)
參數 | |
---|---|
manager | IDeviceManager |