private async Task <ReliabilityLevel> GetActualReliabilityLevelForCluster(CancellationToken cancellationToken)
        {
            UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Entering GetCurrentReliabilityLevelForCluster");
            System.Fabric.Query.NodeList nodes = await StandaloneUtility.GetNodesFromFMAsync(this.fabricClient, cancellationToken).ConfigureAwait(false);

            int seedNodeCount = nodes.Count(p => p.IsSeedNode);

            ReliabilityLevel actualReliabilityLevelInCluster = ReliabilityLevelExtension.GetReliabilityLevel(seedNodeCount);

            UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "SeedNodeCount from cluster {0}, actualReliabilityLevelInCluster {1}", seedNodeCount, actualReliabilityLevelInCluster);

            return(actualReliabilityLevelInCluster);
        }
예제 #2
0
        public ContentResult Get(string observername, string nodename, string format = "json")
        {
            try
            {
                System.Fabric.Query.NodeList node = this.fabricClient.QueryManager.GetNodeListAsync(nodename).Result;

                if (node.Count > 0)
                {
                    string addr = node[0].IpAddressOrFQDN;

                    // By default this service is node-local, http, port 5000.
                    // If you modify the service to support Internet communication over a
                    // secure channel, then change this code to force https.
                    if (!addr.Contains("http://"))
                    {
                        addr = "http://" + addr;
                    }

                    string fqdn = "?fqdn=" + Request.Host;

                    // If you modify the service to support Internet communication over a
                    // secure channel, then change this code to reflect the correct port.
                    WebRequest req = WebRequest.Create(addr + $":5000/api/ObserverLog/{observername}/{format}{fqdn}");
                    req.Credentials = CredentialCache.DefaultCredentials;
                    HttpWebResponse response   = (HttpWebResponse)req.GetResponse();
                    Stream          dataStream = response.GetResponseStream();

                    // Open the stream using a StreamReader for easy access.
                    StreamReader reader             = new StreamReader(dataStream);
                    string       responseFromServer = reader.ReadToEnd();
                    string       ret = responseFromServer;

                    // Cleanup the streams and the response.
                    reader.Close();
                    dataStream.Close();
                    response.Close();

                    return(Content(ret, format.ToLower() == "html" ? "text/html" : "text/json"));
                }

                return(Content("no node found with that name."));
            }
            catch (ArgumentException ae)
            {
                return(Content($"Error processing request: {ae.Message}"));
            }
            catch (IOException ioe)
            {
                return(Content($"Error processing request: {ioe.Message}"));
            }
        }
