Example #1
0
        /// <summary>
        /// Checks if the File system type and DocumentDB type is enabled
        /// and calls the respective handler methods.
        /// </summary>
        public static void Init()
        {
            try
            {
                LogUtility.CheckLogFileEnabled();

                //Get the file Systems that are enabled.
                IEnumerable <BEArcus.Agent.FileSystemType> fileSystems = Configuration.Instance.DataStores.FileSystem.
                                                                         Where(f => f.Enabled);
                LogUtility.LogInfoFunction("Storing data to enbled File Systems");
                IStorageService fileservice = new FileDataController();
                foreach (FileSystemType fileSystem in fileSystems)
                {
                    UserSettingsHelper.CreateFileSystemSettings(fileSystem.Name);
                    AlertController.SaveAlertData(fileservice, fileSystem.Name);
                    JobController.SaveJobData(fileservice, fileSystem.Name);
                    JobHistoryController.SaveJobHistoryData(fileservice, fileSystem.Name);
                    MediaServerController.SaveMediaServerData(fileservice, fileSystem.Name);
                }

                //Get the DocumentDB data store that are enabled.
                IEnumerable <BEArcus.Agent.DocumentDBType> documentDBStreams = Configuration.Instance.DataStores.DocumentDB.
                                                                               Where(d => d.Enabled);
                LogUtility.LogInfoFunction("Storing data to enbled DocumentDB accounts.");
                //IStorageService documentDBService = new DocumentDBDataController();
                foreach (DocumentDBType documentDB in documentDBStreams)
                {
                    UserSettingsHelper.CreateDocumentDBSettings(documentDB.Name);

                    //Decrypt the Authorization Key to check if it was encryped earlier
                    string decrypedAuthorizationKey = SecurityController.Decrypt(documentDB.AuthorizationKey);

                    //Decrypt method returns null if the Authorization key was not Encrypted earlier
                    if (string.IsNullOrEmpty(decrypedAuthorizationKey))
                    {
                        //Encrypt Authorization Key
                        string encryptedAuthorizationKey = SecurityController.Encrypt(documentDB.AuthorizationKey);
                        //Encrypt EndpointUrl
                        string encryptedEndpointUrl = SecurityController.Encrypt(documentDB.EndPointUrl);
                        //Save changes to Configuration.xml
                        SecurityController.UpdateConfiguration(encryptedEndpointUrl, encryptedAuthorizationKey);
                    }
                    IStorageService documentDBService = new DocumentDBDataController();
                    AlertController.SaveAlertData(documentDBService, documentDB.Name);
                    JobController.SaveJobData(documentDBService, documentDB.Name);
                    JobHistoryController.SaveJobHistoryData(documentDBService, documentDB.Name);
                    MediaServerController.SaveMediaServerData(documentDBService, documentDB.Name);
                    PurgeDataController.PurgeAlerts(documentDB.Name);
                    PurgeDataController.PurgeJobHistories(documentDB.Name);
                }
                LogUtility.LogInfoFunctionFinished();
            }
            catch (Exception e)
            {
                Exception baseException = e.GetBaseException();
                LogUtility.LogInfoFunction("Error:" + e.Message + "Message:" + baseException.Message);
                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }
        }
