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 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 void RollLogServerLog(EndecaApplication app) { Logger.Info("Rolling log server log ..."); if (app.LogServer != null && app.LogServer.IsActive) { app.LogServer.RollLog(); } }
private static void ApplyIndex(EndecaApplication app) { var cluster = new DgraphCluster(app); Logger.Info("Applying index ..."); cluster.ApplyIndex(PauseBetweenUpdates); RollLogServerLog(app); }
private static void CleanFoldersAndDistributeIndex(DgraphCluster cluster) { Logger.Info("Cleaning local distribution folder on remote hosts ..."); cluster.CleanLocalIndexDistributionDir(); Logger.Info("Cleaning local update folder on remote hosts ..."); cluster.CleanLocalUpdatesDir(); Logger.Info("Distributing index to remote hosts..."); cluster.DistributeIndex(); }
private static void TestIndex(DgraphCluster cluster) { Logger.Info("Testing index ..."); var indexOk = cluster.ApplyIndex(new[] { IndexTestHostId }); if (!indexOk) { throw new ControlScriptException( String.Format("Index test failed on {0}. At least one Dgraph instance failed to start.", IndexTestHostId)); } }
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 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 RunDgidx(DgidxComponent dgidx) { // backup old index (this will automatically clear dgidx output folder) Logger.Info("Archiving Previous Index ..."); if (!dgidx.ArchiveIndex()) { Logger.Warn("Index backup failed!"); } Logger.Info("Indexing..."); dgidx.ArchiveLog(true); dgidx.Run(); if (dgidx.IsFailed) { throw new ControlScriptException(dgidx.FailureMessage); } }
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(); } }