public async Task <IActionResult> Get(String pc, String hp) { List <String> applicationsList = new List <String>(); FabricClient fabricClient; try { fabricClient = new FabricClient(pc + ":" + GetClientConnectionEndpoint(pc + ":" + hp)); } catch (Exception e) { ServiceEventSource.Current.Message("Web Service: Exception while trying to connect securely: {0}", e); throw; } FabricClient.QueryClient queryClient = fabricClient.QueryManager; ApplicationList appsList = await queryClient.GetApplicationListAsync(); foreach (Application application in appsList) { string applicationName = application.ApplicationName.ToString(); applicationsList.Add(applicationName); } return(this.Json(applicationsList)); }
/// <summary> /// Gets the details for all applications or for a specific application created in the system. /// Also takes in timeout interval, which is the maximum of time the system will allow this operation to continue before returning. /// </summary> public async Task <IEnumerable <ApplicationWrapper> > GetApplicationListAsync(Uri applicationNameFilter, TimeSpan timeout, CancellationToken cancellationToken) { var applicationList = new List <ApplicationWrapper>(); ApplicationList previousResult = null; // Set up the counter that record the time lapse. var stopWatch = Stopwatch.StartNew(); do { cancellationToken.ThrowIfCancellationRequested(); var remaining = timeout - stopWatch.Elapsed; if (remaining.Ticks < 0) { // If the passing time is longer than the timeout duration. throw new TimeoutException($"Unable to enumerate all application pages in the allotted time budget of {timeout.TotalSeconds} seconds"); } previousResult = await ExceptionsHelper.TranslateCancellations( () => _queryClient.GetApplicationListAsync( applicationNameFilter: applicationNameFilter, continuationToken: previousResult?.ContinuationToken, timeout: remaining, cancellationToken: cancellationToken), cancellationToken); applicationList.AddRange(previousResult.Select(MapApp)); }while (!string.IsNullOrEmpty(previousResult?.ContinuationToken)); return(applicationList); ApplicationWrapper MapApp(Application app) => new ApplicationWrapper { ApplicationName = app.ApplicationName, ApplicationTypeName = app.ApplicationTypeName, ApplicationTypeVersion = app.ApplicationTypeVersion, ApplicationParameters = MapAppParameters(app), }; IDictionary <string, string> MapAppParameters(Application app) { // NOTE: App Params in Service Fabric are case insensitive (verified on version 7.0.457.9590). // Since this is not documented behavior, the code below tries to play it safe by ignoring // duplicated app params instead of throwing and preventing such service from working at all // behind the Proxy. var result = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (var param in app.ApplicationParameters) { if (!result.TryAdd(param.Name, param.Value)) { _logger.LogInformation($"Duplicate app parameter '{param.Name}' for application '{app.ApplicationName}'"); } } return(result); } }
public async Task <IActionResult> Get(String pc, String hp) { List <String> applicationsList = new List <String>(); FabricClient fabricClient = new FabricClient(pc + ":" + GetClientConnectionEndpoint(pc + ":" + hp)); FabricClient.QueryClient queryClient = fabricClient.QueryManager; ApplicationList appsList = await queryClient.GetApplicationListAsync(); foreach (Application application in appsList) { string applicationName = application.ApplicationName.ToString(); applicationsList.Add(applicationName); } return(this.Json(applicationsList)); }
public async Task <Dictionary <String, List <List <String> > > > GetApplicationsServices(FabricClient primaryfc, String primarycs, FabricClient secondaryfc, String secondarycs) { Dictionary <String, List <List <String> > > applicationsServicesMap = new Dictionary <String, List <List <String> > >(); FabricClient.QueryClient queryClient = primaryfc.QueryManager; ApplicationList appsList = await queryClient.GetApplicationListAsync(); HashSet <String> configuredApplications = await GetConfiguredApplications(primarycs, secondarycs); HashSet <String> configuredServices = await GetConfiguredServices(); HashSet <String> secServices = new HashSet <string>(); foreach (Application application in appsList) { string applicationName = application.ApplicationName.ToString(); string applicationStatus = "NotConfigured"; ServiceList services = await primaryfc.QueryManager.GetServiceListAsync(new Uri(applicationName)); ServiceList secondaryServices; try { secondaryServices = await secondaryfc.QueryManager.GetServiceListAsync(new Uri(applicationName)); foreach (Service service in secondaryServices) { secServices.Add(service.ServiceName.ToString()); } } catch (System.Fabric.FabricElementNotFoundException e) { ServiceEventSource.Current.Message("Web Service: Could not find application on secondary cluster: {0}", e); applicationStatus = "NotExist"; } catch (Exception e) { ServiceEventSource.Current.Message("Web Service: Exception with Fabric Client Query Manager {0}", e); throw; } if (configuredApplications.Contains(applicationName)) { applicationStatus = "Configured"; } List <List <String> > serviceList = new List <List <String> >(); List <String> appStatusList = new List <String>(); appStatusList.Add(applicationName); appStatusList.Add(applicationStatus); serviceList.Add(appStatusList); foreach (Service service in services) { List <String> serviceInfo = new List <String>(); string serviceName = service.ServiceName.ToString(); if (secServices.Contains(serviceName)) { if (configuredServices.Contains(serviceName)) { //Configured serviceInfo.Add(serviceName); serviceInfo.Add("Configured"); } else if (service.ServiceKind == ServiceKind.Stateless) { //Stateless serviceInfo.Add(serviceName); serviceInfo.Add("Stateless"); } else { //NotConfigured serviceInfo.Add(serviceName); serviceInfo.Add("NotConfigured"); } } else { //NotExist serviceInfo.Add(serviceName); serviceInfo.Add("NotExist"); } serviceList.Add(serviceInfo); } applicationsServicesMap.Add(applicationName, serviceList); } return(applicationsServicesMap); }
public async Task <IActionResult> GetApplications(String primarycs, String primaryThumbprint, String secondarycs, String secondaryThumbprint) { Dictionary <String, List <List <String> > > applicationsServicesMap = new Dictionary <String, List <List <String> > >(); FabricClient primaryfc = GetSecureFabricClient(primarycs, primaryThumbprint); FabricClient secondaryfc = GetSecureFabricClient(secondarycs, secondaryThumbprint); FabricClient.QueryClient queryClient = primaryfc.QueryManager; ApplicationList appsList = await queryClient.GetApplicationListAsync(); HashSet <String> configuredServices = await GetConfiguredServices(); HashSet <String> secServices = new HashSet <string>(); foreach (Application application in appsList) { string applicationName = application.ApplicationName.ToString(); ServiceList services = await primaryfc.QueryManager.GetServiceListAsync(new Uri(applicationName)); ServiceList secondaryServices = await secondaryfc.QueryManager.GetServiceListAsync(new Uri(applicationName)); foreach (Service service in secondaryServices) { secServices.Add(service.ServiceName.ToString()); } List <List <String> > serviceList = new List <List <String> >(); foreach (Service service in services) { List <String> serviceInfo = new List <String>(); string serviceName = service.ServiceName.ToString(); if (secServices.Contains(serviceName)) { if (configuredServices.Contains(serviceName)) { //Configured serviceInfo.Add(serviceName); serviceInfo.Add("Configured"); } else if (service.ServiceKind == ServiceKind.Stateless) { //Stateless serviceInfo.Add(serviceName); serviceInfo.Add("Stateless"); } else { //NotConfigured serviceInfo.Add(serviceName); serviceInfo.Add("NotConfigured"); } } else { //NotExist serviceInfo.Add(serviceName); serviceInfo.Add("NotExist"); } serviceList.Add(serviceInfo); } applicationsServicesMap.Add(applicationName, serviceList); } return(this.Json(applicationsServicesMap)); }