public async Task <IHttpActionResult> PostOrder([FromBody] TicketOrder order) { var error = ""; var handler = HandlersFactory.GetProfilerHandler(TheSettingService, TheLoggerService); handler.Start(LOG_TAG, "PostOrder", GetServiceProperties()); try { TicketOrder.Validate(order); ServiceLocationService locator = new ServiceLocationService(); UriBuilderService builder = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsTicketOrderServiceName); ITicketOrderService dispenderService = locator.Create <ITicketOrderService>(builder.ToUri()); return(Ok(await dispenderService.EnqueueOrder(order))); } catch (Exception ex) { error = ex.Message; return(BadRequest(ex.Message)); } finally { handler.Stop(error); } }
public async Task <IHttpActionResult> PostReprocess([FromBody] EntityTransaction transaction) { var error = ""; var handler = HandlersFactory.GetProfilerHandler(TheSettingService); handler.Start(LOG_TAG, "PostReprocess", GetServiceProperties()); try { ServiceLocationService locator = new ServiceLocationService(); UriBuilderService builder = new UriBuilderService(Constants.ApplicationInstance, Constants.EnqueuerServiceName); var partitionKey = (long)transaction.EntityType; IEnqueuerService enqueuerService = locator.Create <IEnqueuerService>(partitionKey, builder.ToUri()); bool isEnqueued = await enqueuerService.EnqueueProcess(transaction); if (isEnqueued) { return(Ok()); } else { throw new Exception("Enqueuing failed!!!"); } } catch (Exception ex) { error = ex.Message; return(BadRequest(ex.Message)); } finally { handler.Stop(error); } }
public async Task <IHttpActionResult> GetTicketOrderPartitions() { var error = ""; var handler = HandlersFactory.GetProfilerHandler(TheSettingService, TheLoggerService); handler.Start(LOG_TAG, "GetTicketOrderPartitions", GetServiceProperties()); List <TicketOrderServiceInfo> infos = new List <TicketOrderServiceInfo>(); try { ServiceLocationService locator = new ServiceLocationService(); UriBuilderService builder = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsTicketOrderServiceName); //TODO: Task 4.1 - Use the FabricClient to get the list of partitions for the Ticket Order Service 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>(minKey, builder.ToUri()); //TODO: Task 4.2 - Collect the partition info infos.Add(new TicketOrderServiceInfo() { PartitionId = p.PartitionInformation.Id.ToString(), PartitionKind = p.PartitionInformation.Kind.ToString(), PartitionStatus = p.PartitionStatus.ToString(), NodeName = await dispenderService.GetNodeName(), HealthState = p.HealthState.ToString(), ServiceKind = p.ServiceKind.ToString(), ItemsInQueue = await dispenderService.GetOrdersCounter(CancellationToken.None) }); } return(Ok(infos)); } catch (Exception ex) { error = ex.Message; return(BadRequest(ex.Message)); } finally { handler.Stop(error); } }
public async Task <IHttpActionResult> GetActorHealth(string actorname) { var error = ""; var handler = HandlersFactory.GetProfilerHandler(TheSettingService, TheLoggerService); handler.Start(LOG_TAG, "GetActorHealth", GetServiceProperties()); try { ServiceLocationService locator = new ServiceLocationService(); UriBuilderService builder = new UriBuilderService(Constants.ContosoEventsApplicationInstance, actorname); return(Ok(await _fabricClient.HealthManager.GetServiceHealthAsync(builder.ToUri()))); } catch (Exception ex) { error = ex.Message; return(BadRequest(ex.Message)); } finally { handler.Stop(error); } }
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); } }