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);
            }
        }
Beispiel #3
0
        public bool StartPlanAsync(long planInstanceId, bool dryRun, [FromBody] Plan plan)
        {
            string context = GetContext(nameof(StartPlanAsync),
                                        nameof(plan), plan.Name, nameof(dryRun), dryRun, nameof(planInstanceId), planInstanceId);

            try
            {
                SynapseServer.Logger.Debug(context);
                plan.InstanceId = planInstanceId;
                plan.Start(null, dryRun);

                PlanRuntimePod planContainer = new PlanRuntimePod(plan, dryRun, null, plan.InstanceId);

                if (!_isDrainstopped)
                {
                    CancellationTokenSource cts  = new CancellationTokenSource();
                    InProcPlanInfo          info = new InProcPlanInfo()
                    {
                        PlanPod           = planContainer,
                        CancellationToken = cts
                    };

                    //_plans[planContainer.PlanInstanceId] = info;

                    //_tasks.Add( Task.Run( () => { planContainer.Start( cts.Token, PlanComplete ); }, cts.Token ) );
                    //Task.Run( () => { planContainer.Start( cts.Token, null ); }, cts.Token );

                    planContainer.Start(cts.Token, null);
                }

                return(!_isDrainstopped);
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
        }