Esempio n. 1
0
        /// <summary>
        /// Posts a health report against Patch Orchestration Application's NodeAgentService
        /// </summary>
        /// <param name="fabricClient">Fabric client object to carry out HM operations</param>
        /// <param name="applicationName">Name of the application to construct servicename</param>
        /// <param name="healthReportProperty">Property of the health report</param>
        /// <param name="description">Description of the health report</param>
        /// <param name="healthState">HealthState for the health report</param>
        /// <param name="timeToLiveInMinutes">Time to live in minutes for health report</param>
        internal static NodeAgentSfUtilityExitCodes PostServiceHealthReport(FabricClient fabricClient, Uri applicationName, string healthReportProperty, string description,
                                                                            HealthState healthState, long timeToLiveInMinutes = -1)
        {
            HealthInformation healthInformation = new HealthInformation(SourceId, healthReportProperty,
                                                                        healthState)
            {
                RemoveWhenExpired = true,
                Description       = description
            };

            if (timeToLiveInMinutes >= 0)
            {
                healthInformation.TimeToLive = TimeSpan.FromMinutes(timeToLiveInMinutes);
            }

            try
            {
                ServiceHealthReport healthReport = new ServiceHealthReport(new Uri(applicationName + ServiceNameSuffix), healthInformation);
                fabricClient.HealthManager.ReportHealth(healthReport);
                return(NodeAgentSfUtilityExitCodes.Success);
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ErrorMessage(
                    String.Format("HealthManagerHelper.PostNodeHealthReport failed. Exception details {0}", e));
                if (e is FabricTransientException)
                {
                    return(NodeAgentSfUtilityExitCodes.RetryableException);
                }
                else
                {
                    return(NodeAgentSfUtilityExitCodes.Failure);
                }
            }
        }
Esempio n. 2
0
 private EntityHealthEvent GetMockHealthEvent(long sequenceNumber, FabricHealth.HealthState state, string sourceEnityPrefix)
 {
     return(new EntityHealthEvent(
                state,
                string.Format("Test.{0}.Description", sourceEnityPrefix),
                string.Format("Test.{0}.Property", sourceEnityPrefix),
                sequenceNumber,
                string.Format("Test.{0}.Source", sourceEnityPrefix),
                false));
 }
Esempio n. 3
0
        private NodeHealth Create_NodeHealthMock(
            string nodeName,
            FabricHealth.HealthState state,
            IEnumerable <EntityHealthEvent> healthEvents,
            IList <System.Fabric.Health.HealthEvaluation> unhealthyEvaluations)
        {
            var nodeMock = new Mock <NodeHealth>(nodeName, state)
            {
                CallBase = true
            };

            nodeMock.Setup(mock => mock.HealthEvents).Returns(healthEvents);
            nodeMock.Setup(mock => mock.UnhealthyEvaluations).Returns(unhealthyEvaluations);
            return(nodeMock.Object);
        }
Esempio n. 4
0
        private ReplicaHealth Create_ReplicaHealthMock(
            Guid partitionId,
            long replicaId,
            FabricHealth.HealthState state,
            IEnumerable <EntityHealthEvent> healthEvents,
            IList <System.Fabric.Health.HealthEvaluation> unhealthyEvaluations)
        {
            var replicaMock = new Mock <ReplicaHealth>(partitionId, replicaId, state)
            {
                CallBase = true
            };

            replicaMock.Setup(mock => mock.HealthEvents).Returns(healthEvents);
            replicaMock.Setup(mock => mock.UnhealthyEvaluations).Returns(unhealthyEvaluations);
            return(replicaMock.Object);
        }
Esempio n. 5
0
        private ServiceHealth Create_ServiceHealthMock(
            Uri serviceUri,
            FabricHealth.HealthState state,
            IEnumerable <PartitionHealthState> partitionHealthStates,
            IEnumerable <EntityHealthEvent> healthEvents,
            IList <System.Fabric.Health.HealthEvaluation> unhealthyEvaluations)
        {
            var serviceMock = new Mock <ServiceHealth>(serviceUri, state)
            {
                CallBase = true
            };

            serviceMock.Setup(mock => mock.PartitionHealthStates).Returns(partitionHealthStates);
            serviceMock.Setup(mock => mock.HealthEvents).Returns(healthEvents);
            serviceMock.Setup(mock => mock.UnhealthyEvaluations).Returns(unhealthyEvaluations);
            return(serviceMock.Object);
        }
