@@ -115,22 +115,12 @@ public DeleteModelTransportAction(
115
115
protected void doExecute (Task task , ActionRequest request , ActionListener <DeleteResponse > actionListener ) {
116
116
MLModelDeleteRequest mlModelDeleteRequest = MLModelDeleteRequest .fromActionRequest (request );
117
117
String modelId = mlModelDeleteRequest .getModelId ();
118
- try (ThreadContext .StoredContext context = client .threadPool ().getThreadContext ().stashContext ()) {
119
- ActionListener <DeleteResponse > wrappedListener = ActionListener .runBefore (actionListener , () -> context .restore ());
120
- checkDownstreamTaskBeforeDeleteModel (modelId , wrappedListener );
121
- } catch (Exception e ) {
122
- log .error (e .getMessage (), e );
123
- actionListener .onFailure (e );
124
- }
125
-
126
- }
127
-
128
- private void doDeleteModel (String modelId , ActionListener <DeleteResponse > actionListener ) {
129
118
MLModelGetRequest mlModelGetRequest = new MLModelGetRequest (modelId , false , false );
130
119
FetchSourceContext fetchSourceContext = getFetchSourceContext (mlModelGetRequest .isReturnContent ());
131
120
GetRequest getRequest = new GetRequest (ML_MODEL_INDEX ).id (modelId ).fetchSourceContext (fetchSourceContext );
132
121
User user = RestActionUtils .getUserContext (client );
133
122
boolean isSuperAdmin = isSuperAdminUserWrapper (clusterService , client );
123
+
134
124
try (ThreadContext .StoredContext context = client .threadPool ().getThreadContext ().stashContext ()) {
135
125
ActionListener <DeleteResponse > wrappedListener = ActionListener .runBefore (actionListener , () -> context .restore ());
136
126
client .get (getRequest , ActionListener .wrap (r -> {
@@ -156,7 +146,7 @@ private void doDeleteModel(String modelId, ActionListener<DeleteResponse> action
156
146
);
157
147
} else {
158
148
if (isModelNotDeployed (mlModelState )) {
159
- deleteModel (modelId , isHidden , actionListener );
149
+ checkDownstreamTaskBeforeDeleteModel (modelId , isHidden , actionListener );
160
150
} else {
161
151
wrappedListener
162
152
.onFailure (
@@ -179,7 +169,8 @@ private void doDeleteModel(String modelId, ActionListener<DeleteResponse> action
179
169
)
180
170
);
181
171
} else if (isModelNotDeployed (mlModelState )) {
182
- deleteModel (modelId , isHidden , actionListener );
172
+ checkDownstreamTaskBeforeDeleteModel (modelId , isHidden , actionListener );
173
+ ;
183
174
} else {
184
175
wrappedListener
185
176
.onFailure (
@@ -364,7 +355,7 @@ private void checkSearchPipelineBeforeDeleteModel(String modelId, ActionListener
364
355
365
356
}
366
357
367
- private void checkDownstreamTaskBeforeDeleteModel (String modelId , ActionListener <DeleteResponse > actionListener ) {
358
+ private void checkDownstreamTaskBeforeDeleteModel (String modelId , Boolean isHidden , ActionListener <DeleteResponse > actionListener ) {
368
359
CountDownLatch countDownLatch = new CountDownLatch (3 );
369
360
AtomicBoolean noneBlocked = new AtomicBoolean (true );
370
361
List <String > errorMessages = new ArrayList <>();
@@ -373,7 +364,7 @@ private void checkDownstreamTaskBeforeDeleteModel(String modelId, ActionListener
373
364
noneBlocked .compareAndSet (true , b );
374
365
if (countDownLatch .getCount () == 0 ) {
375
366
if (noneBlocked .get ()) {
376
- doDeleteModel (modelId , actionListener );
367
+ deleteModel (modelId , isHidden , actionListener );
377
368
} else {
378
369
actionListener .onFailure (new OpenSearchStatusException (String .join ("," , errorMessages ), RestStatus .CONFLICT ));
379
370
}
0 commit comments