From 3c0e621ad779ffee7b11129aa5db556db5b6bb48 Mon Sep 17 00:00:00 2001 From: Bhavana Ramaram Date: Wed, 4 Oct 2023 16:35:01 -0700 Subject: [PATCH] fix format violations Signed-off-by: Bhavana Ramaram --- .../models/DeleteModelTransportAction.java | 25 ++++++---- .../TransportRegisterModelAction.java | 32 ++++++------ .../TransportRegisterModelActionTests.java | 50 ++++++++++--------- 3 files changed, 57 insertions(+), 50 deletions(-) diff --git a/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java index 3445b5748b..5c0572c08a 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java @@ -5,10 +5,13 @@ package org.opensearch.ml.action.models; -import com.google.common.annotations.VisibleForTesting; -import lombok.AccessLevel; -import lombok.experimental.FieldDefaults; -import lombok.extern.log4j.Log4j2; +import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; +import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX; +import static org.opensearch.ml.common.MLModel.ALGORITHM_FIELD; +import static org.opensearch.ml.common.MLModel.MODEL_ID_FIELD; +import static org.opensearch.ml.utils.MLNodeUtils.createXContentParserFromRegistry; +import static org.opensearch.ml.utils.RestActionUtils.getFetchSourceContext; + import org.opensearch.OpenSearchStatusException; import org.opensearch.ResourceNotFoundException; import org.opensearch.action.ActionRequest; @@ -43,12 +46,11 @@ import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; -import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; -import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX; -import static org.opensearch.ml.common.MLModel.ALGORITHM_FIELD; -import static org.opensearch.ml.common.MLModel.MODEL_ID_FIELD; -import static org.opensearch.ml.utils.MLNodeUtils.createXContentParserFromRegistry; -import static org.opensearch.ml.utils.RestActionUtils.getFetchSourceContext; +import com.google.common.annotations.VisibleForTesting; + +import lombok.AccessLevel; +import lombok.experimental.FieldDefaults; +import lombok.extern.log4j.Log4j2; @Log4j2 @FieldDefaults(level = AccessLevel.PRIVATE) @@ -113,7 +115,8 @@ protected void doExecute(Task task, ActionRequest request, ActionListener { @@ -175,8 +177,8 @@ private void checkUserAccess( // This case handles when user is using the same pre-trained model already registered by another user on the cluster. // The only way here is for the user to first create model group and use its ID in the request if (registerModelInput.getUrl() == null - && registerModelInput.getFunctionName() != FunctionName.REMOTE - && registerModelInput.getConnectorId() == null) { + && registerModelInput.getFunctionName() != FunctionName.REMOTE + && registerModelInput.getConnectorId() == null) { listener .onFailure( new IllegalArgumentException( diff --git a/plugin/src/test/java/org/opensearch/ml/action/register/TransportRegisterModelActionTests.java b/plugin/src/test/java/org/opensearch/ml/action/register/TransportRegisterModelActionTests.java index 26ebfce5b6..66c78d2431 100644 --- a/plugin/src/test/java/org/opensearch/ml/action/register/TransportRegisterModelActionTests.java +++ b/plugin/src/test/java/org/opensearch/ml/action/register/TransportRegisterModelActionTests.java @@ -5,7 +5,23 @@ package org.opensearch.ml.action.register; -import com.google.common.collect.ImmutableList; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_TRUSTED_CONNECTOR_ENDPOINTS_REGEX; +import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_TRUSTED_URL_REGEX; +import static org.opensearch.ml.utils.TestHelper.clusterSetting; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + import org.apache.lucene.search.TotalHits; import org.junit.Before; import org.junit.Rule; @@ -56,22 +72,7 @@ import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportService; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_TRUSTED_CONNECTOR_ENDPOINTS_REGEX; -import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_TRUSTED_URL_REGEX; -import static org.opensearch.ml.utils.TestHelper.clusterSetting; +import com.google.common.collect.ImmutableList; public class TransportRegisterModelActionTests extends OpenSearchTestCase { @Rule @@ -509,18 +510,19 @@ public void test_FailureWhenPreBuildModelNameAlreadyExists() throws IOException }).when(modelAccessControlHelper).validateModelGroupAccess(any(), any(), any(), any()); MLRegisterModelInput registerModelInput = MLRegisterModelInput - .builder() - .modelName("huggingface/sentence-transformers/all-MiniLM-L12-v2") - .modelFormat(MLModelFormat.TORCH_SCRIPT) - .version("1") - .build(); + .builder() + .modelName("huggingface/sentence-transformers/all-MiniLM-L12-v2") + .modelFormat(MLModelFormat.TORCH_SCRIPT) + .version("1") + .build(); transportRegisterModelAction.doExecute(task, new MLRegisterModelRequest(registerModelInput), actionListener); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Exception.class); verify(actionListener).onFailure(argumentCaptor.capture()); assertEquals( - "Without a model group ID, the system will use the model name {huggingface/sentence-transformers/all-MiniLM-L12-v2} to create a new model group. However, this name is taken by another group {model_group_ID} you can't access. To register this pre-trained model, create a new model group and use its ID in your request.", - argumentCaptor.getValue().getMessage() + "Without a model group ID, the system will use the model name {huggingface/sentence-transformers/all-MiniLM-L12-v2} to create a new model group. However, this name is taken by another group {model_group_ID} you can't access. To register this pre-trained model, create a new model group and use its ID in your request.", + argumentCaptor.getValue().getMessage() + ); }