public BankAccountManager(int idleTimeInSeconds = 0, string managerName = null, IOperationLogger logger = null, System.Data.IsolationLevel isolationLevel = System.Data.IsolationLevel.ReadCommitted)
 {
     _idleTimeInSeconds = idleTimeInSeconds;
     _managerName       = managerName;
     _logger            = logger;
     _isolationLevel    = isolationLevel;
 }
        // Constructors

        private OperationCapturer(Session session, IOperationLogger operations)
            : base(session)
        {
            ArgumentValidator.EnsureArgumentNotNull(operations, "operations");
            Operations = operations;
            AttachEventHandlers();
        }
예제 #3
0
            public override void Execute(IOperation operation, IOperationLogger logger)
            {
                logger.Debug($"[Operation: {operation.ComplexOperationId}, note: {NoteId}] Sending notifications for users").Wait();

                var note = noteFolderStore.GetNoteById(operation, NoteId).Result;

                var(_, users) = userDataStore.GetUsers(operation, new UserPagingRequest
                {
                    PageNo   = 0,
                    PageSize = UserIds.Count(),
                    Filter   = new UserPagingFilter
                    {
                        Ids = UserIds
                    }
                }).Result;

                foreach (var user in users)
                {
                    var message = $"[Operation: {operation.ComplexOperationId}, note: {NoteId}] Note \"{note.FolderName}\" -> \"{note.Title}\":";
                    message += $"\n- The following user: {user.FirstName}{(!string.IsNullOrWhiteSpace(user.LastName) ? $" {user.LastName}" : "")} <{user.Email}>";
                    message += $"\n- The text:\n{note.Text}";
                    logger.Info(message).Wait();
                }

                logger.Debug($"[Operation: {operation.ComplexOperationId}, note: {NoteId}] Sent notifications for users").Wait();
            }
예제 #4
0
        /// <nodoc />
        public MetricsAdapter(IStructuredLogger logger, IOperationLogger operations)
        {
            Contract.RequiresNotNull(logger);
            Contract.RequiresNotNull(operations);
            Contract.Requires(logger != operations);

            _logger     = logger;
            _operations = operations;
        }
