Esempio n. 1
0
        /// <inheritdoc />
        public Task <DeployedApplicationInfo> GetDeployedApplicationInfoAsync(
            NodeName nodeName,
            string applicationId,
            long?serverTimeout                  = 60,
            bool?includeHealthState             = false,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nodeName.ThrowIfNull(nameof(nodeName));
            applicationId.ThrowIfNull(nameof(applicationId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Nodes/{nodeName}/$/GetApplications/{applicationId}";

            url = url.Replace("{nodeName}", Uri.EscapeDataString(nodeName.ToString()));
            url = url.Replace("{applicationId}", applicationId);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            includeHealthState?.AddToQueryParameters(queryParams, $"IncludeHealthState={includeHealthState}");
            queryParams.Add("api-version=6.1");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, DeployedApplicationInfoConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task MovePrimaryReplicaAsync(
            PartitionId partitionId,
            NodeName nodeName      = default(NodeName),
            bool?ignoreConstraints = false,
            long?serverTimeout     = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            partitionId.ThrowIfNull(nameof(partitionId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Partitions/{partitionId}/$/MovePrimaryReplica";

            url = url.Replace("{partitionId}", partitionId.ToString());
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            nodeName?.AddToQueryParameters(queryParams, $"NodeName={nodeName.ToString()}");
            ignoreConstraints?.AddToQueryParameters(queryParams, $"IgnoreConstraints={ignoreConstraints}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.5");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Post,
                };

                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
Esempio n. 3
0
        /// <inheritdoc />
        public Task <ApplicationInfo> GetApplicationInfoAsync(
            string applicationId,
            bool?excludeApplicationParameters = false,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            applicationId.ThrowIfNull(nameof(applicationId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Applications/{applicationId}";

            url = url.Replace("{applicationId}", applicationId);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            excludeApplicationParameters?.AddToQueryParameters(queryParams, $"ExcludeApplicationParameters={excludeApplicationParameters}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, ApplicationInfoConverter.Deserialize, requestId, cancellationToken));
        }
Esempio n. 4
0
        /// <inheritdoc />
        public Task <PagedData <PropertyInfo> > GetPropertyInfoListAsync(
            string nameId,
            bool?includeValues = false,
            ContinuationToken continuationToken = default(ContinuationToken),
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nameId.ThrowIfNull(nameof(nameId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Names/{nameId}/$/GetProperties";

            url = url.Replace("{nameId}", nameId);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            includeValues?.AddToQueryParameters(queryParams, $"IncludeValues={includeValues}");
            continuationToken?.AddToQueryParameters(queryParams, $"ContinuationToken={continuationToken.ToString()}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponseAsPagedData(RequestFunc, url, PropertyInfoConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task <UnplacedReplicaInformation> GetUnplacedReplicaInformationAsync(
            string serviceId,
            PartitionId partitionId             = default(PartitionId),
            bool?onlyQueryPrimaries             = false,
            long?serverTimeout                  = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            serviceId.ThrowIfNull(nameof(serviceId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Services/{serviceId}/$/GetUnplacedReplicaInformation";

            url = url.Replace("{serviceId}", serviceId);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            partitionId?.AddToQueryParameters(queryParams, $"PartitionId={partitionId.ToString()}");
            onlyQueryPrimaries?.AddToQueryParameters(queryParams, $"OnlyQueryPrimaries={onlyQueryPrimaries}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.4");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, UnplacedReplicaInformationConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task ToggleVerboseServicePlacementHealthReportingAsync(
            bool?enabled,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            enabled.ThrowIfNull(nameof(enabled));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId   = Guid.NewGuid().ToString();
            var url         = "$/ToggleVerboseServicePlacementHealthReporting";
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            enabled?.AddToQueryParameters(queryParams, $"Enabled={enabled}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.4");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Post,
                };

                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task CancelOperationAsync(
            Guid?operationId,
            bool?force,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            operationId.ThrowIfNull(nameof(operationId));
            force.ThrowIfNull(nameof(force));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId   = Guid.NewGuid().ToString();
            var url         = "Faults/$/Cancel";
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            operationId?.AddToQueryParameters(queryParams, $"OperationId={operationId.ToString()}");
            force?.AddToQueryParameters(queryParams, $"Force={force}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Post,
                };

                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
Esempio n. 8
0
        /// <inheritdoc />
        public Task DeleteApplicationAsync(
            string applicationId,
            bool?forceRemove   = default(bool?),
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            applicationId.ThrowIfNull(nameof(applicationId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Applications/{applicationId}/$/Delete";

            url = url.Replace("{applicationId}", applicationId);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            forceRemove?.AddToQueryParameters(queryParams, $"ForceRemove={forceRemove}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Post,
                };

                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task <PagedData <ApplicationTypeInfo> > GetApplicationTypeInfoListAsync(
            int?applicationTypeDefinitionKindFilter = 0,
            bool?excludeApplicationParameters       = false,
            ContinuationToken continuationToken     = default(ContinuationToken),
            long?maxResults    = 0,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            maxResults?.ThrowIfLessThan("maxResults", 0);
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId   = Guid.NewGuid().ToString();
            var url         = "ApplicationTypes";
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            applicationTypeDefinitionKindFilter?.AddToQueryParameters(queryParams, $"ApplicationTypeDefinitionKindFilter={applicationTypeDefinitionKindFilter}");
            excludeApplicationParameters?.AddToQueryParameters(queryParams, $"ExcludeApplicationParameters={excludeApplicationParameters}");
            continuationToken?.AddToQueryParameters(queryParams, $"ContinuationToken={continuationToken.ToString()}");
            maxResults?.AddToQueryParameters(queryParams, $"MaxResults={maxResults}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponseAsPagedData(RequestFunc, url, ApplicationTypeInfoConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task <DeployedApplicationHealth> GetDeployedApplicationHealthUsingPolicyAsync(
            NodeName nodeName,
            string applicationId,
            int?eventsHealthStateFilter = 0,
            int?deployedServicePackagesHealthStateFilter    = 0,
            ApplicationHealthPolicy applicationHealthPolicy = default(ApplicationHealthPolicy),
            bool?excludeHealthStatistics        = false,
            long?serverTimeout                  = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nodeName.ThrowIfNull(nameof(nodeName));
            applicationId.ThrowIfNull(nameof(applicationId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Nodes/{nodeName}/$/GetApplications/{applicationId}/$/GetHealth";

            url = url.Replace("{nodeName}", Uri.EscapeDataString(nodeName.ToString()));
            url = url.Replace("{applicationId}", applicationId);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            eventsHealthStateFilter?.AddToQueryParameters(queryParams, $"EventsHealthStateFilter={eventsHealthStateFilter}");
            deployedServicePackagesHealthStateFilter?.AddToQueryParameters(queryParams, $"DeployedServicePackagesHealthStateFilter={deployedServicePackagesHealthStateFilter}");
            excludeHealthStatistics?.AddToQueryParameters(queryParams, $"ExcludeHealthStatistics={excludeHealthStatistics}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                if (applicationHealthPolicy != default(ApplicationHealthPolicy))
                {
                    ApplicationHealthPolicyConverter.Serialize(new JsonTextWriter(sw), applicationHealthPolicy);
                }

                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Post,
                    Content = new StringContent(content, Encoding.UTF8),
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, DeployedApplicationHealthConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task <ClusterHealth> GetClusterHealthUsingPolicyAsync(
            int?nodesHealthStateFilter                    = 0,
            int?applicationsHealthStateFilter             = 0,
            int?eventsHealthStateFilter                   = 0,
            bool?excludeHealthStatistics                  = false,
            bool?includeSystemApplicationHealthStatistics = false,
            ClusterHealthPolicies clusterHealthPolicies   = default(ClusterHealthPolicies),
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId   = Guid.NewGuid().ToString();
            var url         = "$/GetClusterHealth";
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            nodesHealthStateFilter?.AddToQueryParameters(queryParams, $"NodesHealthStateFilter={nodesHealthStateFilter}");
            applicationsHealthStateFilter?.AddToQueryParameters(queryParams, $"ApplicationsHealthStateFilter={applicationsHealthStateFilter}");
            eventsHealthStateFilter?.AddToQueryParameters(queryParams, $"EventsHealthStateFilter={eventsHealthStateFilter}");
            excludeHealthStatistics?.AddToQueryParameters(queryParams, $"ExcludeHealthStatistics={excludeHealthStatistics}");
            includeSystemApplicationHealthStatistics?.AddToQueryParameters(queryParams, $"IncludeSystemApplicationHealthStatistics={includeSystemApplicationHealthStatistics}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                if (clusterHealthPolicies != default(ClusterHealthPolicies))
                {
                    ClusterHealthPoliciesConverter.Serialize(new JsonTextWriter(sw), clusterHealthPolicies);
                }

                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Post,
                    Content = new StringContent(content, Encoding.UTF8),
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, ClusterHealthConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task ReportDeployedServicePackageHealthAsync(
            NodeName nodeName,
            string applicationId,
            string servicePackageName,
            HealthInformation healthInformation,
            bool?immediate     = false,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nodeName.ThrowIfNull(nameof(nodeName));
            applicationId.ThrowIfNull(nameof(applicationId));
            servicePackageName.ThrowIfNull(nameof(servicePackageName));
            healthInformation.ThrowIfNull(nameof(healthInformation));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Nodes/{nodeName}/$/GetApplications/{applicationId}/$/GetServicePackages/{servicePackageName}/$/ReportHealth";

            url = url.Replace("{nodeName}", Uri.EscapeDataString(nodeName.ToString()));
            url = url.Replace("{applicationId}", applicationId);
            url = url.Replace("{servicePackageName}", servicePackageName);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            immediate?.AddToQueryParameters(queryParams, $"Immediate={immediate}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                HealthInformationConverter.Serialize(new JsonTextWriter(sw), healthInformation);
                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Post,
                    Content = new StringContent(content, Encoding.UTF8)
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task ReportReplicaHealthAsync(
            PartitionId partitionId,
            ReplicaId replicaId,
            ReplicaHealthReportServiceKind?replicaHealthReportServiceKind,
            HealthInformation healthInformation,
            bool?immediate     = false,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            partitionId.ThrowIfNull(nameof(partitionId));
            replicaId.ThrowIfNull(nameof(replicaId));
            replicaHealthReportServiceKind.ThrowIfNull(nameof(replicaHealthReportServiceKind));
            healthInformation.ThrowIfNull(nameof(healthInformation));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Partitions/{partitionId}/$/GetReplicas/{replicaId}/$/ReportHealth";

            url = url.Replace("{partitionId}", partitionId.ToString());
            url = url.Replace("{replicaId}", replicaId.ToString());
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            replicaHealthReportServiceKind?.AddToQueryParameters(queryParams, $"ReplicaHealthReportServiceKind={replicaHealthReportServiceKind.ToString()}");
            immediate?.AddToQueryParameters(queryParams, $"Immediate={immediate}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                HealthInformationConverter.Serialize(new JsonTextWriter(sw), healthInformation);
                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Post,
                    Content = new StringContent(content, Encoding.UTF8),
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task UpdateApplicationTypeArmMetadataAsync(
            string applicationTypeName,
            string applicationTypeVersion,
            ArmMetadata applicationTypeArmMetadataUpdateDescription,
            long?serverTimeout = 60,
            bool?force         = default(bool?),
            CancellationToken cancellationToken = default(CancellationToken))
        {
            applicationTypeName.ThrowIfNull(nameof(applicationTypeName));
            applicationTypeVersion.ThrowIfNull(nameof(applicationTypeVersion));
            applicationTypeArmMetadataUpdateDescription.ThrowIfNull(nameof(applicationTypeArmMetadataUpdateDescription));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "ApplicationTypes/{applicationTypeName}/$/UpdateArmMetadata";

            url = url.Replace("{applicationTypeName}", Uri.EscapeDataString(applicationTypeName));
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            applicationTypeVersion?.AddToQueryParameters(queryParams, $"ApplicationTypeVersion={applicationTypeVersion}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            force?.AddToQueryParameters(queryParams, $"Force={force}");
            queryParams.Add("api-version=9.0");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                ArmMetadataConverter.Serialize(new JsonTextWriter(sw), applicationTypeArmMetadataUpdateDescription);
                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Post,
                    Content = new StringContent(content, Encoding.UTF8),
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
Esempio n. 15
0
        /// <inheritdoc />
        public Task <IEnumerable <ReplicaEvent> > GetPartitionReplicaEventListAsync(
            PartitionId partitionId,
            ReplicaId replicaId,
            string startTimeUtc,
            string endTimeUtc,
            long?serverTimeout                  = 60,
            string eventsTypesFilter            = default(string),
            bool?excludeAnalysisEvents          = default(bool?),
            bool?skipCorrelationLookup          = default(bool?),
            CancellationToken cancellationToken = default(CancellationToken))
        {
            partitionId.ThrowIfNull(nameof(partitionId));
            replicaId.ThrowIfNull(nameof(replicaId));
            startTimeUtc.ThrowIfNull(nameof(startTimeUtc));
            endTimeUtc.ThrowIfNull(nameof(endTimeUtc));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "EventsStore/Partitions/{partitionId}/$/Replicas/{replicaId}/$/Events";

            url = url.Replace("{partitionId}", partitionId.ToString());
            url = url.Replace("{replicaId}", replicaId.ToString());
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            startTimeUtc?.AddToQueryParameters(queryParams, $"StartTimeUtc={startTimeUtc}");
            endTimeUtc?.AddToQueryParameters(queryParams, $"EndTimeUtc={endTimeUtc}");
            eventsTypesFilter?.AddToQueryParameters(queryParams, $"EventsTypesFilter={eventsTypesFilter}");
            excludeAnalysisEvents?.AddToQueryParameters(queryParams, $"ExcludeAnalysisEvents={excludeAnalysisEvents}");
            skipCorrelationLookup?.AddToQueryParameters(queryParams, $"SkipCorrelationLookup={skipCorrelationLookup}");
            queryParams.Add("api-version=6.4");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponseAsList(RequestFunc, url, ReplicaEventConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task AddConfigurationParameterOverridesAsync(
            NodeName nodeName,
            IEnumerable <ConfigParameterOverride> configParameterOverrideList,
            bool?force         = default(bool?),
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nodeName.ThrowIfNull(nameof(nodeName));
            configParameterOverrideList.ThrowIfNull(nameof(configParameterOverrideList));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Nodes/{nodeName}/$/AddConfigurationParameterOverrides";

            url = url.Replace("{nodeName}", Uri.EscapeDataString(nodeName.ToString()));
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            force?.AddToQueryParameters(queryParams, $"Force={force}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=7.0");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                ListTConverter <ConfigParameterOverride> .Serialize(new JsonTextWriter(sw), configParameterOverrideList, ConfigParameterOverrideConverter.Serialize);

                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Post,
                    Content = new StringContent(content, Encoding.UTF8),
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task UpdateBackupPolicyAsync(
            BackupPolicyDescription backupPolicyDescription,
            string backupPolicyName,
            long?serverTimeout                  = 60,
            bool?validateConnection             = false,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            backupPolicyDescription.ThrowIfNull(nameof(backupPolicyDescription));
            backupPolicyName.ThrowIfNull(nameof(backupPolicyName));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "BackupRestore/BackupPolicies/{backupPolicyName}/$/Update";

            url = url.Replace("{backupPolicyName}", Uri.EscapeDataString(backupPolicyName));
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            validateConnection?.AddToQueryParameters(queryParams, $"ValidateConnection={validateConnection}");
            queryParams.Add("api-version=6.4");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                BackupPolicyDescriptionConverter.Serialize(new JsonTextWriter(sw), backupPolicyDescription);
                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Post,
                    Content = new StringContent(content, Encoding.UTF8),
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task <ContainerLogs> GetContainerLogsDeployedOnNodeAsync(
            NodeName nodeName,
            string applicationId,
            string serviceManifestName,
            string codePackageName,
            string tail        = default(string),
            bool?previous      = false,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nodeName.ThrowIfNull(nameof(nodeName));
            applicationId.ThrowIfNull(nameof(applicationId));
            serviceManifestName.ThrowIfNull(nameof(serviceManifestName));
            codePackageName.ThrowIfNull(nameof(codePackageName));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Nodes/{nodeName}/$/GetApplications/{applicationId}/$/GetCodePackages/$/ContainerLogs";

            url = url.Replace("{nodeName}", Uri.EscapeDataString(nodeName.ToString()));
            url = url.Replace("{applicationId}", applicationId);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            serviceManifestName?.AddToQueryParameters(queryParams, $"ServiceManifestName={serviceManifestName}");
            codePackageName?.AddToQueryParameters(queryParams, $"CodePackageName={codePackageName}");
            tail?.AddToQueryParameters(queryParams, $"Tail={tail}");
            previous?.AddToQueryParameters(queryParams, $"Previous={previous}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.2");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, ContainerLogsConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task <PagedData <BackupInfo> > GetServiceBackupListAsync(
            string serviceId,
            long?serverTimeout                  = 60,
            bool?latest                         = false,
            DateTime?startDateTimeFilter        = default(DateTime?),
            DateTime?endDateTimeFilter          = default(DateTime?),
            ContinuationToken continuationToken = default(ContinuationToken),
            long?maxResults                     = 0,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            serviceId.ThrowIfNull(nameof(serviceId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            maxResults?.ThrowIfLessThan("maxResults", 0);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Services/{serviceId}/$/GetBackups";

            url = url.Replace("{serviceId}", serviceId);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            latest?.AddToQueryParameters(queryParams, $"Latest={latest}");
            startDateTimeFilter?.AddToQueryParameters(queryParams, $"StartDateTimeFilter={System.Xml.XmlConvert.ToString(startDateTimeFilter.Value, System.Xml.XmlDateTimeSerializationMode.Utc).ToString()}");
            endDateTimeFilter?.AddToQueryParameters(queryParams, $"EndDateTimeFilter={System.Xml.XmlConvert.ToString(endDateTimeFilter.Value, System.Xml.XmlDateTimeSerializationMode.Utc).ToString()}");
            continuationToken?.AddToQueryParameters(queryParams, $"ContinuationToken={continuationToken.ToString()}");
            maxResults?.AddToQueryParameters(queryParams, $"MaxResults={maxResults}");
            queryParams.Add("api-version=6.2-preview");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponseAsPagedData(RequestFunc, url, BackupInfoConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task RemoveReplicaAsync(
            NodeName nodeName,
            PartitionId partitionId,
            ReplicaId replicaId,
            bool?forceRemove   = default(bool?),
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nodeName.ThrowIfNull(nameof(nodeName));
            partitionId.ThrowIfNull(nameof(partitionId));
            replicaId.ThrowIfNull(nameof(replicaId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Nodes/{nodeName}/$/GetPartitions/{partitionId}/$/GetReplicas/{replicaId}/$/Delete";

            url = url.Replace("{nodeName}", Uri.EscapeDataString(nodeName.ToString()));
            url = url.Replace("{partitionId}", partitionId.ToString());
            url = url.Replace("{replicaId}", replicaId.ToString());
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            forceRemove?.AddToQueryParameters(queryParams, $"ForceRemove={forceRemove}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Post,
                };

                return(request);
            }

            return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task <PartitionHealth> GetPartitionHealthAsync(
            PartitionId partitionId,
            int?eventsHealthStateFilter         = 0,
            int?replicasHealthStateFilter       = 0,
            bool?excludeHealthStatistics        = false,
            long?serverTimeout                  = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            partitionId.ThrowIfNull(nameof(partitionId));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Partitions/{partitionId}/$/GetHealth";

            url = url.Replace("{partitionId}", partitionId.ToString());
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            eventsHealthStateFilter?.AddToQueryParameters(queryParams, $"EventsHealthStateFilter={eventsHealthStateFilter}");
            replicasHealthStateFilter?.AddToQueryParameters(queryParams, $"ReplicasHealthStateFilter={replicasHealthStateFilter}");
            excludeHealthStatistics?.AddToQueryParameters(queryParams, $"ExcludeHealthStatistics={excludeHealthStatistics}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, PartitionHealthConverter.Deserialize, requestId, cancellationToken));
        }
        /// <inheritdoc />
        public Task <ClusterHealth> GetClusterHealthAsync(
            int?nodesHealthStateFilter                    = 0,
            int?applicationsHealthStateFilter             = 0,
            int?eventsHealthStateFilter                   = 0,
            bool?excludeHealthStatistics                  = false,
            bool?includeSystemApplicationHealthStatistics = false,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId   = Guid.NewGuid().ToString();
            var url         = "$/GetClusterHealth";
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            nodesHealthStateFilter?.AddToQueryParameters(queryParams, $"NodesHealthStateFilter={nodesHealthStateFilter}");
            applicationsHealthStateFilter?.AddToQueryParameters(queryParams, $"ApplicationsHealthStateFilter={applicationsHealthStateFilter}");
            eventsHealthStateFilter?.AddToQueryParameters(queryParams, $"EventsHealthStateFilter={eventsHealthStateFilter}");
            excludeHealthStatistics?.AddToQueryParameters(queryParams, $"ExcludeHealthStatistics={excludeHealthStatistics}");
            includeSystemApplicationHealthStatistics?.AddToQueryParameters(queryParams, $"IncludeSystemApplicationHealthStatistics={includeSystemApplicationHealthStatistics}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get,
                };

                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, ClusterHealthConverter.Deserialize, requestId, cancellationToken));
        }