Skip to content

Commit

Permalink
Rename field TENANT_ID
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun kumar Giri <[email protected]>
  • Loading branch information
arjunkumargiri committed Jun 28, 2024
1 parent ec7429d commit be676a6
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.opensearch.ml.common.connector.ConnectorProtocols.HTTP;
import static org.opensearch.ml.common.connector.ConnectorProtocols.validateProtocol;
import static org.opensearch.ml.common.input.Constants.TENANT_ID;
import static org.opensearch.ml.common.CommonValue.TENANT_ID;
import static org.opensearch.ml.common.utils.StringUtils.getParameterMap;
import static org.opensearch.ml.common.utils.StringUtils.isJson;
import org.opensearch.ml.common.transport.connector.MLCreateConnectorInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ public class Constants {
public static final String AD_ANOMALY_SCORE_THRESHOLD = "anomalyScoreThreshold";
public static final String AD_DATE_FORMAT = "dateFormat";

public static final String TENANT_ID = "x-tenant-id";
public static final String TENANT_ID_HEADER = "x-tenant-id";
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.opensearch.ml.common.MLModel.allowedInterfaceFieldKeys;
import static org.opensearch.ml.common.connector.Connector.createConnector;
import static org.opensearch.ml.common.input.Constants.TENANT_ID;
import static org.opensearch.ml.common.CommonValue.TENANT_ID;
import static org.opensearch.ml.common.utils.StringUtils.filteredParameterMap;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX;
import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX;
import static org.opensearch.ml.common.input.Constants.TENANT_ID;
import static org.opensearch.ml.common.CommonValue.TENANT_ID;
import static org.opensearch.ml.plugin.MachineLearningPlugin.GENERAL_THREAD_POOL;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ public static String getTenantID(Boolean isMultiTenancyEnabled, RestRequest rest
if (isMultiTenancyEnabled) {
Map<String, List<String>> headers = restRequest.getHeaders();
if (headers != null) {
if (headers.containsKey(Constants.TENANT_ID)) {
List<String> tenantIdList = headers.get(Constants.TENANT_ID);
if (headers.containsKey(Constants.TENANT_ID_HEADER)) {
List<String> tenantIdList = headers.get(Constants.TENANT_ID_HEADER);
if (tenantIdList != null && !tenantIdList.isEmpty()) {
String tenantId = tenantIdList.get(0);
if (tenantId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public synchronized Throwable getCause() {
public void testGetTenantID_IndependentNode() {
String tenantId = "test-tenant";
Map<String, List<String>> headers = new HashMap<>();
headers.put(Constants.TENANT_ID, Collections.singletonList(tenantId));
headers.put(Constants.TENANT_ID_HEADER, Collections.singletonList(tenantId));
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build();

String actualTenantID = RestActionUtils.getTenantID(Boolean.TRUE, restRequest);
Expand All @@ -399,7 +399,7 @@ public void testGetTenantID_IndependentNode() {
@Test
public void testGetTenantID_IndependentNode_NullTenantID() {
Map<String, List<String>> headers = new HashMap<>();
headers.put(Constants.TENANT_ID, Collections.singletonList(null));
headers.put(Constants.TENANT_ID_HEADER, Collections.singletonList(null));
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build();

try {
Expand All @@ -417,7 +417,7 @@ public void testGetTenantID_NotIndependentNode() {
settings = Settings.builder().put(ML_COMMONS_MULTI_TENANCY_ENABLED.getKey(), false).build();
String tenantId = "test-tenant";
Map<String, List<String>> headers = new HashMap<>();
headers.put(Constants.TENANT_ID, Collections.singletonList(tenantId));
headers.put(Constants.TENANT_ID_HEADER, Collections.singletonList(tenantId));
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build();

String tenantID = RestActionUtils.getTenantID(Boolean.FALSE, restRequest);
Expand Down
3 changes: 2 additions & 1 deletion plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.opensearch.ml.common.FunctionName;
import org.opensearch.ml.common.dataset.MLInputDataType;
import org.opensearch.ml.common.dataset.SearchQueryInputDataset;
import org.opensearch.ml.common.input.Constants;
import org.opensearch.ml.common.input.MLInput;
import org.opensearch.ml.common.input.execute.metricscorrelation.MetricsCorrelationInput;
import org.opensearch.ml.common.input.execute.samplecalculator.LocalSampleCalculatorInput;
Expand Down Expand Up @@ -220,7 +221,7 @@ public static RestRequest getKMeansRestRequest() {
public static RestRequest getCreateConnectorRestRequest(String tenantId) {
Map<String, List<String>> headers = new HashMap<>();
if (tenantId != null) {
headers.put("tenant_id", Collections.singletonList(tenantId));
headers.put(Constants.TENANT_ID_HEADER, Collections.singletonList(tenantId));
}
final String requestContent = "{\n"
+ " \"name\": \"OpenAI Connector\",\n"
Expand Down

0 comments on commit be676a6

Please sign in to comment.