예제 #5
0
        /// <nodoc />
        public MetricsAdapter(IStructuredLogger logger, IOperationLogger operationsLogger)
        {
            Contract.Requires(logger != null);
            Contract.Requires(operationsLogger != null);
            Contract.Requires(logger != operationsLogger);

            _logger           = logger;
            _operationsLogger = operationsLogger;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RecurrentActivityManager"/> class.
        /// </summary>
        /// <param name="operationLogger">The operation logger.</param>
        /// <param name="monotonicTimer">Instance of <see cref="IMonotonicTimer"/> to aid in testability of the class.</param>
        public RecurrentActivityManager(
            IOperationLogger <RecurrentActivityManager> operationLogger,
            IMonotonicTimer monotonicTimer)
        {
            Contracts.CheckValue(operationLogger, nameof(operationLogger));
            Contracts.CheckValue(monotonicTimer, nameof(monotonicTimer));

            _operationLogger = operationLogger;
            _monotonicTimer  = monotonicTimer;
        }
 public LoadBalancingMiddleware(
     RequestDelegate next,
     ILogger <LoadBalancingMiddleware> logger,
     IOperationLogger <LoadBalancingMiddleware> operationLogger,
     ILoadBalancer loadBalancer)
 {
     _next            = next ?? throw new ArgumentNullException(nameof(next));
     _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
     _operationLogger = operationLogger ?? throw new ArgumentNullException(nameof(operationLogger));
     _loadBalancer    = loadBalancer ?? throw new ArgumentNullException(nameof(loadBalancer));
 }
 public AffinitizeRequestMiddleware(
     RequestDelegate next,
     IEnumerable <ISessionAffinityProvider> sessionAffinityProviders,
     IOperationLogger <AffinitizeRequestMiddleware> operationLogger,
     ILogger <AffinitizeRequestMiddleware> logger)
 {
     _next   = next ?? throw new ArgumentNullException(nameof(next));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _sessionAffinityProviders = sessionAffinityProviders.ToProviderDictionary();
     _operationLogger          = operationLogger ?? throw new ArgumentNullException(nameof(operationLogger));
 }
예제 #9
0
 public override void Execute(IOperation operation, IOperationLogger logger)
 {
     try
     {
         ExecuteWithFallback(operation, logger);
     }
     catch (Exception e)
     {
         throw new CamundaWorkerBpmnError(e.Message, ErrorCode);
     }
 }
 public ProxyInvokerMiddleware(
     RequestDelegate next,
     ILogger <ProxyInvokerMiddleware> logger,
     IOperationLogger <ProxyInvokerMiddleware> operationLogger,
     IHttpProxy httpProxy)
 {
     _next            = next ?? throw new ArgumentNullException(nameof(next));
     _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
     _operationLogger = operationLogger ?? throw new ArgumentNullException(nameof(operationLogger));
     _httpProxy       = httpProxy ?? throw new ArgumentNullException(nameof(httpProxy));
 }
예제 #11
0
 public AffinitizedDestinationLookupMiddleware(
     RequestDelegate next,
     IEnumerable <ISessionAffinityProvider> sessionAffinityProviders,
     IEnumerable <IAffinityFailurePolicy> affinityFailurePolicies,
     IOperationLogger <AffinitizedDestinationLookupMiddleware> operationLogger,
     ILogger <AffinitizedDestinationLookupMiddleware> logger)
 {
     _next                     = next ?? throw new ArgumentNullException(nameof(next));
     _logger                   = logger ?? throw new ArgumentNullException(nameof(logger));
     _operationLogger          = operationLogger ?? throw new ArgumentNullException(nameof(logger));
     _sessionAffinityProviders = sessionAffinityProviders.ToProviderDictionary();
     _affinityFailurePolicies  = affinityFailurePolicies?.ToPolicyDictionary() ?? throw new ArgumentNullException(nameof(affinityFailurePolicies));
 }
예제 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackendProberFactory"/> class.
        /// </summary>
        public BackendProberFactory(IMonotonicTimer timer, ILoggerFactory loggerFactory, IOperationLogger operationLogger, IHealthProbeHttpClientFactory httpClientFactory)
        {
            Contracts.CheckValue(timer, nameof(timer));
            Contracts.CheckValue(loggerFactory, nameof(loggerFactory));
            Contracts.CheckValue(operationLogger, nameof(operationLogger));
            Contracts.CheckValue(httpClientFactory, nameof(httpClientFactory));

            _timer             = timer;
            _loggerFactory     = loggerFactory;
            _httpClientFactory = httpClientFactory;
            _randomFactory     = new RandomFactory();
            _operationLogger   = operationLogger;
        }
예제 #13
0
            public override void Execute(IOperation operation, IOperationLogger logger)
            {
                if (!moduleStore.IsModuleExists(operation, ModuleId).Result)
                {
                    throw CommonExceptions.ModuleWasNotFound(operation, ModuleId);
                }

                logger.Debug($"[Operation: {operation.ComplexOperationId}, module: {ModuleId}] Setting module status to \"{ModuleStatus.GetDescription()}\"").Wait();

                moduleStore.ChangeStatus(operation, ModuleId, ModuleStatus).Wait();

                logger.Debug($"[Operation: {operation.ComplexOperationId}, module: {ModuleId}] Module status was updated").Wait();
            }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClusterProberFactory"/> class.
 /// </summary>
 public ClusterProberFactory(
     IMonotonicTimer timer,
     ILogger <ClusterProber> logger,
     IOperationLogger <ClusterProber> operationLogger,
     IHealthProbeHttpClientFactory httpClientFactory,
     IRandomFactory randomFactory)
 {
     _timer             = timer ?? throw new ArgumentNullException(nameof(timer));
     _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
     _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
     _randomFactory     = randomFactory ?? throw new ArgumentNullException(nameof(randomFactory));
     _operationLogger   = operationLogger ?? throw new ArgumentNullException(nameof(operationLogger));
 }
예제 #15
0
            public override void Execute(IOperation operation, IOperationLogger logger)
            {
                if (!moduleStore.IsModuleExists(operation, ModuleId).Result)
                {
                    throw CommonExceptions.ModuleWasNotFound(operation, ModuleId);
                }

                logger.Debug($"[Operation: {operation.ComplexOperationId}, module: {ModuleId}] Removing module").Wait();

                moduleStore.DeleteModule(operation, ModuleId).Wait();

                logger.Debug($"[Operation: {operation.ComplexOperationId}, module: {ModuleId}] Module status was updated").Wait();
            }
예제 #16
0
            public override void Execute(IOperation operation, IOperationLogger logger)
            {
                if (!moduleStore.IsModuleExists(operation, ModuleId).Result)
                {
                    throw CommonExceptions.ModuleWasNotFound(operation, ModuleId);
                }

                logger.Debug($"[Operation: {operation.ComplexOperationId}, module: {ModuleId}] Module update didn't complete successfully, setting status to \"{ModuleStatus.GetDescription()}\"").Wait();

                moduleStore.ChangeStatus(operation, ModuleId, ModuleStatus).Wait();
                moduleStore.AddModuleHistoryRecord(operation, ModuleId, ErrorMessage).Wait();

                logger.Debug($"[Operation: {operation.ComplexOperationId}, module: {ModuleId}] Module status was updated").Wait();
            }
예제 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClusterProber"/> class.
        /// HealthProber is the unit that checks the health state for all destinations(replica) of a cluster(service)
        /// HealthProbe would query the health controller of the destination and update the health state for every destination
        /// periodically base on the time interval user specified in cluster.
        /// </summary>
        public ClusterProber(string clusterId, ClusterConfig config, IDestinationManager destinationManager, IMonotonicTimer timer, ILogger <ClusterProber> logger, IOperationLogger <ClusterProber> operationLogger, HttpClient httpClient, IRandomFactory randomFactory)
        {
            ClusterId               = clusterId ?? throw new ArgumentNullException(nameof(clusterId));
            Config                  = config ?? throw new ArgumentNullException(nameof(config));
            _destinationManager     = destinationManager ?? throw new ArgumentNullException(nameof(destinationManager));
            _timer                  = timer ?? throw new ArgumentNullException(nameof(timer));
            _logger                 = logger ?? throw new ArgumentNullException(nameof(logger));
            _operationLogger        = operationLogger ?? throw new ArgumentNullException(nameof(operationLogger));
            _randomFactory          = randomFactory ?? throw new ArgumentNullException(nameof(randomFactory));
            _clusterProbeHttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));

            _healthControllerUrl = new Uri(Config.HealthCheckOptions.Path, UriKind.Relative);
            _healthCheckInterval = Config.HealthCheckOptions.Interval;
        }
