Exemplo n.º 1
0
        public long StartPlan(string securityContext, string planUniqueName, bool dryRun = false,
                              string requestNumber = null, Dictionary <string, string> dynamicParameters = null, bool postDynamicParameters = false,
                              string nodeRootUrl   = null, Uri referrer = null, AuthenticationHeaderValue authHeader = null)
        {
            _dal.HasAccessOrException(securityContext, planUniqueName);

            Plan plan = _dal.CreatePlanInstance(planUniqueName);

            plan.StartInfo = new PlanStartInfo()
            {
                RequestUser = securityContext, RequestNumber = requestNumber
            };

            //record "New" status
            Plan initResultPlan = new Plan()
            {
                Name       = plan.Name,
                UniqueName = plan.UniqueName,
                InstanceId = plan.InstanceId,
                StartInfo  = plan.StartInfo,
                Result     = new ExecuteResult()
                {
                    Status       = StatusType.New,
                    BranchStatus = StatusType.New,
                    Message      = $"New Instance of Plan [{plan.UniqueName}/{plan.InstanceId}]."
                }
            };

            _dal.UpdatePlanStatus(initResultPlan);

            //sign the plan
            if (SynapseServer.Config.Controller.SignPlan)
            {
                SynapseServer.Logger.Debug($"Signing Plan [{plan.Name}/{plan.InstanceId}].");

                if (!File.Exists(SynapseServer.Config.Signature.KeyUri))
                {
                    throw new FileNotFoundException(SynapseServer.Config.Signature.KeyUri);
                }

                plan.Sign(SynapseServer.Config.Signature.KeyContainerName, SynapseServer.Config.Signature.KeyUri, SynapseServer.Config.Signature.CspProviderFlags);
                //plan.Name += "foo";  //testing: intentionally crash the sig
            }

            //send plan to Node to start the work
            NodeServiceHttpApiClient nodeClient = GetNodeClientInstance(nodeRootUrl, referrer, authHeader);

            nodeClient.StartPlan(plan, plan.InstanceId, dryRun, dynamicParameters, postDynamicParameters);

            return(plan.InstanceId);
        }
        void DrainQueue()
        {
            while (true)
            {
                if (Instance.Queue.Count == 0)
                {
                    Thread.Sleep(500);   //no pending actions available, pause
                    if (_allowExit)
                    {
                        ReadyToExit = true;
                    }
                    continue;
                }
                _allowExit = true;

                PlanUpdateItem item = null;
                while (Instance.Queue.TryDequeue(out item))
                {
                    _dal.UpdatePlanStatus(item);
                }
            }
        }