Skip to content

Commit 003a671

Browse files
committed
[ML] Add copy constructor for AssignmentStats (elastic#127230)
1 parent 3cc8807 commit 003a671

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/assignment/AssignmentStats.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,22 @@ public int hashCode() {
432432
private final Instant startTime;
433433
private final List<AssignmentStats.NodeStats> nodeStats;
434434

435+
public AssignmentStats(AssignmentStats other) {
436+
this.deploymentId = other.deploymentId;
437+
this.modelId = other.modelId;
438+
this.threadsPerAllocation = other.threadsPerAllocation;
439+
this.numberOfAllocations = other.numberOfAllocations;
440+
this.adaptiveAllocationsSettings = other.adaptiveAllocationsSettings;
441+
this.queueCapacity = other.queueCapacity;
442+
this.startTime = other.startTime;
443+
this.nodeStats = other.nodeStats;
444+
this.state = other.state;
445+
this.reason = other.reason;
446+
this.allocationStatus = other.allocationStatus;
447+
this.cacheSize = other.cacheSize;
448+
this.priority = other.priority;
449+
}
450+
435451
public AssignmentStats(
436452
String deploymentId,
437453
String modelId,
@@ -535,6 +551,12 @@ public AssignmentState getState() {
535551
return state;
536552
}
537553

554+
public AssignmentStats setNodeStats(List<AssignmentStats.NodeStats> nodeStats) {
555+
this.nodeStats.clear();
556+
this.nodeStats.addAll(nodeStats);
557+
return this;
558+
}
559+
538560
public AssignmentStats setState(AssignmentState state) {
539561
this.state = state;
540562
return this;

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/inference/assignment/AssignmentStatsTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ public void testGetOverallInferenceStatsWithOnlyStoppedNodes() {
214214
assertThat(stats.getFailureCount(), equalTo(0L));
215215
}
216216

217+
public void testCopyConstructor() {
218+
AssignmentStats original = randomDeploymentStats();
219+
AssignmentStats copy = new AssignmentStats(original);
220+
assertThat(copy, equalTo(original));
221+
}
222+
217223
@Override
218224
protected Writeable.Reader<AssignmentStats> instanceReader() {
219225
return AssignmentStats::new;

0 commit comments

Comments
 (0)