private static void BaselineUpdate(EndecaApplication app, bool applyNewIndex) { Logger.Info("Baseline update in progress ..."); Logger.Info("Merging web studio and dev studio configs ..."); EacGateway.Instance.StartScript(app.AppId, "PreForgeConfigMerge"); RunForge(app, app.Forges[BaselineForge]); RunDgidx(app.Dgidx); var cluster = new DgraphCluster(app); // Baseline update scenario // 1. Clean local temp folder // 2. Clean local updates folder // 3. Distrubute index // 4. Apply index // 5. Archive updates folder CleanFoldersAndDistributeIndex(cluster); TestIndex(cluster); if (applyNewIndex) { ApplyIndex(app); } Logger.Info("Updating post-forge web studio dimensions ..."); EacGateway.Instance.StartScript(app.AppId, "PostForgeConfigUpdate"); Logger.Info("Baseline update complete!"); }
private static void ApplyIndex(EndecaApplication app) { var cluster = new DgraphCluster(app); Logger.Info("Applying index ..."); cluster.ApplyIndex(PauseBetweenUpdates); RollLogServerLog(app); }
public DgraphCluster(EndecaApplication app) { _app = app; foreach (var host in app.Hosts) { var component = app.Dgraphs.FindOne(host.HostId); if (component != null) { _hostDgraphs.Add(component); } } }
private static void StartLogServer(EndecaApplication app) { if (app.LogServer != null && !app.LogServer.IsActive) { app.LogServer.Start(false); } }
private static void RunForge(EndecaApplication app, ForgeComponent forge) { Logger.Info("Getting forge configs ..."); EacGateway.Instance.StartScript(app.AppId, "ForgeConfigUpdate"); Logger.Info("Forging..."); forge.ArchiveLog(true); forge.CleanDirs(); forge.Run(); if (forge.IsFailed) { throw new ControlScriptException(forge.FailureMessage); } }
private static void RollLogServerLog(EndecaApplication app) { Logger.Info("Rolling log server log ..."); if (app.LogServer != null && app.LogServer.IsActive) { app.LogServer.RollLog(); } }
private static void RollbackIndex(EndecaApplication app) { Logger.Info("Rolling back index ..."); if (app.Dgidx.RollbackIndex()) { var cluster = new DgraphCluster(app); CleanFoldersAndDistributeIndex(cluster); TestIndex(cluster); ApplyIndex(app); } else { Logger.Warn("Rolling back index failed!"); } }
private static void PartialUpdate(EndecaApplication app) { // Partial updates scenario // 1. Distribute update // 2. Apply update // 2.1. Apply update // 2.2. Copy update file to cumulative updates folder // 2.3. Clean updates foder Logger.Info("Partial update in progress ..."); var forge = app.Forges[PartialForge]; Debug.Assert(forge != null); forge.ArchiveLog(false); Logger.Info("Forging..."); forge.Run(); if (forge.IsFailed) { throw new ControlScriptException(forge.FailureMessage); } var cluster = new DgraphCluster(app); Logger.Info("Distributing update to remote hosts..."); cluster.DistributeUpdate(forge); Logger.Info("Applying updates ..."); cluster.ApplyUpdate(); Logger.Info("Update complete!"); }
private static int Main(string[] args) { if (args.Length < 2) { DisplayHelp(); return 1; } var server = args[0]; if (server.Equals(".") || server.Equals("local") || server.Equals("localhost")) server = Environment.MachineName; var app = new EndecaApplication(AppName, server, Port); Logger.Info(String.Format("Loading {0} application on {1}:{2} ...", AppName, server, Port)); Console.CancelKeyPress += delegate { Logger.Warn("Script has been cancelled. Current operation is in progress and will complete!"); app.ReleaseAllLocks(); }; if (args[1] == "/l") { app.ReleaseAllLocks(); Console.WriteLine("Locks released!"); return 0; } if (!app.AcquireUpdateLock()) { Logger.Error("Cannot acquire lock. Update probably in progress!"); return 1; } try { app.LoadApplication(); Logger.Notify("Index update started.\r\n\r\nData feed contents:\r\n\r\n" + GetDirectoryListing(args, app)); Logger.Info(app.GetConfiguration()); // start log server if defined and down StartLogServer(app); switch (args[1]) { case "/baseline_update": case "/b": BaselineUpdate(app, true); break; case "/partial_update": case "/p": PartialUpdate(app); break; case "/u": case "/update_without_applying": BaselineUpdate(app, false); break; case "/a": case "/apply_index": ApplyIndex(app); break; case "/r": case "/rollback_index": RollbackIndex(app); break; default: DisplayHelp(); return 1; } Logger.Info("Script finished"); Logger.Notify("Index successfuly updated.\r\n\r\nSession Log:\r\n" + Logger.GetLog()); return 0; } catch (Exception e) { var msg = string.Format("Script failed:\r\n{0}", e); Logger.Fatal(msg); Logger.NotifyOnError(msg); return 1; } finally { app.ReleaseAllLocks(); } }
private static string GetDirectoryListing(string[] args, EndecaApplication app) { var updateType = ((args[1] == "/p") || (args[1] == "/partial_update")) ? PartialForge : BaselineForge; var path = app.Forges[updateType].InputDirectory.Replace('/', '\\'); var listing = string.Empty; if (Directory.Exists(path)) { var dir = new DirectoryInfo(path); foreach (var f in dir.GetFiles("*.txt")) { listing += string.Format("[{0}] - {1:0,0} bytes - {2:d/MMM/yyyy - HH:mm:ss}\r\r\n", f.Name, f.Length, f.LastWriteTime); } } return string.IsNullOrEmpty(listing) ? string.Format("No input files found in {0}.", path) : string.Format("Path: {0}\r\n\r\n{1}", path, listing); }