/// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, NodeHealth obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.AggregatedHealthState, "AggregatedHealthState", HealthStateConverter.Serialize);
            if (obj.HealthEvents != null)
            {
                writer.WriteEnumerableProperty(obj.HealthEvents, "HealthEvents", HealthEventConverter.Serialize);
            }

            if (obj.UnhealthyEvaluations != null)
            {
                writer.WriteEnumerableProperty(obj.UnhealthyEvaluations, "UnhealthyEvaluations", HealthEvaluationWrapperConverter.Serialize);
            }

            if (obj.HealthStatistics != null)
            {
                writer.WriteProperty(obj.HealthStatistics, "HealthStatistics", HealthStatisticsConverter.Serialize);
            }

            if (obj.Name != null)
            {
                writer.WriteProperty(obj.Name, "Name", NodeNameConverter.Serialize);
            }

            writer.WriteEndObject();
        }
Esempio n. 2
0
        private void ReportHealth(string property, HealthState state, string description = Source)
        {
            LogHelper.Log("Report health for node={0}; source={1};property={2};state={3};description={4}", NodeName, Source, property, state.ToString(), description);
            HealthInformation healthInformation = new HealthInformation(Source, property, state);

            healthInformation.Description = description;
            HealthReport healthReport = new NodeHealthReport(NodeName, healthInformation);

            try
            {
                HealthManager.ReportHealth(healthReport);
            }
            catch (Exception exception)
            {
                Assert.Fail("Report health throws exception {0}", exception.Message);
            }

            bool healthEventUpdated = false;

            while (!healthEventUpdated)
            {
                Thread.Sleep(HealthUpdateDelayTime);
                NodeHealth nodeHealth = HealthManager.GetNodeHealthAsync(NodeName).Result;
                var        eventQuery = from healthEvent in nodeHealth.HealthEvents
                                        where healthEvent.HealthInformation.SourceId == Source &&
                                        healthEvent.HealthInformation.Property == property &&
                                        healthEvent.HealthInformation.HealthState == state
                                        select healthEvent;
                healthEventUpdated = eventQuery.Any();
            }
        }
Esempio n. 3
0
        public void ClearError()
        {
            NodeHealth nodeHealth = HealthManager.GetNodeHealthAsync(NodeName).Result;
            var        eventQuery = from healthEvent in nodeHealth.HealthEvents
                                    where healthEvent.HealthInformation.SourceId == Source &&
                                    healthEvent.HealthInformation.HealthState == HealthState.Error
                                    select healthEvent;

            foreach (var healthEvent in eventQuery)
            {
                ReportOk(healthEvent.HealthInformation.Property);
            }
        }
