Skip to content

Commit e17acd9

Browse files
committed
address review comments
1 parent 9445a28 commit e17acd9

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public ElasticsearchInternalServiceSettings getServiceSettings() {
9191
return (ElasticsearchInternalServiceSettings) super.getServiceSettings();
9292
}
9393

94-
public void updateNumAllocation(Integer numAllocations) {
94+
public void updateNumAllocations(Integer numAllocations) {
9595
this.internalServiceSettings.setNumAllocations(numAllocations);
9696
}
9797

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,16 @@ public List<DefaultConfigId> defaultConfigIds() {
790790

791791
@Override
792792
public void updateModelsWithDynamicFields(List<Model> models, ActionListener<List<Model>> listener) {
793+
794+
if (models.isEmpty()) {
795+
listener.onResponse(models);
796+
return;
797+
}
798+
793799
var modelsByDeploymentIds = new HashMap<String, ElasticsearchInternalModel>();
794800
for (var model : models) {
801+
assert model instanceof ElasticsearchInternalModel;
802+
795803
if (model instanceof ElasticsearchInternalModel esModel) {
796804
modelsByDeploymentIds.put(esModel.mlNodeDeploymentId(), esModel);
797805
} else {
@@ -806,19 +814,14 @@ public void updateModelsWithDynamicFields(List<Model> models, ActionListener<Lis
806814
}
807815
}
808816

809-
if (modelsByDeploymentIds.isEmpty()) {
810-
listener.onResponse(models);
811-
return;
812-
}
813-
814817
String deploymentIds = String.join(",", modelsByDeploymentIds.keySet());
815818
client.execute(
816819
GetDeploymentStatsAction.INSTANCE,
817820
new GetDeploymentStatsAction.Request(deploymentIds),
818821
ActionListener.wrap(stats -> {
819822
for (var deploymentStats : stats.getStats().results()) {
820823
var model = modelsByDeploymentIds.get(deploymentStats.getDeploymentId());
821-
model.updateNumAllocation(deploymentStats.getNumberOfAllocations());
824+
model.updateNumAllocations(deploymentStats.getNumberOfAllocations());
822825
}
823826
listener.onResponse(new ArrayList<>(modelsByDeploymentIds.values()));
824827
}, e -> {

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElserInternalModelTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public void testUpdateNumAllocation() {
2121
null
2222
);
2323

24-
model.updateNumAllocation(1);
24+
model.updateNumAllocations(1);
2525
assertEquals(1, model.getServiceSettings().getNumAllocations().intValue());
2626

27-
model.updateNumAllocation(null);
27+
model.updateNumAllocations(null);
2828
assertNull(model.getServiceSettings().getNumAllocations());
2929
}
3030
}

0 commit comments

Comments
 (0)