/// <inheritdoc />
        public Task <ContainerApiResponse> InvokeContainerApiAsync(
            NodeName nodeName,
            string applicationId,
            string serviceManifestName,
            string codePackageName,
            string codePackageInstanceId,
            ContainerApiRequestBody containerApiRequestBody,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nodeName.ThrowIfNull(nameof(nodeName));
            applicationId.ThrowIfNull(nameof(applicationId));
            serviceManifestName.ThrowIfNull(nameof(serviceManifestName));
            codePackageName.ThrowIfNull(nameof(codePackageName));
            codePackageInstanceId.ThrowIfNull(nameof(codePackageInstanceId));
            containerApiRequestBody.ThrowIfNull(nameof(containerApiRequestBody));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Nodes/{nodeName}/$/GetApplications/{applicationId}/$/GetCodePackages/$/ContainerApi";

            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}");
            codePackageInstanceId?.AddToQueryParameters(queryParams, $"CodePackageInstanceId={codePackageInstanceId}");
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.2");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                ContainerApiRequestBodyConverter.Serialize(new JsonTextWriter(sw), containerApiRequestBody);
                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, ContainerApiResponseConverter.Deserialize, requestId, cancellationToken));
        }
Beispiel #2
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, ContainerApiRequestBody obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.UriPath, "UriPath", JsonWriterExtensions.WriteStringValue);
            if (obj.HttpVerb != null)
            {
                writer.WriteProperty(obj.HttpVerb, "HttpVerb", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ContentType != null)
            {
                writer.WriteProperty(obj.ContentType, "Content-Type", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.Body != null)
            {
                writer.WriteProperty(obj.Body, "Body", JsonWriterExtensions.WriteStringValue);
            }

            writer.WriteEndObject();
        }
Beispiel #3
0
        /// <inheritdoc/>
        protected override void ProcessRecordInternal()
        {
            var containerApiRequestBody = new ContainerApiRequestBody(
                uriPath: this.UriPath,
                httpVerb: this.HttpVerb,
                contentType: this.ContentType,
                body: this.Body);

            var result = this.ServiceFabricClient.CodePackages.InvokeContainerApiAsync(
                nodeName: this.NodeName,
                applicationId: this.ApplicationId,
                serviceManifestName: this.ServiceManifestName,
                codePackageName: this.CodePackageName,
                codePackageInstanceId: this.CodePackageInstanceId,
                containerApiRequestBody: containerApiRequestBody,
                serverTimeout: this.ServerTimeout,
                cancellationToken: this.CancellationToken).GetAwaiter().GetResult();

            if (result != null)
            {
                this.WriteObject(this.FormatOutput(result));
            }
        }