diff --git a/common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorResponseTest.java b/common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorResponseTest.java index 4a829d16f7..b24119a6c7 100644 --- a/common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorResponseTest.java +++ b/common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorResponseTest.java @@ -11,9 +11,13 @@ import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.ml.common.AccessMode; import org.opensearch.ml.common.TestHelper; import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; public class MLCreateConnectorResponseTest { @@ -35,4 +39,23 @@ public void readFromStream() throws IOException { MLCreateConnectorResponse response2 = new MLCreateConnectorResponse(output.bytes().streamInput()); Assert.assertEquals("test_id", response2.getConnectorId()); } + + @Test + public void t() throws IOException { + MLCreateConnectorInput input = MLCreateConnectorInput.builder() + .name("test_connector_name") + .description("this is a test connector") + .version("1") + .protocol("http") + .parameters(Map.of("input", "test input value")) + .credential(Map.of("key", "test_key_value")) + .access(AccessMode.PUBLIC) + .addAllBackendRoles(true) + .backendRoles(Arrays.asList("r1")) + .build(); + BytesStreamOutput output = new BytesStreamOutput(); + input.writeTo(output); + MLCreateConnectorInput input2 = new MLCreateConnectorInput(output.bytes().streamInput()); + Assert.assertNotNull(input2); + } } diff --git a/ml-algorithms/build.gradle b/ml-algorithms/build.gradle index 7b66b4e00e..8c6a9ca0db 100644 --- a/ml-algorithms/build.gradle +++ b/ml-algorithms/build.gradle @@ -64,7 +64,6 @@ dependencies { implementation 'com.amazonaws:aws-encryption-sdk-java:2.4.0' implementation 'com.jayway.jsonpath:json-path:2.8.0' implementation group: 'org.json', name: 'json', version: '20230227' - implementation group: 'org.yaml', name: 'snakeyaml', version: '2.0' } configurations.all { diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngine.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngine.java index 41f6d794c9..a273a6bead 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngine.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngine.java @@ -5,9 +5,6 @@ package org.opensearch.ml.engine; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.stream.JsonReader; import lombok.Getter; import lombok.extern.log4j.Log4j2; import org.opensearch.ml.common.FunctionName; @@ -15,7 +12,6 @@ import org.opensearch.ml.common.dataframe.DataFrame; import org.opensearch.ml.common.dataset.DataFrameInputDataset; import org.opensearch.ml.common.dataset.MLInputDataset; -import org.opensearch.ml.common.exception.MLException; import org.opensearch.ml.common.input.Input; import org.opensearch.ml.common.input.parameter.MLAlgoParams; import org.opensearch.ml.common.input.MLInput; @@ -23,25 +19,10 @@ import org.opensearch.ml.common.output.MLOutput; import org.opensearch.ml.common.output.Output; import org.opensearch.ml.engine.encryptor.Encryptor; -import org.opensearch.ml.engine.encryptor.EncryptorImpl; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; - -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.nio.file.Files; import java.nio.file.Path; -import java.security.AccessController; -import java.security.PrivilegedExceptionAction; -import java.security.SecureRandom; -import java.util.Base64; -import java.util.HashMap; import java.util.Locale; import java.util.Map; -import static org.opensearch.ml.common.CommonValue.MASTER_KEY; - /** * This is the interface to all ml algorithms. */ @@ -68,33 +49,6 @@ public MLEngine(Path opensearchDataFolder, Path opensearchConfigFolder, Encrypto this.mlUserConfigPath = opensearchConfigFolder.resolve("opensearch-ml"); this.mlConfigPath = mlCachePath.resolve("config"); this.encryptor = encryptor; - initMasterKey(); - } - - private synchronized void initMasterKey() { - try { - AccessController.doPrivileged((PrivilegedExceptionAction) () -> { - Path userConfigFilePath = mlUserConfigPath.resolve("security_config.json"); - Map config = null; - if (Files.exists(userConfigFilePath)) { - try (FileInputStream fis = new FileInputStream(userConfigFilePath.toFile());) { - Yaml yaml = new Yaml(); - config = yaml.load(fis); - } - } - if (config == null) { - config = new HashMap<>(); - } - - if (config.containsKey(MASTER_KEY)) { - encryptor.setMasterKey(config.get(MASTER_KEY)); - } - return null; - }); - } catch (Exception e) { - log.error("Failed to save master key", e); - throw new MLException(e); - } } public String getPrebuiltModelMetaListPath() {