Esempio n. 4
0
    private void PopulateNodesPage()
    {
        //Bind Health
        List <KeyValuePair <string, string> > headers = new List <KeyValuePair <string, string> >();
        IRestServiceHelper RESTServiceHelper          = CurrentRequest.Resolver.Resolve <IRestServiceHelper>();
        KeyValuePair <NodeHealth, string> result      = RESTServiceHelper.CallService <NodeHealth>(RESTServiceList.ServerHealthService, (m_health.HealthServiceURL != string.Empty? m_health.HealthServiceURL + "/nodes/" + Request.QueryString["NodeName"]:""), LanguageID, HttpMethod.Get, String.Empty, false, headers);
        string errorMessage = result.Value;

        nodeHealth = result.Key;

        //Errors
        DataTable dtErrors = new DataTable();

        dtErrors.Columns.AddRange(new DataColumn[] { new DataColumn("Severity"), new DataColumn("ParamID"), new DataColumn("Description"), new DataColumn("Duration") });
        gvNodeWarnings.Columns[0].HeaderText = PhraseLib.Lookup("term.severity", LanguageID);
        gvNodeWarnings.Columns[1].HeaderText = PhraseLib.Lookup("term.code", LanguageID);
        gvNodeWarnings.Columns[2].HeaderText = PhraseLib.Lookup("term.description", LanguageID);
        gvNodeWarnings.Columns[3].HeaderText = PhraseLib.Lookup("term.duration", LanguageID);

        if (errorMessage == string.Empty && nodeHealth != null)
        {
            Alert.Checked  = nodeHealth.Machine.Alert;
            Report.Checked = nodeHealth.Machine.Report;

            bool hasPromotionBroker = false;
            bool hasCustomerBroker  = false;

            foreach (var component in nodeHealth.Machine.Components)
            {
                if (!component.Alive)
                {
                    component.Attributes.Insert(0, new CMS.AMS.Models.Attribute {
                        Severity = component.Severity, Code = RequestStatusConstants.Failure, ParamID = (component.ComponentName.ToUpper().Contains(BrokerNameConstants.PromotionBroker) ? (component.IsPromoFetchNode ? ServerHealthErrorCodes.PromoFecthNode_Disconnected: ServerHealthErrorCodes.PromotionBroker_Disconnected) : ServerHealthErrorCodes.CustomerBroker_Disconnected), Description = (PhraseLibExtension.PhraseLib.Lookup("term.disconnected", LanguageID)), LastUpdate = component.LastHeard
                    });
                }

                foreach (var error in component.Attributes.Where(e => e.Code == RequestStatusConstants.Failure))
                {
                    dtErrors.Rows.Add(PhraseLib.Lookup("term." + error.Severity, LanguageID), error.ParamID, ServerHealthHelper.GetErrorDescription(error.ParamID, LanguageID), error.LastUpdate.ConvertToDuration(LanguageID));
                }

                if (component.ComponentName.ToUpper().Contains(BrokerNameConstants.PromotionBroker))
                {
                    lblPBStatus.Text    = component.Alive ? PhraseLib.Lookup("term.connected", LanguageID) : "<font color=\"red\">" + PhraseLib.Lookup("term.disconnected", LanguageID) + "</font>";
                    lblPBLastHeard.Text = component.LastHeard.ConvertToLocalDateTime().ToString();

                    foreach (var attr in component.Attributes)
                    {
                        if (attr.Description.ToUpper().Contains("FETCH"))
                        {
                            lblLastUpdateOffer.Text = attr.LastUpdate.ConvertToLocalDateTime().ToString();
                        }
                        if (attr.Description.ToUpper().Contains("IPL"))
                        {
                            lblLastIPL.Text = attr.LastUpdate.ConvertToLocalDateTime().ToString();
                        }
                    }
                    if (lblLastUpdateOffer.Text == "")
                    {
                        lblLastUpdateOffer.Text = "-";
                    }
                    if (lblLastIPL.Text == "")
                    {
                        lblLastIPL.Text = "-";
                    }
                    hasPromotionBroker = true;
                }
                else if (component.ComponentName.ToUpper().Contains(BrokerNameConstants.CustomerBroker))
                {
                    lblCBStatus.Text          = component.Alive ? PhraseLib.Lookup("term.connected", LanguageID) : "<font color=\"red\">" + PhraseLib.Lookup("term.disconnected", LanguageID) + "</font>";
                    lblCBLastHeard.Text       = component.LastHeard.ConvertToLocalDateTime().ToString();
                    lblLastLookUp.Text        = ServerHealthHelper.RetrieveAttribute(component.Attributes, ServerHealthErrorCodes.CustomerBroker_LastCustomerLookup);
                    lblLastTransDownload.Text = ServerHealthHelper.RetrieveAttribute(component.Attributes, ServerHealthErrorCodes.CustomerBroker_LastTransactionDownload);
                    lblLastTransUpload.Text   = ServerHealthHelper.RetrieveAttribute(component.Attributes, ServerHealthErrorCodes.CustomerBroker_LastTransactionUpload);
                    hasCustomerBroker         = true;
                }
            }
            divCB.Visible         = hasCustomerBroker;
            divPB.Visible         = hasPromotionBroker;
            communication.Visible = hasPromotionBroker;

            if (dtErrors.Rows.Count > 0)
            {
                gvNodeWarnings.DataSource = dtErrors;
                gvNodeWarnings.DataBind();
            }
            else
            {
                lblError.Text = "<center>" + PhraseLib.Lookup("term.norecords", LanguageID) + "</center>";
            }

            //Identification
            lblNodeName.Text  = Server.HtmlEncode(nodeHealth.Machine.NodeName);
            lblIpAddress.Text = Server.HtmlEncode(nodeHealth.Machine.NodeIP);
        }
        else
        {
            ucServerHealthTabs.SetInfoMessage(errorMessage, true, true);
        }
    }
