/// <summary> /// Must be called from the Cloud Master. Syncs Cloud master with all cloud servers /// </summary> public static string ServerSync() { // Get the current data version string toVersionString = string.Empty; AndroAdminDataAccessFactory.GetSettingsDAO().GetByName("DataVersion", out toVersionString); int toVersion = 0; if (!int.TryParse(toVersionString, out toVersion)) { return("Internal error"); } // Get all the hosts IList <AndroAdminDataAccess.Domain.Host> hosts = AndroAdminDataAccessFactory .GetHostDAO() .GetAll(); string errorMessage = string.Empty; foreach (AndroAdminDataAccess.Domain.Host host in hosts) { // 1) Ask the server for it's current data version int fromVersion = 0; errorMessage = AcsSyncHelper.GetAcsServerDataVersion(host, out fromVersion); //todo make the response enumerable //yield errorMessage if (errorMessage.Length == 0) { // 2) Generate a block of XML that contains Add, Delete, Update objects that have changed on Cloud Master after the Cloud Servers version for: string syncXml = string.Empty; errorMessage = AndroAdminSyncHelper.TryGetExportSyncXml(fromVersion, toVersion, out syncXml); if (errorMessage.Length != 0) { return(errorMessage); } // 3) Send sync XML to Cloud Server. Cloud server returns a list of logs and audit data which have occurred since the last update. errorMessage = AcsSyncHelper.SyncAcsServer(host, syncXml); if (errorMessage.Length != 0) { return(errorMessage); } // 4) Insert logs/audit data into Cloud Master. // Run out of time - future task } } return(errorMessage); }
/// <summary> /// Must be called from the cloud signPost master. Syncs cloud SignPost master with all cloud signpost servers /// </summary> public static string ServerSync() { // Get the current data version string toVersionString = string.Empty; AndroAdminDataAccessFactory.GetSettingsDAO().GetByName("DataVersion", out toVersionString); int toVersion = 0; if (!int.TryParse(toVersionString, out toVersion)) { return("Internal error"); } // Get the signpost server names string signpostServerList = ConfigurationManager.AppSettings["SignPostServers"]; string[] signpostServers = signpostServerList.Split(','); string errorMessage = string.Empty; foreach (string signpostServer in signpostServers) { // 1) Ask the server for it's current data version int signpostServerDataVersion = -1; errorMessage = SignpostServerSync.GetSignpostServerDataVersion(signpostServer, out signpostServerDataVersion); if (errorMessage.Length == 0) { // 2) Generate a block of JSON that contains the sync data string exportJson = string.Empty; errorMessage = SignpostServerSync.GenerateExportJson(signpostServerDataVersion, out exportJson); if (errorMessage.Length != 0) { return(errorMessage); } // 3) Send sync XML to signpost server errorMessage = SignpostServerSync.DoSync(signpostServer, exportJson); if (errorMessage != null && errorMessage.Length != 0) { return(errorMessage); } // 4) Insert logs/audit data into Cloud Master. // Run out of time - future task } } return(errorMessage); }
private static string GenerateExportJson(int fromDataVersion, out string exportJson) { string error = ""; exportJson = ""; int toDataVersion = -1; string settingValue = ""; // Get the current data version error = AndroAdminDataAccessFactory.GetSettingsDAO().GetByName("DataVersion", out settingValue); if (String.IsNullOrEmpty(error)) { if (!int.TryParse(settingValue, out toDataVersion)) { error = "Version setting is not a number: " + settingValue; } } SignpostSync signpostSync = null; if (String.IsNullOrEmpty(error)) { List <SignpostACSApplication> signpostACSApplications = new List <SignpostACSApplication>(); // Get the acs applications that have changed since the last sync IList <ACSApplication> acsApplications = AndroAdminDataAccessFactory.GetACSApplicationDAO().GetDataBetweenVersions(fromDataVersion, toDataVersion); signpostSync = new SignpostSync() { fromVersion = fromDataVersion, toVersion = toDataVersion }; foreach (ACSApplication acsApplication in acsApplications) { // Get the sites for the acs application IList <int> siteIds = AndroAdminDataAccessFactory.GetACSApplicationDAO().GetSites(acsApplication.Id); // Put together the ACS application data SignpostACSApplication signpostACSApplication = new SignpostACSApplication() { id = acsApplication.Id, acsApplicationSites = siteIds, environmentId = acsApplication.EnvironmentId, externalApplicationId = acsApplication.ExternalApplicationId, name = acsApplication.Name }; signpostSync.acsApplicationSyncs.Add(signpostACSApplication); } } if (String.IsNullOrEmpty(error)) { if (signpostSync != null) { exportJson = JsonConvert.SerializeObject(signpostSync); } } return(error); }