Esempio n. 6
0
        private ClusterHealth Create_ClusterHealthMock(
            FabricHealth.HealthState state,
            IEnumerable <ApplicationHealthState> applicationHealthStates,
            IEnumerable <NodeHealthState> nodeHealthStates,
            IEnumerable <EntityHealthEvent> healthEvents,
            IList <System.Fabric.Health.HealthEvaluation> unhealthyEvaluations)
        {
            var clusterHealthMock = new Mock <ClusterHealth>(state)
            {
                CallBase = true
            };

            clusterHealthMock.Setup(mock => mock.ApplicationHealthStates).Returns(applicationHealthStates);
            clusterHealthMock.Setup(mock => mock.NodeHealthStates).Returns(nodeHealthStates);
            clusterHealthMock.Setup(mock => mock.HealthEvents).Returns(healthEvents);
            clusterHealthMock.Setup(mock => mock.UnhealthyEvaluations).Returns(unhealthyEvaluations);
            return(clusterHealthMock.Object);
        }
Esempio n. 7
0
        private ApplicationHealth Create_ApplicationHealthMock(
            Uri appUri,
            FabricHealth.HealthState state,
            IEnumerable <ServiceHealthState> serviceHealthStates,
            IEnumerable <DeployedApplicationHealthState> deployedAppHealthStates,
            IEnumerable <EntityHealthEvent> healthEvents,
            IList <System.Fabric.Health.HealthEvaluation> unhealthyEvaluations)
        {
            var appMock = new Mock <ApplicationHealth>(appUri, state)
            {
                CallBase = true
            };

            appMock.Setup(mock => mock.ServiceHealthStates).Returns(serviceHealthStates);
            appMock.Setup(mock => mock.DeployedApplicationHealthStates).Returns(deployedAppHealthStates);
            appMock.Setup(mock => mock.HealthEvents).Returns(healthEvents);
            appMock.Setup(mock => mock.UnhealthyEvaluations).Returns(unhealthyEvaluations);
            return(appMock.Object);
        }
Esempio n. 8
0
        /// <summary>
        /// Suffix name to be appended with ApplicationName
        /// </summary>

        /// <summary>
        /// Posts a health report against Patch Orchestration Application's NodeAgentService
        /// </summary>
        /// <param name="fabricClient">Fabric client object to carry out HM operations</param>
        /// <param name="applicationName">Name of the application to construct servicename</param>
        /// <param name="serviceNameSuffix">serviceNameSuffix of the service to construct servicename</param>
        /// <param name="healthReportProperty">Property of the health report</param>
        /// <param name="description">Description of the health report</param>
        /// <param name="healthState">HealthState for the health report</param>
        /// <param name="timeToLiveInMinutes">Time to live in minutes for health report</param>
        /// <param name="timeout">Configured timeout for this operation.</param>
        internal static NodeAgentSfUtilityExitCodes PostServiceHealthReport(FabricClient fabricClient, Uri applicationName, string serviceNameSuffix, string healthReportProperty, string description,
                                                                            HealthState healthState, TimeSpan timeout, long timeToLiveInMinutes = -1)
        {
            HealthInformation healthInformation = new HealthInformation(SourceId, healthReportProperty,
                                                                        healthState)
            {
                RemoveWhenExpired = true,
                Description       = description
            };

            if (timeToLiveInMinutes >= 0)
            {
                healthInformation.TimeToLive = TimeSpan.FromMinutes(timeToLiveInMinutes);
            }

            try
            {
                ServiceHealthReport     healthReport = new ServiceHealthReport(new Uri(applicationName + serviceNameSuffix), healthInformation);
                HealthReportSendOptions sendOptions  = new HealthReportSendOptions();
                sendOptions.Immediate = true;
                fabricClient.HealthManager.ReportHealth(healthReport, sendOptions);

                Task.Delay(TimeSpan.FromSeconds(2)).GetAwaiter().GetResult();
                return(NodeAgentSfUtilityExitCodes.Success);
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ErrorMessage(
                    String.Format("HealthManagerHelper.PostNodeHealthReport for Service {0} failed. Exception details {1}", serviceNameSuffix, e));
                if (e is FabricTransientException)
                {
                    return(NodeAgentSfUtilityExitCodes.RetryableException);
                }
                else if (e is TimeoutException)
                {
                    return(NodeAgentSfUtilityExitCodes.TimeoutException);
                }
                else
                {
                    return(NodeAgentSfUtilityExitCodes.Failure);
                }
            }
        }