コード例 #1
0
        public async Task <IHttpActionResult> GetServiceHealth(string servicename)
        {
            var error   = "";
            var handler = HandlersFactory.GetProfilerHandler(TheSettingService, TheLoggerService);

            handler.Start(LOG_TAG, "GetServiceHealth", GetServiceProperties());

            try
            {
                ServiceLocationService locator = new ServiceLocationService();
                UriBuilderService      builder = new UriBuilderService(Constants.ContosoEventsApplicationInstance, servicename);
                return(Ok(await _fabricClient.HealthManager.GetServiceHealthAsync(builder.ToUri())));
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(BadRequest(ex.Message));
            }
            finally
            {
                handler.Stop(error);
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> UpdateServiceHealthState(UpdateHealthRequest request)
        {
            var error   = "";
            var handler = HandlersFactory.GetProfilerHandler(TheSettingService, TheLoggerService);

            handler.Start(LOG_TAG, "UpdateServiceHealthState", GetServiceProperties());

            try
            {
                UpdateHealthRequest.Validate(request);

                int ticketOrderServices           = 0;
                int ticketOrderActors             = 0;
                int eventActors                   = 0;
                ServiceLocationService locator    = new ServiceLocationService();
                UriBuilderService      builder    = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsTicketOrderServiceName);
                ServicePartitionList   partitions = await _fabricClient.QueryManager.GetPartitionListAsync(builder.ToUri());

                foreach (Partition p in partitions)
                {
                    long minKey = (p.PartitionInformation as Int64RangePartitionInformation).LowKey;
                    ITicketOrderService dispenderService = locator.Create <ITicketOrderService>(builder.ToUri());
                    await dispenderService.UpdateHealthState(GetHealthStateFromString(request.State), request.Message);

                    ticketOrderServices++;
                }

                ActorLocationService actorLocator         = new ActorLocationService();
                UriBuilderService    orderActorBuilder    = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsTicketOrderActorName);
                ServicePartitionList orderActorPartitions = await _fabricClient.QueryManager.GetPartitionListAsync(orderActorBuilder.ToUri());

                foreach (Partition p in orderActorPartitions)
                {
                    string            minKey = (p.PartitionInformation as Int64RangePartitionInformation).Id.ToString();
                    ITicketOrderActor actor  = actorLocator.Create <ITicketOrderActor>(new ActorId(minKey), Constants.ContosoEventsApplicationName);
                    await actor.UpdateHealthState(GetHealthStateFromString(request.State), request.Message);

                    ticketOrderActors++;
                    // May require contiunuation
                }

                IDataStoreService  dataService = ServiceFactory.GetInstance().GetDataStoreService(TheSettingService, TheLoggerService);
                List <TicketEvent> events      = await dataService.GetEvents();

                UriBuilderService eventActorBuilder = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsEventActorName);
                foreach (var tEvent in events)
                {
                    IEventActor actor = actorLocator.Create <IEventActor>(new ActorId(tEvent.Id), Constants.ContosoEventsApplicationName);
                    await actor.UpdateHealthState(GetHealthStateFromString(request.State), request.Message);

                    eventActors++;
                    // May require contiunuation
                }

                return(Ok("Done: " + ticketOrderServices + "|" + ticketOrderActors + "|" + eventActors));
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(BadRequest(ex.Message));
            }
            finally
            {
                handler.Stop(error);
            }
        }