private async Task <int?> GetOngoingRequestCountAsync([NotNull] Channel channel, [NotNull] string serviceName) { try { _logger.LogDebug("Getting load report from {serviceName} at {channel}...", serviceName, channel); var loadRequest = new LoadReportRequest { ServiceName = serviceName }; LoadReportingGrpc.LoadReportingGrpcClient loadClient = new LoadReportingGrpc.LoadReportingGrpcClient(channel); LoadReportResponse loadReportResponse = await loadClient.ReportLoadAsync(loadRequest); return(loadReportResponse.ServerStats.CurrentRequests); } catch (Exception e) { _logger.LogDebug(e, "Error getting load report from {serviceName}: {errorMessage}", serviceName, e.Message); return(null); } }
public override Task <LoadReportResponse> ReportLoad(LoadReportRequest request, ServerCallContext context) { var result = new LoadReportResponse(); var serverStats = new ServerStats(); result.ServerStats = serverStats; try { if (!_loadByService.TryGetValue(request.ServiceName, out IServiceLoad currentLoad)) { // Unknown service; return(Task.FromException <LoadReportResponse>( new RpcException(new Status(StatusCode.OutOfRange, $"Service name {request.ServiceName} not found.")))); } if (currentLoad == null) { // Unknown load or unknown service; return(Task.FromException <LoadReportResponse>( new RpcException(new Status(StatusCode.OutOfRange, $"Service {request.ServiceName} has no load.")))); } result.TimestampTicks = currentLoad.ReportStart.Ticks; result.KnownLoadRate = currentLoad.KnownLoadRate; serverStats.RequestCapacity = currentLoad.ProcessCapacity; serverStats.CurrentRequests = currentLoad.CurrentProcessCount; serverStats.ServerUtilization = currentLoad.ServerUtilization; currentLoad.Reset(); } catch (Exception e) { var rpcException = new RpcException( new Status(StatusCode.Internal, e.ToString()), e.Message); return(Task.FromException <LoadReportResponse>(rpcException)); } return(Task.FromResult(result)); }
private static async Task <LoadReportResponse> GetLoadReport( [NotNull] ServiceLocation serviceLocation, Channel channel, TimeSpan timeout) { var loadRequest = new LoadReportRequest { Scope = serviceLocation.Scope, ServiceName = serviceLocation.ServiceName }; LoadReportingGrpc.LoadReportingGrpcClient loadClient = new LoadReportingGrpc.LoadReportingGrpcClient(channel); LoadReportResponse loadReportResponse = await TaskUtils.TimeoutAfter( GetLoadReport(loadClient, loadRequest), timeout); return(loadReportResponse); }
/// <summary> /// step 1 /// </summary> protected void LoadReport(ReportRequest request, ref ReportExecuteResult result) { if (string.IsNullOrEmpty(request.Path)) { throw new ReportException("Please set ReportPath to execute."); } try { if (!string.IsNullOrEmpty(request.SessionId)) { try { if (request.Reset) { var r = ReportClient.ResetExecutionAsync(new ResetExecutionRequest()).GetAwaiter().GetResult(); result.SessionId = r.executionInfo.ExecutionID; } ReportClient.ExecutionHeader.ExecutionID = request.SessionId; var rr = ReportClient.GetExecutionInfoAsync(new GetExecutionInfoRequest()).GetAwaiter().GetResult(); } catch { request.SessionId = null; } } if (string.IsNullOrEmpty(request.SessionId)) { LoadReportRequest request0 = new LoadReportRequest(request.Path, null); LoadReportResponse response = ReportClient.LoadReportAsync(request0).GetAwaiter().GetResult(); try { var match = VersionRegex.Match(response.ServerInfoHeader.ReportServerVersion); if (match.Success) { Versions.TryAdd(this.ReportSettings.ReportServer, Version.Parse(match.Result("$1"))); } } catch { } result.ParametersRequired = response.executionInfo.ParametersRequired; var dict = new Dictionary <string, string>(response.executionInfo.Parameters.Length); if (response.executionInfo.Parameters.Length > 0) { foreach (var p in response.executionInfo.Parameters) { if (p.DefaultValues != null && p.DefaultValues.Length > 0) { dict[p.Name] = p.DefaultValues.SingleOrDefault(); } if (request.Parameters.ContainsKey(p.Name)) { dict[p.Name] = request.Parameters[p.Name]; } } } request.Parameters = dict; result.SessionId = request.SessionId = response.executionInfo.ExecutionID; //ReportClient.ToggleItemAsync() SetParameters(request, result); } } catch (Exception ex) { throw new ReportException("LoadReport error: " + ex.Message, ex); } }
public async Task <IActionResult> MovieSellersReport(int movieId) { var reportName = "MovieSellers"; //Render a PDF of the sellers for the given movie // //Configure Report Proxy // var ssrsClient = getSSRS2005ExecClient(); try { await ssrsClient.OpenAsync(); var ssrsSettings = _config.GetSection("SSRS"); // //Load report // var loadRequest = new LoadReportRequest(); loadRequest.Report = string.Format("/{0}/{1}", ssrsSettings["ReportsFolder"].Trim('/'), reportName); var loadResponse = await ssrsClient.LoadReportAsync(loadRequest); // //Setup Parameters // // this report has one parameter, the MovieId var reportParams = new ParameterValue[] { new ParameterValue() { Name = "MovieId", Value = movieId.ToString() } }; //Note, if you have a parameter that is optional, still include it but set its value to null var ssrsParamRequest = new SetExecutionParametersRequest(); ssrsParamRequest.ExecutionHeader = loadResponse.ExecutionHeader; ssrsParamRequest.Parameters = reportParams; ssrsParamRequest.ParameterLanguage = "en-us"; var setParamResponse = await ssrsClient.SetExecutionParametersAsync(ssrsParamRequest); // //Render Report // var renderRequest = new RenderRequest(loadResponse.ExecutionHeader, null, "PDF", null); var renderResponse = await ssrsClient.RenderAsync(renderRequest); var returnedReport = renderResponse.Result; await ssrsClient.CloseAsync(); //Send report to user if (returnedReport != null) { //return report to client. Browser handler will show (in edge, this will show automatically in browser) OR, if no browser handler for PDF, report will show up as a download. return(new FileContentResult(returnedReport, "application/pdf")); } else { //Error rendering the report. ViewBag.ErrorMessage = "The report failed to render. Check the report server."; } } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; } finally { if (ssrsClient.State != CommunicationState.Closed) { ssrsClient.Abort(); } } return(RedirectToAction("ErrorUserFacing", "Home", new { errorMessage = ViewBag.ErrorMessage })); }
private static async Task <LoadReportResponse> GetLoadReport( [NotNull] LoadReportingGrpc.LoadReportingGrpcClient loadClient, [NotNull] LoadReportRequest loadRequest) { return(await loadClient.ReportLoadAsync(loadRequest)); }