예제 #18
0
            public override void Execute(IOperation operation, IOperationLogger logger)
            {
                Index++;

                if (ModuleIdsAndStatuses.Count > Index)
                {
                    ModuleId = ModuleIdsAndStatuses.Keys.ToList()[Index];
                    ComponentsStopRequired = ModuleIdsAndStatuses.Values.ToList()[Index] == ModuleStatus.Run;
                }
                else
                {
                    ModuleId = null;
                    ComponentsStopRequired = null;
                }
            }
예제 #19
0
        public ProxyInvoker(
            ILogger <ProxyInvoker> logger,
            IOperationLogger operationLogger,
            ILoadBalancer loadBalancer,
            IHttpProxy httpProxy)
        {
            Contracts.CheckValue(logger, nameof(logger));
            Contracts.CheckValue(operationLogger, nameof(operationLogger));
            Contracts.CheckValue(loadBalancer, nameof(loadBalancer));
            Contracts.CheckValue(httpProxy, nameof(httpProxy));

            _logger          = logger;
            _operationLogger = operationLogger;
            _loadBalancer    = loadBalancer;
            _httpProxy       = httpProxy;
        }
        protected override void ExecuteWithFallback(IOperation operation, IOperationLogger logger)
        {
            if (!moduleStore.IsModuleExists(operation, ModuleId).Result)
            {
                throw CommonExceptions.ModuleWasNotFound(operation, ModuleId);
            }

            logger.Debug($"[Operation: {operation.ComplexOperationId}, module: {ModuleId}] Starting to download module file configuration").Wait();

            var module = moduleStore.GetModule(operation, ModuleId).Result;
            var fileId = (Regression ? Action switch
            {
                ActionType.Upgrade => module.PreviousConfiguration,
                ActionType.Downgrade => module.NextConfiguration,
                ActionType.NoChanges => module.CurrentConfiguration,
                _ => throw CommonExceptions.ModuleConfigurationWasNotFound(operation)
            } : module.CurrentConfiguration).FileId;
        private async Task DeleteDeployment(IOperation operation, IOperationLogger logger, DeploymentListItem deployment)
        {
            var response = await new Deployment.DeleteRequest(deployment.Id)
            {
                Cascade = true
            }.SendRequest(operation, camundaClient);

            if (response.IsWithoutErrors())
            {
                await logger.Info($"Camunda deployment was deleted:\n{JsonConvert.SerializeObject(deployment, Formatting.Indented)}");
            }
            else
            {
                await logger.Error($"Camunda deployments wasn't deleted:\n{JsonConvert.SerializeObject(response.Errors, Formatting.Indented)}");

                throw CommonExceptions.FailedToDeleteCamundaDeployment(operation);
            }
        }
예제 #22
0
        internal Operation(
            OperationData operationData,
            string dataCenterName,
            IOperationLogger operationLogger)
        {
            this.operationData   = operationData;
            this.startTime       = DateTime.UtcNow;
            this.propertyBag     = new Dictionary <string, object>();
            this.operationLogger = operationLogger;
            this.errorLevel      = ErrorLevel.None;
            this.dataCenter      = dataCenterName;

            // Until explicitly marked as Failure, the operation result is always a Success
            this.operationResult = OperationResult.Success;

            // Only failure will have exception
            this.exception = string.Empty;
        }
예제 #23
0
            public override void Execute(IOperation operation, IOperationLogger logger)
            {
                var moduleIdsAndStatuses = new Dictionary <int, ModuleStatus>();

                foreach (var(id, instanceId) in ModuleProcessInstanceIds)
                {
                    new ProcessInstance.DeleteRequest(instanceId)
                    {
                        FailIfNotExists = false
                    }.SendRequest(operation, camundaClient, true).Wait();

                    moduleStore.ChangeStatus(operation, id, ModuleStatus.UpdatedToUninstall).Wait();
                    moduleIdsAndStatuses.Add(id, ModuleIdsAndStatuses[id]);
                }

                ModuleIdsAndStatuses  = moduleIdsAndStatuses;
                var(moduleId, status) = moduleIdsAndStatuses.FirstOrDefault();
                ModuleId = moduleId;
                ComponentsStopRequired = status == ModuleStatus.Run;
            }
예제 #24
0
            public override void Execute(IOperation operation, IOperationLogger logger)
            {
                ModuleIdsAndStatuses = moduleStore.GetHostModuleIds(operation, HostId).Result;
                foreach (var(moduleId, _) in ModuleIdsAndStatuses)
                {
                    var response = new ProcessInstance.GetListRequest
                    {
                        BusinessKey            = moduleId.ToString(),
                        ProcessDefinitionKeyIn = new[]
                        {
                            CamundaWorkerKey.ModuleInstallationProcess,
                            CamundaWorkerKey.ModuleUpgradeProcess,
                            CamundaWorkerKey.ModuleRollbackProcess
                        }
                    }.SendRequest(operation, camundaClient, true).Result;

                    foreach (var item in response.Response)
                    {
                        ModuleProcessInstanceIds.Add(int.Parse(item.BusinessKey), item.Id);
                    }
                }
            }
예제 #25
0
        private async Task ExtendLock(IOperation operation, IOperationLogger logger, LockedExternalTaskListItem item, CancellationToken token)
        {
            while (true)
            {
                try
                {
                    while (true)
                    {
                        await logger.Debug($"[Operation: {operation.ComplexOperationId}] Extending lock");

                        var response = await new ExternalTask.ExtendLockRequest(item.Id)
                        {
                            WorkerId    = item.WorkerId,
                            NewDuration = Properties.LockDuration
                        }.SendRequest(operation, CamundaClient);

                        if (!response.IsWithoutErrors())
                        {
                            var retryAfter = TimeSpan.FromSeconds(5);
                            await logger.Error($"[Operation: {operation.ComplexOperationId}] Couldn't extend lock for task, retry after {retryAfter}", response.ToLog());

                            await Task.Delay(retryAfter, token);
                        }
                        else
                        {
                            await logger.Debug($"[Operation: {operation.ComplexOperationId}] Extend lock process is successful");

                            await Task.Delay(TimeSpan.FromMilliseconds(Properties.LockDuration).Divide(2), token);

                            break;
                        }
                    }
                }
                catch
                {
                    break;
                }
            }
        }
            /// <summary>
            /// Start the execution of a work item.
            /// </summary>
            /// <param name="operationLogger">Instance of <see cref="IOperationLogger"/>.</param>
            /// <param name="monotonicTimer">Instance of <see cref="IMonotonicTimer"/>.</param>
            internal async void Start(IOperationLogger <RecurrentActivityManager> operationLogger, IMonotonicTimer monotonicTimer)
            {
                Contracts.Check(_isExecuting == false, "Expected work item was not executing");

                _isExecuting  = true;
                LastExecution = monotonicTimer.CurrentTime;
                try
                {
                    await operationLogger.ExecuteAsync(
                        OperationName,
                        async() =>
                    {
                        await Func(_cts.Token);
                    });
                }
                catch (Exception e) when(!e.IsFatal())
                {
                    // Exceptions are not expected, but are already logged above and service must remain executing.
                }
                finally
                {
                    _isExecuting = false;
                }
            }
예제 #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackendProber"/> class.
        /// HealthProber is the unit that checks the health state for all destinations(replica) of a backend(service)
        /// HealthProbe would query the health controller of the destination and update the health state for every destination
        /// periodically base on the time interval user specified in backend.
        /// </summary>
        public BackendProber(string backendId, BackendConfig config, IDestinationManager destinationManager, IMonotonicTimer timer, ILogger <BackendProber> logger, IOperationLogger <BackendProber> operationLogger, HttpClient httpClient, IRandomFactory randomFactory)
        {
            Contracts.CheckValue(backendId, nameof(backendId));
            Contracts.CheckValue(config, nameof(config));
            Contracts.CheckValue(destinationManager, nameof(destinationManager));
            Contracts.CheckValue(timer, nameof(timer));
            Contracts.CheckValue(logger, nameof(logger));
            Contracts.CheckValue(operationLogger, nameof(operationLogger));
            Contracts.CheckValue(httpClient, nameof(httpClient));
            Contracts.CheckValue(randomFactory, nameof(randomFactory));

            BackendId           = backendId;
            Config              = config;
            _destinationManager = destinationManager;
            _timer              = timer;
            _logger             = logger;
            _operationLogger    = operationLogger;
            _randomFactory      = randomFactory;

            _healthControllerUrl = new Uri(Config.HealthCheckOptions.Path, UriKind.Relative);
            _healthCheckInterval = Config.HealthCheckOptions.Interval;

            _backendProbeHttpClient = httpClient;
        }
 protected abstract void ExecuteWithFileConfiguration(IOperation operation, IOperationLogger logger, OperatingSystemInstructions instructions, IRemoteHostClientService client);
예제 #29
0
 protected override void ExecuteWithFileConfiguration(IOperation operation, IOperationLogger logger, OperatingSystemInstructions instructions, IRemoteHostClientService client)
 {
     SendCommands(operation, logger, client, instructions.Camunda?.Workers?.Stop);
 }
예제 #30
0
 public HomeController(IOperationStorage operationService, IResultStorage storage, IOperationLogger logger)
 {
     _operationService = operationService;
     _storage          = storage;
     _logger           = logger;
 }