Esempio n. 5
0
    private void PopulateEnginesPage()
    {
        //Bind Health
        string errorMessage = "";
        List <KeyValuePair <string, string> > headers = new List <KeyValuePair <string, string> >();
        IRestServiceHelper RESTServiceHelper          = CurrentRequest.Resolver.Resolve <IRestServiceHelper>();
        KeyValuePair <NodeHealth, string> result      = RESTServiceHelper.CallService <NodeHealth>(RESTServiceList.ServerHealthService, (hdnURL.Value != string.Empty? hdnURL.Value + "/engines/":"") + Request.QueryString["NodeName"], LanguageID, HttpMethod.Get, String.Empty, false, headers);

        engineHealth = result.Key;
        errorMessage = result.Value;

        if (errorMessage == string.Empty && engineHealth != null)
        {
            //Identification
            lblEngineName.Text        = Server.HtmlEncode(engineHealth.Machine.NodeName);
            lblIpAddress.Text         = Server.HtmlEncode(engineHealth.Machine.NodeIP);
            lblStatus.Text            = engineHealth.Machine.Components[0].Alive ? PhraseLib.Lookup("term.connected", LanguageID) : "<font color=\"red\">" + PhraseLib.Lookup("term.disconnected", LanguageID) + "</font>";
            lblType.Text              = (engineHealth.Machine.Components[0].EnterpriseEngine) ? PhraseLib.Lookup("serverhealth.enterpriseengine", LanguageID) : PhraseLib.Lookup("serverhealth.storeengine", LanguageID);
            Alert.Checked             = engineHealth.Machine.Alert;
            Report.Checked            = engineHealth.Machine.Report;
            hdnLocationID.Value       = engineHealth.Machine.StoreID;
            hdnEnterpriseEngine.Value = engineHealth.Machine.Components[0].EnterpriseEngine.ToString().ToLower();

            if (engineHealth.Machine.Components[0].EnterpriseEngine)
            {
                linkConfig.Visible = false;
            }
            else
            {
                linkConfig.Text        = PhraseLib.Lookup("term.storeconfiguration", LanguageID);
                linkConfig.NavigateUrl = "../store-edit.aspx?LocationID=" + hdnLocationID.Value;
                linkConfig.Visible     = true;
            }

            lblStore.Text = Server.HtmlEncode((engineHealth.Machine.Components[0].EnterpriseEngine) ? PhraseLib.Lookup("term.all", LanguageID) + " " + PhraseLib.Lookup("term.stores", LanguageID) : engineHealth.Machine.StoreName);

            //Last CardHolder Look-Up
            lblCardholderlookup.Text = ServerHealthHelper.RetrieveAttribute(engineHealth.Machine.Components[0].Attributes, (engineHealth.Machine.Components[0].EnterpriseEngine == true ? ServerHealthErrorCodes.EnterpriseEngine_LastCustomerLookup : ServerHealthErrorCodes.PromotionEngine_LastCustomerLookup));

            //Last TransUpload
            lblTransactionupload.Text = ServerHealthHelper.RetrieveAttribute(engineHealth.Machine.Components[0].Attributes, (engineHealth.Machine.Components[0].EnterpriseEngine == true ? ServerHealthErrorCodes.EnterpriseEngine_LastTransactionUpload : ServerHealthErrorCodes.PromotionEngine_LastTransactionUpload));

            //Last Sync
            lblsync.Text = ServerHealthHelper.RetrieveAttribute(engineHealth.Machine.Components[0].Attributes, (engineHealth.Machine.Components[0].EnterpriseEngine == true ? ServerHealthErrorCodes.EnterpriseEngine_LastSync: ServerHealthErrorCodes.PromotionEngine_LastSync));

            //Last Heard
            lblLastHeard.Text = engineHealth.Machine.Components[0].LastHeard.ConvertToLocalDateTime().ToString();

            //Broker to Engine Pending Files
            //BindFiles(hdnURL.Value + "/engines/" + engineHealth.Machine.NodeName + "/files?offset=0&pagesize=" + hdnPageSize.Value, gvEngineFiles, hdnPageSize, hdnPageCount, loadmoreajaxloader);
            BindFiles(engineHealth.PendingFilesURL + "?offset=0&pagesize=" + hdnPageSize.Value, gvEngineFiles, hdnPageSize, hdnPageCount, loadmoreajaxloader);
            hdnPendingFilesURL.Value = engineHealth.PendingFilesURL;

            //Logix to Broker Pending Files
            if (engineHealth.Machine.Components[0].EnterpriseEngine)
            {
                BindFiles(hdnURL.Value + "/enterprise/logixfiles?offset=0&pagesize=" + hdnPageSize1.Value, gvBrokerFiles, hdnPageSize1, hdnPageCount1, loadmoreajaxloader1);
            }
            else
            {
                BindFiles(hdnURL.Value + "/stores/" + hdnLocationID.Value + "/logixfiles?offset=0&pagesize=" + hdnPageSize1.Value, gvBrokerFiles, hdnPageSize1, hdnPageCount1, loadmoreajaxloader1);
            }

            //Errors
            if (!engineHealth.Machine.Components[0].Alive)
            {
                engineHealth.Machine.Components[0].Attributes.Insert(0, new CMS.AMS.Models.Attribute {
                    Severity = engineHealth.Machine.Components[0].Severity, Code = RequestStatusConstants.Failure, ParamID = (engineHealth.Machine.Components[0].EnterpriseEngine ? ServerHealthErrorCodes.EnterpriseEngine_Disconnected : ServerHealthErrorCodes.PromotionEngine_Disconnected), Description = (PhraseLibExtension.PhraseLib.Lookup("term.engine", LanguageID) + " " + PhraseLibExtension.PhraseLib.Lookup("term.disconnected", LanguageID)), LastUpdate = engineHealth.Machine.Components[0].LastHeard
                });
            }

            DataTable dtErrors = new DataTable();
            dtErrors.Columns.AddRange(new DataColumn[] { new DataColumn("Severity"), new DataColumn("ParamID"), new DataColumn("Description"), new DataColumn("Duration") });

            foreach (var error in engineHealth.Machine.Components[0].Attributes.Where(e => e.Code == RequestStatusConstants.Failure))
            {
                dtErrors.Rows.Add(PhraseLib.Lookup("term." + error.Severity, LanguageID), error.ParamID, ServerHealthHelper.GetErrorDescription(error.ParamID, LanguageID), error.LastUpdate.ConvertToDuration(LanguageID));
            }

            gvEngineWarnings.Columns[0].HeaderText = PhraseLib.Lookup("term.severity", LanguageID);
            gvEngineWarnings.Columns[1].HeaderText = PhraseLib.Lookup("term.code", LanguageID);
            gvEngineWarnings.Columns[2].HeaderText = PhraseLib.Lookup("term.description", LanguageID);
            gvEngineWarnings.Columns[3].HeaderText = PhraseLib.Lookup("term.duration", LanguageID);

            if (dtErrors.Rows.Count == 0)
            {
                lblError.Text = "<center>" + PhraseLib.Lookup("term.norecords", LanguageID) + "</center>";
            }
            else
            {
                gvEngineWarnings.DataSource = dtErrors;
                gvEngineWarnings.DataBind();
            }
        }
        else
        {
            ucServerHealthTabs.SetInfoMessage(errorMessage, true, true);
            loadmoreajaxloader.Visible  = false;
            loadmoreajaxloader1.Visible = false;
        }
    }
        public void NodeHealthSerializationTest()
        {
            NodeHealth nodeHealth = this.random.CreateRandom <NodeHealth>();

            TestUsingSerializer(this.Serializer, nodeHealth);
        }