diff --git a/common/src/main/java/org/opensearch/ml/common/connector/HttpConnector.java b/common/src/main/java/org/opensearch/ml/common/connector/HttpConnector.java index 205384f674..6e85454d0e 100644 --- a/common/src/main/java/org/opensearch/ml/common/connector/HttpConnector.java +++ b/common/src/main/java/org/opensearch/ml/common/connector/HttpConnector.java @@ -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; diff --git a/common/src/main/java/org/opensearch/ml/common/input/Constants.java b/common/src/main/java/org/opensearch/ml/common/input/Constants.java index 6e144991f5..5e0f9b9f8c 100644 --- a/common/src/main/java/org/opensearch/ml/common/input/Constants.java +++ b/common/src/main/java/org/opensearch/ml/common/input/Constants.java @@ -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"; } diff --git a/common/src/main/java/org/opensearch/ml/common/transport/register/MLRegisterModelInput.java b/common/src/main/java/org/opensearch/ml/common/transport/register/MLRegisterModelInput.java index 7bd9a62040..8feddb4571 100644 --- a/common/src/main/java/org/opensearch/ml/common/transport/register/MLRegisterModelInput.java +++ b/common/src/main/java/org/opensearch/ml/common/transport/register/MLRegisterModelInput.java @@ -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; diff --git a/plugin/src/main/java/org/opensearch/ml/action/connector/DeleteConnectorTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/connector/DeleteConnectorTransportAction.java index 696467d637..427453fcb4 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/connector/DeleteConnectorTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/connector/DeleteConnectorTransportAction.java @@ -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; diff --git a/plugin/src/main/java/org/opensearch/ml/utils/RestActionUtils.java b/plugin/src/main/java/org/opensearch/ml/utils/RestActionUtils.java index 16c27f2aad..738f1f8d3e 100644 --- a/plugin/src/main/java/org/opensearch/ml/utils/RestActionUtils.java +++ b/plugin/src/main/java/org/opensearch/ml/utils/RestActionUtils.java @@ -315,8 +315,8 @@ public static String getTenantID(Boolean isMultiTenancyEnabled, RestRequest rest if (isMultiTenancyEnabled) { Map> headers = restRequest.getHeaders(); if (headers != null) { - if (headers.containsKey(Constants.TENANT_ID)) { - List tenantIdList = headers.get(Constants.TENANT_ID); + if (headers.containsKey(Constants.TENANT_ID_HEADER)) { + List tenantIdList = headers.get(Constants.TENANT_ID_HEADER); if (tenantIdList != null && !tenantIdList.isEmpty()) { String tenantId = tenantIdList.get(0); if (tenantId != null) { diff --git a/plugin/src/test/java/org/opensearch/ml/utils/RestActionUtilsTests.java b/plugin/src/test/java/org/opensearch/ml/utils/RestActionUtilsTests.java index 7e2be7c5e7..2782853b09 100644 --- a/plugin/src/test/java/org/opensearch/ml/utils/RestActionUtilsTests.java +++ b/plugin/src/test/java/org/opensearch/ml/utils/RestActionUtilsTests.java @@ -389,7 +389,7 @@ public synchronized Throwable getCause() { public void testGetTenantID_IndependentNode() { String tenantId = "test-tenant"; Map> 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); @@ -399,7 +399,7 @@ public void testGetTenantID_IndependentNode() { @Test public void testGetTenantID_IndependentNode_NullTenantID() { Map> 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 { @@ -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> 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); diff --git a/plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java b/plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java index d450fce320..e196cec388 100644 --- a/plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java +++ b/plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java @@ -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; @@ -220,7 +221,7 @@ public static RestRequest getKMeansRestRequest() { public static RestRequest getCreateConnectorRestRequest(String tenantId) { Map> 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"