Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/115363.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 115363
summary: Avoid use of `GroupedActionListener` when the group size is zero
area: Machine Learning
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public final class GroupedActionListener<T> extends DelegatingActionListener<T,
* Creates a new listener
* @param groupSize the group size
* @param delegate the delegate listener
* @throws IllegalArgumentException if groupSize is less than or equal to 0
*/
public GroupedActionListener(int groupSize, ActionListener<Collection<T>> delegate) {
public GroupedActionListener(int groupSize, ActionListener<Collection<T>> delegate) throws IllegalArgumentException {
super(delegate);
if (groupSize <= 0) {
assert false : "illegal group size [" + groupSize + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.inference.InferenceServiceRegistry;
import org.elasticsearch.inference.Model;
import org.elasticsearch.inference.ModelConfigurations;
import org.elasticsearch.inference.TaskType;
import org.elasticsearch.inference.UnparsedModel;
import org.elasticsearch.injection.guice.Inject;
Expand Down Expand Up @@ -148,25 +149,32 @@ private void parseModels(List<UnparsedModel> unparsedModels, ActionListener<GetI
);
}

var groupedListener = new GroupedActionListener<List<Model>>(
parsedModelsByService.entrySet().size(),
listener.delegateFailureAndWrap((delegate, listOfListOfModels) -> {
var modifiable = new ArrayList<Model>();
for (var l : listOfListOfModels) {
modifiable.addAll(l);
}
modifiable.sort(Comparator.comparing(Model::getInferenceEntityId));
delegate.onResponse(
new GetInferenceModelAction.Response(modifiable.stream().map(Model::getConfigurations).collect(Collectors.toList()))
);
})
);

for (var entry : parsedModelsByService.entrySet()) {
serviceRegistry.getService(entry.getKey())
.get() // must be non-null to get this far
.updateModelsWithDynamicFields(entry.getValue(), groupedListener);
if (parsedModelsByService.isEmpty() == false) {
var groupedListener = new GroupedActionListener<List<Model>>(
parsedModelsByService.entrySet().size(),
listener.delegateFailureAndWrap((delegate, listOfListOfModels) -> {
var modifiable = new ArrayList<Model>();
for (var l : listOfListOfModels) {
modifiable.addAll(l);
}
modifiable.sort(Comparator.comparing(Model::getInferenceEntityId));
delegate.onResponse(
new GetInferenceModelAction.Response(
modifiable.stream().map(Model::getConfigurations).collect(Collectors.toList())
)
);
})
);

for (var entry : parsedModelsByService.entrySet()) {
serviceRegistry.getService(entry.getKey())
.get() // must be non-null to get this far
.updateModelsWithDynamicFields(entry.getValue(), groupedListener);
}
} else {
listener.onResponse(new GetInferenceModelAction.Response(new ArrayList<ModelConfigurations>(0)));
}

} catch (Exception e) {
listener.onFailure(e);
}
Expand Down
Loading