use of com.testsigma.agent.exception.DeviceContainerException in project testsigma by testsigmahq.
the class DeviceContainer method disconnectDevices.
public void disconnectDevices() throws DeviceContainerException {
try {
for (Entry<String, MobileDevice> entry : deviceMap.entrySet()) {
String key = entry.getKey();
MobileDevice device = entry.getValue();
log.info("Removing the device " + key + " from device container");
AgentDeviceDTO agentDeviceDTO = getAgentDevice(key);
if (agentDeviceDTO != null) {
agentDeviceDTO.setIsOnline(false);
updateAgentDevice(agentDeviceDTO);
}
deviceMap.remove(key);
muxDeviceMap.remove(device.getMuxDeviceId());
}
log.info("Removed all the devices - " + deviceMap.size());
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new DeviceContainerException(e.getMessage(), e);
}
}
use of com.testsigma.agent.exception.DeviceContainerException in project testsigma by testsigmahq.
the class DeviceContainer method createAgentDevice.
private AgentDeviceDTO createAgentDevice(AgentDeviceDTO agentDeviceRequest) throws DeviceContainerException {
try {
AgentDeviceDTO agentDeviceDTO = null;
String agentUuid = agentConfig.getUUID();
String authHeader = WebAppHttpClient.BEARER + " " + this.agentConfig.getJwtApiKey();
HttpResponse<AgentDeviceDTO> response = httpClient.post(ServerURLBuilder.agentConnectedDevicesURL(agentUuid), agentDeviceRequest, new TypeReference<>() {
}, authHeader);
if (response.getStatusCode() == HttpStatus.CREATED.value()) {
agentDeviceDTO = response.getResponseEntity();
}
return agentDeviceDTO;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new DeviceContainerException(e.getMessage(), e);
}
}
use of com.testsigma.agent.exception.DeviceContainerException in project testsigma by testsigmahq.
the class DeviceContainer method updateAgentDevice.
private AgentDeviceDTO updateAgentDevice(AgentDeviceDTO agentDeviceRequest) throws DeviceContainerException {
try {
AgentDeviceDTO agentDeviceDTO = null;
String agentUuid = agentConfig.getUUID();
String authHeader = WebAppHttpClient.BEARER + " " + this.agentConfig.getJwtApiKey();
HttpResponse<AgentDeviceDTO> response = httpClient.put(ServerURLBuilder.agentConnectedDeviceURL(agentUuid, agentDeviceRequest.getUniqueId()), agentDeviceRequest, new TypeReference<>() {
}, authHeader);
if (response.getStatusCode() == HttpStatus.OK.value()) {
agentDeviceDTO = response.getResponseEntity();
}
return agentDeviceDTO;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new DeviceContainerException(e.getMessage(), e);
}
}
use of com.testsigma.agent.exception.DeviceContainerException in project testsigma by testsigmahq.
the class DeviceContainer method addDevice.
public void addDevice(MobileDevice mobileDevice) throws DeviceContainerException {
try {
if (mobileDevice == null) {
return;
}
String deviceUniqueId = mobileDevice.getUniqueId();
if (deviceUniqueId != null && !deviceMap.containsKey(deviceUniqueId)) {
AgentDeviceDTO agentDeviceDTO = getAgentDevice(deviceUniqueId);
if (agentDeviceDTO == null) {
log.info("Found a new device. Adding an entry for the device: " + mobileDevice);
createAgentDevice(mobileDeviceMapper.map(mobileDevice));
} else {
log.info("Found an existing device. Updating the entry for the device: " + mobileDevice);
mobileDeviceMapper.merge(mobileDevice, agentDeviceDTO);
updateAgentDevice(agentDeviceDTO);
}
deviceMap.put(mobileDevice.getUniqueId(), mobileDevice);
if (mobileDevice.getMuxDeviceId() != null) {
muxDeviceMap.put(mobileDevice.getMuxDeviceId(), mobileDevice);
}
mobileAutomationServerService.installDrivers(mobileDevice.getOsName(), mobileDevice.getUniqueId());
syncBrowserDrivers(mobileDevice);
} else {
log.info("Device " + deviceUniqueId + " already in container...");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new DeviceContainerException(e.getMessage(), e);
}
}
use of com.testsigma.agent.exception.DeviceContainerException in project testsigma by testsigmahq.
the class DeviceContainer method deleteDevice.
public void deleteDevice(String uniqueId) throws DeviceContainerException {
try {
for (Entry<String, MobileDevice> entry : deviceMap.entrySet()) {
String key = entry.getKey();
MobileDevice device = entry.getValue();
if (key.equals(uniqueId)) {
log.info("Removing the device " + key + " from device container");
AgentDeviceDTO agentDeviceDTO = getAgentDevice(key);
if (agentDeviceDTO != null) {
agentDeviceDTO.setIsOnline(false);
updateAgentDevice(agentDeviceDTO);
}
deviceMap.remove(key);
muxDeviceMap.remove(device.getMuxDeviceId());
break;
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new DeviceContainerException(e.getMessage(), e);
}
}
Aggregations