Skip to content

Commit ea4a4ac

Browse files
* Prevents future UT build issues addresses opensearch-project#2967 Depending on the GitHub CI workflow executes it will invoke ./gradlew build which will run tests on random parameters everytime, there are local-code's that will break a build one of them being az-Cyrl. The solution here was preventing (explicitly writing the local to be set to en-US) Github actions building on these random parameters that will interupt a build and lose time. Manual testing was done to prove that using this flag breaks a build, you can check the issue opensearch-project#2967 or you can run ./gradlew build -Dtests.local=az-Cyrl to see it breaks Signed-off-by: Brian Flores <[email protected]> * Updates current codebase with Local.Root to string operations The previous commit made a hard change on the build while ignoring the root problem, which was making sure that our codebase currently supports string operations regardless of the locale code. In this new commit String operations like toUpperCase have a extra argument of Locale.Root making the codebase agnostic to the rules of other langugages such as Spanish or Turkish. Manual testing was done like raised in the GitHub issue opensearch-project#2967 also ./gradlew build -Dtests.Local=az-Cyrl passes Signed-off-by: Brian Flores <[email protected]> --------- Signed-off-by: Brian Flores <[email protected]> (cherry picked from commit cd83590) Co-authored-by: Brian Flores <[email protected]>
1 parent a4950e5 commit ea4a4ac

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static boolean isValidActionInModelPrediction(ActionType actionType) {
208208

209209
public static boolean isValidAction(String action) {
210210
try {
211-
ActionType.valueOf(action.toUpperCase());
211+
ActionType.valueOf(action.toUpperCase(Locale.ROOT));
212212
return true;
213213
} catch (IllegalArgumentException e) {
214214
return false;

common/src/main/java/org/opensearch/ml/common/input/parameter/clustering/RCFSummarizeParams.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
99

1010
import java.io.IOException;
11+
import java.util.Locale;
1112

1213
import org.opensearch.core.ParseField;
1314
import org.opensearch.core.common.io.stream.StreamInput;
@@ -97,7 +98,7 @@ public static MLAlgoParams parse(XContentParser parser) throws IOException {
9798
parallel = parser.booleanValue();
9899
break;
99100
case DISTANCE_TYPE_FIELD:
100-
distanceType = DistanceType.from(parser.text().toUpperCase());
101+
distanceType = DistanceType.from(parser.text().toUpperCase(Locale.ROOT));
101102
break;
102103
default:
103104
parser.skipChildren();

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLAgentExecutor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.security.PrivilegedExceptionAction;
1414
import java.util.ArrayList;
1515
import java.util.List;
16+
import java.util.Locale;
1617
import java.util.Map;
1718

1819
import org.opensearch.ResourceNotFoundException;
@@ -281,7 +282,7 @@ private ActionListener<Object> createAgentActionListener(
281282

282283
@VisibleForTesting
283284
protected MLAgentRunner getAgentRunner(MLAgent mlAgent) {
284-
final MLAgentType agentType = MLAgentType.from(mlAgent.getType().toUpperCase());
285+
final MLAgentType agentType = MLAgentType.from(mlAgent.getType().toUpperCase(Locale.ROOT));
285286
switch (agentType) {
286287
case FLOW:
287288
return new MLFlowAgentRunner(client, settings, clusterService, xContentRegistry, toolFactories, memoryFactoryMap);

plugin/src/main/java/org/opensearch/ml/action/batch/TransportBatchIngestionAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.time.Instant;
1717
import java.util.List;
18+
import java.util.Locale;
1819
import java.util.Map;
1920
import java.util.regex.Pattern;
2021
import java.util.stream.Collectors;
@@ -101,7 +102,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<MLBatc
101102
mlTaskManager.add(mlTask);
102103
listener.onResponse(new MLBatchIngestionResponse(taskId, MLTaskType.BATCH_INGEST, MLTaskState.CREATED.name()));
103104
String ingestType = (String) mlBatchIngestionInput.getDataSources().get(TYPE);
104-
Ingestable ingestable = MLEngineClassLoader.initInstance(ingestType.toLowerCase(), client, Client.class);
105+
Ingestable ingestable = MLEngineClassLoader.initInstance(ingestType.toLowerCase(Locale.ROOT), client, Client.class);
105106
threadPool.executor(INGEST_THREAD_POOL).execute(() -> {
106107
executeWithErrorHandling(() -> {
107108
double successRate = ingestable.ingest(mlBatchIngestionInput);
@@ -193,7 +194,7 @@ private void validateBatchIngestInput(MLBatchIngestionInput mlBatchIngestionInpu
193194
if (dataSources.get(TYPE) == null || dataSources.get(SOURCE) == null) {
194195
throw new IllegalArgumentException("The batch ingest input data source is missing data type or source");
195196
}
196-
if (((String) dataSources.get(TYPE)).toLowerCase() == "s3") {
197+
if (((String) dataSources.get(TYPE)).equalsIgnoreCase("s3")) {
197198
List<String> s3Uris = (List<String>) dataSources.get(SOURCE);
198199
if (s3Uris == null || s3Uris.isEmpty()) {
199200
throw new IllegalArgumentException("The batch ingest input s3Uris is empty");

plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ MLPredictionTaskRequest getRequest(String modelId, String algorithm, RestRequest
130130
ActionType actionType = ActionType.from(getActionTypeFromRestRequest(request));
131131
if (FunctionName.REMOTE.name().equals(algorithm) && !mlFeatureEnabledSetting.isRemoteInferenceEnabled()) {
132132
throw new IllegalStateException(REMOTE_INFERENCE_DISABLED_ERR_MSG);
133-
} else if (FunctionName.isDLModel(FunctionName.from(algorithm.toUpperCase())) && !mlFeatureEnabledSetting.isLocalModelEnabled()) {
133+
} else if (FunctionName.isDLModel(FunctionName.from(algorithm.toUpperCase(Locale.ROOT)))
134+
&& !mlFeatureEnabledSetting.isLocalModelEnabled()) {
134135
throw new IllegalStateException(LOCAL_MODEL_DISABLED_ERR_MSG);
135136
} else if (ActionType.BATCH_PREDICT == actionType && !mlFeatureEnabledSetting.isOfflineBatchInferenceEnabled()) {
136137
throw new IllegalStateException(BATCH_INFERENCE_DISABLED_ERR_MSG);

0 commit comments

Comments
 (0)