Search in sources :

Example 1 with AgentOs

use of com.testsigma.agent.constants.AgentOs in project testsigma by testsigmahq.

the class AgentBrowserService method sync.

public void sync() throws AgentDeletedException {
    try {
        if (!startSync()) {
            return;
        }
        log.info("Syncing agent details");
        String hostName = AgentService.getComputerName();
        String uuid = agentConfig.getUUID();
        AgentDTO agentDTO = new AgentDTO();
        AgentOs osType = AgentOs.getLocalAgentOs();
        agentDTO.setOsType(osType);
        agentDTO.setOsVersion(AgentService.getOsVersion());
        agentDTO.setHostName(hostName);
        agentDTO.setIpAddress(NetworkUtil.getCurrentIpAddress());
        agentDTO.setAgentVersion(this.agentConfig.getAgentVersion());
        agentDTO.setBrowserList(this.getBrowserList());
        String authHeader = WebAppHttpClient.BEARER + " " + this.agentConfig.getJwtApiKey();
        HttpResponse<AgentDTO> response = httpClient.put(ServerURLBuilder.agentURL(uuid), agentDTO, new TypeReference<>() {
        }, authHeader);
        log.debug(response);
        if (response.getStatusCode() == HttpStatus.OK.value()) {
            log.info("Successfully updated latest agent details...");
        } else {
            log.info("Failed to sync latest hybrid agent details to application server");
            log.info("Error code: " + response.getStatusCode() + " - " + response.getStatusMessage());
        }
    } catch (AgentDeletedException e) {
        throw e;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    log.debug("Finished syncing agent details");
}
Also used : AgentDTO(com.testsigma.agent.dto.AgentDTO) AgentOs(com.testsigma.agent.constants.AgentOs) AgentDeletedException(com.testsigma.automator.exceptions.AgentDeletedException) AgentDeletedException(com.testsigma.automator.exceptions.AgentDeletedException)

Example 2 with AgentOs

use of com.testsigma.agent.constants.AgentOs in project testsigma by testsigmahq.

the class HomeController method register.

@PutMapping(value = "/{uuid}/register", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> register(@PathVariable("uuid") String uuid, @RequestParam(value = "jwtApiKey", required = false) String jwtApiKey) {
    ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.ACCEPTED);
    try {
        log.debug("Received sync request for agent with uuid - " + uuid);
        String hostName = AgentService.getComputerName();
        AgentOs osType = AgentOs.getLocalAgentOs();
        AgentDTO agentDTO = new AgentDTO();
        agentDTO.setHostName(hostName);
        agentDTO.setOsVersion(AgentService.getOsVersion());
        agentDTO.setAgentVersion(this.agentConfig.getAgentVersion());
        agentDTO.setBrowserList(agentBrowserService.getBrowserList());
        agentDTO.setHostName(hostName);
        agentDTO.setOsType(osType);
        String authHeader = WebAppHttpClient.BEARER + " " + jwtApiKey;
        HttpResponse<AgentDTO> syncResponse = httpClient.put(ServerURLBuilder.agentURL(uuid), agentDTO, new TypeReference<>() {
        }, authHeader);
        if (syncResponse.getStatusCode() == HttpStatus.OK.value()) {
            agentConfig.setJwtApiKey(jwtApiKey);
            agentConfig.setUUID(uuid);
            agentConfig.setRegistered("true");
            agentConfig.saveConfig();
            BaseScheduler.setSkip(Boolean.FALSE);
            ExecutorService executorService = Executors.newSingleThreadExecutor();
            executorService.submit(androidDeviceListener);
            ExecutorService executorService1 = Executors.newSingleThreadExecutor();
            executorService1.submit(iosDeviceListener);
        } else {
            response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
    return response;
}
Also used : AgentDTO(com.testsigma.agent.dto.AgentDTO) ResponseEntity(org.springframework.http.ResponseEntity) AgentOs(com.testsigma.agent.constants.AgentOs) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

AgentOs (com.testsigma.agent.constants.AgentOs)2 AgentDTO (com.testsigma.agent.dto.AgentDTO)2 AgentDeletedException (com.testsigma.automator.exceptions.AgentDeletedException)1 ExecutorService (java.util.concurrent.ExecutorService)1 ResponseEntity (org.springframework.http.ResponseEntity)1