From 3ed723dae7a32c92c535233c6f73c224b0829415 Mon Sep 17 00:00:00 2001
From: Russ Cam <russ.cam@elastic.co>
Date: Tue, 30 Jun 2020 09:58:30 +1000
Subject: [PATCH] Add assigned node to OpenJob/StartDatafeed response (#4815)

Relates: elastic/elasticsearch#55473, #4803
---
 .../XPack/MachineLearning/OpenJob/OpenJobResponse.cs |  8 ++++++++
 .../StartDatafeed/StartDatafeedResponse.cs           |  8 ++++++++
 .../XPack/MachineLearning/OpenJob/OpenJobApiTests.cs | 10 +++++++++-
 .../StartDatafeed/StartDatafeedApiTests.cs           | 12 ++++++++++--
 4 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/src/Nest/XPack/MachineLearning/OpenJob/OpenJobResponse.cs b/src/Nest/XPack/MachineLearning/OpenJob/OpenJobResponse.cs
index 174b4b03792..d99ce070270 100644
--- a/src/Nest/XPack/MachineLearning/OpenJob/OpenJobResponse.cs
+++ b/src/Nest/XPack/MachineLearning/OpenJob/OpenJobResponse.cs
@@ -10,5 +10,13 @@ public class OpenJobResponse : ResponseBase
 	{
 		[DataMember(Name ="opened")]
 		public bool Opened { get; internal set; }
+
+		/// <summary>
+		/// The node that the job was assigned to
+		/// <para />
+		/// Available in Elasticsearch 7.8.0+
+		/// </summary>
+		[DataMember(Name = "node")]
+		public string Node { get; internal set; }
 	}
 }
diff --git a/src/Nest/XPack/MachineLearning/StartDatafeed/StartDatafeedResponse.cs b/src/Nest/XPack/MachineLearning/StartDatafeed/StartDatafeedResponse.cs
index f28c925406a..aae67edd817 100644
--- a/src/Nest/XPack/MachineLearning/StartDatafeed/StartDatafeedResponse.cs
+++ b/src/Nest/XPack/MachineLearning/StartDatafeed/StartDatafeedResponse.cs
@@ -10,5 +10,13 @@ public class StartDatafeedResponse : ResponseBase
 	{
 		[DataMember(Name ="started")]
 		public bool Started { get; internal set; }
+
+		/// <summary>
+		/// The node that the job was assigned to
+		/// <para />
+		/// Available in Elasticsearch 7.8.0+
+		/// </summary>
+		[DataMember(Name = "node")]
+		public string Node { get; internal set; }
 	}
 }
diff --git a/tests/Tests/XPack/MachineLearning/OpenJob/OpenJobApiTests.cs b/tests/Tests/XPack/MachineLearning/OpenJob/OpenJobApiTests.cs
index 5a1de4d58ce..35f53b389c0 100644
--- a/tests/Tests/XPack/MachineLearning/OpenJob/OpenJobApiTests.cs
+++ b/tests/Tests/XPack/MachineLearning/OpenJob/OpenJobApiTests.cs
@@ -6,6 +6,8 @@
 using Elasticsearch.Net;
 using FluentAssertions;
 using Nest;
+using Tests.Core.Client;
+using Tests.Core.Extensions;
 using Tests.Framework.EndpointTests.TestState;
 
 namespace Tests.XPack.MachineLearning.OpenJob
@@ -45,6 +47,12 @@ protected override LazyResponses ClientUsage() => Calls(
 
 		protected override OpenJobDescriptor NewDescriptor() => new OpenJobDescriptor(CallIsolatedValue);
 
-		protected override void ExpectResponse(OpenJobResponse response) => response.Opened.Should().BeTrue();
+		protected override void ExpectResponse(OpenJobResponse response)
+		{
+			response.Opened.Should().BeTrue();
+
+			if (TestClient.Configuration.InRange(">=7.8.0"))
+				response.Node.Should().NotBeNullOrEmpty();
+		}
 	}
 }
diff --git a/tests/Tests/XPack/MachineLearning/StartDatafeed/StartDatafeedApiTests.cs b/tests/Tests/XPack/MachineLearning/StartDatafeed/StartDatafeedApiTests.cs
index 4dad11f67f4..3192f973a13 100644
--- a/tests/Tests/XPack/MachineLearning/StartDatafeed/StartDatafeedApiTests.cs
+++ b/tests/Tests/XPack/MachineLearning/StartDatafeed/StartDatafeedApiTests.cs
@@ -2,10 +2,12 @@
 // Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information
 
-using System;
+using System;
 using Elasticsearch.Net;
 using FluentAssertions;
 using Nest;
+using Tests.Core.Client;
+using Tests.Core.Extensions;
 using Tests.Framework.EndpointTests.TestState;
 
 namespace Tests.XPack.MachineLearning.StartDatafeed
@@ -51,6 +53,12 @@ protected override LazyResponses ClientUsage() => Calls(
 
 		protected override StartDatafeedDescriptor NewDescriptor() => new StartDatafeedDescriptor(CallIsolatedValue + "-datafeed");
 
-		protected override void ExpectResponse(StartDatafeedResponse response) => response.Started.Should().BeTrue();
+		protected override void ExpectResponse(StartDatafeedResponse response)
+		{
+			response.Started.Should().BeTrue();
+
+			if (TestClient.Configuration.InRange(">=7.8.0"))
+				response.Node.Should().NotBeNullOrEmpty();
+		}
 	}
 }