Skip to content

Commit

Permalink
DeviceManager Refactor1: rename device manager (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou9584 authored Mar 6, 2023
1 parent e0e62df commit b40c643
Show file tree
Hide file tree
Showing 37 changed files with 1,926 additions and 1,924 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import com.microsoft.hydralab.agent.socket.AgentWebSocketClient;
import com.microsoft.hydralab.common.management.AgentType;
import com.microsoft.hydralab.common.management.AppiumServerManager;
import com.microsoft.hydralab.common.management.DeviceManager;
import com.microsoft.hydralab.common.management.impl.AndroidDeviceManager;
import com.microsoft.hydralab.common.management.device.TestDeviceManager;
import com.microsoft.hydralab.common.management.device.impl.AndroidTestDeviceManager;
import com.microsoft.hydralab.common.management.listener.DeviceStatusListenerManager;
import com.microsoft.hydralab.common.management.listener.impl.DeviceStabilityMonitor;
import com.microsoft.hydralab.common.monitor.MetricPushGateway;
Expand Down Expand Up @@ -98,12 +98,12 @@ public AgentWebSocketClient agentWebSocketClient(AgentWebSocketClientService age
}

@Bean
public DeviceManager initDeviceManager(StorageServiceClientProxy storageServiceClientProxy, ADBOperateUtil adbOperateUtil, AppiumServerManager appiumServerManager,
DeviceStatusListenerManager deviceStatusListenerManager) {
public TestDeviceManager initDeviceManager(StorageServiceClientProxy storageServiceClientProxy, ADBOperateUtil adbOperateUtil, AppiumServerManager appiumServerManager,
DeviceStatusListenerManager deviceStatusListenerManager) {
AgentType agentType = AgentType.formAgentType(agentTypeValue);
DeviceManager deviceManager = agentType.getManager();
if (deviceManager instanceof AndroidDeviceManager) {
((AndroidDeviceManager) deviceManager).setADBOperateUtil(adbOperateUtil);
TestDeviceManager testDeviceManager = agentType.getManager();
if (testDeviceManager instanceof AndroidTestDeviceManager) {
((AndroidTestDeviceManager) testDeviceManager).setADBOperateUtil(adbOperateUtil);
}
if (StringUtils.isNotBlank(adbServerHost)) {
logger.info("Setting the adb server hostname to {}", adbServerHost);
Expand All @@ -115,39 +115,39 @@ public DeviceManager initDeviceManager(StorageServiceClientProxy storageServiceC
throw new RuntimeException("adbDeviceManager dir.mkdirs() failed: " + testBaseDir);
}
}
deviceManager.setTestBaseDir(testBaseDir);
testDeviceManager.setTestBaseDir(testBaseDir);
File preAppDir = new File(appOptions.getPreAppStorageLocation());
if (!preAppDir.exists()) {
if (!preAppDir.mkdirs()) {
throw new RuntimeException("adbDeviceManager dir.mkdirs() failed: " + preAppDir);
}
}
deviceManager.setPreAppDir(preAppDir);
deviceManager.setPreInstallFailurePolicy(
testDeviceManager.setPreAppDir(preAppDir);
testDeviceManager.setPreInstallFailurePolicy(
shutdownIfFail ? Const.PreInstallFailurePolicy.SHUTDOWN : Const.PreInstallFailurePolicy.IGNORE);
deviceManager.setDeviceStatusListenerManager(deviceStatusListenerManager);
deviceManager.setTestBaseDirUrlMapping(AppOptions.TEST_CASE_RESULT_STORAGE_MAPPING_REL_PATH);
testDeviceManager.setDeviceStatusListenerManager(deviceStatusListenerManager);
testDeviceManager.setTestBaseDirUrlMapping(AppOptions.TEST_CASE_RESULT_STORAGE_MAPPING_REL_PATH);
File deviceLogBaseDir = new File(appOptions.getDeviceLogStorageLocation());
if (!deviceLogBaseDir.exists()) {
if (!deviceLogBaseDir.mkdirs()) {
throw new RuntimeException("adbDeviceManager dir.mkdirs() failed: " + deviceLogBaseDir);
}
}
deviceManager.setDeviceLogBaseDir(deviceLogBaseDir);
deviceManager.setStorageServiceClientProxy(storageServiceClientProxy);
testDeviceManager.setDeviceLogBaseDir(deviceLogBaseDir);
testDeviceManager.setStorageServiceClientProxy(storageServiceClientProxy);

deviceManager.setScreenshotDir(getScreenshotDir());
deviceManager.setDeviceFolderUrlPrefix(AppOptions.DEVICE_STORAGE_MAPPING_REL_PATH);
deviceManager.setDeviceStoragePath(appOptions.getDeviceStorageLocation());
testDeviceManager.setScreenshotDir(getScreenshotDir());
testDeviceManager.setDeviceFolderUrlPrefix(AppOptions.DEVICE_STORAGE_MAPPING_REL_PATH);
testDeviceManager.setDeviceStoragePath(appOptions.getDeviceStorageLocation());

if (StringUtils.isNotBlank(appiumServerHost)) {
logger.info("Setting the appium server hostname to {}", appiumServerHost);
appiumServerManager.setAppiumServerHost(appiumServerHost);
}
appiumServerManager.setWorkspacePath(appOptions.getLocation());

deviceManager.setAppiumServerManager(appiumServerManager);
return deviceManager;
testDeviceManager.setAppiumServerManager(appiumServerManager);
return testDeviceManager;
}

@Bean
Expand Down Expand Up @@ -177,13 +177,13 @@ public SmartTestUtil smartTestUtil() {
}

@Bean
public DeviceStabilityMonitor deviceStabilityMonitor(DeviceManager deviceManager, MeterRegistry meterRegistry) {
public DeviceStabilityMonitor deviceStabilityMonitor(TestDeviceManager testDeviceManager, MeterRegistry meterRegistry) {
DeviceStabilityMonitor deviceStabilityMonitor = new DeviceStabilityMonitor();

deviceStabilityMonitor.setDeviceStateChangeThreshold(deviceStateChangeThreshold);
deviceStabilityMonitor.setDeviceStateChangeWindowTime(deviceStateChangeWindowTime);
deviceStabilityMonitor.setDeviceStateChangeRecoveryTime(deviceStateChangeRecoveryTime);
deviceStabilityMonitor.setDeviceManager(deviceManager);
deviceStabilityMonitor.setTestDeviceManager(testDeviceManager);
deviceStabilityMonitor.setMeterRegistry(meterRegistry);

return deviceStabilityMonitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.microsoft.hydralab.agent.runner.t2c.T2CRunner;
import com.microsoft.hydralab.agent.service.TestTaskEngineService;
import com.microsoft.hydralab.common.entity.common.TestTask;
import com.microsoft.hydralab.common.management.DeviceManager;
import com.microsoft.hydralab.common.management.device.TestDeviceManager;
import com.microsoft.hydralab.common.util.ADBOperateUtil;
import com.microsoft.hydralab.performance.PerformanceTestManagementService;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -49,54 +49,54 @@ public PerformanceTestManagementService performanceTestManagementService() {
}

@Bean
public EspressoRunner espressoRunner(DeviceManager deviceManager, TestTaskEngineService testTaskEngineService,
public EspressoRunner espressoRunner(TestDeviceManager testDeviceManager, TestTaskEngineService testTaskEngineService,
PerformanceTestManagementService performanceTestManagementService,
ADBOperateUtil adbOperateUtil) {
return new EspressoRunner(deviceManager, testTaskEngineService, performanceTestManagementService,
return new EspressoRunner(testDeviceManager, testTaskEngineService, performanceTestManagementService,
adbOperateUtil);
}

@Bean
public AdbMonkeyRunner adbMonkeyRunner(DeviceManager deviceManager, TestTaskEngineService testTaskEngineService,
public AdbMonkeyRunner adbMonkeyRunner(TestDeviceManager testDeviceManager, TestTaskEngineService testTaskEngineService,
PerformanceTestManagementService performanceTestManagementService,
ADBOperateUtil adbOperateUtil) {
return new AdbMonkeyRunner(deviceManager, testTaskEngineService, performanceTestManagementService,
return new AdbMonkeyRunner(testDeviceManager, testTaskEngineService, performanceTestManagementService,
adbOperateUtil);
}

@Bean
public AppiumMonkeyRunner appiumMonkeyRunner(DeviceManager deviceManager,
public AppiumMonkeyRunner appiumMonkeyRunner(TestDeviceManager testDeviceManager,
TestTaskEngineService testTaskEngineService,
PerformanceTestManagementService performanceTestManagementService) {
return new AppiumMonkeyRunner(deviceManager, testTaskEngineService, performanceTestManagementService);
return new AppiumMonkeyRunner(testDeviceManager, testTaskEngineService, performanceTestManagementService);
}

@Bean
public AppiumRunner appiumRunner(DeviceManager deviceManager, TestTaskEngineService testTaskEngineService,
public AppiumRunner appiumRunner(TestDeviceManager testDeviceManager, TestTaskEngineService testTaskEngineService,
PerformanceTestManagementService performanceTestManagementService) {
return new AppiumRunner(deviceManager, testTaskEngineService, performanceTestManagementService);
return new AppiumRunner(testDeviceManager, testTaskEngineService, performanceTestManagementService);
}

@Bean
public AppiumCrossRunner appiumCrossRunner(DeviceManager deviceManager,
public AppiumCrossRunner appiumCrossRunner(TestDeviceManager testDeviceManager,
TestTaskEngineService testTaskEngineService,
PerformanceTestManagementService performanceTestManagementService) {
return new AppiumCrossRunner(deviceManager, testTaskEngineService, performanceTestManagementService,
return new AppiumCrossRunner(testDeviceManager, testTaskEngineService, performanceTestManagementService,
agentName);
}

@Bean
public SmartRunner smartRunner(DeviceManager deviceManager, TestTaskEngineService testTaskEngineService,
public SmartRunner smartRunner(TestDeviceManager testDeviceManager, TestTaskEngineService testTaskEngineService,
PerformanceTestManagementService performanceTestManagementService,
SmartTestUtil smartTestUtil) {
return new SmartRunner(deviceManager, testTaskEngineService, performanceTestManagementService,
return new SmartRunner(testDeviceManager, testTaskEngineService, performanceTestManagementService,
smartTestUtil);
}

@Bean
public T2CRunner t2cRunner(DeviceManager deviceManager, TestTaskEngineService testTaskEngineService,
public T2CRunner t2cRunner(TestDeviceManager testDeviceManager, TestTaskEngineService testTaskEngineService,
PerformanceTestManagementService performanceTestManagementService) {
return new T2CRunner(deviceManager, testTaskEngineService, performanceTestManagementService, agentName);
return new T2CRunner(testDeviceManager, testTaskEngineService, performanceTestManagementService, agentName);
}

@ConfigurationProperties(prefix = "app.device-script.commands")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.alibaba.fastjson.JSONObject;
import com.microsoft.hydralab.common.entity.common.DeviceAction;
import com.microsoft.hydralab.common.entity.common.DeviceInfo;
import com.microsoft.hydralab.common.management.DeviceManager;
import com.microsoft.hydralab.common.management.device.TestDeviceManager;
import com.microsoft.hydralab.common.util.HydraLabRuntimeException;
import com.microsoft.hydralab.common.util.ThreadUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class ActionExecutor {
"changeSystemSetting", "execCommandOnDevice", "execCommandOnAgent", "pushFileToDevice",
"pullFileFromDevice");

public List<Exception> doActions(@NotNull DeviceManager deviceManager, @NotNull DeviceInfo deviceInfo,
public List<Exception> doActions(@NotNull TestDeviceManager testDeviceManager, @NotNull DeviceInfo deviceInfo,
@NotNull Logger logger,
@NotNull Map<String, List<DeviceAction>> actions, @NotNull String when) {
List<Exception> exceptions = new ArrayList<>();
Expand All @@ -48,7 +48,7 @@ public List<Exception> doActions(@NotNull DeviceManager deviceManager, @NotNull
logger.info("Start to execute actions! Current timing is {}, action size is {}", when, todoActions.size());
for (DeviceAction deviceAction : todoActions) {
try {
doAction(deviceManager, deviceInfo, logger, deviceAction);
doAction(testDeviceManager, deviceInfo, logger, deviceAction);
} catch (InvocationTargetException | IllegalAccessException | HydraLabRuntimeException e) {
exceptions.add(e);
logger.error("Execute {} action: fail", deviceAction.getMethod(), e);
Expand All @@ -59,18 +59,18 @@ public List<Exception> doActions(@NotNull DeviceManager deviceManager, @NotNull
return exceptions;
}

public void doAction(@NotNull DeviceManager deviceManager, @NotNull DeviceInfo deviceInfo,
public void doAction(@NotNull TestDeviceManager testDeviceManager, @NotNull DeviceInfo deviceInfo,
@NotNull Logger logger,
@NotNull DeviceAction deviceAction)
throws InvocationTargetException, IllegalAccessException {
if (!actionTypes.contains(deviceAction.getMethod())) {
return;
}
logger.info("Start to analysis action type! Current action is {}", deviceAction.getMethod());
Method method = Arrays.stream(deviceManager.getClass().getMethods())
Method method = Arrays.stream(testDeviceManager.getClass().getMethods())
.filter(tempMethod -> tempMethod.getName().equals(deviceAction.getMethod()))
.findFirst().orElse(
Arrays.stream(deviceManager.getClass().getDeclaredMethods())
Arrays.stream(testDeviceManager.getClass().getDeclaredMethods())
.filter(tempMethod -> tempMethod.getName().equals(deviceAction.getMethod()))
.findFirst().orElse(null)
);
Expand All @@ -85,7 +85,7 @@ public void doAction(@NotNull DeviceManager deviceManager, @NotNull DeviceInfo d

logger.info("Start to execute action! Current action is {}", deviceAction.getMethod());
method.setAccessible(true);
method.invoke(deviceManager, methodArgs);
method.invoke(testDeviceManager, methodArgs);
}

private Object[] convertArgs(@NotNull DeviceInfo deviceInfo, @NotNull Logger logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.microsoft.hydralab.common.entity.agent.DeviceTaskControl;
import com.microsoft.hydralab.common.entity.common.DeviceInfo;
import com.microsoft.hydralab.common.management.DeviceManager;
import com.microsoft.hydralab.common.management.device.TestDeviceManager;
import com.microsoft.hydralab.common.util.ThreadPoolUtil;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand All @@ -23,7 +23,7 @@ public class DeviceTaskControlExecutor {
@SuppressWarnings("constantname")
static final Logger log = LoggerFactory.getLogger(DeviceTaskControlExecutor.class);
@Resource
DeviceManager deviceManager;
TestDeviceManager testDeviceManager;

@Nullable
public DeviceTaskControl runForAllDeviceAsync(Collection<DeviceInfo> allDevices, DeviceTask task,
Expand Down Expand Up @@ -72,7 +72,7 @@ public DeviceTaskControl runForAllDeviceAsync(Collection<DeviceInfo> allDevices,
}
Logger logger = null;
if (logging) {
logger = deviceManager.getDeviceLogger(device);
logger = testDeviceManager.getDeviceLogger(device);
}
final Logger fLogger = logger;
devices.add(device);
Expand Down
Loading

0 comments on commit b40c643

Please sign in to comment.