public async Task <List <ProcessorRuntimeStatus> > GetDetailedStatus([FromUri] string ProcessorName)
        {
            string[] validationErrors = Processor.ValidateProcessName(ProcessorName);
            if (null != validationErrors)
            {
                Utils.ThrowHttpError(validationErrors);
            }

            Processor processor;

            using (ITransaction tx = this.Svc.StateManager.CreateTransaction())
            {
                // do we have it?
                ConditionalValue <Processor> cResults = await this.Svc.ProcessorStateStore.TryGetValueAsync(tx, ProcessorName);

                if (!cResults.HasValue)
                {
                    Utils.ThrowHttpError(string.Format("Processor with the name {0} does not exist", ProcessorName));
                }

                processor = cResults.Value;
            }

            ProcessorOperationHandlerFactory factory          = new ProcessorOperationHandlerFactory();
            ProcessorOperationHandlerBase    operationHandler = factory.CreateHandler(
                this.Svc,
                new ProcessorOperation()
            {
                OperationType = ProcessorOperationType.RuntimeStatusCheck, ProcessorName = ProcessorName
            });

            List <ProcessorRuntimeStatus> runtimeStatus = new List <ProcessorRuntimeStatus>();

            Task <HttpResponseMessage>[] tasks = await operationHandler.ExecuteOperation <Task <HttpResponseMessage>[]>(null);

            await Task.WhenAll(tasks);

            foreach (Task <HttpResponseMessage> completedTask in tasks)
            {
                HttpResponseMessage httpResponse = completedTask.Result;
                if (!httpResponse.IsSuccessStatusCode)
                {
                    Utils.ThrowHttpError("error aggregating status from processor partitions");
                }

                runtimeStatus.Add(JsonConvert.DeserializeObject <ProcessorRuntimeStatus>(await httpResponse.Content.ReadAsStringAsync()));
            }
            return(runtimeStatus);
        }
예제 #2
0
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            this.SetProcessorAppInstanceDefaults();

            // subscribe to configuration changes
            this.Context.CodePackageActivationContext.ConfigurationPackageModifiedEvent +=
                this.CodePackageActivationContext_ConfigurationPackageModifiedEvent;

            this.ProcessorStateStore = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, Processor> >(ProcessorDefinitionStateDictionaryName);

            this.ProcessorOperationsQueue = await this.StateManager.GetOrAddAsync <IReliableQueue <ProcessorOperation> >(OperationQueueName);

            this.ProcessorOperationFactory = new ProcessorOperationHandlerFactory();

            ProcessorOperation processorOperation = null;

            // pump and execute ProcessorPperation from the queue
            while (!cancellationToken.IsCancellationRequested)
            {
                using (ITransaction tx = this.StateManager.CreateTransaction())
                {
                    try
                    {
                        ConditionalValue <ProcessorOperation> result = await this.ProcessorOperationsQueue.TryDequeueAsync(
                            tx,
                            TimeSpan.FromMilliseconds(1000),
                            cancellationToken);

                        if (result.HasValue)
                        {
                            processorOperation = result.Value;
                            ProcessorOperationHandlerBase handler = this.ProcessorOperationFactory.CreateHandler(this, processorOperation);
                            await handler.RunOperation(tx);

                            await tx.CommitAsync();
                        }
                        else
                        {
                            await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
                        }
                    }
                    catch (TimeoutException toe)
                    {
                        ServiceEventSource.Current.Message(
                            string.Format("Controller service encountered timeout in a work operations de-queue process {0} and will try again", toe.StackTrace));
                    }
                    catch (AggregateException aex)
                    {
                        AggregateException ae = aex.Flatten();

                        string sError = string.Empty;
                        if (null == processorOperation)
                        {
                            sError =
                                string.Format(
                                    "Event Processor Management Service encountered an error processing Processor-Operation {0} {1} and will terminate replica",
                                    ae.GetCombinedExceptionMessage(),
                                    ae.GetCombinedExceptionStackTrace());
                        }
                        else
                        {
                            sError =
                                string.Format(
                                    "Event Processor Management Service encountered an error processing Processor-opeartion {0} against {1} Error {2} stack trace {3} and will terminate replica",
                                    processorOperation.OperationType.ToString(),
                                    processorOperation.ProcessorName,
                                    ae.GetCombinedExceptionMessage(),
                                    ae.GetCombinedExceptionStackTrace());
                        }


                        ServiceEventSource.Current.ServiceMessage(this, sError);
                        throw;
                    }
                }
            }
        }