10
10
import org .apache .lucene .util .Counter ;
11
11
import org .elasticsearch .cluster .ClusterState ;
12
12
import org .elasticsearch .cluster .metadata .Metadata ;
13
- import org .elasticsearch .ingest .ConfigurationUtils ;
14
13
import org .elasticsearch .ingest .IngestMetadata ;
15
- import org .elasticsearch .ingest .Pipeline ;
16
14
import org .elasticsearch .transport .Transports ;
17
15
18
16
import java .util .HashMap ;
24
22
import java .util .function .Consumer ;
25
23
26
24
import static org .elasticsearch .inference .InferenceResults .MODEL_ID_RESULTS_FIELD ;
25
+ import static org .elasticsearch .ingest .Pipeline .ON_FAILURE_KEY ;
27
26
import static org .elasticsearch .ingest .Pipeline .PROCESSORS_KEY ;
28
27
29
28
/**
@@ -53,16 +52,10 @@ public static int countInferenceProcessors(ClusterState state) {
53
52
Counter counter = Counter .newCounter ();
54
53
ingestMetadata .getPipelines ().forEach ((pipelineId , configuration ) -> {
55
54
Map <String , Object > configMap = configuration .getConfigAsMap ();
56
- List <Map <String , Object >> processorConfigs = ConfigurationUtils . readList ( null , null , configMap , PROCESSORS_KEY );
55
+ List <Map <String , Object >> processorConfigs = ( List < Map < String , Object >>) configMap . get ( PROCESSORS_KEY );
57
56
for (Map <String , Object > processorConfigWithKey : processorConfigs ) {
58
57
for (Map .Entry <String , Object > entry : processorConfigWithKey .entrySet ()) {
59
- addModelsAndPipelines (
60
- entry .getKey (),
61
- pipelineId ,
62
- (Map <String , Object >) entry .getValue (),
63
- pam -> counter .addAndGet (1 ),
64
- 0
65
- );
58
+ addModelsAndPipelines (entry .getKey (), pipelineId , entry .getValue (), pam -> counter .addAndGet (1 ), 0 );
66
59
}
67
60
}
68
61
});
@@ -73,7 +66,6 @@ public static int countInferenceProcessors(ClusterState state) {
73
66
* @param ingestMetadata The ingestMetadata of current ClusterState
74
67
* @return The set of model IDs referenced by inference processors
75
68
*/
76
- @ SuppressWarnings ("unchecked" )
77
69
public static Set <String > getModelIdsFromInferenceProcessors (IngestMetadata ingestMetadata ) {
78
70
if (ingestMetadata == null ) {
79
71
return Set .of ();
@@ -82,7 +74,7 @@ public static Set<String> getModelIdsFromInferenceProcessors(IngestMetadata inge
82
74
Set <String > modelIds = new LinkedHashSet <>();
83
75
ingestMetadata .getPipelines ().forEach ((pipelineId , configuration ) -> {
84
76
Map <String , Object > configMap = configuration .getConfigAsMap ();
85
- List <Map <String , Object >> processorConfigs = ConfigurationUtils . readList (null , null , configMap , PROCESSORS_KEY );
77
+ List <Map <String , Object >> processorConfigs = readList (configMap , PROCESSORS_KEY );
86
78
for (Map <String , Object > processorConfigWithKey : processorConfigs ) {
87
79
for (Map .Entry <String , Object > entry : processorConfigWithKey .entrySet ()) {
88
80
addModelsAndPipelines (entry .getKey (), pipelineId , entry .getValue (), pam -> modelIds .add (pam .modelIdOrAlias ()), 0 );
@@ -96,7 +88,6 @@ public static Set<String> getModelIdsFromInferenceProcessors(IngestMetadata inge
96
88
* @param state Current cluster state
97
89
* @return a map from Model or Deployment IDs or Aliases to each pipeline referencing them.
98
90
*/
99
- @ SuppressWarnings ("unchecked" )
100
91
public static Map <String , Set <String >> pipelineIdsByResource (ClusterState state , Set <String > ids ) {
101
92
assert Transports .assertNotTransportThread ("non-trivial nested loops over cluster state structures" );
102
93
Map <String , Set <String >> pipelineIdsByModelIds = new HashMap <>();
@@ -110,7 +101,7 @@ public static Map<String, Set<String>> pipelineIdsByResource(ClusterState state,
110
101
}
111
102
ingestMetadata .getPipelines ().forEach ((pipelineId , configuration ) -> {
112
103
Map <String , Object > configMap = configuration .getConfigAsMap ();
113
- List <Map <String , Object >> processorConfigs = ConfigurationUtils . readList (null , null , configMap , PROCESSORS_KEY );
104
+ List <Map <String , Object >> processorConfigs = readList (configMap , PROCESSORS_KEY );
114
105
for (Map <String , Object > processorConfigWithKey : processorConfigs ) {
115
106
for (Map .Entry <String , Object > entry : processorConfigWithKey .entrySet ()) {
116
107
addModelsAndPipelines (entry .getKey (), pipelineId , entry .getValue (), pam -> {
@@ -128,7 +119,6 @@ public static Map<String, Set<String>> pipelineIdsByResource(ClusterState state,
128
119
* @param state Current {@link ClusterState}
129
120
* @return a map from Model or Deployment IDs or Aliases to each pipeline referencing them.
130
121
*/
131
- @ SuppressWarnings ("unchecked" )
132
122
public static Set <String > pipelineIdsForResource (ClusterState state , Set <String > ids ) {
133
123
assert Transports .assertNotTransportThread ("non-trivial nested loops over cluster state structures" );
134
124
Set <String > pipelineIds = new HashSet <>();
@@ -142,7 +132,7 @@ public static Set<String> pipelineIdsForResource(ClusterState state, Set<String>
142
132
}
143
133
ingestMetadata .getPipelines ().forEach ((pipelineId , configuration ) -> {
144
134
Map <String , Object > configMap = configuration .getConfigAsMap ();
145
- List <Map <String , Object >> processorConfigs = ConfigurationUtils . readList (null , null , configMap , PROCESSORS_KEY );
135
+ List <Map <String , Object >> processorConfigs = readList (configMap , PROCESSORS_KEY );
146
136
for (Map <String , Object > processorConfigWithKey : processorConfigs ) {
147
137
for (Map .Entry <String , Object > entry : processorConfigWithKey .entrySet ()) {
148
138
addModelsAndPipelines (entry .getKey (), pipelineId , entry .getValue (), pam -> {
@@ -188,21 +178,16 @@ private static void addModelsAndPipelines(
188
178
addModelsAndPipelines (
189
179
innerProcessorWithName .getKey (),
190
180
pipelineId ,
191
- ( Map < String , Object >) innerProcessorWithName .getValue (),
181
+ innerProcessorWithName .getValue (),
192
182
handler ,
193
183
level + 1
194
184
);
195
185
}
196
186
}
197
187
return ;
198
188
}
199
- if (processorDefinition instanceof Map <?, ?> definitionMap && definitionMap .containsKey (Pipeline .ON_FAILURE_KEY )) {
200
- List <Map <String , Object >> onFailureConfigs = ConfigurationUtils .readList (
201
- null ,
202
- null ,
203
- (Map <String , Object >) definitionMap ,
204
- Pipeline .ON_FAILURE_KEY
205
- );
189
+ if (processorDefinition instanceof Map <?, ?> definitionMap && definitionMap .containsKey (ON_FAILURE_KEY )) {
190
+ List <Map <String , Object >> onFailureConfigs = readList (definitionMap , ON_FAILURE_KEY );
206
191
onFailureConfigs .stream ()
207
192
.flatMap (map -> map .entrySet ().stream ())
208
193
.forEach (entry -> addModelsAndPipelines (entry .getKey (), pipelineId , entry .getValue (), handler , level + 1 ));
@@ -211,4 +196,16 @@ private static void addModelsAndPipelines(
211
196
212
197
private record PipelineAndModel (String pipelineId , String modelIdOrAlias ) {}
213
198
199
+ /**
200
+ * A local alternative to ConfigurationUtils.readList(...) that reads list properties out of the processor configuration map,
201
+ * but doesn't rely on mutating the configuration map.
202
+ */
203
+ @ SuppressWarnings ("unchecked" )
204
+ private static List <Map <String , Object >> readList (Map <?, ?> processorConfig , String key ) {
205
+ Object val = processorConfig .get (key );
206
+ if (val == null ) {
207
+ throw new IllegalArgumentException ("Missing required property [" + key + "]" );
208
+ }
209
+ return (List <Map <String , Object >>) val ;
210
+ }
214
211
}
0 commit comments