private void LogException(Exception ex, ErrorResultTO allErrors) { _stateNotifier?.LogExecuteException(ex, this); Dev2Logger.Error(DisplayName, ex, GlobalConstants.WarewolfError); _dataObject.ExecutionException = ex; allErrors.AddError(ex.Message); }
override protected void EvalInner(IDSFDataObject dsfDataObject, IDev2Activity resource, int update) { var outerStateLogger = dsfDataObject.StateNotifier; IStateNotifier stateNotifier = null; try { dsfDataObject.Settings = new Dev2WorkflowSettingsTO { EnableDetailedLogging = Config.Server.EnableDetailedLogging, LoggerType = LoggerType.JSON, KeepLogsForDays = 2, CompressOldLogFiles = true }; if (dsfDataObject.Settings.EnableDetailedLogging) { stateNotifier = LogManager.CreateStateNotifier(dsfDataObject); dsfDataObject.StateNotifier = stateNotifier; } AddExecutionToExecutionManager(dsfDataObject, resource); WorkflowExecutionWatcher.HasAWorkflowBeenExecuted = true; Dev2Logger.Debug("Starting Execute", GlobalConstants.WarewolfDebug); stateNotifier?.LogPreExecuteState(resource); IDev2Activity next; IDev2Activity lastActivity; try { lastActivity = resource; next = resource.Execute(dsfDataObject, update); stateNotifier?.LogPostExecuteState(resource, next); } catch (Exception e) { stateNotifier?.LogExecuteException(e, resource); throw; } ExecuteNode(dsfDataObject, update, ref next, ref lastActivity); } finally { _executionManager?.CompleteExecution(); stateNotifier?.Dispose(); dsfDataObject.StateNotifier = outerStateLogger; } }
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 }
public string ResumeJob(IDSFDataObject dsfDataObject, string jobId, bool overrideVariables, string environment) { try { var monitoringApi = _jobStorage.GetMonitoringApi(); var jobDetails = monitoringApi.JobDetails(jobId); var currentState = jobDetails.History.OrderBy(s => s.CreatedAt).LastOrDefault(); if (currentState?.StateName != "Scheduled" && currentState?.StateName != "Failed") { return(GlobalConstants.Failed); } var values = jobDetails.Job.Args[0] as Dictionary <string, StringBuilder>; values.TryGetValue("environment", out StringBuilder persistedEnvironment); var decryptEnvironment = persistedEnvironment.ToString().CanBeDecrypted() ? DpapiWrapper.Decrypt(persistedEnvironment.ToString()) : persistedEnvironment.ToString(); if (overrideVariables) { if (values.ContainsKey("environment")) { values["environment"] = new StringBuilder(environment); } } else { values["environment"] = new StringBuilder(decryptEnvironment); } values.TryGetValue("currentuserprincipal", out StringBuilder currentUserPrincipal); var decryptCurrentUserPrincipal = currentUserPrincipal.ToString().CanBeDecrypted() ? DpapiWrapper.Decrypt(currentUserPrincipal.ToString()) : currentUserPrincipal.ToString(); if (values.ContainsKey("environment")) { values["currentuserprincipal"] = new StringBuilder(decryptCurrentUserPrincipal); } var workflowResume = new WorkflowResume(); var result = workflowResume.Execute(values, null); var serializer = new Dev2JsonSerializer(); var executeMessage = serializer.Deserialize <ExecuteMessage>(result); if (executeMessage.HasError) { var failedState = new FailedState(new Exception(executeMessage.Message?.ToString())); _client.ChangeState(jobId, failedState, ScheduledState.StateName); return(GlobalConstants.Failed); } values.TryGetValue("resourceID", out StringBuilder workflowId); values.TryGetValue("environment", out StringBuilder environments); values.TryGetValue("startActivityId", out StringBuilder startActivityId); values.TryGetValue("versionNumber", out StringBuilder versionNumber); values.TryGetValue("currentprincipal", out StringBuilder currentprincipal); _stateNotifier = dsfDataObject.StateNotifier; var audit = new Audit { WorkflowID = workflowId?.ToString(), Environment = environments?.ToString(), VersionNumber = versionNumber?.ToString(), NextActivityId = startActivityId?.ToString(), AuditDate = DateTime.Now, AuditType = "LogResumeExecutionState", LogLevel = LogLevel.Info, User = currentprincipal?.ToString() }; _stateNotifier?.LogAdditionalDetail(audit, nameof(ResumeJob)); var manuallyResumedState = new ManuallyResumedState(environments?.ToString()); _client.ChangeState(jobId, manuallyResumedState, currentState?.StateName); return(GlobalConstants.Success); } catch (Exception ex) { _stateNotifier?.LogExecuteException(ex, this); Dev2Logger.Error(nameof(ResumeJob), ex, GlobalConstants.WarewolfError); throw new Exception(ex.Message); } }
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); } }