Skip to content

Commit 80de6e3

Browse files
authored
Primary setup for Multi-tenancy (opensearch-project#3307)
* multi-tenancy primary setup Signed-off-by: Dhrubo Saha <[email protected]> * addressed comments Signed-off-by: Dhrubo Saha <[email protected]> * addressed comments + fixed dependency issue Signed-off-by: Dhrubo Saha <[email protected]> * adding more log to debug the testVisualizationFound issue Signed-off-by: Dhrubo Saha <[email protected]> * changing back Signed-off-by: Dhrubo Saha <[email protected]> --------- Signed-off-by: Dhrubo Saha <[email protected]>
1 parent 441af6e commit 80de6e3

File tree

27 files changed

+633
-21
lines changed

27 files changed

+633
-21
lines changed

.github/workflows/CI-workflow.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252
with:
5353
role-to-assume: ${{ secrets.ML_ROLE }}
5454
aws-region: us-west-2
55-
5655
- name: Checkout MLCommons
5756
uses: actions/checkout@v4
5857
with:

common/src/main/java/org/opensearch/ml/common/CommonValue.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class CommonValue {
2121
public static final String UNDEPLOYED = "undeployed";
2222
public static final String NOT_FOUND = "not_found";
2323

24+
/** The field name containing the tenant id */
25+
public static final String TENANT_ID_FIELD = "tenant_id";
26+
2427
public static final String MASTER_KEY = "master_key";
2528
public static final String CREATE_TIME_FIELD = "create_time";
2629
public static final String LAST_UPDATE_TIME_FIELD = "last_update_time";
@@ -63,4 +66,5 @@ public class CommonValue {
6366
public static final Version VERSION_2_16_0 = Version.fromString("2.16.0");
6467
public static final Version VERSION_2_17_0 = Version.fromString("2.17.0");
6568
public static final Version VERSION_2_18_0 = Version.fromString("2.18.0");
69+
public static final Version VERSION_2_19_0 = Version.fromString("2.19.0");
6670
}

common/src/main/java/org/opensearch/ml/common/connector/AbstractConnector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public abstract class AbstractConnector implements Connector {
7171
protected Instant lastUpdateTime;
7272
@Setter
7373
protected ConnectorClientConfig connectorClientConfig;
74+
@Setter
75+
protected String tenantId;
7476

7577
protected Map<String, String> createDecryptedHeaders(Map<String, String> headers) {
7678
if (headers == null) {

common/src/main/java/org/opensearch/ml/common/connector/Connector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public interface Connector extends ToXContentObject, Writeable {
4343

4444
String getName();
4545

46+
String getTenantId();
47+
48+
void setTenantId(String tenantId);
49+
4650
String getProtocol();
4751

4852
void setCreatedTime(Instant createdTime);

common/src/main/java/org/opensearch/ml/common/input/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ public class Constants {
3636
public static final String AD_TRAINING_DATA_SIZE = "trainingDataSize";
3737
public static final String AD_ANOMALY_SCORE_THRESHOLD = "anomalyScoreThreshold";
3838
public static final String AD_DATE_FORMAT = "dateFormat";
39+
public static final String TENANT_ID_HEADER = "x-tenant-id";
3940
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.ml.common.settings;
7+
8+
/**
9+
* Interface for handling settings changes in the OpenSearch ML plugin.
10+
*/
11+
public interface SettingsChangeListener {
12+
/**
13+
* Callback method that gets triggered when the multi-tenancy setting changes.
14+
*
15+
* @param isEnabled A boolean value indicating the new state of the multi-tenancy setting:
16+
* <ul>
17+
* <li><code>true</code> if multi-tenancy is enabled</li>
18+
* <li><code>false</code> if multi-tenancy is disabled</li>
19+
* </ul>
20+
*/
21+
void onMultiTenancyEnabledChanged(boolean isEnabled);
22+
}

common/src/main/java/org/opensearch/ml/common/transport/connector/MLConnectorGetRequest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
package org.opensearch.ml.common.transport.connector;
77

88
import static org.opensearch.action.ValidateActions.addValidationError;
9+
import static org.opensearch.ml.common.CommonValue.VERSION_2_19_0;
910

1011
import java.io.ByteArrayInputStream;
1112
import java.io.ByteArrayOutputStream;
1213
import java.io.IOException;
1314
import java.io.UncheckedIOException;
1415

16+
import org.opensearch.Version;
1517
import org.opensearch.action.ActionRequest;
1618
import org.opensearch.action.ActionRequestValidationException;
1719
import org.opensearch.core.common.io.stream.InputStreamStreamInput;
@@ -26,24 +28,34 @@
2628
public class MLConnectorGetRequest extends ActionRequest {
2729

2830
String connectorId;
31+
String tenantId;
2932
boolean returnContent;
3033

3134
@Builder
32-
public MLConnectorGetRequest(String connectorId, boolean returnContent) {
35+
public MLConnectorGetRequest(String connectorId, String tenantId, boolean returnContent) {
3336
this.connectorId = connectorId;
37+
this.tenantId = tenantId;
3438
this.returnContent = returnContent;
3539
}
3640

3741
public MLConnectorGetRequest(StreamInput in) throws IOException {
3842
super(in);
43+
Version streamInputVersion = in.getVersion();
3944
this.connectorId = in.readString();
45+
if (streamInputVersion.onOrAfter(VERSION_2_19_0)) {
46+
this.tenantId = in.readOptionalString();
47+
}
4048
this.returnContent = in.readBoolean();
4149
}
4250

4351
@Override
4452
public void writeTo(StreamOutput out) throws IOException {
4553
super.writeTo(out);
54+
Version streamOutputVersion = out.getVersion();
4655
out.writeString(this.connectorId);
56+
if (streamOutputVersion.onOrAfter(VERSION_2_19_0)) {
57+
out.writeOptionalString(this.tenantId);
58+
}
4759
out.writeBoolean(returnContent);
4860
}
4961

common/src/main/resources/index-mappings/ml_agent.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"_meta": {
3-
"schema_version": 2
3+
"schema_version": 3
44
},
55
"properties": {
66
"name": {
@@ -33,6 +33,9 @@
3333
"is_hidden": {
3434
"type": "boolean"
3535
},
36+
"tenant_id": {
37+
"type": "keyword"
38+
},
3639
"created_time": {
3740
"type": "date",
3841
"format": "strict_date_time||epoch_millis"

common/src/main/resources/index-mappings/ml_config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"_meta": {
3-
"schema_version": 4
3+
"schema_version": 5
44
},
55
"properties": {
66
"master_key": {
@@ -9,6 +9,9 @@
99
"config_type": {
1010
"type": "keyword"
1111
},
12+
"tenant_id": {
13+
"type": "keyword"
14+
},
1215
"ml_configuration": {
1316
"type": "flat_object"
1417
},

common/src/main/resources/index-mappings/ml_connector.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"_meta": {
3-
"schema_version": 3
3+
"schema_version": 4
44
},
55
"properties": {
66
"name": {
@@ -30,6 +30,9 @@
3030
"client_config": {
3131
"type": "flat_object"
3232
},
33+
"tenant_id": {
34+
"type": "keyword"
35+
},
3336
"actions": {
3437
"type": "flat_object"
3538
},

0 commit comments

Comments
 (0)