From 38867a700ca361d67c43f28f265d6f3ae3562365 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Tue, 12 Mar 2024 14:47:44 -0400 Subject: [PATCH] Suppress [removal] AccessController in java.security has been deprecated and marked for removal Signed-off-by: Andriy Redko --- .../java/org/opensearch/ml/common/MLCommonsClassLoader.java | 1 + .../java/org/opensearch/ml/common/connector/Connector.java | 1 + .../org/opensearch/ml/common/output/model/ModelTensor.java | 1 + .../main/java/org/opensearch/ml/common/utils/StringUtils.java | 3 +++ .../java/org/opensearch/ml/engine/MLEngineClassLoader.java | 1 + .../src/main/java/org/opensearch/ml/engine/ModelHelper.java | 3 +++ .../main/java/org/opensearch/ml/engine/algorithms/DLModel.java | 2 ++ .../org/opensearch/ml/engine/algorithms/DLModelExecute.java | 1 + .../org/opensearch/ml/engine/algorithms/agent/AgentUtils.java | 1 + .../opensearch/ml/engine/algorithms/agent/MLAgentExecutor.java | 1 + .../algorithms/agent/MLConversationalFlowAgentRunner.java | 1 + .../ml/engine/algorithms/agent/MLFlowAgentRunner.java | 1 + .../opensearch/ml/engine/algorithms/rcf/RCFModelSerDeSer.java | 3 +++ .../ml/engine/algorithms/remote/AwsConnectorExecutor.java | 1 + .../ml/engine/algorithms/remote/HttpJsonConnectorExecutor.java | 1 + .../main/java/org/opensearch/ml/engine/utils/FileUtils.java | 1 + .../java/org/opensearch/ml/breaker/DiskCircuitBreaker.java | 1 + .../src/main/java/org/opensearch/ml/utils/RestActionUtils.java | 1 + 18 files changed, 25 insertions(+) diff --git a/common/src/main/java/org/opensearch/ml/common/MLCommonsClassLoader.java b/common/src/main/java/org/opensearch/ml/common/MLCommonsClassLoader.java index 7fbb788e4f..75046e9bfd 100644 --- a/common/src/main/java/org/opensearch/ml/common/MLCommonsClassLoader.java +++ b/common/src/main/java/org/opensearch/ml/common/MLCommonsClassLoader.java @@ -30,6 +30,7 @@ import java.util.Set; @Log4j2 +@SuppressWarnings("removal") public class MLCommonsClassLoader { private static Map, Class> parameterClassMap = new HashMap<>(); diff --git a/common/src/main/java/org/opensearch/ml/common/connector/Connector.java b/common/src/main/java/org/opensearch/ml/common/connector/Connector.java index c6d6a1875f..e74a453dc9 100644 --- a/common/src/main/java/org/opensearch/ml/common/connector/Connector.java +++ b/common/src/main/java/org/opensearch/ml/common/connector/Connector.java @@ -110,6 +110,7 @@ static Connector createConnector(XContentBuilder builder, String connectorProtoc } } + @SuppressWarnings("removal") static Connector createConnector(XContentParser parser) throws IOException { Map connectorMap = parser.map(); String jsonStr; diff --git a/common/src/main/java/org/opensearch/ml/common/output/model/ModelTensor.java b/common/src/main/java/org/opensearch/ml/common/output/model/ModelTensor.java index a30336dced..d90294536c 100644 --- a/common/src/main/java/org/opensearch/ml/common/output/model/ModelTensor.java +++ b/common/src/main/java/org/opensearch/ml/common/output/model/ModelTensor.java @@ -229,6 +229,7 @@ public ModelTensor(StreamInput in) throws IOException { } } + @SuppressWarnings("removal") @Override public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(name); diff --git a/common/src/main/java/org/opensearch/ml/common/utils/StringUtils.java b/common/src/main/java/org/opensearch/ml/common/utils/StringUtils.java index cd58292672..8e692ef2fa 100644 --- a/common/src/main/java/org/opensearch/ml/common/utils/StringUtils.java +++ b/common/src/main/java/org/opensearch/ml/common/utils/StringUtils.java @@ -94,6 +94,7 @@ public static Map fromJson(String jsonStr, String defaultKey) { return result; } + @SuppressWarnings("removal") public static Map getParameterMap(Map parameterObjs) { Map parameters = new HashMap<>(); for (String key : parameterObjs.keySet()) { @@ -114,6 +115,7 @@ public static Map getParameterMap(Map parameterObjs) return parameters; } + @SuppressWarnings("removal") public static String toJson(Object value) { try { return AccessController.doPrivileged((PrivilegedExceptionAction) () -> { @@ -128,6 +130,7 @@ public static String toJson(Object value) { } } + @SuppressWarnings("removal") public static Map convertScriptStringToJsonString(Map processedInput) { Map parameterStringMap = new HashMap<>(); try { diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngineClassLoader.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngineClassLoader.java index 4a2c074235..9add9a4f9e 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngineClassLoader.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngineClassLoader.java @@ -22,6 +22,7 @@ import org.opensearch.ml.engine.annotation.Function; import org.reflections.Reflections; +@SuppressWarnings("removal") public class MLEngineClassLoader { private static final Logger logger = LogManager.getLogger(MLEngineClassLoader.class); diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java index 1f606bcaa4..64867554cb 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java @@ -55,6 +55,7 @@ public ModelHelper(MLEngine mlEngine) { this.mlEngine = mlEngine; } + @SuppressWarnings("removal") public void downloadPrebuiltModelConfig( String taskId, MLRegisterModelInput registerModelInput, @@ -182,6 +183,7 @@ public boolean isModelAllowed(MLRegisterModelInput registerModelInput, List mode return false; } + @SuppressWarnings("removal") public List downloadPrebuiltModelMetaList(String taskId, MLRegisterModelInput registerModelInput) throws PrivilegedActionException { String modelName = registerModelInput.getModelName(); String version = registerModelInput.getVersion(); @@ -215,6 +217,7 @@ public List downloadPrebuiltModelMetaList(String taskId, MLRegisterModelInput re * @param modelContentHash model content hash value * @param listener action listener */ + @SuppressWarnings("removal") public void downloadAndSplit( MLModelFormat modelFormat, String taskId, diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/DLModel.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/DLModel.java index e5db51324f..546a01b386 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/DLModel.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/DLModel.java @@ -74,6 +74,7 @@ public MLOutput predict(MLInput mlInput, MLModel model) { throw new IllegalArgumentException("model not deployed"); } + @SuppressWarnings("removal") @Override public MLOutput predict(MLInput mlInput) { if (modelHelper == null || modelId == null) { @@ -233,6 +234,7 @@ protected void doLoadModel( log.info("Model {} is successfully deployed on {} devices", modelId, devices.length); } + @SuppressWarnings("removal") protected void loadModel( File modelZipFile, String modelId, diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/DLModelExecute.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/DLModelExecute.java index 0ae0c44dc7..d2d0824a4d 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/DLModelExecute.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/DLModelExecute.java @@ -122,6 +122,7 @@ public void close() { * @param version version of the model * @param engine engine where model will be run. For now, we are supporting only pytorch engine only. */ + @SuppressWarnings("removal") private void loadModel(File modelZipFile, String modelId, String modelName, String version, String engine) { try { List> predictorList = new ArrayList<>(); diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java index 513d177558..cfd0ddb636 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java @@ -356,6 +356,7 @@ public static String findMatchedPart(String text, List patternList) { return null; } + @SuppressWarnings("removal") public static String outputToOutputString(Object output) throws PrivilegedActionException { String outputString; if (output instanceof ModelTensorOutput) { diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLAgentExecutor.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLAgentExecutor.java index 8b7cf10ef9..715ea94348 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLAgentExecutor.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLAgentExecutor.java @@ -229,6 +229,7 @@ private void executeAgent(RemoteInferenceInputDataSet inputDataSet, MLAgent mlAg mlAgentRunner.run(mlAgent, inputDataSet.getParameters(), agentActionListener); } + @SuppressWarnings("removal") private ActionListener createAgentActionListener( ActionListener listener, List outputs, diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLConversationalFlowAgentRunner.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLConversationalFlowAgentRunner.java index 6f374e0bb8..672890c030 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLConversationalFlowAgentRunner.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLConversationalFlowAgentRunner.java @@ -232,6 +232,7 @@ private void runAgent( } } + @SuppressWarnings("removal") private void processOutput( Map params, ActionListener listener, diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLFlowAgentRunner.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLFlowAgentRunner.java index 7126cd45be..38ad680d99 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLFlowAgentRunner.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLFlowAgentRunner.java @@ -73,6 +73,7 @@ public MLFlowAgentRunner( this.memoryFactoryMap = memoryFactoryMap; } + @SuppressWarnings("removal") @Override public void run(MLAgent mlAgent, Map params, ActionListener listener) { List toolSpecs = getMlToolSpecs(mlAgent, params); diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/rcf/RCFModelSerDeSer.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/rcf/RCFModelSerDeSer.java index a100fcafd3..7cabdbea8d 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/rcf/RCFModelSerDeSer.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/rcf/RCFModelSerDeSer.java @@ -22,6 +22,7 @@ import lombok.experimental.UtilityClass; @UtilityClass +@SuppressWarnings("removal") public class RCFModelSerDeSer { private static final int SERIALIZATION_BUFFER_BYTES = 512; private static final Schema rcfSchema = AccessController @@ -55,12 +56,14 @@ public static ThresholdedRandomCutForestState deserializeTRCF(byte[] bytes) { return deserialize(bytes, trcfSchema); } + @SuppressWarnings("removal") private static byte[] serialize(T model, Schema schema) { LinkedBuffer buffer = LinkedBuffer.allocate(SERIALIZATION_BUFFER_BYTES); byte[] bytes = AccessController.doPrivileged((PrivilegedAction) () -> ProtostuffIOUtil.toByteArray(model, schema, buffer)); return bytes; } + @SuppressWarnings("removal") private static T deserialize(byte[] bytes, Schema schema) { T model = schema.newMessage(); AccessController.doPrivileged((PrivilegedAction) () -> { diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/AwsConnectorExecutor.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/AwsConnectorExecutor.java index f06450278d..49f651eadb 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/AwsConnectorExecutor.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/AwsConnectorExecutor.java @@ -100,6 +100,7 @@ public AwsConnectorExecutor(Connector connector) { } } + @SuppressWarnings("removal") @Override public void invokeRemoteModel(MLInput mlInput, Map parameters, String payload, List tensorOutputs) { try { diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/HttpJsonConnectorExecutor.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/HttpJsonConnectorExecutor.java index b1ef5b500c..1c7b2eaf36 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/HttpJsonConnectorExecutor.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/HttpJsonConnectorExecutor.java @@ -79,6 +79,7 @@ public HttpJsonConnectorExecutor(Connector connector, CloseableHttpClient httpCl this.httpClient = httpClient; } + @SuppressWarnings("removal") @Override public void invokeRemoteModel(MLInput mlInput, Map parameters, String payload, List tensorOutputs) { try { diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/utils/FileUtils.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/utils/FileUtils.java index ef92bade9d..677ca1aa9d 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/utils/FileUtils.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/utils/FileUtils.java @@ -153,6 +153,7 @@ public static void deleteFileQuietly(Path path) { deleteFileQuietly(new File(path.toUri())); } + @SuppressWarnings("removal") public static void deleteFileQuietly(File file) { if (file.exists()) { AccessController.doPrivileged((PrivilegedAction) () -> { diff --git a/plugin/src/main/java/org/opensearch/ml/breaker/DiskCircuitBreaker.java b/plugin/src/main/java/org/opensearch/ml/breaker/DiskCircuitBreaker.java index ab059b7c65..2b5dd6e060 100644 --- a/plugin/src/main/java/org/opensearch/ml/breaker/DiskCircuitBreaker.java +++ b/plugin/src/main/java/org/opensearch/ml/breaker/DiskCircuitBreaker.java @@ -37,6 +37,7 @@ public String getName() { return ML_DISK_CB; } + @SuppressWarnings("removal") @Override public boolean isOpen() { try { diff --git a/plugin/src/main/java/org/opensearch/ml/utils/RestActionUtils.java b/plugin/src/main/java/org/opensearch/ml/utils/RestActionUtils.java index 3517d31782..50665026f0 100644 --- a/plugin/src/main/java/org/opensearch/ml/utils/RestActionUtils.java +++ b/plugin/src/main/java/org/opensearch/ml/utils/RestActionUtils.java @@ -225,6 +225,7 @@ public static User getUserContext(Client client) { } // TODO: Integration test needs to be added (MUST) + @SuppressWarnings("removal") public static boolean isSuperAdminUser(ClusterService clusterService, Client client) { final List adminDnsA = clusterService.getSettings().getAsList(SECURITY_AUTHCZ_ADMIN_DN, Collections.emptyList());