18
18
import static org .opensearch .ml .action .models .DeleteModelTransportAction .OS_STATUS_EXCEPTION_MESSAGE ;
19
19
import static org .opensearch .ml .action .models .DeleteModelTransportAction .SEARCH_FAILURE_MSG ;
20
20
import static org .opensearch .ml .action .models .DeleteModelTransportAction .TIMEOUT_MSG ;
21
- import static org .opensearch .ml .common .CommonValue .ML_AGENT_INDEX ;
22
21
import static org .opensearch .ml .common .CommonValue .ML_MODEL_INDEX ;
23
22
24
- import java .io .ByteArrayOutputStream ;
25
23
import java .io .IOException ;
26
- import java .io .ObjectOutputStream ;
27
- import java .nio .ByteBuffer ;
28
24
import java .nio .charset .StandardCharsets ;
29
25
import java .util .ArrayList ;
30
26
import java .util .Arrays ;
52
48
import org .opensearch .action .search .SearchResponse ;
53
49
import org .opensearch .action .support .ActionFilters ;
54
50
import org .opensearch .client .Client ;
55
- import org .opensearch .client .Response ;
56
51
import org .opensearch .cluster .service .ClusterService ;
57
52
import org .opensearch .common .settings .Settings ;
58
53
import org .opensearch .common .util .concurrent .ThreadContext ;
59
54
import org .opensearch .common .xcontent .XContentFactory ;
60
- import org .opensearch .common .xcontent .XContentType ;
61
55
import org .opensearch .core .action .ActionListener ;
62
- import org .opensearch .core .action .ActionResponse ;
63
56
import org .opensearch .core .common .bytes .BytesArray ;
64
57
import org .opensearch .core .common .bytes .BytesReference ;
65
- import org .opensearch .core .xcontent .MediaType ;
66
58
import org .opensearch .core .xcontent .MediaTypeRegistry ;
67
59
import org .opensearch .core .xcontent .NamedXContentRegistry ;
68
60
import org .opensearch .core .xcontent .ToXContent ;
80
72
import org .opensearch .ml .model .MLModelManager ;
81
73
import org .opensearch .search .SearchHit ;
82
74
import org .opensearch .search .SearchHits ;
83
- import org .opensearch .search .pipeline .PipelineConfiguration ;
84
75
import org .opensearch .test .OpenSearchTestCase ;
85
76
import org .opensearch .threadpool .ThreadPool ;
86
77
import org .opensearch .transport .TransportService ;
@@ -139,7 +130,6 @@ public class DeleteModelTransportActionTests extends OpenSearchTestCase {
139
130
@ Mock
140
131
private org .opensearch .search .pipeline .PipelineConfiguration searchPipelineConfiguration ;
141
132
142
-
143
133
@ Mock
144
134
GetPipelineResponse getIngestionPipelineResponse ;
145
135
@@ -217,7 +207,9 @@ public void testDeleteModel_BlockedBySearchPipeline() throws IOException {
217
207
218
208
public void testDeleteModel_BlockedByIngestPipeline () throws IOException {
219
209
org .opensearch .ingest .PipelineConfiguration ingestPipelineConfiguration = new org .opensearch .ingest .PipelineConfiguration (
220
- "1" , new BytesArray ("{\" model_id\" : \" test_id\" }" .getBytes (StandardCharsets .UTF_8 )), MediaTypeRegistry .JSON
210
+ "1" ,
211
+ new BytesArray ("{\" model_id\" : \" test_id\" }" .getBytes (StandardCharsets .UTF_8 )),
212
+ MediaTypeRegistry .JSON
221
213
);
222
214
when (getIngestionPipelineResponse .pipelines ()).thenReturn (List .of (ingestPipelineConfiguration ));
223
215
doAnswer (invocation -> {
@@ -229,7 +221,10 @@ public void testDeleteModel_BlockedByIngestPipeline() throws IOException {
229
221
deleteModelTransportAction .doExecute (null , mlModelDeleteRequest , actionListener );
230
222
ArgumentCaptor <Exception > argumentCaptor = ArgumentCaptor .forClass (Exception .class );
231
223
verify (actionListener ).onFailure (argumentCaptor .capture ());
232
- assertEquals ("1 ingest pipelines are still using this model, please delete or update the pipelines first: [1]" , argumentCaptor .getValue ().getMessage ());
224
+ assertEquals (
225
+ "1 ingest pipelines are still using this model, please delete or update the pipelines first: [1]" ,
226
+ argumentCaptor .getValue ().getMessage ()
227
+ );
233
228
}
234
229
235
230
public void testDeleteModel_BlockedByAgent () throws IOException {
@@ -245,7 +240,10 @@ public void testDeleteModel_BlockedByAgent() throws IOException {
245
240
deleteModelTransportAction .doExecute (null , mlModelDeleteRequest , actionListener );
246
241
ArgumentCaptor <Exception > argumentCaptor = ArgumentCaptor .forClass (Exception .class );
247
242
verify (actionListener ).onFailure (argumentCaptor .capture ());
248
- assertEquals ("1 agents are still using this model, please delete or update the agents first: [1]" , argumentCaptor .getValue ().getMessage ());
243
+ assertEquals (
244
+ "1 agents are still using this model, please delete or update the agents first: [1]" ,
245
+ argumentCaptor .getValue ().getMessage ()
246
+ );
249
247
}
250
248
251
249
public void testDeleteRemoteModel_Success () throws IOException {
@@ -277,7 +275,6 @@ public void testDeleteRemoteModel_deleteModelController_failed() throws IOExcept
277
275
return null ;
278
276
}).when (client ).delete (any (), any ());
279
277
280
-
281
278
GetResponse getResponse = prepareModelWithFunction (MLModelState .REGISTERED , null , false , FunctionName .REMOTE );
282
279
doAnswer (invocation -> {
283
280
ActionListener <GetResponse > actionListener = invocation .getArgument (1 );
@@ -460,7 +457,6 @@ public void testDeleteModel_deleteModelController_ResourceNotFoundException() th
460
457
return null ;
461
458
}).when (client ).delete (any (), any ());
462
459
463
-
464
460
GetResponse getResponse = prepareMLModel (MLModelState .REGISTERED , null , false );
465
461
doAnswer (invocation -> {
466
462
ActionListener <GetResponse > actionListener = invocation .getArgument (1 );
@@ -504,7 +500,6 @@ public void testDeleteRemoteModel_modelNotFound_ResourceNotFoundException() thro
504
500
return null ;
505
501
}).when (client ).delete (any (), any ());
506
502
507
-
508
503
GetResponse getResponse = prepareModelWithFunction (MLModelState .REGISTERED , null , false , FunctionName .REMOTE );
509
504
doAnswer (invocation -> {
510
505
ActionListener <GetResponse > actionListener = invocation .getArgument (1 );
@@ -529,7 +524,6 @@ public void testDeleteRemoteModel_modelNotFound_RuntimeException() throws IOExce
529
524
return null ;
530
525
}).when (client ).delete (any (), any ());
531
526
532
-
533
527
GetResponse getResponse = prepareModelWithFunction (MLModelState .REGISTERED , null , false , FunctionName .REMOTE );
534
528
doAnswer (invocation -> {
535
529
ActionListener <GetResponse > actionListener = invocation .getArgument (1 );
@@ -683,7 +677,7 @@ private GetResponse buildResponse(MLModel mlModel) throws IOException {
683
677
684
678
private void prepare () {
685
679
emptyBulkByScrollResponse = new BulkByScrollResponse (new ArrayList <>(), null );
686
- SearchHits hits = new SearchHits (new SearchHit [] { }, new TotalHits (0 , TotalHits .Relation .EQUAL_TO ), 0.0f );
680
+ SearchHits hits = new SearchHits (new SearchHit [] {}, new TotalHits (0 , TotalHits .Relation .EQUAL_TO ), 0.0f );
687
681
when (searchResponse .getHits ()).thenReturn (hits );
688
682
when (getIngestionPipelineResponse .pipelines ()).thenReturn (List .of ());
689
683
@@ -693,7 +687,6 @@ private void prepare() {
693
687
return null ;
694
688
}).when (client ).search (any (), any ());
695
689
696
-
697
690
doAnswer (invocation -> {
698
691
ActionListener <BulkByScrollResponse > listener = invocation .getArgument (2 );
699
692
listener .onResponse (emptyBulkByScrollResponse );
@@ -712,8 +705,8 @@ private void prepare() {
712
705
listener .onResponse (getSearchPipelineResponse );
713
706
return null ;
714
707
}).when (client ).execute (eq (GetSearchPipelineAction .INSTANCE ), any (), any ());
715
- configDataMap = Map . of ( "model_id" , "test_id" , "list_model_id" , List . of ( "test_list_id" ),
716
- "test_map_id" , Map .of ("test_key" , "test_map_id" ));
708
+ configDataMap = Map
709
+ . of ( "model_id" , "test_id" , "list_model_id" , List . of ( "test_list_id" ), "test_map_id" , Map .of ("test_key" , "test_map_id" ));
717
710
doAnswer (invocation -> new SearchRequest ()).when (relatedModelIdHelper ).constructQueryRequest (any ());
718
711
}
719
712
}
0 commit comments