private async Task <Uri> LocateCacheStoreAsync()
        {
            try
            {
                bool hasPages = true;
                var  query    = new ApplicationQueryDescription()
                {
                    MaxResults = 50
                };

                while (hasPages)
                {
                    var apps = await _fabricClient.QueryManager.GetApplicationPagedListAsync(query);

                    query.ContinuationToken = apps.ContinuationToken;

                    hasPages = !string.IsNullOrEmpty(query.ContinuationToken);

                    foreach (var app in apps)
                    {
                        var serviceName = await LocateCacheStoreServiceInApplicationAsync(app.ApplicationName);

                        if (serviceName != null)
                        {
                            return(serviceName);
                        }
                    }
                }
            }
            catch { }

            return(null);
        }
        /// <summary>
        /// Locates the registered broker service.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="BrokerNotFoundException"></exception>
        private async Task <Uri> LocateAsync()
        {
            if (_brokerServiceUri != null)
            {
                return(_brokerServiceUri);
            }

            try
            {
                // check current context
                var activationContext = FabricRuntime.GetActivationContext();
                var property          = await GetBrokerPropertyOrNull(activationContext.ApplicationName);

                if (property == null)
                {
                    // try to find broker name in other application types
                    bool hasPages = true;

                    var query = new ApplicationQueryDescription {
                        MaxResults = 50
                    };

                    while (hasPages)
                    {
                        var apps = await _fabricClient.QueryManager.GetApplicationPagedListAsync(query);

                        query.ContinuationToken = apps.ContinuationToken;

                        hasPages = !string.IsNullOrEmpty(query.ContinuationToken);

                        foreach (var app in apps)
                        {
                            var found = await LocateAsync(app.ApplicationName);

                            if (found != null)
                            {
                                _brokerServiceUri = found;
                                return(_brokerServiceUri);
                            }
                        }
                    }
                }
                else
                {
                    _brokerServiceUri = new Uri(property.GetValue <string>());
                    return(_brokerServiceUri);
                }
            }
            catch
            {
                // ignored
            }

            throw new BrokerNotFoundException("No brokerService was discovered in the cluster.");
        }
Beispiel #3
0
        /// <inheritdoc />
        public async Task <Uri> LocateAsync()
        {
            try
            {
                // check current context
                var activationContext = FabricRuntime.GetActivationContext();
                var property          = await GetBrokerPropertyOrNull(activationContext.ApplicationName);

                if (property == null)
                {
                    // try to find broker name in other application types
                    bool hasPages = true;

                    var query = new ApplicationQueryDescription()
                    {
                        MaxResults = 50
                    };

                    while (hasPages)
                    {
                        var apps = await _fabricClient.QueryManager.GetApplicationPagedListAsync(query);

                        query.ContinuationToken = apps.ContinuationToken;

                        hasPages = !string.IsNullOrEmpty(query.ContinuationToken);

                        foreach (var app in apps)
                        {
                            var found = await LocateAsync(app.ApplicationName);

                            if (found != null)
                            {
                                return(found);
                            }
                        }
                    }
                }
                else
                {
                    return(new Uri(property.GetValue <string>()));
                }
            }
            catch
            {
                ;
            }
            return(null);
        }
Beispiel #4
0
        private void GetResultsWithPagedQuery(IClusterConnection clusterConnection)
        {
            var queryDescription = new ApplicationQueryDescription();

            queryDescription.ExcludeApplicationParameters = this.ExcludeApplicationParameters;

            if (this.MaxResults.HasValue)
            {
                queryDescription.MaxResults = this.MaxResults.Value;
            }

            if (!string.IsNullOrEmpty(this.ApplicationTypeName))
            {
                queryDescription.ApplicationTypeNameFilter = this.ApplicationTypeName;
            }

            if ((this.ApplicationName != null) && (!string.IsNullOrEmpty(this.ApplicationName.OriginalString)))
            {
                queryDescription.ApplicationNameFilter = this.ApplicationName;
            }

            if (!string.IsNullOrEmpty(this.ContinuationToken))
            {
                queryDescription.ContinuationToken = this.ContinuationToken;
            }

            if (this.ApplicationDefinitionKindFilter.HasValue)
            {
                queryDescription.ApplicationDefinitionKindFilter = this.ApplicationDefinitionKindFilter.Value;
            }

            var queryResult = clusterConnection.GetApplicationPagedListAsync(
                queryDescription,
                this.GetTimeout(),
                this.GetCancellationToken()).Result;

            // Continuation token is not added as a PsObject because it breaks the pipeline scenarios
            // like Get-ServiceFabricNode | Get-ServiceFabricNodeHealth
            this.WriteObject(this.FormatOutput(queryResult));

            // If the user selects the "Verbose" option, then print the continuation token
            this.WriteVerbose("Continuation Token: " + queryResult.ContinuationToken);
        }
Beispiel #5
0
        private void GetAllQueryResultPages(IClusterConnection clusterConnection)
        {
            // If the results do not fit a message, the continuation token is set.
            // Keep getting data until all entries are received.
            bool   morePages = true;
            string currentContinuationToken = null;

            currentContinuationToken = this.ContinuationToken;

            var queryDescription = new ApplicationQueryDescription()
            {
                ApplicationNameFilter        = this.ApplicationName,
                ApplicationTypeNameFilter    = this.ApplicationTypeName,
                ContinuationToken            = currentContinuationToken,
                ExcludeApplicationParameters = this.ExcludeApplicationParameters
            };

            if (this.ApplicationDefinitionKindFilter.HasValue)
            {
                queryDescription.ApplicationDefinitionKindFilter = this.ApplicationDefinitionKindFilter.Value;
            }

            while (morePages)
            {
                var queryResult = clusterConnection.GetApplicationPagedListAsync(
                    queryDescription,
                    this.GetTimeout(),
                    this.GetCancellationToken()).Result;

                foreach (var item in queryResult)
                {
                    this.WriteObject(this.FormatOutput(item));
                }

                morePages = Helpers.ResultHasMorePages(this, queryResult.ContinuationToken, out currentContinuationToken);

                // Update continuation token
                queryDescription.ContinuationToken = currentContinuationToken;
            }
        }
        private async Task <Uri> LocateCacheStoreAsync()
        {
            if (_options.CacheStoreServiceUri != null)
            {
                return(_options.CacheStoreServiceUri);
            }
            try
            {
                bool hasPages = true;
                var  query    = new ApplicationQueryDescription()
                {
                    MaxResults = 50
                };

                while (hasPages)
                {
                    var apps = await _fabricClient.QueryManager.GetApplicationPagedListAsync(query);

                    query.ContinuationToken = apps.ContinuationToken;

                    hasPages = !string.IsNullOrEmpty(query.ContinuationToken);

                    foreach (var app in apps)
                    {
                        var serviceName = await LocateCacheStoreServiceInApplicationAsync(app.ApplicationName);

                        if (serviceName != null)
                        {
                            return(serviceName);
                        }
                    }
                }
            }
            catch { }

            throw new CacheStoreNotFoundException("Cache store not found in Service Fabric cluster.  Try setting the 'CacheStoreServiceUri' configuration option to the location of your cache store.");;
        }
 public GetApplicationListRequest(IFabricClient fabricClient, ApplicationQueryDescription description, TimeSpan timeout)
     : base(fabricClient, timeout)
 {
     this.ApplicationQueryDescription = description;
 }