From bb37f94cd808dba8febd69f0343d2900c478a98a Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:51:15 -0700 Subject: [PATCH 1/2] Fix init encryption master key (#2554) (#2606) * fix init master key Signed-off-by: Yaliang Wu (cherry picked from commit 487f33a2e35e642429e9a3ea1eb0d715d542ea9f) Co-authored-by: Yaliang Wu --- .../ml/engine/encryptor/EncryptorImpl.java | 82 ++++- .../engine/encryptor/EncryptorImplTest.java | 348 +++++++++++++++++- .../opensearch/ml/cluster/MLSyncUpCron.java | 2 + .../ml/plugin/MachineLearningPlugin.java | 4 +- 4 files changed, 412 insertions(+), 24 deletions(-) diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java index 617c6871e5..1c02a7f915 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java @@ -8,29 +8,36 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.opensearch.ml.common.CommonValue.MASTER_KEY; import static org.opensearch.ml.common.CommonValue.ML_CONFIG_INDEX; +import static org.opensearch.ml.common.MLConfig.CREATE_TIME_FIELD; import java.nio.charset.StandardCharsets; import java.security.SecureRandom; +import java.time.Instant; import java.util.Base64; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import javax.crypto.spec.SecretKeySpec; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.LatchedActionListener; +import org.opensearch.action.DocWriteRequest; import org.opensearch.action.get.GetRequest; -import org.opensearch.action.get.GetResponse; +import org.opensearch.action.index.IndexRequest; +import org.opensearch.action.support.WriteRequest; import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.index.engine.VersionConflictEngineException; import org.opensearch.ml.common.exception.MLException; +import org.opensearch.ml.engine.indices.MLIndicesHandler; import com.amazonaws.encryptionsdk.AwsCrypto; import com.amazonaws.encryptionsdk.CommitmentPolicy; import com.amazonaws.encryptionsdk.CryptoResult; import com.amazonaws.encryptionsdk.jce.JceMasterKey; +import com.google.common.collect.ImmutableMap; import lombok.extern.log4j.Log4j2; @@ -42,11 +49,13 @@ public class EncryptorImpl implements Encryptor { private ClusterService clusterService; private Client client; private volatile String masterKey; + private MLIndicesHandler mlIndicesHandler; - public EncryptorImpl(ClusterService clusterService, Client client) { + public EncryptorImpl(ClusterService clusterService, Client client, MLIndicesHandler mlIndicesHandler) { this.masterKey = null; this.clusterService = clusterService; this.client = client; + this.mlIndicesHandler = mlIndicesHandler; } public EncryptorImpl(String masterKey) { @@ -104,28 +113,68 @@ private void initMasterKey() { AtomicReference exceptionRef = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); - if (clusterService.state().metadata().hasIndex(ML_CONFIG_INDEX)) { + mlIndicesHandler.initMLConfigIndex(ActionListener.wrap(r -> { + GetRequest getRequest = new GetRequest(ML_CONFIG_INDEX).id(MASTER_KEY); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) { - GetRequest getRequest = new GetRequest(ML_CONFIG_INDEX).id(MASTER_KEY); - client.get(getRequest, ActionListener.runBefore(new LatchedActionListener(ActionListener.wrap(r -> { - if (r.isExists()) { - String masterKey = (String) r.getSourceAsMap().get(MASTER_KEY); - this.masterKey = masterKey; + client.get(getRequest, ActionListener.wrap(getResponse -> { + if (getResponse == null || !getResponse.isExists()) { + IndexRequest indexRequest = new IndexRequest(ML_CONFIG_INDEX).id(MASTER_KEY); + final String generatedMasterKey = generateMasterKey(); + indexRequest + .source(ImmutableMap.of(MASTER_KEY, generatedMasterKey, CREATE_TIME_FIELD, Instant.now().toEpochMilli())); + indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + indexRequest.opType(DocWriteRequest.OpType.CREATE); + client.index(indexRequest, ActionListener.wrap(indexResponse -> { + this.masterKey = generatedMasterKey; + log.info("ML encryption master key initialized successfully"); + latch.countDown(); + }, e -> { + + if (ExceptionUtils.getRootCause(e) instanceof VersionConflictEngineException) { + GetRequest getMasterKeyRequest = new GetRequest(ML_CONFIG_INDEX).id(MASTER_KEY); + try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { + client.get(getMasterKeyRequest, ActionListener.wrap(getMasterKeyResponse -> { + if (getMasterKeyResponse != null && getMasterKeyResponse.isExists()) { + final String masterKey = (String) getMasterKeyResponse.getSourceAsMap().get(MASTER_KEY); + this.masterKey = masterKey; + log.info("ML encryption master key already initialized, no action needed"); + latch.countDown(); + } else { + exceptionRef.set(new ResourceNotFoundException(MASTER_KEY_NOT_READY_ERROR)); + latch.countDown(); + } + }, error -> { + log.debug("Failed to get ML encryption master key", e); + exceptionRef.set(error); + latch.countDown(); + })); + } + } else { + log.debug("Failed to index ML encryption master key", e); + exceptionRef.set(e); + latch.countDown(); + } + })); } else { - exceptionRef.set(new ResourceNotFoundException(MASTER_KEY_NOT_READY_ERROR)); + final String masterKey = (String) getResponse.getSourceAsMap().get(MASTER_KEY); + this.masterKey = masterKey; + log.info("ML encryption master key already initialized, no action needed"); + latch.countDown(); } }, e -> { - log.error("Failed to get ML encryption master key", e); + log.debug("Failed to get ML encryption master key from config index", e); exceptionRef.set(e); - }), latch), () -> context.restore())); + latch.countDown(); + })); } - } else { - exceptionRef.set(new ResourceNotFoundException(MASTER_KEY_NOT_READY_ERROR)); + }, e -> { + log.debug("Failed to init ML config index", e); + exceptionRef.set(e); latch.countDown(); - } + })); try { - latch.await(5, SECONDS); + latch.await(1, SECONDS); } catch (InterruptedException e) { throw new IllegalStateException(e); } @@ -142,4 +191,5 @@ private void initMasterKey() { throw new ResourceNotFoundException(MASTER_KEY_NOT_READY_ERROR); } } + } diff --git a/ml-algorithms/src/test/java/org/opensearch/ml/engine/encryptor/EncryptorImplTest.java b/ml-algorithms/src/test/java/org/opensearch/ml/engine/encryptor/EncryptorImplTest.java index 211ea017c3..bd228fb665 100644 --- a/ml-algorithms/src/test/java/org/opensearch/ml/engine/encryptor/EncryptorImplTest.java +++ b/ml-algorithms/src/test/java/org/opensearch/ml/engine/encryptor/EncryptorImplTest.java @@ -2,6 +2,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.opensearch.ml.common.CommonValue.CREATE_TIME_FIELD; @@ -9,7 +10,9 @@ import static org.opensearch.ml.common.CommonValue.ML_CONFIG_INDEX; import static org.opensearch.ml.engine.encryptor.EncryptorImpl.MASTER_KEY_NOT_READY_ERROR; +import java.io.IOException; import java.time.Instant; +import java.util.Map; import org.junit.Assert; import org.junit.Before; @@ -21,6 +24,7 @@ import org.opensearch.ResourceNotFoundException; import org.opensearch.Version; import org.opensearch.action.get.GetResponse; +import org.opensearch.action.index.IndexResponse; import org.opensearch.client.Client; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.metadata.IndexMetadata; @@ -30,6 +34,10 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.commons.ConfigConstants; import org.opensearch.core.action.ActionListener; +import org.opensearch.core.index.shard.ShardId; +import org.opensearch.index.engine.VersionConflictEngineException; +import org.opensearch.ml.common.exception.MLException; +import org.opensearch.ml.engine.indices.MLIndicesHandler; import org.opensearch.threadpool.ThreadPool; import com.google.common.collect.ImmutableMap; @@ -46,6 +54,9 @@ public class EncryptorImplTest { @Mock ClusterState clusterState; + @Mock + private MLIndicesHandler mlIndicesHandler; + String masterKey; @Mock @@ -100,14 +111,319 @@ public void setUp() { } @Test - public void encrypt() { - Encryptor encryptor = new EncryptorImpl(clusterService, client); + public void encrypt_ExistingMasterKey() { + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(true); + when(response.getSourceAsMap()).thenReturn(Map.of(MASTER_KEY, masterKey)); + actionListener.onResponse(response); + return null; + }).when(client).get(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); Assert.assertNull(encryptor.getMasterKey()); String encrypted = encryptor.encrypt("test"); Assert.assertNotNull(encrypted); Assert.assertEquals(masterKey, encryptor.getMasterKey()); } + @Test + public void encrypt_NonExistingMasterKey() { + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).when(client).get(any(), any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + IndexResponse response = mock(IndexResponse.class); + actionListener.onResponse(response); + return null; + }).when(client).index(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + Assert.assertNull(encryptor.getMasterKey()); + String encrypted = encryptor.encrypt("test"); + Assert.assertNotNull(encrypted); + Assert.assertNotEquals(masterKey, encryptor.getMasterKey()); + } + + @Test + public void encrypt_NonExistingMasterKey_FailedToCreateNewKey() { + exceptionRule.expect(RuntimeException.class); + exceptionRule.expectMessage("random test exception"); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).when(client).get(any(), any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener.onFailure(new RuntimeException("random test exception")); + return null; + }).when(client).index(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + Assert.assertNull(encryptor.getMasterKey()); + encryptor.encrypt("test"); + } + + @Test + public void encrypt_NonExistingMasterKey_FailedToCreateNewKey_NonRuntimeException() { + exceptionRule.expect(MLException.class); + exceptionRule.expectMessage("random IO exception"); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).when(client).get(any(), any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener.onFailure(new IOException("random IO exception")); + return null; + }).when(client).index(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + Assert.assertNull(encryptor.getMasterKey()); + encryptor.encrypt("test"); + } + + @Test + public void encrypt_NonExistingMasterKey_FailedToCreateNewKey_VersionConflict() { + exceptionRule.expect(ResourceNotFoundException.class); + exceptionRule.expectMessage(MASTER_KEY_NOT_READY_ERROR); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).when(client).get(any(), any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener + .onFailure(new VersionConflictEngineException(new ShardId(ML_CONFIG_INDEX, "index_uuid", 1), "test_id", "failed")); + return null; + }).when(client).index(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + Assert.assertNull(encryptor.getMasterKey()); + encryptor.encrypt("test"); + } + + @Test + public void encrypt_NonExistingMasterKey_FailedToCreateNewKey_VersionConflict_NullGetResponse() { + exceptionRule.expect(ResourceNotFoundException.class); + exceptionRule.expectMessage(MASTER_KEY_NOT_READY_ERROR); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = null; + actionListener.onResponse(response); + return null; + }).when(client).get(any(), any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener + .onFailure(new VersionConflictEngineException(new ShardId(ML_CONFIG_INDEX, "index_uuid", 1), "test_id", "failed")); + return null; + }).when(client).index(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + Assert.assertNull(encryptor.getMasterKey()); + encryptor.encrypt("test"); + } + + @Test + public void encrypt_NonExistingMasterKey_FailedToCreateNewKey_VersionConflict_NullResponse() { + exceptionRule.expect(ResourceNotFoundException.class); + exceptionRule.expectMessage(MASTER_KEY_NOT_READY_ERROR); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = null; + actionListener.onResponse(response); + return null; + }).doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).when(client).get(any(), any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener + .onFailure(new VersionConflictEngineException(new ShardId(ML_CONFIG_INDEX, "index_uuid", 1), "test_id", "failed")); + return null; + }).when(client).index(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + Assert.assertNull(encryptor.getMasterKey()); + encryptor.encrypt("test"); + } + + @Test + public void encrypt_NonExistingMasterKey_FailedToCreateNewKey_VersionConflict_GetExistingMasterKey() { + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(true); + when(response.getSourceAsMap()).thenReturn(Map.of(MASTER_KEY, masterKey)); + actionListener.onResponse(response); + return null; + }).when(client).get(any(), any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener + .onFailure(new VersionConflictEngineException(new ShardId(ML_CONFIG_INDEX, "index_uuid", 1), "test_id", "failed")); + return null; + }).when(client).index(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + Assert.assertNull(encryptor.getMasterKey()); + String encrypted = encryptor.encrypt("test"); + Assert.assertNotNull(encrypted); + Assert.assertEquals(masterKey, encryptor.getMasterKey()); + } + + @Test + public void encrypt_NonExistingMasterKey_FailedToCreateNewKey_VersionConflict_FailedToGetExistingMasterKey() { + exceptionRule.expect(RuntimeException.class); + exceptionRule.expectMessage("random test exception"); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(false); + actionListener.onResponse(response); + return null; + }).doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener.onFailure(new RuntimeException("random test exception")); + return null; + }).when(client).get(any(), any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener + .onFailure(new VersionConflictEngineException(new ShardId(ML_CONFIG_INDEX, "index_uuid", 1), "test_id", "failed")); + return null; + }).when(client).index(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + Assert.assertNull(encryptor.getMasterKey()); + String encrypted = encryptor.encrypt("test"); + Assert.assertNotNull(encrypted); + Assert.assertEquals(masterKey, encryptor.getMasterKey()); + } + + @Test + public void encrypt_ThrowExceptionWhenInitMLConfigIndex() { + exceptionRule.expect(RuntimeException.class); + exceptionRule.expectMessage("test exception"); + doThrow(new RuntimeException("test exception")).when(mlIndicesHandler).initMLConfigIndex(any()); + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + encryptor.encrypt(masterKey); + } + + @Test + public void encrypt_FailedToInitMLConfigIndex() { + exceptionRule.expect(RuntimeException.class); + exceptionRule.expectMessage("random test exception"); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onFailure(new RuntimeException("random test exception")); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + encryptor.encrypt(masterKey); + } + + @Test + public void encrypt_FailedToGetMasterKey() { + exceptionRule.expect(RuntimeException.class); + exceptionRule.expectMessage("random test exception"); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(1); + actionListener.onFailure(new RuntimeException("random test exception")); + return null; + }).when(client).get(any(), any()); + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); + encryptor.encrypt(masterKey); + } + @Test public void encrypt_DifferentMasterKey() { Encryptor encryptor = new EncryptorImpl(masterKey); @@ -121,7 +437,22 @@ public void encrypt_DifferentMasterKey() { @Test public void decrypt() { - Encryptor encryptor = new EncryptorImpl(clusterService, client); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); + doAnswer(invocation -> { + ActionListener listener = invocation.getArgument(1); + GetResponse response = mock(GetResponse.class); + when(response.isExists()).thenReturn(true); + when(response.getSourceAsMap()) + .thenReturn(ImmutableMap.of(MASTER_KEY, masterKey, CREATE_TIME_FIELD, Instant.now().toEpochMilli())); + listener.onResponse(response); + return null; + }).when(client).get(any(), any()); + + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); Assert.assertNull(encryptor.getMasterKey()); String encrypted = encryptor.encrypt("test"); String decrypted = encryptor.decrypt(encrypted); @@ -142,7 +473,7 @@ public void encrypt_NullMasterKey_NullMasterKey_MasterKeyNotExistInIndex() { return null; }).when(client).get(any(), any()); - Encryptor encryptor = new EncryptorImpl(clusterService, client); + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); Assert.assertNull(encryptor.getMasterKey()); encryptor.encrypt("test"); } @@ -152,13 +483,18 @@ public void decrypt_NullMasterKey_GetMasterKey_Exception() { exceptionRule.expect(RuntimeException.class); exceptionRule.expectMessage("test error"); + doAnswer(invocation -> { + ActionListener actionListener = (ActionListener) invocation.getArgument(0); + actionListener.onResponse(true); + return null; + }).when(mlIndicesHandler).initMLConfigIndex(any()); doAnswer(invocation -> { ActionListener listener = invocation.getArgument(1); listener.onFailure(new RuntimeException("test error")); return null; }).when(client).get(any(), any()); - Encryptor encryptor = new EncryptorImpl(clusterService, client); + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); Assert.assertNull(encryptor.getMasterKey()); encryptor.decrypt("test"); } @@ -177,7 +513,7 @@ public void decrypt_MLConfigIndexNotFound() { return null; }).when(client).get(any(), any()); - Encryptor encryptor = new EncryptorImpl(clusterService, client); + Encryptor encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); Assert.assertNull(encryptor.getMasterKey()); encryptor.decrypt("test"); } diff --git a/plugin/src/main/java/org/opensearch/ml/cluster/MLSyncUpCron.java b/plugin/src/main/java/org/opensearch/ml/cluster/MLSyncUpCron.java index 023d44404e..447eb105e9 100644 --- a/plugin/src/main/java/org/opensearch/ml/cluster/MLSyncUpCron.java +++ b/plugin/src/main/java/org/opensearch/ml/cluster/MLSyncUpCron.java @@ -22,6 +22,7 @@ import java.util.concurrent.Semaphore; import java.util.stream.Collectors; +import org.opensearch.action.DocWriteRequest; import org.opensearch.action.bulk.BulkRequest; import org.opensearch.action.get.GetRequest; import org.opensearch.action.index.IndexRequest; @@ -234,6 +235,7 @@ void initMLConfig() { final String masterKey = encryptor.generateMasterKey(); indexRequest.source(ImmutableMap.of(MASTER_KEY, masterKey, CREATE_TIME_FIELD, Instant.now().toEpochMilli())); indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + indexRequest.opType(DocWriteRequest.OpType.CREATE); client.index(indexRequest, ActionListener.wrap(indexResponse -> { log.info("ML configuration initialized successfully"); encryptor.setMasterKey(masterKey); diff --git a/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java b/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java index 7655c28b02..cfaa019b5f 100644 --- a/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java +++ b/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java @@ -462,7 +462,8 @@ public Collection createComponents( Path dataPath = environment.dataFiles()[0]; Path configFile = environment.configFile(); - encryptor = new EncryptorImpl(clusterService, client); + mlIndicesHandler = new MLIndicesHandler(clusterService, client); + encryptor = new EncryptorImpl(clusterService, client, mlIndicesHandler); mlEngine = new MLEngine(dataPath, encryptor); nodeHelper = new DiscoveryNodeHelper(clusterService, settings); @@ -496,7 +497,6 @@ public Collection createComponents( stats.put(MLNodeLevelStat.ML_CIRCUIT_BREAKER_TRIGGER_COUNT, new MLStat<>(false, new CounterSupplier())); this.mlStats = new MLStats(stats); - mlIndicesHandler = new MLIndicesHandler(clusterService, client); mlTaskManager = new MLTaskManager(client, threadPool, mlIndicesHandler); modelHelper = new ModelHelper(mlEngine); mlModelManager = new MLModelManager( From 18e8048a7b4665ca9be90c38b566019bc5d23eb7 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Wed, 3 Jul 2024 12:38:44 -0700 Subject: [PATCH 2/2] Simplify instantiating Data Object Request/Response builders (#2608) Signed-off-by: Daniel Widdis --- .../sdk/DeleteDataObjectRequest.java | 10 +++- .../sdk/DeleteDataObjectResponse.java | 10 +++- .../opensearch/sdk/GetDataObjectRequest.java | 10 +++- .../opensearch/sdk/GetDataObjectResponse.java | 10 +++- .../opensearch/sdk/PutDataObjectRequest.java | 10 +++- .../opensearch/sdk/PutDataObjectResponse.java | 10 +++- .../sdk/SearchDataObjectRequest.java | 10 +++- .../sdk/SearchDataObjectResponse.java | 10 +++- .../sdk/UpdateDataObjectRequest.java | 10 +++- .../sdk/UpdateDataObjectResponse.java | 10 +++- .../sdk/DeleteDataObjectRequestTests.java | 2 +- .../sdk/DeleteDataObjectResponseTests.java | 5 +- .../sdk/GetDataObjectRequestTests.java | 2 +- .../sdk/GetDataObjectResponseTests.java | 2 +- .../sdk/PutDataObjectRequestTests.java | 2 +- .../sdk/PutDataObjectResponseTests.java | 2 +- .../sdk/SearchDataObjectRequestTests.java | 2 +- .../sdk/SearchDataObjectResponseTests.java | 2 +- .../sdk/UpdateDataObjectRequestTests.java | 4 +- .../sdk/UpdateDataObjectResponseTests.java | 2 +- .../agents/DeleteAgentTransportAction.java | 6 ++- .../agents/GetAgentTransportAction.java | 3 +- .../agents/TransportRegisterAgentAction.java | 2 +- .../DeleteConnectorTransportAction.java | 5 +- .../GetConnectorTransportAction.java | 3 +- .../SearchConnectorTransportAction.java | 3 +- .../TransportCreateConnectorAction.java | 3 +- .../UpdateConnectorTransportAction.java | 9 ++-- .../ml/action/handler/MLSearchHandler.java | 9 ++-- .../DeleteModelGroupTransportAction.java | 5 +- .../GetModelGroupTransportAction.java | 3 +- .../SearchModelGroupTransportAction.java | 3 +- .../TransportUpdateModelGroupAction.java | 3 +- .../models/DeleteModelTransportAction.java | 10 ++-- .../models/GetModelTransportAction.java | 3 +- .../models/UpdateModelTransportAction.java | 8 +-- .../tasks/DeleteTaskTransportAction.java | 6 ++- .../action/tasks/GetTaskTransportAction.java | 3 +- .../TransportUndeployModelsAction.java | 3 +- .../helper/ConnectorAccessControlHelper.java | 3 +- .../ml/helper/ModelAccessControlHelper.java | 2 +- .../ml/model/MLModelGroupManager.java | 8 +-- .../opensearch/ml/model/MLModelManager.java | 14 ++--- .../ml/sdkclient/DDBOpenSearchClient.java | 8 +-- .../sdkclient/LocalClusterIndicesClient.java | 15 +++--- .../sdkclient/RemoteClusterIndicesClient.java | 10 ++-- .../ConnectorAccessControlHelperTests.java | 15 ++---- .../sdkclient/DDBOpenSearchClientTests.java | 53 +++++++++---------- .../LocalClusterIndicesClientTests.java | 39 ++++++++------ .../RemoteClusterIndicesClientTests.java | 36 +++++++------ 50 files changed, 260 insertions(+), 158 deletions(-) diff --git a/common/src/main/java/org/opensearch/sdk/DeleteDataObjectRequest.java b/common/src/main/java/org/opensearch/sdk/DeleteDataObjectRequest.java index 70e9506388..6dfed07293 100644 --- a/common/src/main/java/org/opensearch/sdk/DeleteDataObjectRequest.java +++ b/common/src/main/java/org/opensearch/sdk/DeleteDataObjectRequest.java @@ -51,6 +51,14 @@ public String id() { public String tenantId() { return this.tenantId; } + + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } /** * Class for constructing a Builder for this Request Object @@ -63,7 +71,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add an index to this builder diff --git a/common/src/main/java/org/opensearch/sdk/DeleteDataObjectResponse.java b/common/src/main/java/org/opensearch/sdk/DeleteDataObjectResponse.java index 7b27b6bbea..d7939d574b 100644 --- a/common/src/main/java/org/opensearch/sdk/DeleteDataObjectResponse.java +++ b/common/src/main/java/org/opensearch/sdk/DeleteDataObjectResponse.java @@ -42,6 +42,14 @@ public XContentParser parser() { return this.parser; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Response Object */ @@ -52,7 +60,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add an id to this builder diff --git a/common/src/main/java/org/opensearch/sdk/GetDataObjectRequest.java b/common/src/main/java/org/opensearch/sdk/GetDataObjectRequest.java index ee81411709..05d100d380 100644 --- a/common/src/main/java/org/opensearch/sdk/GetDataObjectRequest.java +++ b/common/src/main/java/org/opensearch/sdk/GetDataObjectRequest.java @@ -65,6 +65,14 @@ public FetchSourceContext fetchSourceContext() { return this.fetchSourceContext; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Request Object */ @@ -77,7 +85,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add an index to this builder diff --git a/common/src/main/java/org/opensearch/sdk/GetDataObjectResponse.java b/common/src/main/java/org/opensearch/sdk/GetDataObjectResponse.java index ad6f13435b..24c4c72a83 100644 --- a/common/src/main/java/org/opensearch/sdk/GetDataObjectResponse.java +++ b/common/src/main/java/org/opensearch/sdk/GetDataObjectResponse.java @@ -56,6 +56,14 @@ public Map source() { return this.source; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Response Object */ @@ -67,7 +75,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add an id to this builder diff --git a/common/src/main/java/org/opensearch/sdk/PutDataObjectRequest.java b/common/src/main/java/org/opensearch/sdk/PutDataObjectRequest.java index 9052ef6d40..22734f14df 100644 --- a/common/src/main/java/org/opensearch/sdk/PutDataObjectRequest.java +++ b/common/src/main/java/org/opensearch/sdk/PutDataObjectRequest.java @@ -63,6 +63,14 @@ public ToXContentObject dataObject() { return this.dataObject; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Request Object */ @@ -75,7 +83,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add an index to this builder diff --git a/common/src/main/java/org/opensearch/sdk/PutDataObjectResponse.java b/common/src/main/java/org/opensearch/sdk/PutDataObjectResponse.java index fd82bcab34..20b1db3ca0 100644 --- a/common/src/main/java/org/opensearch/sdk/PutDataObjectResponse.java +++ b/common/src/main/java/org/opensearch/sdk/PutDataObjectResponse.java @@ -42,6 +42,14 @@ public XContentParser parser() { return this.parser; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Response Object */ @@ -52,7 +60,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add an id to this builder diff --git a/common/src/main/java/org/opensearch/sdk/SearchDataObjectRequest.java b/common/src/main/java/org/opensearch/sdk/SearchDataObjectRequest.java index 24eb2e87c0..62f3d0fab1 100644 --- a/common/src/main/java/org/opensearch/sdk/SearchDataObjectRequest.java +++ b/common/src/main/java/org/opensearch/sdk/SearchDataObjectRequest.java @@ -55,6 +55,14 @@ public SearchSourceBuilder searchSourceBuilder() { return this.searchSourceBuilder; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Request Object */ @@ -66,7 +74,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add a indices to this builder diff --git a/common/src/main/java/org/opensearch/sdk/SearchDataObjectResponse.java b/common/src/main/java/org/opensearch/sdk/SearchDataObjectResponse.java index 71995974d4..381e38f5bd 100644 --- a/common/src/main/java/org/opensearch/sdk/SearchDataObjectResponse.java +++ b/common/src/main/java/org/opensearch/sdk/SearchDataObjectResponse.java @@ -29,6 +29,14 @@ public XContentParser parser() { return this.parser; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Response Object */ @@ -38,7 +46,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add aparser to this builder diff --git a/common/src/main/java/org/opensearch/sdk/UpdateDataObjectRequest.java b/common/src/main/java/org/opensearch/sdk/UpdateDataObjectRequest.java index 4ec4cfa251..99cb757bc4 100644 --- a/common/src/main/java/org/opensearch/sdk/UpdateDataObjectRequest.java +++ b/common/src/main/java/org/opensearch/sdk/UpdateDataObjectRequest.java @@ -69,6 +69,14 @@ public ToXContentObject dataObject() { return this.dataObject; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Request Object */ @@ -81,7 +89,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add an index to this builder diff --git a/common/src/main/java/org/opensearch/sdk/UpdateDataObjectResponse.java b/common/src/main/java/org/opensearch/sdk/UpdateDataObjectResponse.java index 6b62334a28..6b3514e05f 100644 --- a/common/src/main/java/org/opensearch/sdk/UpdateDataObjectResponse.java +++ b/common/src/main/java/org/opensearch/sdk/UpdateDataObjectResponse.java @@ -42,6 +42,14 @@ public XContentParser parser() { return this.parser; } + /** + * Instantiate a builder for this object + * @return a builder instance + */ + public static Builder builder() { + return new Builder(); + } + /** * Class for constructing a Builder for this Response Object */ @@ -52,7 +60,7 @@ public static class Builder { /** * Empty Constructor for the Builder object */ - public Builder() {} + private Builder() {} /** * Add an id to this builder diff --git a/common/src/test/java/org/opensearch/sdk/DeleteDataObjectRequestTests.java b/common/src/test/java/org/opensearch/sdk/DeleteDataObjectRequestTests.java index 4210e17215..3fc0ddd263 100644 --- a/common/src/test/java/org/opensearch/sdk/DeleteDataObjectRequestTests.java +++ b/common/src/test/java/org/opensearch/sdk/DeleteDataObjectRequestTests.java @@ -27,7 +27,7 @@ public void setUp() { @Test public void testDeleteDataObjectRequest() { - DeleteDataObjectRequest request = new DeleteDataObjectRequest.Builder().index(testIndex).id(testId).tenantId(testTenantId).build(); + DeleteDataObjectRequest request = DeleteDataObjectRequest.builder().index(testIndex).id(testId).tenantId(testTenantId).build(); assertEquals(testIndex, request.index()); assertEquals(testId, request.id()); diff --git a/common/src/test/java/org/opensearch/sdk/DeleteDataObjectResponseTests.java b/common/src/test/java/org/opensearch/sdk/DeleteDataObjectResponseTests.java index 683ccaed93..5ca9a5784f 100644 --- a/common/src/test/java/org/opensearch/sdk/DeleteDataObjectResponseTests.java +++ b/common/src/test/java/org/opensearch/sdk/DeleteDataObjectResponseTests.java @@ -10,9 +10,6 @@ import org.junit.Before; import org.junit.Test; -import org.opensearch.action.support.replication.ReplicationResponse.ShardInfo; -import org.opensearch.core.common.Strings; -import org.opensearch.core.index.shard.ShardId; import org.opensearch.core.xcontent.XContentParser; import static org.junit.Assert.assertEquals; @@ -31,7 +28,7 @@ public void setUp() { @Test public void testDeleteDataObjectResponse() { - DeleteDataObjectResponse response = new DeleteDataObjectResponse.Builder().id(testId).parser(testParser).build(); + DeleteDataObjectResponse response = DeleteDataObjectResponse.builder().id(testId).parser(testParser).build(); assertEquals(testId, response.id()); assertEquals(testParser, response.parser()); diff --git a/common/src/test/java/org/opensearch/sdk/GetDataObjectRequestTests.java b/common/src/test/java/org/opensearch/sdk/GetDataObjectRequestTests.java index 0fc88c4468..4053fac843 100644 --- a/common/src/test/java/org/opensearch/sdk/GetDataObjectRequestTests.java +++ b/common/src/test/java/org/opensearch/sdk/GetDataObjectRequestTests.java @@ -32,7 +32,7 @@ public void setUp() { @Test public void testGetDataObjectRequest() { - GetDataObjectRequest request = new GetDataObjectRequest.Builder() + GetDataObjectRequest request = GetDataObjectRequest.builder() .index(testIndex) .id(testId) .tenantId(testTenantId) diff --git a/common/src/test/java/org/opensearch/sdk/GetDataObjectResponseTests.java b/common/src/test/java/org/opensearch/sdk/GetDataObjectResponseTests.java index 6b318e4f58..8f25e68829 100644 --- a/common/src/test/java/org/opensearch/sdk/GetDataObjectResponseTests.java +++ b/common/src/test/java/org/opensearch/sdk/GetDataObjectResponseTests.java @@ -31,7 +31,7 @@ public void setUp() { @Test public void testGetDataObjectResponse() { - GetDataObjectResponse response = new GetDataObjectResponse.Builder().id(testId).parser(testParser).source(testSource).build(); + GetDataObjectResponse response = GetDataObjectResponse.builder().id(testId).parser(testParser).source(testSource).build(); assertEquals(testId, response.id()); assertEquals(testParser, response.parser()); diff --git a/common/src/test/java/org/opensearch/sdk/PutDataObjectRequestTests.java b/common/src/test/java/org/opensearch/sdk/PutDataObjectRequestTests.java index b1909966da..28b6d1bd0a 100644 --- a/common/src/test/java/org/opensearch/sdk/PutDataObjectRequestTests.java +++ b/common/src/test/java/org/opensearch/sdk/PutDataObjectRequestTests.java @@ -30,7 +30,7 @@ public void setUp() { @Test public void testPutDataObjectRequest() { - PutDataObjectRequest request = new PutDataObjectRequest.Builder().index(testIndex).tenantId(testTenantId).dataObject(testDataObject).build(); + PutDataObjectRequest request = PutDataObjectRequest.builder().index(testIndex).tenantId(testTenantId).dataObject(testDataObject).build(); assertEquals(testIndex, request.index()); assertEquals(testTenantId, request.tenantId()); diff --git a/common/src/test/java/org/opensearch/sdk/PutDataObjectResponseTests.java b/common/src/test/java/org/opensearch/sdk/PutDataObjectResponseTests.java index 5665e3f54d..b94a1cd588 100644 --- a/common/src/test/java/org/opensearch/sdk/PutDataObjectResponseTests.java +++ b/common/src/test/java/org/opensearch/sdk/PutDataObjectResponseTests.java @@ -28,7 +28,7 @@ public void setUp() { @Test public void testPutDataObjectResponse() { - PutDataObjectResponse response = new PutDataObjectResponse.Builder().id(testId).parser(testParser).build(); + PutDataObjectResponse response = PutDataObjectResponse.builder().id(testId).parser(testParser).build(); assertEquals(testId, response.id()); assertEquals(testParser, response.parser()); diff --git a/common/src/test/java/org/opensearch/sdk/SearchDataObjectRequestTests.java b/common/src/test/java/org/opensearch/sdk/SearchDataObjectRequestTests.java index 1d1caf8c5e..60676507cc 100644 --- a/common/src/test/java/org/opensearch/sdk/SearchDataObjectRequestTests.java +++ b/common/src/test/java/org/opensearch/sdk/SearchDataObjectRequestTests.java @@ -30,7 +30,7 @@ public void setUp() { @Test public void testGetDataObjectRequest() { - SearchDataObjectRequest request = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest request = SearchDataObjectRequest.builder() .indices(testIndices) .tenantId(testTenantId) .searchSourceBuilder(testSearchSourceBuilder) diff --git a/common/src/test/java/org/opensearch/sdk/SearchDataObjectResponseTests.java b/common/src/test/java/org/opensearch/sdk/SearchDataObjectResponseTests.java index df080f60e6..c789f05575 100644 --- a/common/src/test/java/org/opensearch/sdk/SearchDataObjectResponseTests.java +++ b/common/src/test/java/org/opensearch/sdk/SearchDataObjectResponseTests.java @@ -26,7 +26,7 @@ public void setUp() { @Test public void testSearchDataObjectResponse() { - SearchDataObjectResponse response = new SearchDataObjectResponse.Builder().parser(testParser).build(); + SearchDataObjectResponse response = SearchDataObjectResponse.builder().parser(testParser).build(); assertEquals(testParser, response.parser()); } diff --git a/common/src/test/java/org/opensearch/sdk/UpdateDataObjectRequestTests.java b/common/src/test/java/org/opensearch/sdk/UpdateDataObjectRequestTests.java index f5718e05c0..b31ad53691 100644 --- a/common/src/test/java/org/opensearch/sdk/UpdateDataObjectRequestTests.java +++ b/common/src/test/java/org/opensearch/sdk/UpdateDataObjectRequestTests.java @@ -40,7 +40,7 @@ public void setUp() { @Test public void testUpdateDataObjectRequest() { - UpdateDataObjectRequest request = new UpdateDataObjectRequest.Builder().index(testIndex).id(testId).tenantId(testTenantId).dataObject(testDataObject).build(); + UpdateDataObjectRequest request = UpdateDataObjectRequest.builder().index(testIndex).id(testId).tenantId(testTenantId).dataObject(testDataObject).build(); assertEquals(testIndex, request.index()); assertEquals(testId, request.id()); @@ -50,7 +50,7 @@ public void testUpdateDataObjectRequest() { @Test public void testUpdateDataObjectMapRequest() { - UpdateDataObjectRequest request = new UpdateDataObjectRequest.Builder().index(testIndex).id(testId).tenantId(testTenantId).dataObject(testDataObjectMap).build(); + UpdateDataObjectRequest request = UpdateDataObjectRequest.builder().index(testIndex).id(testId).tenantId(testTenantId).dataObject(testDataObjectMap).build(); assertEquals(testIndex, request.index()); assertEquals(testId, request.id()); diff --git a/common/src/test/java/org/opensearch/sdk/UpdateDataObjectResponseTests.java b/common/src/test/java/org/opensearch/sdk/UpdateDataObjectResponseTests.java index cbb8a11832..f77941f5b3 100644 --- a/common/src/test/java/org/opensearch/sdk/UpdateDataObjectResponseTests.java +++ b/common/src/test/java/org/opensearch/sdk/UpdateDataObjectResponseTests.java @@ -31,7 +31,7 @@ public void setUp() { @Test public void testUpdateDataObjectResponse() { - UpdateDataObjectResponse response = new UpdateDataObjectResponse.Builder().id(testId).parser(testParser).build(); + UpdateDataObjectResponse response = UpdateDataObjectResponse.builder().id(testId).parser(testParser).build(); assertEquals(testId, response.id()); assertEquals(testParser, response.parser()); diff --git a/plugin/src/main/java/org/opensearch/ml/action/agents/DeleteAgentTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/agents/DeleteAgentTransportAction.java index 0f553ecbe2..72b5db0f60 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/agents/DeleteAgentTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/agents/DeleteAgentTransportAction.java @@ -83,7 +83,8 @@ protected void doExecute(Task task, ActionRequest request, ActionListener { 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 913d2c8762..68c97ca28b 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 @@ -125,7 +125,8 @@ private void checkForModelsUsingConnector(String connectorId, String tenantId, A sourceBuilder.query(QueryBuilders.matchQuery(TENANT_ID, tenantId)); } - SearchDataObjectRequest searchDataObjectRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchDataObjectRequest = SearchDataObjectRequest + .builder() .indices(ML_MODEL_INDEX) .searchSourceBuilder(sourceBuilder) .build(); @@ -191,7 +192,7 @@ private void deleteConnector(String connectorId, ActionListener try { sdkClient .deleteDataObjectAsync( - new DeleteDataObjectRequest.Builder().index(deleteRequest.index()).id(deleteRequest.id()).build(), + DeleteDataObjectRequest.builder().index(deleteRequest.index()).id(deleteRequest.id()).build(), client.threadPool().executor(GENERAL_THREAD_POOL) ) .whenComplete((response, throwable) -> handleDeleteResponse(response, throwable, connectorId, actionListener)); diff --git a/plugin/src/main/java/org/opensearch/ml/action/connector/GetConnectorTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/connector/GetConnectorTransportAction.java index cecb3d7816..dbf9b8cbd8 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/connector/GetConnectorTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/connector/GetConnectorTransportAction.java @@ -72,7 +72,8 @@ protected void doExecute(Task task, ActionRequest request, ActionListener action SearchSourceBuilder sourceBuilder = connectorAccessControlHelper.addUserBackendRolesFilter(user, request.source()); request.source(sourceBuilder); } - SearchDataObjectRequest searchDataObjectRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchDataObjectRequest = SearchDataObjectRequest + .builder() .indices(request.indices()) .searchSourceBuilder(request.source()) .build(); diff --git a/plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java b/plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java index 244f5a56f5..1cd4db9b97 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java @@ -144,7 +144,8 @@ private void indexConnector(Connector connector, ActionListener wrapListenerToHandleSearchIndexNotFound(e, wrappedListener)); if (modelAccessControlHelper.skipModelAccessControl(user) || !clusterService.state().metadata().hasIndex(CommonValue.ML_MODEL_GROUP_INDEX)) { - SearchDataObjectRequest searchDataObjectRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchDataObjectRequest = SearchDataObjectRequest + .builder() .indices(request.indices()) .searchSourceBuilder(request.source()) .build(); @@ -175,7 +176,8 @@ public void search(SdkClient sdkClient, SearchRequest request, ActionListener handleDeleteResponse(response, throwable, deleteRequest.id(), actionListener)); diff --git a/plugin/src/main/java/org/opensearch/ml/action/model_group/GetModelGroupTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/model_group/GetModelGroupTransportAction.java index 1dda37c291..acd118fbe3 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/model_group/GetModelGroupTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/model_group/GetModelGroupTransportAction.java @@ -89,7 +89,8 @@ protected void doExecute(Task task, ActionRequest request, ActionListener actionListener) { - DeleteDataObjectRequest deleteDataObjectRequest = new DeleteDataObjectRequest.Builder().index(ML_MODEL_INDEX).id(modelId).build(); + DeleteDataObjectRequest deleteDataObjectRequest = DeleteDataObjectRequest.builder().index(ML_MODEL_INDEX).id(modelId).build(); sdkClient .deleteDataObjectAsync(deleteDataObjectRequest, client.threadPool().executor(GENERAL_THREAD_POOL)) .whenComplete((r, throwable) -> { @@ -342,10 +343,7 @@ private void deleteModelChunksAndController( * @param modelId model ID */ private void deleteController(String modelId, Boolean isHidden, ActionListener actionListener) { - DeleteDataObjectRequest deleteDataObjectRequest = new DeleteDataObjectRequest.Builder() - .index(ML_CONTROLLER_INDEX) - .id(modelId) - .build(); + DeleteDataObjectRequest deleteDataObjectRequest = DeleteDataObjectRequest.builder().index(ML_CONTROLLER_INDEX).id(modelId).build(); sdkClient .deleteDataObjectAsync(deleteDataObjectRequest, client.threadPool().executor(GENERAL_THREAD_POOL)) .whenComplete((r, throwable) -> { diff --git a/plugin/src/main/java/org/opensearch/ml/action/models/GetModelTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/models/GetModelTransportAction.java index 9908cc2433..a33cb3bbe3 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/models/GetModelTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/models/GetModelTransportAction.java @@ -99,7 +99,8 @@ protected void doExecute(Task task, ActionRequest request, ActionListener SearchRequest searchRequest = new SearchRequest(ML_MODEL_INDEX).source(searchSourceBuilder); - SearchDataObjectRequest searchDataObjectRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchDataObjectRequest = SearchDataObjectRequest + .builder() .indices(searchRequest.indices()) .searchSourceBuilder(searchRequest.source()) .build(); diff --git a/plugin/src/main/java/org/opensearch/ml/helper/ConnectorAccessControlHelper.java b/plugin/src/main/java/org/opensearch/ml/helper/ConnectorAccessControlHelper.java index 917615d05f..bf719164b2 100644 --- a/plugin/src/main/java/org/opensearch/ml/helper/ConnectorAccessControlHelper.java +++ b/plugin/src/main/java/org/opensearch/ml/helper/ConnectorAccessControlHelper.java @@ -109,7 +109,8 @@ public void validateConnectorAccess( try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) { ActionListener wrappedListener = ActionListener.runBefore(listener, context::restore); FetchSourceContext fetchSourceContext = getFetchSourceContext(true); - GetDataObjectRequest getDataObjectRequest = new GetDataObjectRequest.Builder() + GetDataObjectRequest getDataObjectRequest = GetDataObjectRequest + .builder() .index(ML_CONNECTOR_INDEX) .id(connectorId) .fetchSourceContext(fetchSourceContext) diff --git a/plugin/src/main/java/org/opensearch/ml/helper/ModelAccessControlHelper.java b/plugin/src/main/java/org/opensearch/ml/helper/ModelAccessControlHelper.java index 9cc3af2d39..00b2bc93f3 100644 --- a/plugin/src/main/java/org/opensearch/ml/helper/ModelAccessControlHelper.java +++ b/plugin/src/main/java/org/opensearch/ml/helper/ModelAccessControlHelper.java @@ -164,7 +164,7 @@ public void validateModelGroupAccess( } List userBackendRoles = user.getBackendRoles(); - GetDataObjectRequest getModelGroupRequest = new GetDataObjectRequest.Builder().index(ML_MODEL_GROUP_INDEX).id(modelGroupId).build(); + GetDataObjectRequest getModelGroupRequest = GetDataObjectRequest.builder().index(ML_MODEL_GROUP_INDEX).id(modelGroupId).build(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) { ActionListener wrappedListener = ActionListener.runBefore(listener, () -> context.restore()); sdkClient diff --git a/plugin/src/main/java/org/opensearch/ml/model/MLModelGroupManager.java b/plugin/src/main/java/org/opensearch/ml/model/MLModelGroupManager.java index 2073511e9b..b35bda8867 100644 --- a/plugin/src/main/java/org/opensearch/ml/model/MLModelGroupManager.java +++ b/plugin/src/main/java/org/opensearch/ml/model/MLModelGroupManager.java @@ -130,7 +130,8 @@ public void createModelGroup(MLRegisterModelGroupInput input, ActionListener { sdkClient .putDataObjectAsync( - new PutDataObjectRequest.Builder() + PutDataObjectRequest + .builder() .tenantId(mlModelGroup.getTenantId()) .index(ML_MODEL_GROUP_INDEX) .dataObject(mlModelGroup) @@ -224,7 +225,8 @@ public void validateUniqueModelGroupName(String name, ActionListener listener) { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(ML_MODEL_GROUP_INDEX).id(modelGroupId).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(ML_MODEL_GROUP_INDEX).id(modelGroupId).build(); sdkClient.getDataObjectAsync(getRequest, client.threadPool().executor(GENERAL_THREAD_POOL)).whenComplete((r, throwable) -> { if (throwable == null) { try { diff --git a/plugin/src/main/java/org/opensearch/ml/model/MLModelManager.java b/plugin/src/main/java/org/opensearch/ml/model/MLModelManager.java index f1ae25deda..7522a2affe 100644 --- a/plugin/src/main/java/org/opensearch/ml/model/MLModelManager.java +++ b/plugin/src/main/java/org/opensearch/ml/model/MLModelManager.java @@ -367,10 +367,7 @@ public void registerMLRemoteModel( mlStats.getStat(MLNodeLevelStat.ML_EXECUTING_TASK_COUNT).increment(); String modelGroupId = mlRegisterModelInput.getModelGroupId(); - GetDataObjectRequest getModelGroupRequest = new GetDataObjectRequest.Builder() - .index(ML_MODEL_GROUP_INDEX) - .id(modelGroupId) - .build(); + GetDataObjectRequest getModelGroupRequest = GetDataObjectRequest.builder().index(ML_MODEL_GROUP_INDEX).id(modelGroupId).build(); sdkClient .getDataObjectAsync(getModelGroupRequest, client.threadPool().executor(GENERAL_THREAD_POOL)) .whenComplete((r, throwable) -> { @@ -391,7 +388,8 @@ public void registerMLRemoteModel( */ modelGroupSourceMap.put(MLModelGroup.LATEST_VERSION_FIELD, updatedVersion); modelGroupSourceMap.put(MLModelGroup.LAST_UPDATED_TIME_FIELD, Instant.now().toEpochMilli()); - UpdateDataObjectRequest updateDataObjectRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateDataObjectRequest = UpdateDataObjectRequest + .builder() .index(ML_MODEL_GROUP_INDEX) .id(modelGroupId) // TODO need to track these for concurrency @@ -584,7 +582,8 @@ private void indexRemoteModel( .tenantId(registerModelInput.getTenantId()) .build(); - PutDataObjectRequest putModelMetaRequest = new PutDataObjectRequest.Builder() + PutDataObjectRequest putModelMetaRequest = PutDataObjectRequest + .builder() .index(ML_MODEL_INDEX) .id(Boolean.TRUE.equals(registerModelInput.getIsHidden()) ? modelName : null) .dataObject(mlModelMeta) @@ -1647,7 +1646,8 @@ public void getModel(String modelId, String[] includes, String[] excludes, Actio * @param listener action listener */ public void getModel(SdkClient sdkClient, String modelId, String[] includes, String[] excludes, ActionListener listener) { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder() + GetDataObjectRequest getRequest = GetDataObjectRequest + .builder() .index(ML_MODEL_INDEX) .id(modelId) .fetchSourceContext(new FetchSourceContext(true, includes, excludes)) diff --git a/plugin/src/main/java/org/opensearch/ml/sdkclient/DDBOpenSearchClient.java b/plugin/src/main/java/org/opensearch/ml/sdkclient/DDBOpenSearchClient.java index a5ddd05855..030313ae05 100644 --- a/plugin/src/main/java/org/opensearch/ml/sdkclient/DDBOpenSearchClient.java +++ b/plugin/src/main/java/org/opensearch/ml/sdkclient/DDBOpenSearchClient.java @@ -116,7 +116,7 @@ public CompletionStage putDataObjectAsync(PutDataObjectRe source, Map.of("result", "created") ); - return new PutDataObjectResponse.Builder().id(id).parser(createParser(simulatedIndexResponse)).build(); + return PutDataObjectResponse.builder().id(id).parser(createParser(simulatedIndexResponse)).build(); } catch (IOException e) { // Rethrow unchecked exception on XContent parsing error throw new OpenSearchStatusException("Failed to parse data object " + request.id(), RestStatus.BAD_REQUEST); @@ -165,7 +165,7 @@ public CompletionStage getDataObjectAsync(GetDataObjectRe .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, simulatedGetResponse) ) .getSourceAsMap(); - return new GetDataObjectResponse.Builder().id(request.id()).parser(parser).source(sourceAsMap).build(); + return GetDataObjectResponse.builder().id(request.id()).parser(parser).source(sourceAsMap).build(); } catch (IOException e) { // Rethrow unchecked exception on XContent parsing error throw new OpenSearchStatusException("Failed to parse response", RestStatus.INTERNAL_SERVER_ERROR); @@ -195,7 +195,7 @@ public CompletionStage updateDataObjectAsync(UpdateDat dynamoDbClient.updateItem(updateItemRequest); String simulatedUpdateResponse = simulateOpenSearchResponse(request.index(), request.id(), source, Map.of("found", true)); - return new UpdateDataObjectResponse.Builder().id(request.id()).parser(createParser(simulatedUpdateResponse)).build(); + return UpdateDataObjectResponse.builder().id(request.id()).parser(createParser(simulatedUpdateResponse)).build(); } catch (IOException e) { log.error("Error updating {} in {}: {}", request.id(), request.index(), e.getMessage(), e); // Rethrow unchecked exception on update IOException @@ -234,7 +234,7 @@ public CompletionStage deleteDataObjectAsync(DeleteDat null, Map.of("result", "deleted") ); - return new DeleteDataObjectResponse.Builder().id(request.id()).parser(createParser(simulatedDeleteResponse)).build(); + return DeleteDataObjectResponse.builder().id(request.id()).parser(createParser(simulatedDeleteResponse)).build(); } catch (IOException e) { // Rethrow unchecked exception on XContent parsing error throw new OpenSearchStatusException("Failed to parse response", RestStatus.INTERNAL_SERVER_ERROR); diff --git a/plugin/src/main/java/org/opensearch/ml/sdkclient/LocalClusterIndicesClient.java b/plugin/src/main/java/org/opensearch/ml/sdkclient/LocalClusterIndicesClient.java index 4265cb9a77..54551cc28a 100644 --- a/plugin/src/main/java/org/opensearch/ml/sdkclient/LocalClusterIndicesClient.java +++ b/plugin/src/main/java/org/opensearch/ml/sdkclient/LocalClusterIndicesClient.java @@ -87,7 +87,7 @@ public CompletionStage putDataObjectAsync(PutDataObjectRe ) .actionGet(); log.info("Creation status for id {}: {}", indexResponse.getId(), indexResponse.getResult()); - return new PutDataObjectResponse.Builder().id(indexResponse.getId()).parser(createParser(indexResponse)).build(); + return PutDataObjectResponse.builder().id(indexResponse.getId()).parser(createParser(indexResponse)).build(); } catch (IOException e) { // Rethrow unchecked exception on XContent parsing error throw new OpenSearchStatusException( @@ -108,10 +108,11 @@ public CompletionStage getDataObjectAsync(GetDataObjectRe .actionGet(); if (getResponse == null) { log.info("Null GetResponse"); - return new GetDataObjectResponse.Builder().id(request.id()).parser(null).build(); + return GetDataObjectResponse.builder().id(request.id()).parser(null).build(); } log.info("Retrieved data object"); - return new GetDataObjectResponse.Builder() + return GetDataObjectResponse + .builder() .id(getResponse.getId()) .parser(createParser(getResponse)) .source(getResponse.getSource()) @@ -138,10 +139,10 @@ public CompletionStage updateDataObjectAsync(UpdateDat .actionGet(); if (updateResponse == null) { log.info("Null UpdateResponse"); - return new UpdateDataObjectResponse.Builder().id(request.id()).parser(null).build(); + return UpdateDataObjectResponse.builder().id(request.id()).parser(null).build(); } log.info("Update status for id {}: {}", updateResponse.getId(), updateResponse.getResult()); - return new UpdateDataObjectResponse.Builder().id(updateResponse.getId()).parser(createParser(updateResponse)).build(); + return UpdateDataObjectResponse.builder().id(updateResponse.getId()).parser(createParser(updateResponse)).build(); } catch (IOException e) { // Rethrow unchecked exception on XContent parsing error throw new OpenSearchStatusException( @@ -159,7 +160,7 @@ public CompletionStage deleteDataObjectAsync(DeleteDat log.info("Deleting {} from {}", request.id(), request.index()); DeleteResponse deleteResponse = client.delete(new DeleteRequest(request.index(), request.id())).actionGet(); log.info("Deletion status for id {}: {}", deleteResponse.getId(), deleteResponse.getResult()); - return new DeleteDataObjectResponse.Builder().id(deleteResponse.getId()).parser(createParser(deleteResponse)).build(); + return DeleteDataObjectResponse.builder().id(deleteResponse.getId()).parser(createParser(deleteResponse)).build(); } catch (IOException e) { // Rethrow unchecked exception on XContent parsing error throw new OpenSearchStatusException( @@ -177,7 +178,7 @@ public CompletionStage searchDataObjectAsync(SearchDat SearchResponse searchResponse = client.search(new SearchRequest(request.indices(), request.searchSourceBuilder())).actionGet(); log.info("Search returned {} hits", searchResponse.getHits().getTotalHits()); try { - return new SearchDataObjectResponse.Builder().parser(createParser(searchResponse)).build(); + return SearchDataObjectResponse.builder().parser(createParser(searchResponse)).build(); } catch (IOException e) { // Rethrow unchecked exception on XContent parsing error throw new OpenSearchStatusException( diff --git a/plugin/src/main/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClient.java b/plugin/src/main/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClient.java index c21c88d99e..3473ad20ee 100644 --- a/plugin/src/main/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClient.java +++ b/plugin/src/main/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClient.java @@ -89,7 +89,7 @@ public CompletionStage putDataObjectAsync(PutDataObjectRe log.info("Indexing data object in {}", request.index()); IndexResponse indexResponse = openSearchClient.index(indexRequest); log.info("Creation status for id {}: {}", indexResponse.id(), indexResponse.result()); - return new PutDataObjectResponse.Builder().id(indexResponse.id()).parser(createParser(indexResponse)).build(); + return PutDataObjectResponse.builder().id(indexResponse.id()).parser(createParser(indexResponse)).build(); } catch (IOException e) { log.error("Error putting data object in {}: {}", request.index(), e.getMessage(), e); // Rethrow unchecked exception on XContent parsing error @@ -110,7 +110,7 @@ public CompletionStage getDataObjectAsync(GetDataObjectRe GetResponse> getResponse = openSearchClient.get(getRequest, MAP_DOCTYPE); log.info("Get found status for id {}: {}", getResponse.id(), getResponse.found()); Map source = getResponse.source(); - return new GetDataObjectResponse.Builder().id(getResponse.id()).parser(createParser(getResponse)).source(source).build(); + return GetDataObjectResponse.builder().id(getResponse.id()).parser(createParser(getResponse)).source(source).build(); } catch (IOException e) { log.error("Error getting data object {} from {}: {}", request.id(), request.index(), e.getMessage(), e); // Rethrow unchecked exception on XContent parser creation error @@ -138,7 +138,7 @@ public CompletionStage updateDataObjectAsync(UpdateDat log.info("Updating {} in {}", request.id(), request.index()); UpdateResponse> updateResponse = openSearchClient.update(updateRequest, MAP_DOCTYPE); log.info("Update status for id {}: {}", updateResponse.id(), updateResponse.result()); - return new UpdateDataObjectResponse.Builder().id(updateResponse.id()).parser(createParser(updateResponse)).build(); + return UpdateDataObjectResponse.builder().id(updateResponse.id()).parser(createParser(updateResponse)).build(); } catch (IOException e) { log.error("Error updating {} in {}: {}", request.id(), request.index(), e.getMessage(), e); // Rethrow unchecked exception on update IOException @@ -158,7 +158,7 @@ public CompletionStage deleteDataObjectAsync(DeleteDat log.info("Deleting {} from {}", request.id(), request.index()); DeleteResponse deleteResponse = openSearchClient.delete(deleteRequest); log.info("Deletion status for id {}: {}", deleteResponse.id(), deleteResponse.result()); - return new DeleteDataObjectResponse.Builder().id(deleteResponse.id()).parser(createParser(deleteResponse)).build(); + return DeleteDataObjectResponse.builder().id(deleteResponse.id()).parser(createParser(deleteResponse)).build(); } catch (IOException e) { log.error("Error deleting {} from {}: {}", request.id(), request.index(), e.getMessage(), e); // Rethrow unchecked exception on deletion IOException @@ -180,7 +180,7 @@ public CompletionStage searchDataObjectAsync(SearchDat searchRequest = searchRequest.toBuilder().index(Arrays.asList(request.indices())).build(); SearchResponse searchResponse = openSearchClient.search(searchRequest, MAP_DOCTYPE); log.info("Search returned {} hits", searchResponse.hits().total().value()); - return new SearchDataObjectResponse.Builder().parser(createParser(searchResponse)).build(); + return SearchDataObjectResponse.builder().parser(createParser(searchResponse)).build(); } catch (IOException e) { log.error("Error searching {}: {}", Arrays.toString(request.indices()), e.getMessage(), e); // Rethrow unchecked exception on exception diff --git a/plugin/src/test/java/org/opensearch/ml/helper/ConnectorAccessControlHelperTests.java b/plugin/src/test/java/org/opensearch/ml/helper/ConnectorAccessControlHelperTests.java index 3983d4ef83..bf20cb04c2 100644 --- a/plugin/src/test/java/org/opensearch/ml/helper/ConnectorAccessControlHelperTests.java +++ b/plugin/src/test/java/org/opensearch/ml/helper/ConnectorAccessControlHelperTests.java @@ -439,10 +439,7 @@ public void test_addUserBackendRolesFilter_nonBoolQuery() { @Test public void testGetConnectorHappyCase() throws IOException, InterruptedException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder() - .index(CommonValue.ML_CONNECTOR_INDEX) - .id("connectorId") - .build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(CommonValue.ML_CONNECTOR_INDEX).id("connectorId").build(); GetResponse getResponse = prepareConnector(); PlainActionFuture future = PlainActionFuture.newFuture(); @@ -469,10 +466,7 @@ public void testGetConnectorHappyCase() throws IOException, InterruptedException @Test public void testGetConnectorException() throws IOException, InterruptedException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder() - .index(CommonValue.ML_CONNECTOR_INDEX) - .id("connectorId") - .build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(CommonValue.ML_CONNECTOR_INDEX).id("connectorId").build(); PlainActionFuture future = PlainActionFuture.newFuture(); future.onFailure(new RuntimeException("Failed to get connector")); @@ -498,10 +492,7 @@ public void testGetConnectorException() throws IOException, InterruptedException @Test public void testGetConnectorIndexNotFound() throws IOException, InterruptedException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder() - .index(CommonValue.ML_CONNECTOR_INDEX) - .id("connectorId") - .build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(CommonValue.ML_CONNECTOR_INDEX).id("connectorId").build(); PlainActionFuture future = PlainActionFuture.newFuture(); future.onFailure(new IndexNotFoundException("Index not found")); diff --git a/plugin/src/test/java/org/opensearch/ml/sdkclient/DDBOpenSearchClientTests.java b/plugin/src/test/java/org/opensearch/ml/sdkclient/DDBOpenSearchClientTests.java index 6643ab5690..e85c12d714 100644 --- a/plugin/src/test/java/org/opensearch/ml/sdkclient/DDBOpenSearchClientTests.java +++ b/plugin/src/test/java/org/opensearch/ml/sdkclient/DDBOpenSearchClientTests.java @@ -125,7 +125,8 @@ public void setup() { @Test public void testPutDataObject_HappyCase() throws IOException { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder() + PutDataObjectRequest putRequest = PutDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .tenantId(TENANT_ID) @@ -160,7 +161,8 @@ public void testPutDataObject_WithComplexData() throws IOException { .testList(Arrays.asList("123", "hello", null)) .testObject(testDataObject) .build(); - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder() + PutDataObjectRequest putRequest = PutDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .tenantId(TENANT_ID) @@ -184,11 +186,7 @@ public void testPutDataObject_WithComplexData() throws IOException { @Test public void testPutDataObject_NullTenantId_SetsDefaultTenantId() throws IOException { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder() - .index(TEST_INDEX) - .id(TEST_ID) - .dataObject(testDataObject) - .build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).dataObject(testDataObject).build(); Mockito.when(dynamoDbClient.putItem(Mockito.any(PutItemRequest.class))).thenReturn(PutItemResponse.builder().build()); sdkClient.putDataObjectAsync(putRequest, testThreadPool.executor(GENERAL_THREAD_POOL)).toCompletableFuture().join(); Mockito.verify(dynamoDbClient).putItem(putItemRequestArgumentCaptor.capture()); @@ -199,7 +197,7 @@ public void testPutDataObject_NullTenantId_SetsDefaultTenantId() throws IOExcept @Test public void testPutDataObject_NullId_SetsDefaultTenantId() throws IOException { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder().index(TEST_INDEX).dataObject(testDataObject).build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).dataObject(testDataObject).build(); Mockito.when(dynamoDbClient.putItem(Mockito.any(PutItemRequest.class))).thenReturn(PutItemResponse.builder().build()); PutDataObjectResponse response = sdkClient .putDataObjectAsync(putRequest, testThreadPool.executor(GENERAL_THREAD_POOL)) @@ -214,11 +212,7 @@ public void testPutDataObject_NullId_SetsDefaultTenantId() throws IOException { @Test public void testPutDataObject_DDBException_ThrowsException() { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder() - .index(TEST_INDEX) - .id(TEST_ID) - .dataObject(testDataObject) - .build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).dataObject(testDataObject).build(); Mockito.when(dynamoDbClient.putItem(Mockito.any(PutItemRequest.class))).thenThrow(new RuntimeException("Test exception")); CompletableFuture future = sdkClient .putDataObjectAsync(putRequest, testThreadPool.executor(GENERAL_THREAD_POOL)) @@ -230,7 +224,7 @@ public void testPutDataObject_DDBException_ThrowsException() { @Test public void testGetDataObject_HappyCase() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).tenantId(TENANT_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).tenantId(TENANT_ID).build(); GetItemResponse getItemResponse = GetItemResponse .builder() .item(Map.ofEntries(Map.entry("data", AttributeValue.builder().s("foo").build()))) @@ -261,7 +255,7 @@ public void testGetDataObject_HappyCase() throws IOException { @Test public void testGetDataObject_ComplexDataObject() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).tenantId(TENANT_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).tenantId(TENANT_ID).build(); GetItemResponse getItemResponse = GetItemResponse .builder() .item( @@ -305,7 +299,7 @@ public void testGetDataObject_ComplexDataObject() throws IOException { @Test public void testGetDataObject_NoExistingDoc() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).tenantId(TENANT_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).tenantId(TENANT_ID).build(); GetItemResponse getItemResponse = GetItemResponse.builder().build(); Mockito.when(dynamoDbClient.getItem(Mockito.any(GetItemRequest.class))).thenReturn(getItemResponse); GetDataObjectResponse response = sdkClient @@ -319,7 +313,7 @@ public void testGetDataObject_NoExistingDoc() throws IOException { @Test public void testGetDataObject_UseDefaultTenantIdIfNull() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); GetItemResponse getItemResponse = GetItemResponse.builder().build(); Mockito.when(dynamoDbClient.getItem(Mockito.any(GetItemRequest.class))).thenReturn(getItemResponse); sdkClient.getDataObjectAsync(getRequest, testThreadPool.executor(GENERAL_THREAD_POOL)).toCompletableFuture().join(); @@ -330,7 +324,7 @@ public void testGetDataObject_UseDefaultTenantIdIfNull() throws IOException { @Test public void testGetDataObject_DDBException_ThrowsOSException() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).tenantId(TENANT_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).tenantId(TENANT_ID).build(); Mockito.when(dynamoDbClient.getItem(Mockito.any(GetItemRequest.class))).thenThrow(new RuntimeException("Test exception")); CompletableFuture future = sdkClient .getDataObjectAsync(getRequest, testThreadPool.executor(GENERAL_THREAD_POOL)) @@ -341,11 +335,7 @@ public void testGetDataObject_DDBException_ThrowsOSException() throws IOExceptio @Test public void testDeleteDataObject_HappyCase() throws IOException { - DeleteDataObjectRequest deleteRequest = new DeleteDataObjectRequest.Builder() - .id(TEST_ID) - .index(TEST_INDEX) - .tenantId(TENANT_ID) - .build(); + DeleteDataObjectRequest deleteRequest = DeleteDataObjectRequest.builder().id(TEST_ID).index(TEST_INDEX).tenantId(TENANT_ID).build(); Mockito.when(dynamoDbClient.deleteItem(deleteItemRequestArgumentCaptor.capture())).thenReturn(DeleteItemResponse.builder().build()); DeleteDataObjectResponse deleteResponse = sdkClient .deleteDataObjectAsync(deleteRequest, testThreadPool.executor(GENERAL_THREAD_POOL)) @@ -367,7 +357,7 @@ public void testDeleteDataObject_HappyCase() throws IOException { @Test public void testDeleteDataObject_NullTenantId_UsesDefaultTenantId() { - DeleteDataObjectRequest deleteRequest = new DeleteDataObjectRequest.Builder().id(TEST_ID).index(TEST_INDEX).build(); + DeleteDataObjectRequest deleteRequest = DeleteDataObjectRequest.builder().id(TEST_ID).index(TEST_INDEX).build(); Mockito.when(dynamoDbClient.deleteItem(deleteItemRequestArgumentCaptor.capture())).thenReturn(DeleteItemResponse.builder().build()); sdkClient.deleteDataObjectAsync(deleteRequest, testThreadPool.executor(GENERAL_THREAD_POOL)).toCompletableFuture().join(); DeleteItemRequest deleteItemRequest = deleteItemRequestArgumentCaptor.getValue(); @@ -376,7 +366,8 @@ public void testDeleteDataObject_NullTenantId_UsesDefaultTenantId() { @Test public void updateDataObjectAsync_HappyCase() { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .id(TEST_ID) .index(TEST_INDEX) .tenantId(TENANT_ID) @@ -399,7 +390,8 @@ public void updateDataObjectAsync_HappyCase() { @Test public void updateDataObjectAsync_HappyCaseWithMap() { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .id(TEST_ID) .index(TEST_INDEX) .tenantId(TENANT_ID) @@ -422,7 +414,8 @@ public void updateDataObjectAsync_HappyCaseWithMap() { @Test public void updateDataObjectAsync_NullTenantId_UsesDefaultTenantId() { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .id(TEST_ID) .index(TEST_INDEX) .tenantId(TENANT_ID) @@ -437,7 +430,8 @@ public void updateDataObjectAsync_NullTenantId_UsesDefaultTenantId() { @Test public void searchDataObjectAsync_HappyCase() { SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.searchSource(); - SearchDataObjectRequest searchDataObjectRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchDataObjectRequest = SearchDataObjectRequest + .builder() .indices(TEST_INDEX, TEST_INDEX_2) .tenantId(TENANT_ID) .searchSourceBuilder(searchSourceBuilder) @@ -457,7 +451,8 @@ public void searchDataObjectAsync_HappyCase() { @Test public void searchDataObjectAsync_SystemIndex() { SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.searchSource(); - SearchDataObjectRequest searchDataObjectRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchDataObjectRequest = SearchDataObjectRequest + .builder() .indices(TEST_SYSTEM_INDEX) .tenantId(TENANT_ID) .searchSourceBuilder(searchSourceBuilder) diff --git a/plugin/src/test/java/org/opensearch/ml/sdkclient/LocalClusterIndicesClientTests.java b/plugin/src/test/java/org/opensearch/ml/sdkclient/LocalClusterIndicesClientTests.java index f402b5c102..9d28e61650 100644 --- a/plugin/src/test/java/org/opensearch/ml/sdkclient/LocalClusterIndicesClientTests.java +++ b/plugin/src/test/java/org/opensearch/ml/sdkclient/LocalClusterIndicesClientTests.java @@ -120,7 +120,7 @@ public static void cleanup() { } public void testPutDataObject() throws IOException { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder().index(TEST_INDEX).dataObject(testDataObject).build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).dataObject(testDataObject).build(); IndexResponse indexResponse = new IndexResponse(new ShardId(TEST_INDEX, "_na_", 0), TEST_ID, 1, 0, 2, true); @SuppressWarnings("unchecked") @@ -144,7 +144,7 @@ public void testPutDataObject() throws IOException { } public void testPutDataObject_Exception() throws IOException { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder().index(TEST_INDEX).dataObject(testDataObject).build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).dataObject(testDataObject).build(); when(mockedClient.index(any(IndexRequest.class))).thenThrow(new UnsupportedOperationException("test")); @@ -165,7 +165,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws throw new IOException("test"); } }; - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder().index(TEST_INDEX).dataObject(badDataObject).build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).dataObject(badDataObject).build(); CompletableFuture future = sdkClient .putDataObjectAsync(putRequest, testThreadPool.executor(GENERAL_THREAD_POOL)) @@ -178,7 +178,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } public void testGetDataObject() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); String json = testDataObject.toJson(); GetResponse getResponse = new GetResponse(new GetResult(TEST_INDEX, TEST_ID, -2, 0, 1, true, new BytesArray(json), null, null)); @@ -210,7 +210,7 @@ public void testGetDataObject() throws IOException { } public void testGetDataObject_NullResponse() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); @SuppressWarnings("unchecked") ActionFuture future = mock(ActionFuture.class); @@ -231,7 +231,7 @@ public void testGetDataObject_NullResponse() throws IOException { } public void testGetDataObject_NotFound() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); GetResponse getResponse = new GetResponse(new GetResult(TEST_INDEX, TEST_ID, -2, 0, 1, false, null, null, null)); @SuppressWarnings("unchecked") @@ -253,7 +253,7 @@ public void testGetDataObject_NotFound() throws IOException { } public void testGetDataObject_Exception() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); ArgumentCaptor getRequestCaptor = ArgumentCaptor.forClass(GetRequest.class); when(mockedClient.get(getRequestCaptor.capture())).thenThrow(new UnsupportedOperationException("test")); @@ -269,7 +269,8 @@ public void testGetDataObject_Exception() throws IOException { } public void testUpdateDataObject() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(testDataObject) @@ -309,7 +310,8 @@ public void testUpdateDataObject() throws IOException { } public void testUpdateDataObjectWithMap() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(Map.of("foo", "bar")) @@ -340,7 +342,8 @@ public void testUpdateDataObjectWithMap() throws IOException { } public void testUpdateDataObject_NotFound() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(testDataObject) @@ -380,7 +383,8 @@ public void testUpdateDataObject_NotFound() throws IOException { } public void testUpdateDataObject_Null() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(testDataObject) @@ -404,7 +408,8 @@ public void testUpdateDataObject_Null() throws IOException { } public void testUpdateDataObject_Exception() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(testDataObject) @@ -424,7 +429,7 @@ public void testUpdateDataObject_Exception() throws IOException { } public void testDeleteDataObject() throws IOException { - DeleteDataObjectRequest deleteRequest = new DeleteDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + DeleteDataObjectRequest deleteRequest = DeleteDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); DeleteResponse deleteResponse = new DeleteResponse(new ShardId(TEST_INDEX, "_na_", 0), TEST_ID, 1, 0, 2, true); PlainActionFuture future = PlainActionFuture.newFuture(); @@ -447,7 +452,7 @@ public void testDeleteDataObject() throws IOException { } public void testDeleteDataObject_Exception() throws IOException { - DeleteDataObjectRequest deleteRequest = new DeleteDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + DeleteDataObjectRequest deleteRequest = DeleteDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); ArgumentCaptor deleteRequestCaptor = ArgumentCaptor.forClass(DeleteRequest.class); when(mockedClient.delete(deleteRequestCaptor.capture())).thenThrow(new UnsupportedOperationException("test")); @@ -464,7 +469,8 @@ public void testDeleteDataObject_Exception() throws IOException { public void testSearchDataObject() throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - SearchDataObjectRequest searchRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchRequest = SearchDataObjectRequest + .builder() .indices(TEST_INDEX) .searchSourceBuilder(searchSourceBuilder) .build(); @@ -508,7 +514,8 @@ public void testSearchDataObject() throws IOException { public void testSearchDataObject_Exception() throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - SearchDataObjectRequest searchRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchRequest = SearchDataObjectRequest + .builder() .indices(TEST_INDEX) .searchSourceBuilder(searchSourceBuilder) .build(); diff --git a/plugin/src/test/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClientTests.java b/plugin/src/test/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClientTests.java index 467bc2c137..7dbe7062d6 100644 --- a/plugin/src/test/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClientTests.java +++ b/plugin/src/test/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClientTests.java @@ -126,7 +126,7 @@ public static void cleanup() { } public void testPutDataObject() throws IOException { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder().index(TEST_INDEX).dataObject(testDataObject).build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).dataObject(testDataObject).build(); IndexResponse indexResponse = new IndexResponse.Builder() .id(TEST_ID) @@ -159,7 +159,7 @@ public void testPutDataObject() throws IOException { } public void testPutDataObject_Updated() throws IOException { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder().index(TEST_INDEX).dataObject(testDataObject).build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).dataObject(testDataObject).build(); IndexResponse indexResponse = new IndexResponse.Builder() .id(TEST_ID) @@ -192,7 +192,7 @@ public void testPutDataObject_Updated() throws IOException { } public void testPutDataObject_Exception() throws IOException { - PutDataObjectRequest putRequest = new PutDataObjectRequest.Builder().index(TEST_INDEX).dataObject(testDataObject).build(); + PutDataObjectRequest putRequest = PutDataObjectRequest.builder().index(TEST_INDEX).dataObject(testDataObject).build(); ArgumentCaptor> indexRequestCaptor = ArgumentCaptor.forClass(IndexRequest.class); when(mockedOpenSearchClient.index(indexRequestCaptor.capture())).thenThrow(new IOException("test")); @@ -207,7 +207,7 @@ public void testPutDataObject_Exception() throws IOException { @SuppressWarnings({ "unchecked", "rawtypes" }) public void testGetDataObject() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); GetResponse getResponse = new GetResponse.Builder<>() .index(TEST_INDEX) @@ -242,7 +242,7 @@ public void testGetDataObject() throws IOException { @SuppressWarnings({ "unchecked", "rawtypes" }) public void testGetDataObject_NotFound() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); GetResponse getResponse = new GetResponse.Builder<>().index(TEST_INDEX).id(TEST_ID).found(false).build(); @@ -263,7 +263,7 @@ public void testGetDataObject_NotFound() throws IOException { @SuppressWarnings({ "unchecked", "rawtypes" }) public void testGetDataObject_Exception() throws IOException { - GetDataObjectRequest getRequest = new GetDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + GetDataObjectRequest getRequest = GetDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); ArgumentCaptor getRequestCaptor = ArgumentCaptor.forClass(GetRequest.class); ArgumentCaptor> mapClassCaptor = ArgumentCaptor.forClass(Class.class); @@ -278,7 +278,8 @@ public void testGetDataObject_Exception() throws IOException { } public void testUpdateDataObject() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(testDataObject) @@ -316,7 +317,8 @@ public void testUpdateDataObject() throws IOException { } public void testUpdateDataObjectWithMap() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(Map.of("foo", "bar")) @@ -344,7 +346,8 @@ public void testUpdateDataObjectWithMap() throws IOException { } public void testUpdateDataObject_NotFound() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(testDataObject) @@ -382,7 +385,8 @@ public void testUpdateDataObject_NotFound() throws IOException { } public void testtUpdateDataObject_Exception() throws IOException { - UpdateDataObjectRequest updateRequest = new UpdateDataObjectRequest.Builder() + UpdateDataObjectRequest updateRequest = UpdateDataObjectRequest + .builder() .index(TEST_INDEX) .id(TEST_ID) .dataObject(testDataObject) @@ -400,7 +404,7 @@ public void testtUpdateDataObject_Exception() throws IOException { } public void testDeleteDataObject() throws IOException { - DeleteDataObjectRequest deleteRequest = new DeleteDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + DeleteDataObjectRequest deleteRequest = DeleteDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); DeleteResponse deleteResponse = new DeleteResponse.Builder() .id(TEST_ID) @@ -433,7 +437,7 @@ public void testDeleteDataObject() throws IOException { } public void testDeleteDataObject_NotFound() throws IOException { - DeleteDataObjectRequest deleteRequest = new DeleteDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + DeleteDataObjectRequest deleteRequest = DeleteDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); DeleteResponse deleteResponse = new DeleteResponse.Builder() .id(TEST_ID) @@ -463,7 +467,7 @@ public void testDeleteDataObject_NotFound() throws IOException { } public void testDeleteDataObject_Exception() throws IOException { - DeleteDataObjectRequest deleteRequest = new DeleteDataObjectRequest.Builder().index(TEST_INDEX).id(TEST_ID).build(); + DeleteDataObjectRequest deleteRequest = DeleteDataObjectRequest.builder().index(TEST_INDEX).id(TEST_ID).build(); ArgumentCaptor deleteRequestCaptor = ArgumentCaptor.forClass(DeleteRequest.class); when(mockedOpenSearchClient.delete(deleteRequestCaptor.capture())).thenThrow(new IOException("test")); @@ -479,7 +483,8 @@ public void testDeleteDataObject_Exception() throws IOException { @SuppressWarnings({ "unchecked", "rawtypes" }) public void testSearchDataObject() throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - SearchDataObjectRequest searchRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchRequest = SearchDataObjectRequest + .builder() .indices(TEST_INDEX) .searchSourceBuilder(searchSourceBuilder) .build(); @@ -515,7 +520,8 @@ public void testSearchDataObject() throws IOException { public void testSearchDataObject_Exception() throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - SearchDataObjectRequest searchRequest = new SearchDataObjectRequest.Builder() + SearchDataObjectRequest searchRequest = SearchDataObjectRequest + .builder() .indices(TEST_INDEX) .searchSourceBuilder(searchSourceBuilder) .build();