Skip to content

Commit

Permalink
Update DeviceAgentManagementService.java
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou9584 committed Dec 8, 2023
1 parent 290cffc commit 1f9400f
Showing 1 changed file with 11 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,35 +386,30 @@ private void updateAgentDeviceGroup(AgentSessionInfo savedSession, List<DeviceIn
* 2. ONLINE/OFFLINE/UNSTABLE can only be set in AGENT and sync to CENTER
*/
updateDeviceGroup(latestDeviceInfos, savedSession.agentUser.getId());

AgentDeviceGroup agentDeviceGroup = agentDeviceGroups.get(savedSession.agentUser.getId());
if (agentDeviceGroup != null) {
// update
updateAgentDevices(latestDeviceInfos, agentDeviceGroup);
} else {
AgentDeviceGroup newAgentDeviceGroup = new AgentDeviceGroup();
newAgentDeviceGroup.initWithAgentUser(savedSession.agentUser);
newAgentDeviceGroup.setDevices(new ArrayList<>(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<DeviceInfo> 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());
}
}

Expand Down Expand Up @@ -564,27 +559,6 @@ public void updateDeviceScope(String deviceSerial, Boolean isPrivate) {
sendMessageToSession(agentSession.session, message);
}

private void updateAgentDevices(List<DeviceInfo> 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);
Expand Down

0 comments on commit 1f9400f

Please sign in to comment.