예제 #3
0
        private string GetHtml(string name)
        {
            string html = string.Empty;
            string logFolder;
            string nodeName = this.serviceContext.NodeContext.NodeName;

            System.Fabric.Description.ConfigurationSettings configSettings = this.serviceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config").Settings;
            string networkObserverLogText = null, osObserverLogText = null, nodeObserverLogText = null, appObserverLogText = null, fabricSystemObserverLogText = null, diskObserverLogText = null;

            logFolder = Utilities.GetConfigurationSetting(configSettings, "FabricObserverLogs", "ObserverLogBaseFolderPath");

            // Observer log paths.
            string appObserverLogPath = Path.Combine(logFolder, "AppObserver", "AppObserver.log");
            string osObserverLogPath = Path.Combine(logFolder, "OSObserver", "OSObserver.log");
            string diskObserverLogPath = Path.Combine(logFolder, "DiskObserver", "DiskObserver.log");
            string networkObserverLogPath = Path.Combine(logFolder, "NetworkObserver", "NetworkObserver.log");
            string fabricSystemObserverLogPath = Path.Combine(logFolder, "FabricSystemObserver", "FabricSystemObserver.log");
            string nodeObserverLogPath = Path.Combine(logFolder, "NodeObserver", "NodeObserver.log");

            // Implicit retry loop. Will run only once if no exceptions arise.
            // Can only run at most MaxRetries times.
            for (int i = 0; i < MaxRetries; i++)
            {
                try
                {
                    if (System.IO.File.Exists(appObserverLogPath) &&
                        System.IO.File.GetCreationTimeUtc(appObserverLogPath).ToShortDateString() == DateTime.UtcNow.ToShortDateString())
                    {
                        appObserverLogText = System.IO.File.ReadAllText(appObserverLogPath, Encoding.UTF8).Replace(Environment.NewLine, "<br/>");
                    }

                    if (System.IO.File.Exists(diskObserverLogPath) &&
                        System.IO.File.GetCreationTimeUtc(diskObserverLogPath).ToShortDateString() == DateTime.UtcNow.ToShortDateString())
                    {
                        diskObserverLogText = System.IO.File.ReadAllText(diskObserverLogPath, Encoding.UTF8).Replace(Environment.NewLine, "<br/>");
                    }

                    if (System.IO.File.Exists(fabricSystemObserverLogPath) &&
                        System.IO.File.GetCreationTimeUtc(fabricSystemObserverLogPath).ToShortDateString() == DateTime.UtcNow.ToShortDateString())
                    {
                        fabricSystemObserverLogText = System.IO.File.ReadAllText(fabricSystemObserverLogPath, Encoding.UTF8).Replace(Environment.NewLine, "<br/>");
                    }

                    if (System.IO.File.Exists(networkObserverLogPath) &&
                        System.IO.File.GetCreationTimeUtc(networkObserverLogPath).ToShortDateString() == DateTime.UtcNow.ToShortDateString())
                    {
                        networkObserverLogText = System.IO.File.ReadAllText(networkObserverLogPath, Encoding.UTF8).Replace(Environment.NewLine, "<br/>");
                    }

                    if (System.IO.File.Exists(nodeObserverLogPath) &&
                        System.IO.File.GetCreationTimeUtc(nodeObserverLogPath).ToShortDateString() == DateTime.UtcNow.ToShortDateString())
                    {
                        nodeObserverLogText = System.IO.File.ReadAllText(nodeObserverLogPath, Encoding.UTF8).Replace(Environment.NewLine, "<br/>");
                    }

                    if (System.IO.File.Exists(osObserverLogPath) &&
                        System.IO.File.GetCreationTimeUtc(osObserverLogPath).ToShortDateString() == DateTime.UtcNow.ToShortDateString())
                    {
                        osObserverLogText = System.IO.File.ReadAllText(osObserverLogPath, Encoding.UTF8).Trim();
                    }

                    string host = Request.Host.Value;

                    string nodeLinks = string.Empty;

                    // Request originating from ObserverWeb node hyperlinks.
                    if (Request.QueryString.HasValue && Request.Query.ContainsKey("fqdn"))
                    {
                        host = Request.Query["fqdn"];

                        // Node links.
                        System.Fabric.Query.NodeList nodeList = this.fabricClient.QueryManager.GetNodeListAsync().Result;
                        IOrderedEnumerable <System.Fabric.Query.Node> ordered = nodeList.OrderBy(node => node.NodeName);

                        foreach (System.Fabric.Query.Node node in ordered)
                        {
                            nodeLinks += "| <a href='" + Request.Scheme + "://" + host + "/api/ObserverLog/" + name + "/" + node.NodeName + "/html'>" + node.NodeName + "</a> | ";
                        }
                    }

                    this.sb = new StringBuilder();

                    _ = this.sb.AppendLine("<html>\n\t<head>");
                    _ = this.sb.AppendLine("\n\t\t<title>FabricObserver Observer Report: Errors and Warnings</title>");
                    _ = this.sb.AppendLine("\n\t\t" + this.script);
                    _ = this.sb.AppendLine("\n\t\t<style type=\"text/css\">\n" +
                                           "\t\t\t.container {\n" +
                                           "\t\t\t\tfont-family: Consolas; font-size: 14px; background-color: lightblue; padding: 5px; border: 1px solid grey; " +
                                           "width: 98%;\n" +
                                           "\t\t\t}\n" +
                                           "\t\t\t.header {\n" +
                                           "\t\t\t\tfont-size: 25px; text-align: center; background-color: lightblue; " +
                                           "padding 5px; margin-bottom: 10px;\n" +
                                           "\t\t\t}\n" +
                                           "\t\t\tpre {\n" +
                                           "\t\t\t\toverflow-x: auto; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;" +
                                           "\t\t\t}\n" +
                                           "\t\t\t a:link { text-decoration: none; }" +
                                           "\n\t\t</style>");
                    _ = this.sb.AppendLine("\n\t</head>");
                    _ = this.sb.AppendLine("\n\t<body>");
                    _ = this.sb.AppendLine("\n\t\t\t <br/>");
                    _ = this.sb.AppendLine("\n\t\t\t\t<div class=\"container\"><div style=\"position: relative; width: 100%; margin-left: auto; margin-right: auto;\"><br/><strong>Errors and Warnings for " + name + " on " + nodeName + "</strong><br/><br/>" + nodeLinks);

                    switch (name.ToLower())
                    {
                    case "appobserver":
                        if (!string.IsNullOrEmpty(appObserverLogText))
                        {
                            _ = this.sb.AppendLine("\n\t\t\t<br/><br/>" + "\n\t\t\t" + appObserverLogText + "<br/><br/>");
                        }

                        break;

                    case "diskobserver":
                        if (!string.IsNullOrEmpty(diskObserverLogText))
                        {
                            _ = this.sb.AppendLine("\n\t\t\t<br/><br/>" + "\n\t\t\t" + diskObserverLogText + "<br/><br/>");
                        }

                        break;

                    case "fabricsystemobserver":
                        if (!string.IsNullOrEmpty(fabricSystemObserverLogText))
                        {
                            _ = this.sb.AppendLine("\n\t\t\t<br/><br/>" + "\n\t\t\t" + fabricSystemObserverLogText + "<br/><br/>");
                        }

                        break;

                    case "networkobserver":
                        if (!string.IsNullOrEmpty(networkObserverLogText))
                        {
                            _ = this.sb.AppendLine("\n\t\t\t<br/><br/>" + "\n\t\t\t" + networkObserverLogText + "<br/><br/>");
                        }

                        break;

                    case "nodeobserver":
                        if (!string.IsNullOrEmpty(nodeObserverLogText))
                        {
                            _ = this.sb.AppendLine("\n\t\t\t<br/><br/>" + "\n\t\t\t" + nodeObserverLogText + "<br/><br/>");
                        }

                        break;

                    case "osobserver":
                        if (!string.IsNullOrEmpty(osObserverLogText))
                        {
                            _ = this.sb.AppendLine("\n\t\t\t<br/><br/>" + "\n\t\t\t" + osObserverLogText + "<br/><br/>");
                        }

                        break;

                    default:
                        _ = this.sb.AppendLine("\n\t\t\t<br/>Specified Observer, " + name + ", does not exist.");
                        break;
                    }

                    _    = this.sb.AppendLine("\n\t\t\t</div>");
                    _    = this.sb.AppendLine("\n\t</body>");
                    _    = this.sb.AppendLine("</html>");
                    html = this.sb.ToString();
                    _    = this.sb.Clear();
                    break;
                }
                catch (IOException ie)
                {
                    html = ie.ToString();
                }

                // If we get here, let's wait a few seconds before the next iteration.
                Task.Delay(2000).Wait();
            }

            return(html);
        }