Example #2
0
        public static void SaveMediaServerData(IStorageService storageType, string storageId)
        {
            LogUtility.LogInfoFunction("Entered SaveMediaServerData.");
            MediaServer mediaServerObject = GetMediaSeverData();
            double      capacity          = 0;

            //We are calculating Estimated Capacity Usage using job log files.
            //Whenever BEMCLI commands are available, we will use the interface to calculate Estimated Capacity Usage.
            //Arcus is calculating approximate Estimated Capacity Usage and might not exactly match with BE.

            try
            {
                DateTime fromDate = DateTime.Now.AddDays(-30);
                DateTime toDate   = DateTime.Now;
                int?     number   = null;

                LogUtility.LogInfoFunction("Entered GetSuccessfullJobHistoryByDate.");
                //For Loading the powershell scripts ( Main.ps1 ) in memory.
                LogUtility.LogInfoFunction("Calling BemcliHelper function LoadPowerShellScript(); ");
                BemcliHelper bemcliObject = new BemcliHelper();
                PowerShell   powershell   = BemcliHelper.LoadPowerShellScript();

                //Calling the powershell function GetSuccessfullJobHistoryByDate(FromTime,ToTime,Number) which is present in BEMCLIScripts\MediaServer.psm1
                LogUtility.LogInfoFunction("Invoking PowerShell Command GetSuccessfullJobHistoryByDate");
                powershell.AddCommand("GetSuccessfullJobHistoryByDate");
                powershell.AddParameter("FromTime", fromDate);
                powershell.AddParameter("ToTime", toDate);
                powershell.AddParameter("Number", number);
                powershell.AddCommand("Out-String");
                var results = powershell.Invoke <string>();

                //check if the results string is empty
                if (String.IsNullOrWhiteSpace(results[0]))
                {
                    LogUtility.LogInfoFunction("Successfull Job History List is empty");
                    //If the string is empty, there were no records found. Threfore return null.
                    LogUtility.LogInfoFunctionFinished();
                }

                else
                {
                    //Converting json document into object format
                    List <JobHistory>           jobHistoryObjects = JobHistoryController.ConvertFromJson(results[0]);
                    string                      resourcePath      = "";
                    Dictionary <string, double> resourcesKeyValue = new Dictionary <string, double>();

                    foreach (JobHistory jobHistory in jobHistoryObjects)
                    {
                        string      pathnew = jobHistory.JobLogFilePath;
                        XmlDocument Docs    = new XmlDocument();

                        //Opening Log file
                        Docs.Load(pathnew);
                        XmlElement  root  = Docs.DocumentElement;
                        XmlNodeList nodes = root.SelectNodes("//backup/machine/set");

                        foreach (XmlNode node in nodes)
                        {
                            //Get the resource name
                            resourcePath = node["set_resource_name"].InnerText.ToString();

                            XmlNode consumedDataNode = root.SelectSingleNode("//backup/machine/set/summary");
                            //Get the consumed data
                            string consumedDataSummary = consumedDataNode["new_processed_bytes"].InnerText.ToString();

                            //Convert consumed data into appropriate format
                            consumedDataSummary = consumedDataSummary.Replace(",", "");
                            string consumedResourceData     = new string(consumedDataSummary.SkipWhile(c => !char.IsDigit(c)).TakeWhile(c => char.IsDigit(c)).ToArray());
                            double consumedResourceDataSize = double.Parse(consumedResourceData);

                            //Convert consumed data into GB
                            //We will always display Estimated Capacity usage in GB
                            consumedResourceDataSize = consumedResourceDataSize / 1024 / 1024 / 1024;

                            resourcePath = resourcePath.Trim().ToLower();
                            if (resourcesKeyValue.ContainsKey(resourcePath)) // Check if path exist in dictionary, update the data consumed value
                            {
                                double value = resourcesKeyValue[resourcePath];
                                if (consumedResourceDataSize > value)
                                {
                                    resourcesKeyValue[resourcePath] = consumedResourceDataSize;
                                }
                            }
                            else
                            {
                                resourcesKeyValue.Add(resourcePath, consumedResourceDataSize);  // if a path not added in dictionary, here we are adding
                            }
                        }
                    }

                    foreach (KeyValuePair <string, double> kvp in resourcesKeyValue)
                    {
                        // Calculate Estimated Capacity Usage
                        capacity = capacity + kvp.Value;
                    }
                }
            }
            catch (Exception e)
            {
                Exception baseException = e.GetBaseException();
                LogUtility.LogInfoFunction("Error:" + e.Message + "Message:" + baseException.Message);
                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }

            if (mediaServerObject != null)
            {
                string usedData = string.Format("{0:N3}", capacity);
                //We will always display Estimated Capacity usage in GB
                usedData = usedData + " GB";
                mediaServerObject.EstimatedUsedCapacity = usedData;
                storageType.SaveMediaServerData(mediaServerObject, storageId);
            }
            else
            {
                LogUtility.LogInfoFunction("No media server record fetched.");
            }
            LogUtility.LogInfoFunctionFinished();
        }