コード例 #1
0
        /// <summary>
        /// Creates a new Heartbeat entity for the specified Agent id
        /// </summary>
        /// <param name="request"></param>
        /// <param name="agentId"></param>
        /// <returns>Newly created Heartbeat</returns>
        public AgentHeartbeat PerformAgentHeartbeat(HeartbeatViewModel request, string agentId)
        {
            Agent agent = _agentRepo.GetOne(new Guid(agentId));

            if (agent == null)
            {
                throw new EntityDoesNotExistException("The Agent ID provided does not match any existing Agents");
            }

            if (agent.IsConnected == false)
            {
                throw new EntityOperationException("Agent is not connected. Please connect the agent and try again");
            }

            if (request.IsHealthy == false)
            {
                _webhookPublisher.PublishAsync("Agents.UnhealthyReported", agent.Id.ToString(), agent.Name).ConfigureAwait(false);
            }

            AgentHeartbeat agentHeartbeat = request.Map(request);

            //Add HeartBeat Values
            agentHeartbeat.AgentId        = new Guid(agentId);
            agentHeartbeat.CreatedBy      = _caller?.Identity.Name;
            agentHeartbeat.CreatedOn      = DateTime.UtcNow;
            agentHeartbeat.LastReportedOn = request.LastReportedOn ?? DateTime.UtcNow;
            _agentHeartbeatRepo.Add(agentHeartbeat);

            return(agentHeartbeat);
        }
コード例 #2
0
        private void InitializeHeartbeat()
        {
            if (Heartbeat == null)
            {
                Heartbeat = new HeartbeatViewModel();
            }

            Heartbeat.LastReportedStatus  = AgentStatus.Available.ToString();
            Heartbeat.LastReportedWork    = string.Empty;
            Heartbeat.LastReportedMessage = string.Empty;
            Heartbeat.IsHealthy           = true;
            Heartbeat.GetNextJob          = true;
        }
コード例 #3
0
        public async Task <IActionResult> Heartbeat(string id,
                                                    [FromBody] HeartbeatViewModel request)
        {
            try
            {
                if (request == null)
                {
                    ModelState.AddModelError("HeartBeat", "No data passed");
                    return(BadRequest(ModelState));
                }

                Guid entityId = new Guid(id);
                var  agent    = agentRepo.GetOne(entityId);

                if (agent == null)
                {
                    return(NotFound("The Agent ID provided does not match any existing Agents"));
                }

                if (agent.IsConnected == false)
                {
                    ModelState.AddModelError("HeartBeat", "Agent is not connected");
                    return(BadRequest(ModelState));
                }

                JsonPatchDocument <AgentModel> heartbeatPatch = new JsonPatchDocument <AgentModel>();

                heartbeatPatch.Replace(e => e.LastReportedOn, request.LastReportedOn);
                heartbeatPatch.Replace(e => e.LastReportedStatus, request.LastReportedStatus);
                heartbeatPatch.Replace(e => e.LastReportedWork, request.LastReportedWork);
                heartbeatPatch.Replace(e => e.LastReportedMessage, request.LastReportedMessage);
                heartbeatPatch.Replace(e => e.IsHealthy, request.IsHealthy);

                return(await base.PatchEntity(id, heartbeatPatch));
            }

            catch (Exception ex)
            {
                ModelState.AddModelError("Heartbeat", ex.Message);
                return(ex.GetActionResult());
            }
        }
コード例 #4
0
        public async Task <IActionResult> AddHeartbeat([FromBody] HeartbeatViewModel request, string agentId)
        {
            try
            {
                var newHeartBeat = _agentManager.PerformAgentHeartbeat(request, agentId);
                var resultRoute  = "GetAgentHeartbeat";

                CreatedAtRoute(resultRoute, new { id = newHeartBeat.Id.Value.ToString("b") }, newHeartBeat);

                if (request.GetNextJob)
                {
                    var nextJob = _agentManager.GetNextJob(agentId);
                    return(Ok(nextJob));
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
コード例 #5
0
 public ExecutionManager(HeartbeatViewModel agentHeartbeat)
 {
     JobsQueueManager = new JobsQueueManager();
     _agentHeartbeat  = agentHeartbeat;
 }
コード例 #6
0
        public static NextJobViewModel SendAgentHeartBeat(UserInfo userInfo, string agentId, HeartbeatViewModel body)
        {
            var agentsApi = GetApiInstance(userInfo.Token, userInfo.ServerUrl);

            try
            {
                return(agentsApi.ApiVapiVersionAgentsAgentIdAddHeartbeatPostWithHttpInfo(agentId, userInfo.ApiVersion, userInfo.OrganizationId, body).Data);
            }
            catch (Exception ex)
            {
                if (ex.Message != "One or more errors occurred.")
                {
                    throw new InvalidOperationException("Exception when calling AgentsApi.SendAgentHeartBeat: " + ex.Message);
                }
                else
                {
                    throw new InvalidOperationException(ex.InnerException.Message);
                }
            }
        }
コード例 #7
0
        public static NextJobViewModel SendAgentHeartBeat(UserInfo userInfo, string agentId, HeartbeatViewModel body, int count = 0)
        {
            var agentsApi = GetApiInstance(userInfo.Token, userInfo.ServerUrl);

            try
            {
                return(agentsApi.ApiVapiVersionAgentsAgentIdAddHeartbeatPostWithHttpInfo(agentId, userInfo.ApiVersion, userInfo.OrganizationId, body).Data);
            }
            catch (Exception ex)
            {
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401" && count < 2)
                {
                    UtilityMethods.RefreshToken(userInfo);
                    count++;
                    return(SendAgentHeartBeat(userInfo, agentId, body, count));
                }
                else if (ex.Message != "One or more errors occurred.")
                {
                    throw new InvalidOperationException("Exception when calling AgentsApi.SendAgentHeartBeat: " + ex.Message);
                }
                else
                {
                    throw new InvalidOperationException(ex.InnerException.Message);
                }
            }
        }
コード例 #8
0
        public static ApiResponse <NextJobViewModel> SendAgentHeartBeat(AuthAPIManager apiManager, string agentId, HeartbeatViewModel body)
        {
            AgentsApi agentsApi = new AgentsApi(apiManager.Configuration);

            try
            {
                return(agentsApi.ApiV1AgentsAgentIdAddHeartbeatPostWithHttpInfo(agentId, body));
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    agentsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(agentsApi.ApiV1AgentsAgentIdAddHeartbeatPostWithHttpInfo(agentId, body));
                }
                throw ex;
            }
        }