From ee7660e0d74b5288c9f861557ae6e6bf44124b4a Mon Sep 17 00:00:00 2001 From: Le Zhou <2428499107@qq.com> Date: Fri, 8 Dec 2023 11:39:20 +0800 Subject: [PATCH 1/5] Bugfix: update center device status and list totally --- .../service/DeviceAgentManagementService.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java index 70f606b1e..b30f0202c 100644 --- a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java +++ b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java @@ -567,31 +567,23 @@ public void updateDeviceScope(String deviceSerial, Boolean isPrivate) { private void updateAgentDevices(List agentDeviceInfos, AgentDeviceGroup agentDeviceGroup) { for (DeviceInfo agentDeviceInfo : agentDeviceInfos) { - boolean hasDevice = false; for (DeviceInfo centerDeviceInfo : agentDeviceGroup.getDevices()) { //if the status saved in Center is testing, the value will not be covered - if (deviceListMap.get(centerDeviceInfo.getSerialNum()) != null && deviceListMap.get(centerDeviceInfo.getSerialNum()).isTesting()) { - centerDeviceInfo.setStatus(DeviceInfo.TESTING); - hasDevice = true; + if (deviceListMap.get(agentDeviceInfo.getSerialNum()) != null && deviceListMap.get(agentDeviceInfo.getSerialNum()).isTesting()) { + agentDeviceInfo.setStatus(DeviceInfo.TESTING); log.info("Updating device status of agent: {}, device SN: {}", agentDeviceGroup.getAgentName(), agentDeviceInfo.getSerialNum()); break; } if (centerDeviceInfo.getSerialNum().equals(agentDeviceInfo.getSerialNum())) { - hasDevice = true; if (DeviceInfo.TESTING.equals(agentDeviceInfo.getStatus())) { log.warn("Device status is out-of-sync between center/agent, CENTER: {}, AGENT: {}", centerDeviceInfo.getStatus(), agentDeviceInfo.getStatus()); agentDeviceInfo.setStatus(centerDeviceInfo.getStatus()); } - BeanUtil.copyProperties(agentDeviceInfo, centerDeviceInfo); - log.info("Updating device info of agent: {}, device SN: {}", agentDeviceGroup.getAgentName(), agentDeviceInfo.getSerialNum()); break; } } - if (!hasDevice) { - log.info("Adding device info of agent: {}, device SN: {}", agentDeviceGroup.getAgentName(), agentDeviceInfo.getSerialNum()); - agentDeviceGroup.getDevices().add(agentDeviceInfo); - } } + agentDeviceGroup.setDevices(agentDeviceInfos); } private void requestList(Session session) { From 290cffce4ca16bcee5e3173958b8c3a73422392d Mon Sep 17 00:00:00 2001 From: Le Zhou <2428499107@qq.com> Date: Fri, 8 Dec 2023 16:42:02 +0800 Subject: [PATCH 2/5] Update DeviceAgentManagementService.java --- .../hydralab/center/service/DeviceAgentManagementService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java index b30f0202c..a856651ec 100644 --- a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java +++ b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java @@ -3,7 +3,6 @@ package com.microsoft.hydralab.center.service; -import cn.hutool.core.bean.BeanUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.android.ddmlib.IDevice; From 1f9400f4516f00ba1c0f9fbf0e9f7feb93e558ac Mon Sep 17 00:00:00 2001 From: Le Zhou <2428499107@qq.com> Date: Fri, 8 Dec 2023 16:55:27 +0800 Subject: [PATCH 3/5] Update DeviceAgentManagementService.java --- .../service/DeviceAgentManagementService.java | 48 +++++-------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java index a856651ec..d5d509987 100644 --- a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java +++ b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java @@ -386,35 +386,30 @@ private void updateAgentDeviceGroup(AgentSessionInfo savedSession, List(latestDeviceInfos)); - agentDeviceGroups.put(savedSession.agentUser.getId(), newAgentDeviceGroup); - log.info("Adding info of new agent: {}, device SN: {}", newAgentDeviceGroup.getAgentName(), + if (agentDeviceGroup == null) { + agentDeviceGroup = new AgentDeviceGroup(); + agentDeviceGroup.initWithAgentUser(savedSession.agentUser); + agentDeviceGroups.put(savedSession.agentUser.getId(), agentDeviceGroup); + log.info("Adding info of new agent: {}, device SN: {}", agentDeviceGroup.getAgentName(), latestDeviceInfos.stream().map(MobileDevice::getSerialNum).collect(Collectors.joining(","))); } + agentDeviceGroup.setDevices(new ArrayList<>(latestDeviceInfos)); } public void updateDeviceGroup(List agentDeviceInfos, String agentId) { for (DeviceInfo agentDeviceInfo : agentDeviceInfos) { //init agent info agentDeviceInfo.setAgentId(agentId); - + DeviceInfo centerDevice = deviceListMap.get(agentDeviceInfo.getSerialNum()); // if the status saved in Center is testing, the value will not be covered - if (deviceListMap.get(agentDeviceInfo.getSerialNum()) != null) { - if (deviceListMap.get(agentDeviceInfo.getSerialNum()).isTesting()) { - log.warn("Center status: {}, Agent status: {}, status should be synced to CENTER's value when TESTING.", - deviceListMap.get(agentDeviceInfo.getSerialNum()).getStatus(), agentDeviceInfo.getStatus()); + if (centerDevice != null) { + if (centerDevice.isTesting()) { + log.warn("Center status: {}, Agent status: {}, status should be synced to CENTER's value when TESTING.", centerDevice.getStatus(), agentDeviceInfo.getStatus()); agentDeviceInfo.setStatus(DeviceInfo.TESTING); } else if (agentDeviceInfo.isTesting()) { log.warn("Test on the device is canceled, status of device in AGENT should be reset to ONLINE, otherwise TESTING would never be covered by agent"); - agentDeviceInfo.setStatus(DeviceInfo.ONLINE); + agentDeviceInfo.setStatus(centerDevice.getStatus()); } } @@ -564,27 +559,6 @@ public void updateDeviceScope(String deviceSerial, Boolean isPrivate) { sendMessageToSession(agentSession.session, message); } - private void updateAgentDevices(List agentDeviceInfos, AgentDeviceGroup agentDeviceGroup) { - for (DeviceInfo agentDeviceInfo : agentDeviceInfos) { - for (DeviceInfo centerDeviceInfo : agentDeviceGroup.getDevices()) { - //if the status saved in Center is testing, the value will not be covered - if (deviceListMap.get(agentDeviceInfo.getSerialNum()) != null && deviceListMap.get(agentDeviceInfo.getSerialNum()).isTesting()) { - agentDeviceInfo.setStatus(DeviceInfo.TESTING); - log.info("Updating device status of agent: {}, device SN: {}", agentDeviceGroup.getAgentName(), agentDeviceInfo.getSerialNum()); - break; - } - if (centerDeviceInfo.getSerialNum().equals(agentDeviceInfo.getSerialNum())) { - if (DeviceInfo.TESTING.equals(agentDeviceInfo.getStatus())) { - log.warn("Device status is out-of-sync between center/agent, CENTER: {}, AGENT: {}", centerDeviceInfo.getStatus(), agentDeviceInfo.getStatus()); - agentDeviceInfo.setStatus(centerDeviceInfo.getStatus()); - } - break; - } - } - } - agentDeviceGroup.setDevices(agentDeviceInfos); - } - private void requestList(Session session) { Message message = new Message(); message.setPath(Const.Path.DEVICE_LIST); From 49e0602954b3086492376d4bfe19a4bd097ea9d4 Mon Sep 17 00:00:00 2001 From: Le Zhou <2428499107@qq.com> Date: Fri, 8 Dec 2023 17:00:50 +0800 Subject: [PATCH 4/5] Update DeviceAgentManagementService.java --- .../hydralab/center/service/DeviceAgentManagementService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java index d5d509987..835145ed8 100644 --- a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java +++ b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java @@ -409,7 +409,7 @@ public void updateDeviceGroup(List agentDeviceInfos, String agentId) agentDeviceInfo.setStatus(DeviceInfo.TESTING); } else if (agentDeviceInfo.isTesting()) { log.warn("Test on the device is canceled, status of device in AGENT should be reset to ONLINE, otherwise TESTING would never be covered by agent"); - agentDeviceInfo.setStatus(centerDevice.getStatus()); + agentDeviceInfo.setStatus(DeviceInfo.ONLINE); } } From e01098f0dc5047a3da5399ef7e59732f76992621 Mon Sep 17 00:00:00 2001 From: Le Zhou <2428499107@qq.com> Date: Wed, 13 Dec 2023 10:08:18 +0800 Subject: [PATCH 5/5] Update DeviceAgentManagementService.java --- .../service/DeviceAgentManagementService.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java index 835145ed8..9d8b4fb6e 100644 --- a/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java +++ b/center/src/main/java/com/microsoft/hydralab/center/service/DeviceAgentManagementService.java @@ -403,14 +403,12 @@ public void updateDeviceGroup(List agentDeviceInfos, String agentId) agentDeviceInfo.setAgentId(agentId); DeviceInfo centerDevice = deviceListMap.get(agentDeviceInfo.getSerialNum()); // if the status saved in Center is testing, the value will not be covered - if (centerDevice != null) { - if (centerDevice.isTesting()) { - log.warn("Center status: {}, Agent status: {}, status should be synced to CENTER's value when TESTING.", centerDevice.getStatus(), agentDeviceInfo.getStatus()); - agentDeviceInfo.setStatus(DeviceInfo.TESTING); - } else if (agentDeviceInfo.isTesting()) { - log.warn("Test on the device is canceled, status of device in AGENT should be reset to ONLINE, otherwise TESTING would never be covered by agent"); - agentDeviceInfo.setStatus(DeviceInfo.ONLINE); - } + if (centerDevice != null && centerDevice.isTesting()) { + log.warn("Center status: {}, Agent status: {}, status should be synced to CENTER's value when TESTING.", centerDevice.getStatus(), agentDeviceInfo.getStatus()); + agentDeviceInfo.setStatus(DeviceInfo.TESTING); + } else if (agentDeviceInfo.isTesting()) { + log.warn("Test on the device is canceled, status of device in AGENT should be reset to ONLINE, otherwise TESTING would never be covered by agent"); + agentDeviceInfo.setStatus(DeviceInfo.ONLINE); } deviceListMap.put(agentDeviceInfo.getSerialNum(), agentDeviceInfo);