Esempio n. 1
0
        public override IDev2Activity Execute(IDSFDataObject data, int update)
        {
            _previousParentId = data.ParentInstanceID;
            _debugInputs?.Clear();
            _debugOutputs?.Clear();
            _dataObject = data;
            var allErrors = new ErrorResultTO();

            try
            {
                _stateNotifier?.LogActivityExecuteState(this);

                bool firstExecution = true;
                if (_dataObject.Gates.TryGetValue(this, out (RetryState, IEnumerator <bool>)retryState))
                {
                    firstExecution = false;
                }
                else
                {
                    retryState = (new RetryState(), null);
                }
                var isRetry = retryState.Item1.NumberOfRetries > 0;

                if (firstExecution)
                {
                    if (GateOptions.GateOpts is Continue onResume)
                    {
                        retryState.Item2 = onResume.Strategy.Create().GetEnumerator();
                    }
                    _dataObject.Gates.Add(this, retryState);
                    _originalExecutionEnvironment = data.Environment.Snapshot();
                }
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("Retry: " + retryState.Item1.NumberOfRetries.ToString(), "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }
                if (firstExecution || !isRetry)
                {
                    if (retryState.Item1.NumberOfRetries > 0)
                    {
                        throw new GateException("gate execution corrupt: first execution with invalid number of retries");
                    }
                    if (_dataObject.IsDebugMode())
                    {
                        var debugItemStaticDataParams = new DebugItemStaticDataParams(nameof(ExecuteNormal), "", true);
                        AddDebugOutputItem(debugItemStaticDataParams);
                    }

                    if (_dataObject.IsServiceTestExecution && _originalUniqueId == Guid.Empty)
                    {
                        _originalUniqueId = Guid.Parse(UniqueID);
                    }

                    return(ExecuteNormal(data, update, allErrors));
                }

                return(ExecuteRetry(data, update, allErrors, retryState.Item2));
            }
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            _errorsTo = new ErrorResultTO();
            try
            {
                var suspensionId = EvalSuspensionId();
                if (string.IsNullOrWhiteSpace(suspensionId))
                {
                    Response = GlobalConstants.Failed;
                    throw new Exception(ErrorResource.ManualResumptionSuspensionIdBlank);
                }

                if (!_persistenceEnabled)
                {
                    Response = GlobalConstants.Failed;
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                var overrideVariables = "";
                if (OverrideInputVariables)
                {
                    var innerActivity = InnerActivity();
                    overrideVariables = ExecuteOverrideDataFunc(innerActivity);
                }

                Response = _scheduler.ResumeJob(_dataObject, suspensionId, OverrideInputVariables, overrideVariables);
                _stateNotifier?.LogActivityExecuteState(this);

                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("SuspensionID: " + suspensionId, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Override Variables: " + OverrideInputVariables, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Result: " + Response, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }

                return(new List <string> {
                    Response
                });
            }
            catch (Exception ex)
            {
                Response = GlobalConstants.Failed;
                _stateNotifier?.LogExecuteException(ex, this);
                Dev2Logger.Error(nameof(ManualResumptionActivity), ex, GlobalConstants.WarewolfError);
                throw new Exception(ex.GetAllMessages());
            }
        }
        public override IDev2Activity Execute(IDSFDataObject data, int update)
        {
            _previousParentId = data.ParentInstanceID;
            _debugInputs?.Clear();
            _debugOutputs?.Clear();
            _dataObject = data;
            _update     = update;
            _originalExecutionEnvironment = data.Environment.Snapshot();

            _suspensionId = "";
            var allErrors = new ErrorResultTO();

            try
            {
                _dataObject.ForEachNestingLevel++;
                if (!_persistenceEnabled)
                {
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                if (NextNodes is null)
                {
                    throw new Exception(ErrorResource.NextNodeRequiredForSuspendExecution);
                }

                var persistScheduleValue = PersistSchedulePersistValue();

                if (string.IsNullOrEmpty(persistScheduleValue))
                {
                    throw new Exception(string.Format(ErrorResource.SuspendOptionValueNotSet, GetSuspendValidationMessageType(SuspendOption)));
                }

                var currentEnvironment   = _originalExecutionEnvironment.ToJson();
                var currentuserprincipal = _dataObject.ExecutingUser.Identity.Name;
                var versionNumber        = _dataObject.VersionNumber.ToString();
                var resourceId           = _dataObject.ResourceID;
                if (EncryptData)
                {
                    currentEnvironment   = DpapiWrapper.Encrypt(currentEnvironment);
                    currentuserprincipal = DpapiWrapper.Encrypt(currentuserprincipal);
                }

                var firstActivity = NextNodes.First();
                var activityId    = Guid.Parse(firstActivity?.UniqueID ??
                                               throw new Exception(GlobalConstants.NextNodeIDNotFound));
                var values = new Dictionary <string, StringBuilder>
                {
                    { "resourceID", new StringBuilder(resourceId.ToString()) },
                    { "environment", new StringBuilder(currentEnvironment) },
                    { "startActivityId", new StringBuilder(activityId.ToString()) },
                    { nameof(versionNumber), new StringBuilder(versionNumber) },
                    { nameof(currentuserprincipal), new StringBuilder(currentuserprincipal) }
                };

                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("Allow Manual Resumption: " + AllowManualResumption, "", true);
                    AddDebugInputItem(debugItemStaticDataParams);
                }

                DispatchDebug(_dataObject, StateType.Before, _update);
                _suspensionId = _scheduler.CreateAndScheduleJob(SuspendOption, persistScheduleValue, values);

                _dataObject.ParentInstanceID = UniqueID;
                _dataObject.IsDebugNested    = true;
                DispatchDebug(_dataObject, StateType.After, _update);

                Response = _suspensionId;
                _dataObject.Environment.Assign(Result, Response, 0);
                _dataObject.Environment.CommitAssign();
                _stateNotifier?.LogActivityExecuteState(this);
                Dev2Logger.Debug($"{_dataObject.ServiceName} execution suspended: SuspensionId {_suspensionId} scheduled", GlobalConstants.WarewolfDebug);
                if (AllowManualResumption)
                {
                    ExecuteSaveDataFunc();
                }

                if (_dataObject.IsServiceTestExecution && _originalUniqueID == Guid.Empty)
                {
                    _originalUniqueID = Guid.Parse(UniqueID);
                }
            }
            catch (Hangfire.BackgroundJobClientException)
            {
                LogException(new Exception(ErrorResource.BackgroundJobClientCreateFailed), allErrors);
            }
            catch (Exception ex)
            {
                _stateNotifier?.LogExecuteException(ex, this);
                LogException(ex, allErrors);
            }
            finally
            {
                var serviceTestStep = HandleServiceTestExecution(_dataObject);
                _dataObject.ParentInstanceID = _previousParentId;
                _dataObject.ForEachNestingLevel--;
                _dataObject.IsDebugNested = false;
                HandleDebug(_dataObject, serviceTestStep);
                HandleErrors(_dataObject, allErrors);
            }
            return(null); //fire once the rest should be done on resumption service
        }
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            _errorsTo     = new ErrorResultTO();
            _suspensionId = "";
            var allErrors  = new ErrorResultTO();
            var dataObject = _dataObject;

            try
            {
                dataObject.ForEachNestingLevel++;
                if (!_persistenceEnabled)
                {
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                if (NextNodes is null)
                {
                    throw new Exception(ErrorResource.NextNodeRequiredForSuspendExecution);
                }

                var activityId = Guid.Parse(NextNodes.First()?.UniqueID ??
                                            throw new Exception(GlobalConstants.NextNodeIDNotFound));
                var currentEnvironment   = _dataObject.Environment.ToJson();
                var currentuserprincipal = _dataObject.ExecutingUser.Identity.Name;
                var versionNumber        = _dataObject.VersionNumber.ToString();
                if (EncryptData)
                {
                    currentEnvironment   = DpapiWrapper.Encrypt(currentEnvironment);
                    currentuserprincipal = DpapiWrapper.Encrypt(currentuserprincipal);
                }

                var values = new Dictionary <string, StringBuilder>
                {
                    { "resourceID", new StringBuilder(_dataObject.ResourceID.ToString()) },
                    { "environment", new StringBuilder(currentEnvironment) },
                    { "startActivityId", new StringBuilder(activityId.ToString()) },
                    { nameof(versionNumber), new StringBuilder(_dataObject.VersionNumber.ToString()) },
                    { nameof(currentuserprincipal), new StringBuilder(currentuserprincipal) }
                };
                var persistScheduleValue = PersistSchedulePersistValue();
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("Allow Manual Resumption: " + AllowManualResumption, "", true);
                    AddDebugInputItem(debugItemStaticDataParams);
                }

                DispatchDebug(dataObject, StateType.Before, _update);
                _suspensionId = _scheduler.CreateAndScheduleJob(SuspendOption, persistScheduleValue, values);

                dataObject.ParentInstanceID = UniqueID;
                dataObject.IsDebugNested    = true;
                DispatchDebug(dataObject, StateType.After, _update);

                Response = _suspensionId;
                _dataObject.Environment.Assign(Result, _suspensionId, 0);
                _dataObject.Environment.CommitAssign();
                _stateNotifier?.LogActivityExecuteState(this);
                Dev2Logger.Debug($"{_dataObject.ServiceName} execution suspended: SuspensionId {_suspensionId} scheduled", GlobalConstants.WarewolfDebug);
                if (AllowManualResumption)
                {
                    ExecuteSaveDataFunc();
                }

                if (_dataObject.IsServiceTestExecution && _originalUniqueID == Guid.Empty)
                {
                    _originalUniqueID = Guid.Parse(UniqueID);
                }

                _dataObject.StopExecution = true;
                return(new List <string> {
                    _suspensionId
                });
            }
            catch (Exception ex)
            {
                _stateNotifier?.LogExecuteException(ex, this);
                Dev2Logger.Error(nameof(SuspendExecutionActivity), ex, GlobalConstants.WarewolfError);
                _dataObject.StopExecution = true;
                allErrors.AddError(ex.GetAllMessages());
                throw;
            }
            finally
            {
                var serviceTestStep = HandleServiceTestExecution(dataObject);
                dataObject.ParentInstanceID = _previousParentId;
                dataObject.ForEachNestingLevel--;
                dataObject.IsDebugNested = false;
                HandleDebug(dataObject, serviceTestStep);
                HandleErrors(dataObject, allErrors);
            }
        }
Esempio n. 5
0
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            var allErrors = new ErrorResultTO();

            Response = string.Empty;
            try
            {
                var suspensionId = EvalSuspensionId();
                if (string.IsNullOrWhiteSpace(suspensionId))
                {
                    throw new Exception(ErrorResource.ManualResumptionSuspensionIdBlank);
                }

                if (!_persistenceEnabled)
                {
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                _logger.Info("Performing Resume of job {" + suspensionId + "}, connection established.", suspensionId);

                const string OverrideVariables = "";
                if (OverrideInputVariables)
                {
                    var persistedValues = _scheduler.GetPersistedValues(suspensionId);
                    if (string.IsNullOrEmpty(persistedValues.SuspendedEnvironment))
                    {
                        throw new Exception(ErrorResource.ManualResumptionSuspensionEnvBlank);
                    }

                    if (persistedValues.SuspendedEnvironment.StartsWith("Failed:"))
                    {
                        throw new Exception(persistedValues.SuspendedEnvironment);
                    }
                    var envArray     = _dataObject.Environment.ToJson();
                    var resumeObject = _dataObject;
                    resumeObject.StartActivityId = persistedValues.StartActivityId;
                    resumeObject.Environment.FromJson(persistedValues.SuspendedEnvironment);
                    resumeObject.Environment.FromJson(envArray);
                    resumeObject.ExecutingUser = persistedValues.ExecutingUser;
                    InnerActivity(resumeObject, _update);
                    Response = _scheduler.ManualResumeWithOverrideJob(resumeObject, suspensionId);
                }
                else
                {
                    Response = _scheduler.ResumeJob(_dataObject, suspensionId, OverrideInputVariables, OverrideVariables);
                }

                _stateNotifier?.LogActivityExecuteState(this);
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("SuspensionID: " + suspensionId, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Override Variables: " + OverrideInputVariables, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Result: " + Response, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                LogException(new Exception(ErrorResource.BackgroundJobClientResumeFailed), allErrors);
            }
            catch (Exception ex)
            {
                LogException(ex, allErrors);
            }
            finally
            {
                HandleErrors(_dataObject, allErrors);
            }

            return(new List <string> {
                Response
            });
        }