Skip to content

Commit 760bc00

Browse files
committed
Add tasks list status and description
Closes #2133
1 parent 4983703 commit 760bc00

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

src/Nest/Cluster/TaskManagement/TasksList/TasksListResponse.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq.Expressions;
44
using Newtonsoft.Json;
55
using System.Linq;
6+
using System.Threading.Tasks;
67

78
namespace Nest
89
{
@@ -25,7 +26,6 @@ public class TasksListResponse : ResponseBase, ITasksListResponse
2526
public IEnumerable<Throwable> NodeFailures { get; internal set; }
2627
}
2728

28-
2929
public class TaskExecutingNode
3030
{
3131
[JsonProperty("name")]
@@ -58,6 +58,12 @@ public class TaskState
5858
[JsonProperty("action")]
5959
public string Action { get; internal set; }
6060

61+
[JsonProperty("status")]
62+
public TaskStatus Status { get; internal set; }
63+
64+
[JsonProperty("description")]
65+
public string Description { get; internal set; }
66+
6167
[JsonProperty("start_time_in_millis")]
6268
public long StartTimeInMilliseconds { get; internal set; }
6369

@@ -66,6 +72,29 @@ public class TaskState
6672

6773
[JsonProperty("parent_task_id")]
6874
public TaskId ParentTaskId { get; internal set; }
75+
}
76+
77+
public class TaskStatus
78+
{
79+
[JsonProperty("total")]
80+
public long Total { get; internal set; }
81+
82+
[JsonProperty("updated")]
83+
public long Updated { get; internal set; }
84+
85+
[JsonProperty("created")]
86+
public long Created { get; internal set; }
87+
88+
[JsonProperty("deleted")]
89+
public long Deleted { get; internal set; }
90+
91+
[JsonProperty("batches")]
92+
public long Batches { get; internal set; }
93+
94+
[JsonProperty("version_conflicts")]
95+
public long VersionConflicts { get; internal set; }
6996

97+
[JsonProperty("noops")]
98+
public long Noops { get; internal set; }
7099
}
71100
}

src/Tests/Cluster/TaskManagement/TasksList/TasksListApiTests.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Nest;
66
using Tests.Framework;
77
using Tests.Framework.Integration;
8+
using Tests.Framework.MockData;
89
using Xunit;
910

1011
namespace Tests.Cluster.TaskManagement.TasksList
@@ -56,8 +57,86 @@ protected override void ExpectResponse(ITasksListResponse response)
5657
var parentTask = taskExecutingNode.Tasks[task.ParentTaskId];
5758
parentTask.Should().NotBeNull();
5859
parentTask.ParentTaskId.Should().BeNull();
60+
}
61+
}
62+
63+
[SkipVersion("<2.3.0", "")]
64+
public class TasksListDetailedApiTests : ApiIntegrationTestBase<IntrusiveOperationCluster, ITasksListResponse, ITasksListRequest, TasksListDescriptor, TasksListRequest>
65+
{
66+
private static TaskId _taskId = new TaskId("fakeid:1");
67+
68+
public TasksListDetailedApiTests(IntrusiveOperationCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
69+
protected override LazyResponses ClientUsage() => Calls(
70+
fluent: (client, f) => client.TasksList(f),
71+
fluentAsync: (client, f) => client.TasksListAsync(f),
72+
request: (client, r) => client.TasksList(r),
73+
requestAsync: (client, r) => client.TasksListAsync(r)
74+
);
75+
76+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
77+
{
78+
var seeder = new Seeder(this.Cluster.Node);
79+
seeder.SeedNode();
80+
81+
// get a suitable load of projects in order to get a decent task status out
82+
var bulkResponse = client.IndexMany(Project.Generator.Generate(20000));
83+
if (!bulkResponse.IsValid)
84+
throw new Exception("failure in setting up integration");
85+
86+
var response = client.ReindexOnServer(r => r
87+
.Source(s => s
88+
.Index(Infer.Index<Project>())
89+
.Type(typeof(Project))
90+
)
91+
.Destination(d => d
92+
.Index("tasks-list-projects")
93+
.OpType(OpType.Create)
94+
)
95+
.Conflicts(Conflicts.Proceed)
96+
.WaitForCompletion(false)
97+
.Refresh()
98+
);
99+
100+
_taskId = response.Task;
101+
}
102+
103+
protected override bool ExpectIsValid => true;
104+
protected override int ExpectStatusCode => 200;
105+
protected override HttpMethod HttpMethod => HttpMethod.GET;
106+
protected override string UrlPath => $"/_tasks/{Uri.EscapeDataString(_taskId.ToString())}?detailed=true";
59107

108+
protected override Func<TasksListDescriptor, ITasksListRequest> Fluent => s => s
109+
.TaskId(_taskId)
110+
.Detailed();
111+
112+
protected override TasksListRequest Initializer => new TasksListRequest(_taskId)
113+
{
114+
Detailed = true
115+
};
116+
117+
protected override void ExpectResponse(ITasksListResponse response)
118+
{
119+
response.Nodes.Should().NotBeEmpty();
120+
var taskExecutingNode = response.Nodes.First().Value;
121+
taskExecutingNode.Host.Should().NotBeNullOrWhiteSpace();
122+
taskExecutingNode.Ip.Should().NotBeNullOrWhiteSpace();
123+
taskExecutingNode.Name.Should().NotBeNullOrWhiteSpace();
124+
taskExecutingNode.TransportAddress.Should().NotBeNullOrWhiteSpace();
125+
taskExecutingNode.Tasks.Should().NotBeEmpty();
126+
taskExecutingNode.Tasks.Count().Should().Be(1);
127+
128+
var task = taskExecutingNode.Tasks[_taskId];
129+
task.Action.Should().NotBeNullOrWhiteSpace();
130+
task.Type.Should().NotBeNullOrWhiteSpace();
131+
task.Id.Should().BePositive();
132+
task.Node.Should().NotBeNullOrWhiteSpace();
133+
task.RunningTimeInNanoSeconds.Should().BeGreaterThan(0);
134+
task.StartTimeInMilliseconds.Should().BeGreaterThan(0);
60135

136+
var status = task.Status;
137+
status.Should().NotBeNull();
138+
status.Total.Should().BeGreaterOrEqualTo(0);
139+
status.Batches.Should().BeGreaterOrEqualTo(0);
61140
}
62141
}
63142
}

0 commit comments

Comments
 (0)