public static void RunConsole(string[] args = null) { if (!Environment.UserInteractive) { string msg = "This is a Debug build of SynapseServer and will not run as Service."; Logger.Fatal(msg); new SynapseServer().WriteEventLog(msg); Environment.Exit(1); } if (Config == null) { DeserialzeConfig(args); } ConsoleColor current = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Starting Synapse.Server as {Config?.Service.Role}: Press Ctrl-C/Ctrl-Break to stop."); Console.ForegroundColor = current; //can't setup the Logger until after deserializing Config SetupLogger(); using (SynapseServer s = new SynapseServer()) { s.OnStart(null); Thread.Sleep(Timeout.Infinite); Console.WriteLine("Terminating Synapse.Server."); s.OnStop(); } }
public long StartPlan(string planUniqueName, bool dryRun = false, string requestNumber = null, string nodeRootUrl = null) { InitPlanServer(); if (!string.IsNullOrWhiteSpace(requestNumber)) { requestNumber = System.Web.HttpUtility.UrlDecode(requestNumber); } if (!string.IsNullOrWhiteSpace(nodeRootUrl)) { requestNumber = System.Web.HttpUtility.UrlDecode(nodeRootUrl); } Uri uri = CurrentUrl.Request.RequestUri; string context = GetContext(nameof(StartPlan), nameof(CurrentUserName), CurrentUserName, nameof(planUniqueName), planUniqueName, nameof(dryRun), dryRun, nameof(requestNumber), requestNumber, nameof(nodeRootUrl), nodeRootUrl, "QueryString", uri.Query); Impersonator runAsUser = null; if (SynapseServer.UseImpersonation(CurrentUser?.Identity)) { if (Request?.Headers?.Authorization?.Scheme?.ToLower() == "basic") { runAsUser = new Impersonator(this.AuthenticationHeader); } else { runAsUser = new Impersonator((WindowsIdentity)(CurrentUser?.Identity)); } runAsUser.Start(SynapseServer.Logger); } try { SynapseServer.Logger.Debug(context); Dictionary <string, string> dynamicParameters = uri.ParseQueryString(); if (dynamicParameters.ContainsKey(nameof(dryRun))) { dynamicParameters.Remove(nameof(dryRun)); } return(_server.StartPlan(CurrentUserName, planUniqueName, dryRun, requestNumber, dynamicParameters, nodeRootUrl: nodeRootUrl, referrer: CurrentUrl.Request.RequestUri, authHeader: this.AuthenticationHeader)); } catch (Exception ex) { SynapseServer.Logger.Error( Utilities.UnwindException(context, ex, asSingleLine: true)); throw; } finally { runAsUser?.Stop(SynapseServer.Logger); } }
public void StartPlanAsync(long planInstanceId, bool dryRun, [FromBody] string planString) { Uri uri = this.Url.Request.RequestUri; planString = CryptoHelpers.Decode(planString); Plan plan = Plan.FromYaml(new StringReader(planString)); string context = GetContext(nameof(StartPlanAsync), nameof(plan), plan.Name, nameof(dryRun), dryRun, nameof(planInstanceId), planInstanceId, "QueryString", uri.Query); Impersonator runAsUser = null; if (SynapseServer.UseImpersonation(User?.Identity)) { if (Request?.Headers?.Authorization?.Scheme?.ToLower() == "basic") { runAsUser = new Impersonator(Request.Headers.Authorization); } else { runAsUser = new Impersonator((WindowsIdentity)User.Identity); } runAsUser.Start(SynapseServer.Logger); } try { SynapseServer.Logger.Debug(context); plan.InstanceId = planInstanceId; ValidatePlanSignature(plan); Dictionary <string, string> dynamicParameters = uri.ParseQueryString(); if (dynamicParameters.ContainsKey(nameof(dryRun))) { dynamicParameters.Remove(nameof(dryRun)); } PlanRuntimePod p = new PlanRuntimePod(plan, dryRun, dynamicParameters, plan.InstanceId, this.Url.Request.Headers.Referrer, this.Request?.Headers?.Authorization); _scheduler.StartPlan(p); } catch (Exception ex) { SynapseServer.Logger.Error( Utilities.UnwindException(context, ex, asSingleLine: true)); throw; } finally { runAsUser?.Stop(SynapseServer.Logger); } }
public void StartPlanAsyncWithParametersAsPost(long planInstanceId, bool dryRun, [FromBody] string planString) { StartPlanEnvelope planEnvelope = StartPlanEnvelope.FromYaml(planString, isEncoded: true); Plan plan = planEnvelope.Plan; string context = GetContext(nameof(StartPlanAsyncWithParametersAsPost), nameof(plan), plan.Name, nameof(dryRun), dryRun, nameof(planInstanceId), planInstanceId); Impersonator runAsUser = null; try { SynapseServer.Logger.Debug(context); plan.InstanceId = planInstanceId; ValidatePlanSignature(plan); if (SynapseServer.UseImpersonation(User?.Identity)) { if (Request?.Headers?.Authorization?.Scheme?.ToLower() == "basic") { runAsUser = new Impersonator(Request.Headers.Authorization); } else { runAsUser = new Impersonator((WindowsIdentity)User.Identity); } runAsUser.Start(SynapseServer.Logger); } PlanRuntimePod p = new PlanRuntimePod(plan, dryRun, planEnvelope.GetCaseInsensitiveDynamicParameters(), plan.InstanceId, this.Url.Request.Headers.Referrer, this.Request?.Headers?.Authorization); _scheduler.StartPlan(p); } catch (Exception ex) { SynapseServer.Logger.Error( Utilities.UnwindException(context, ex, asSingleLine: true)); throw; } finally { runAsUser?.Stop(SynapseServer.Logger); } }
public long StartPlan([FromBody] StartPlanEnvelope planEnvelope, string planUniqueName, bool dryRun = false, string requestNumber = null, string nodeRootUrl = null) { InitPlanServer(); if (!string.IsNullOrWhiteSpace(requestNumber)) { requestNumber = System.Web.HttpUtility.UrlDecode(requestNumber); } if (!string.IsNullOrWhiteSpace(nodeRootUrl)) { requestNumber = System.Web.HttpUtility.UrlDecode(nodeRootUrl); } TryGetPlanEnvelopeFromRawBodyIfNull(ref planEnvelope); bool failedToDeserialize = false; Dictionary <string, string> dynamicParameters = planEnvelope?.TryGetCaseInsensitiveDynamicParameters(); StringBuilder parms = new StringBuilder(); if (dynamicParameters != null) { string s = string.Empty; foreach (string key in dynamicParameters.Keys) { parms.Append($"{s}{key}: {dynamicParameters[key]}"); s = ", "; } } else { failedToDeserialize = !string.IsNullOrWhiteSpace(RawBody); if (failedToDeserialize) { parms.Append(RawBody); } } string context = GetContext(nameof(StartPlan), nameof(CurrentUserName), CurrentUserName, nameof(planUniqueName), planUniqueName, nameof(dryRun), dryRun, nameof(requestNumber), requestNumber, nameof(nodeRootUrl), nodeRootUrl, "planParameters", parms.ToString()); Impersonator runAsUser = null; if (SynapseServer.UseImpersonation(CurrentUser?.Identity)) { if (Request?.Headers?.Authorization?.Scheme?.ToLower() == "basic") { runAsUser = new Impersonator(this.AuthenticationHeader); } else { runAsUser = new Impersonator((WindowsIdentity)(CurrentUser?.Identity)); } runAsUser.Start(SynapseServer.Logger); } try { SynapseServer.Logger.Info(context); if (failedToDeserialize) { throw new Exception($"Failed to deserialize message body:\r\n{parms.ToString()}"); } return(_server.StartPlan(CurrentUserName, planUniqueName, dryRun, requestNumber, dynamicParameters, postDynamicParameters: true, nodeRootUrl: nodeRootUrl, referrer: CurrentUrl.Request.RequestUri, authHeader: this.AuthenticationHeader)); } catch (Exception ex) { SynapseServer.Logger.Error( Utilities.UnwindException(context, ex, asSingleLine: true)); throw; } finally { runAsUser?.Stop(SynapseServer.Logger); } }