void TryGetPlanEnvelopeFromRawBodyIfNull(ref StartPlanEnvelope planEnvelope) { if (planEnvelope == null && !string.IsNullOrWhiteSpace(RawBody)) { try { planEnvelope = StartPlanEnvelope.FromXml(RawBody); } catch { try { planEnvelope = StartPlanEnvelope.FromYaml(RawBody); } catch { } } } }
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); } }
protected virtual void RunStartPlanMethod(string[] args, Dictionary <string, string> parameters, bool isSync) { string methodName = "StartPlan"; ControllerServiceHttpApiClient instance = new ControllerServiceHttpApiClient(BaseUrl); bool needHelp = args.Length == 2 && args[1].ToLower().Contains("help"); if (needHelp) { Dictionary <string, Type> parms = new Dictionary <string, Type> { { "planName", typeof(string) }, { "dryRun", typeof(bool) }, { "requestNumber", typeof(string) } }; if (isSync) { parms.Add("path", typeof(string)); parms.Add("serializationType", typeof(SerializationType)); parms.Add("setContentType", typeof(bool)); parms.Add("pollingIntervalSeconds", typeof(int)); parms.Add("timeoutSeconds", typeof(int)); } parms.Add("nodeRootUrl", typeof(string)); parms.Add("asPost", typeof(string)); Console.WriteLine($"Parameter options for {methodName}:\r\n"); WriteMethodParametersHelp(parms); Console.WriteLine("\r\nRemaining argname:argvalue pairs will be passed as dynamic parameters, unless"); Console.WriteLine("'asPost' is specified, in which case a file of {key: value} pairs is posted"); Console.WriteLine("and remaining parameters are ignored. Layout of 'asPost' file is:\r\n"); Console.WriteLine("DynamicParameters:\r\n key0: value0\r\n key1: value1\r\n key2: value2\r\n"); } else { string planName = null; string pn = nameof(planName); if (parameters.ContainsKey(pn)) { planName = parameters[pn]; parameters.Remove(pn); } else { throw new Exception("PlanName is required."); } bool dryRun = false; string dr = nameof(dryRun); if (parameters.ContainsKey(dr)) { bool.TryParse(parameters[dr], out dryRun); parameters.Remove(dr); } string requestNumber = null; string rn = nameof(requestNumber); if (parameters.ContainsKey(rn)) { requestNumber = parameters[rn]; parameters.Remove(rn); } string path = "Actions[0]:Result:ExitData"; SerializationType serializationType = SerializationType.Json; bool setContentType = true; int pollingIntervalSeconds = 1; int timeoutSeconds = 120; if (isSync) { string pa = nameof(path); if (parameters.ContainsKey(pa)) { path = parameters[pa]; parameters.Remove(pa); } string st = nameof(serializationType); if (parameters.ContainsKey(st)) { Enum.TryParse(parameters[st], true, out serializationType); parameters.Remove(st); } string sct = nameof(setContentType); if (parameters.ContainsKey(sct)) { bool.TryParse(parameters[sct], out setContentType); parameters.Remove(sct); } string pi = nameof(pollingIntervalSeconds); if (parameters.ContainsKey(pi)) { int.TryParse(parameters[pi], out pollingIntervalSeconds); parameters.Remove(pi); } string to = nameof(timeoutSeconds); if (parameters.ContainsKey(to)) { int.TryParse(parameters[to], out timeoutSeconds); parameters.Remove(to); } } string nodeRootUrl = null; string nu = nameof(nodeRootUrl); if (parameters.ContainsKey(nu)) { nodeRootUrl = parameters[nu]; parameters.Remove(nu); } bool postDynamicParameters = false; string asPost = null; string ap = nameof(asPost); if (parameters.ContainsKey(ap)) { string fileName = parameters[ap]; parameters.Remove(ap); try { if (!File.Exists(fileName)) { throw new FileNotFoundException($"Could not find DynamicParameters file: {fileName}.", fileName); } string yaml = File.ReadAllText(fileName); StartPlanEnvelope planEnvelope = StartPlanEnvelope.FromYaml(yaml); if (planEnvelope == null) { throw new Exception($"Could not deserialize DynamicParameters file: {fileName}."); } parameters = planEnvelope.DynamicParameters; postDynamicParameters = true; } catch (Exception ex) { WriteException(ex); Environment.Exit(1); } } try { if (isSync) { object result = instance.StartPlanWait(planName, dryRun, requestNumber, parameters, postDynamicParameters, path, serializationType, setContentType, pollingIntervalSeconds, timeoutSeconds, nodeRootUrl); Console.WriteLine(result); } else { long result = instance.StartPlan(planName, dryRun, requestNumber, parameters, postDynamicParameters, nodeRootUrl); Console.WriteLine(result); } } catch (Exception ex) { WriteException(ex); } } }