7
7
8
8
import static org .opensearch .ml .common .CommonValue .TENANT_ID_FIELD ;
9
9
import static org .opensearch .ml .common .MLTask .MODEL_ID_FIELD ;
10
+ import static org .opensearch .ml .common .input .Constants .TENANT_ID_HEADER ;
10
11
import static org .opensearch .ml .rest .RestMLRAGSearchProcessorIT .COHERE_CONNECTOR_BLUEPRINT ;
11
12
12
13
import java .util .Map ;
15
16
import org .opensearch .action .search .SearchResponse ;
16
17
import org .opensearch .client .Response ;
17
18
import org .opensearch .client .ResponseException ;
19
+ import org .opensearch .core .rest .RestStatus ;
18
20
import org .opensearch .rest .RestRequest ;
19
21
20
22
public class RestMLModelTenantAwareIT extends MLCommonsTenantAwareRestTestCase {
@@ -32,7 +34,14 @@ public void testModelCRUD() throws Exception {
32
34
Map <String , Object > map = responseToMap (response );
33
35
assertTrue (map .containsKey (CONNECTOR_ID ));
34
36
String connectorId = map .get (CONNECTOR_ID ).toString ();
35
- // Create a second connector from other tenant
37
+ // Create a second connector with same tenant for deletion tests later
38
+ response = makeRequest (createConnectorRequest , POST , CONNECTORS_PATH + "_create" );
39
+ assertOK (response );
40
+ map = responseToMap (response );
41
+ assertTrue (map .containsKey (CONNECTOR_ID ));
42
+ String secondConnectorId = map .get (CONNECTOR_ID ).toString ();
43
+
44
+ // Create a third connector from other tenant
36
45
createConnectorRequest = getRestRequestWithHeadersAndContent (otherTenantId , COHERE_CONNECTOR_BLUEPRINT );
37
46
response = makeRequest (createConnectorRequest , POST , CONNECTORS_PATH + "_create" );
38
47
assertOK (response );
@@ -308,6 +317,17 @@ public void testModelCRUD() throws Exception {
308
317
assertEquals (MISSING_TENANT_REASON , getErrorReasonFromResponseMap (map ));
309
318
}
310
319
320
+ // Try to delete connector while model exists
321
+ ResponseException ex = assertThrows (
322
+ ResponseException .class ,
323
+ () -> makeRequest (tenantRequest , DELETE , CONNECTORS_PATH + connectorId )
324
+ );
325
+ response = ex .getResponse ();
326
+ assertEquals (RestStatus .CONFLICT .getStatus (), response .getStatusLine ().getStatusCode ());
327
+ // but it should work with the connector not in a model
328
+ response = makeRequest (tenantRequest , DELETE , CONNECTORS_PATH + secondConnectorId );
329
+ assertOK (response );
330
+
311
331
// Now actually do the deletions. Same result whether multi-tenancy is enabled.
312
332
// Verify still exists
313
333
response = makeRequest (tenantRequest , GET , MODELS_PATH + modelId );
@@ -320,7 +340,7 @@ public void testModelCRUD() throws Exception {
320
340
assertEquals (modelId , map .get (DOC_ID ).toString ());
321
341
322
342
// Verify the deletion
323
- ResponseException ex = assertThrows (ResponseException .class , () -> makeRequest (tenantRequest , GET , MODELS_PATH + modelId ));
343
+ ex = assertThrows (ResponseException .class , () -> makeRequest (tenantRequest , GET , MODELS_PATH + modelId ));
324
344
response = ex .getResponse ();
325
345
assertNotFound (response );
326
346
map = responseToMap (response );
0 commit comments