From 9d61f2403afb6ea6b16b17f9bf9f0e8457cd4779 Mon Sep 17 00:00:00 2001 From: Mattia Dal Ben Date: Wed, 18 May 2022 08:43:38 +0200 Subject: [PATCH 1/7] feat: improve decrypted model directory creation Signed-off-by: Mattia Dal Ben --- .../kura/ai/triton/server/TritonServerEncryptionUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtils.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtils.java index 6e1f991aa5a..519cc88045b 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtils.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtils.java @@ -25,6 +25,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; import java.security.Security; import java.util.Arrays; import java.util.HashSet; @@ -76,11 +77,9 @@ protected static void createDecryptionFolder(String folderPath) throws IOExcepti logger.debug("Creating decryption folder at path: {}", folderPath); - Files.createDirectories(targetFolderPath); - Set permissions = new HashSet<>(Arrays.asList(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE)); - Files.setPosixFilePermissions(targetFolderPath, permissions); + Files.createDirectories(targetFolderPath, PosixFilePermissions.asFileAttribute(permissions)); } protected static void decryptModel(String password, String inputFilePath, String outputFilePath) From 45ea9ab408210b46694e1172e895c3018cdbb726 Mon Sep 17 00:00:00 2001 From: Mattia Dal Ben Date: Wed, 18 May 2022 09:11:41 +0200 Subject: [PATCH 2/7] feat(EncryptionUtils): use createTempDirectory for decryption dir Signed-off-by: Mattia Dal Ben --- .../server/TritonServerEncryptionUtils.java | 17 ++++----- .../TritonServerEncryptionUtilsTest.java | 36 +++++-------------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtils.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtils.java index 519cc88045b..3b4df08b6fe 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtils.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtils.java @@ -68,18 +68,15 @@ protected static String getEncryptedModelPath(String modelName, String folderPat return files[0].toString(); } - protected static void createDecryptionFolder(String folderPath) throws IOException { - Path targetFolderPath = Paths.get(folderPath); - - if (Files.exists(targetFolderPath)) { - throw new IOException("Target path " + targetFolderPath.toString() + " already exists"); - } - - logger.debug("Creating decryption folder at path: {}", folderPath); - + protected static String createDecryptionFolder(String prefix) throws IOException { Set permissions = new HashSet<>(Arrays.asList(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE)); - Files.createDirectories(targetFolderPath, PosixFilePermissions.asFileAttribute(permissions)); + Path tempFolderPath = Files.createTempDirectory(prefix, PosixFilePermissions.asFileAttribute(permissions)); + // TODO shutdown hook tempFolderPath.toFile().deleteOnExit(); + + logger.debug("Created temporary directory at path {}", tempFolderPath); + + return tempFolderPath.toString(); } protected static void decryptModel(String password, String inputFilePath, String outputFilePath) diff --git a/kura/test/org.eclipse.kura.ai.triton.server.test/src/test/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtilsTest.java b/kura/test/org.eclipse.kura.ai.triton.server.test/src/test/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtilsTest.java index d468d486747..abb51a31b06 100644 --- a/kura/test/org.eclipse.kura.ai.triton.server.test/src/test/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtilsTest.java +++ b/kura/test/org.eclipse.kura.ai.triton.server.test/src/test/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtilsTest.java @@ -38,8 +38,9 @@ public class TritonServerEncryptionUtilsTest { - private static final String WORKDIR = System.getProperty("java.io.tmpdir") + "/decr_folder"; + private static final String WORKDIR = System.getProperty("java.io.tmpdir") + "decr_folder"; private boolean exceptionOccurred = false; + private String tempDirectoryPrefix; private String targetFolder; private String modelName; private String expectedEncryptedModelPath; @@ -114,38 +115,15 @@ public void getEncryptedModelPathShouldThrowIfMultipleMatchesFound() { @Test public void createDecryptionFolderShouldWork() { - givenTargetFolder(WORKDIR + "/target_folder"); - givenNoFileExistsAtPath(targetFolder); - - whenCreateDecryptionFolderIsCalledWith(targetFolder); - - thenAFolderExistsAtPath(targetFolder); - thenTargetFolderHasPermissions(targetFolder, "rwx------"); - thenNoExceptionOccurred(); - } - - @Test - public void createDecryptionFolderShouldWorkWithNestedPath() { - givenTargetFolder(WORKDIR + "/new/nested/folder"); - givenNoFileExistsAtPath(targetFolder); + givenTempDirectoryPrefix("prefix"); - whenCreateDecryptionFolderIsCalledWith(targetFolder); + whenCreateDecryptionFolderIsCalledWith(tempDirectoryPrefix); thenAFolderExistsAtPath(targetFolder); thenTargetFolderHasPermissions(targetFolder, "rwx------"); thenNoExceptionOccurred(); } - @Test - public void createDecryptionFolderShouldThrowOnNameClashes() { - givenTargetFolder(WORKDIR + "/another_folder"); - givenAFileAreadyExistsAtPath(targetFolder); - - whenCreateDecryptionFolderIsCalledWith(targetFolder); - - thenAnExceptionOccurred(); - } - @Test public void decryptModelShouldWork() { givenEncryptedFileAtPath("target/test-classes/plain_file.gpg"); @@ -328,6 +306,10 @@ private void givenExpectedModelPath(String modelPath) { this.expectedEncryptedModelPath = modelPath; } + private void givenTempDirectoryPrefix(String prefix) { + this.tempDirectoryPrefix = prefix; + } + private void givenTargetFolder(String folderPath) { this.targetFolder = folderPath; } @@ -411,7 +393,7 @@ private void whenGetEncryptedModelPathIsCalledWith(String modelName, String fold private void whenCreateDecryptionFolderIsCalledWith(String folderPath) { try { - TritonServerEncryptionUtils.createDecryptionFolder(folderPath); + this.targetFolder = TritonServerEncryptionUtils.createDecryptionFolder(folderPath); } catch (IOException e) { e.printStackTrace(); this.exceptionOccurred = true; From 4a5e12e9b8d7bc8bc334c81606636496d8be5fe2 Mon Sep 17 00:00:00 2001 From: Mattia Dal Ben Date: Wed, 18 May 2022 09:40:07 +0200 Subject: [PATCH 3/7] feat(EncryptionUtils): dynamic decrypted model folder Signed-off-by: Mattia Dal Ben --- .../server/TritonServerLocalManager.java | 6 ++- .../server/TritonServerServiceImpl.java | 42 ++++++++++--------- .../server/TritonServerServiceOptions.java | 2 - 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerLocalManager.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerLocalManager.java index a4e930ed737..f38d84c79e9 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerLocalManager.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerLocalManager.java @@ -36,6 +36,7 @@ public class TritonServerLocalManager { private static final int MONITOR_PERIOD = 30; private static final String[] TRITONSERVER = new String[] { "tritonserver" }; + private final String decryptionFolderPath; private final CommandExecutorService commandExecutorService; private final TritonServerServiceOptions options; private Command serverCommand; @@ -44,9 +45,10 @@ public class TritonServerLocalManager { private ScheduledFuture scheduledFuture; protected TritonServerLocalManager(TritonServerServiceOptions options, - CommandExecutorService commandExecutorService) { + CommandExecutorService commandExecutorService, String decryptionFolderPath) { this.options = options; this.commandExecutorService = commandExecutorService; + this.decryptionFolderPath = decryptionFolderPath; this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); } @@ -138,7 +140,7 @@ private Command createServerCommand() { List commandString = new ArrayList<>(); commandString.add("tritonserver"); if (!this.options.getModelRepositoryPassword().isEmpty()) { - commandString.add("--model-repository=" + TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH); + commandString.add("--model-repository=" + this.decryptionFolderPath); } else { commandString.add("--model-repository=" + this.options.getModelRepositoryPath()); } diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java index b8d168b3a3a..e5251b1894a 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java @@ -23,7 +23,6 @@ import java.nio.IntBuffer; import java.nio.LongBuffer; import java.nio.ShortBuffer; -import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; @@ -75,6 +74,7 @@ public class TritonServerServiceImpl implements InferenceEngineService, ConfigurableComponent { private static final Logger logger = LoggerFactory.getLogger(TritonServerServiceImpl.class); + private static final String TEMP_DIRECTORY_PREFIX = "decrypted_models"; private CommandExecutorService commandExecutorService; private CryptoService cryptoService; @@ -83,6 +83,7 @@ public class TritonServerServiceImpl implements InferenceEngineService, Configur private ManagedChannel grpcChannel; private GRPCInferenceServiceBlockingStub grpcStub; + private String decryptionFolderPath = ""; public void setCommandExecutorService(CommandExecutorService executorService) { this.commandExecutorService = executorService; @@ -98,18 +99,18 @@ protected void activate(Map properties) { if (isConfigurationValid()) { setGrpcResources(); if (this.options.isLocalEnabled()) { - if (!this.options.getModelRepositoryPassword().isEmpty() - && !Files.isDirectory(Paths.get(TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH))) { - logger.info("Creating decryption model directory at {}", - TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH); + if (!this.options.getModelRepositoryPassword().isEmpty()) { try { - TritonServerEncryptionUtils - .createDecryptionFolder(TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH); + decryptionFolderPath = TritonServerEncryptionUtils + .createDecryptionFolder(TEMP_DIRECTORY_PREFIX); } catch (IOException e) { logger.warn("Failed to create decryption model directory", e); } + + logger.info("Creating decryption model directory at {}", decryptionFolderPath); } - this.tritonServerLocalManager = new TritonServerLocalManager(this.options, this.commandExecutorService); + this.tritonServerLocalManager = new TritonServerLocalManager(this.options, this.commandExecutorService, + this.decryptionFolderPath); this.tritonServerLocalManager.start(); } loadModels(); @@ -127,18 +128,18 @@ public void updated(Map properties) { if (isConfigurationValid()) { setGrpcResources(); if (this.options.isLocalEnabled()) { - if (!this.options.getModelRepositoryPassword().isEmpty() - && !Files.isDirectory(Paths.get(TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH))) { - logger.info("Creating decryption model directory at {}", - TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH); + if (!this.options.getModelRepositoryPassword().isEmpty()) { try { - TritonServerEncryptionUtils - .createDecryptionFolder(TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH); + decryptionFolderPath = TritonServerEncryptionUtils + .createDecryptionFolder(TEMP_DIRECTORY_PREFIX); } catch (IOException e) { logger.warn("Failed to create decryption model directory", e); } + + logger.info("Created decryption model directory at {}", decryptionFolderPath); } - this.tritonServerLocalManager = new TritonServerLocalManager(this.options, this.commandExecutorService); + this.tritonServerLocalManager = new TritonServerLocalManager(this.options, this.commandExecutorService, + this.decryptionFolderPath); this.tritonServerLocalManager.start(); } else { this.tritonServerLocalManager = null; @@ -209,14 +210,13 @@ public void loadModel(String modelName, Optional modelPath) throws KuraE String plainPassword = String.valueOf(cryptoService.decryptAes(password.toCharArray())); String encryptedModelPath = TritonServerEncryptionUtils.getEncryptedModelPath(modelName, this.options.getModelRepositoryPath()); - String decryptedModelPath = TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH + modelName + ".zip"; + String decryptedModelPath = Paths.get(decryptionFolderPath, modelName + ".zip").toString(); logger.info("Model decryption password detected. Decrypting model {} at {} into {}", modelName, encryptedModelPath, decryptedModelPath); try { TritonServerEncryptionUtils.decryptModel(plainPassword, encryptedModelPath, decryptedModelPath); - TritonServerEncryptionUtils.unzipModel(decryptedModelPath, - TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH); + TritonServerEncryptionUtils.unzipModel(decryptedModelPath, decryptionFolderPath); } catch (KuraIOException | IOException e) { throw new KuraIOException(e, "Cannot decrypt the model " + modelName); } @@ -227,7 +227,9 @@ public void loadModel(String modelName, Optional modelPath) throws KuraE try { this.grpcStub.repositoryModelLoad(builder.build()); } catch (StatusRuntimeException e) { - TritonServerEncryptionUtils.cleanRepository(TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH); + if (!password.isEmpty() && !decryptionFolderPath.isEmpty()) { + TritonServerEncryptionUtils.cleanRepository(decryptionFolderPath); + } throw new KuraIOException(e, "Cannot load the model " + modelName); } @@ -240,7 +242,7 @@ public void loadModel(String modelName, Optional modelPath) throws KuraE } TritonServerLocalManager.sleepFor(250); } - TritonServerEncryptionUtils.cleanRepository(TritonServerServiceOptions.DECRYPTED_MODELS_REPO_PATH); + TritonServerEncryptionUtils.cleanRepository(decryptionFolderPath); } } diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java index 2890b8d5bf9..dab81a92542 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java @@ -26,8 +26,6 @@ public class TritonServerServiceOptions { - public static final String DECRYPTED_MODELS_REPO_PATH = "/tmp/decrypted_models/"; - private static final String PROPERTY_ADDRESS = "server.address"; private static final String PROPERTY_PORTS = "server.ports"; private static final String PROPERTY_LOCAL_MODEL_REPOSITORY_PATH = "local.model.repository.path"; From c16cd8b3e836e5db45e77c3a66cb9d22b6a2c40b Mon Sep 17 00:00:00 2001 From: Mattia Dal Ben Date: Wed, 18 May 2022 10:09:19 +0200 Subject: [PATCH 4/7] refactor: create startLocalInstance method Signed-off-by: Mattia Dal Ben --- .../server/TritonServerServiceImpl.java | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java index e5251b1894a..3ae2b8dda12 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java @@ -99,19 +99,7 @@ protected void activate(Map properties) { if (isConfigurationValid()) { setGrpcResources(); if (this.options.isLocalEnabled()) { - if (!this.options.getModelRepositoryPassword().isEmpty()) { - try { - decryptionFolderPath = TritonServerEncryptionUtils - .createDecryptionFolder(TEMP_DIRECTORY_PREFIX); - } catch (IOException e) { - logger.warn("Failed to create decryption model directory", e); - } - - logger.info("Creating decryption model directory at {}", decryptionFolderPath); - } - this.tritonServerLocalManager = new TritonServerLocalManager(this.options, this.commandExecutorService, - this.decryptionFolderPath); - this.tritonServerLocalManager.start(); + startLocalInstance(); } loadModels(); } else { @@ -128,19 +116,7 @@ public void updated(Map properties) { if (isConfigurationValid()) { setGrpcResources(); if (this.options.isLocalEnabled()) { - if (!this.options.getModelRepositoryPassword().isEmpty()) { - try { - decryptionFolderPath = TritonServerEncryptionUtils - .createDecryptionFolder(TEMP_DIRECTORY_PREFIX); - } catch (IOException e) { - logger.warn("Failed to create decryption model directory", e); - } - - logger.info("Created decryption model directory at {}", decryptionFolderPath); - } - this.tritonServerLocalManager = new TritonServerLocalManager(this.options, this.commandExecutorService, - this.decryptionFolderPath); - this.tritonServerLocalManager.start(); + startLocalInstance(); } else { this.tritonServerLocalManager = null; } @@ -150,6 +126,21 @@ public void updated(Map properties) { } } + private void startLocalInstance() { + if (!this.options.getModelRepositoryPassword().isEmpty()) { + try { + decryptionFolderPath = TritonServerEncryptionUtils.createDecryptionFolder(TEMP_DIRECTORY_PREFIX); + } catch (IOException e) { + logger.warn("Failed to create decryption model directory", e); + } + + logger.info("Created decryption model directory at {}", decryptionFolderPath); + } + this.tritonServerLocalManager = new TritonServerLocalManager(this.options, this.commandExecutorService, + this.decryptionFolderPath); + this.tritonServerLocalManager.start(); + } + protected void deactivate() { logger.info("Deactivate TritonServerService..."); if (nonNull(this.tritonServerLocalManager)) { From 46b6b9cb95e130e1916aa6b1d63622b309f5c3aa Mon Sep 17 00:00:00 2001 From: Mattia Dal Ben Date: Wed, 18 May 2022 10:15:13 +0200 Subject: [PATCH 5/7] refactor: add isModelEncryptionActive method --- .../ai/triton/server/TritonServerServiceImpl.java | 11 +++++------ .../ai/triton/server/TritonServerServiceOptions.java | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java index 3ae2b8dda12..5df81f06bb4 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java @@ -127,7 +127,7 @@ public void updated(Map properties) { } private void startLocalInstance() { - if (!this.options.getModelRepositoryPassword().isEmpty()) { + if (this.options.isModelEncryptionActive()) { try { decryptionFolderPath = TritonServerEncryptionUtils.createDecryptionFolder(TEMP_DIRECTORY_PREFIX); } catch (IOException e) { @@ -195,9 +195,8 @@ protected void loadModels() { @Override public void loadModel(String modelName, Optional modelPath) throws KuraException { - String password = this.options.getModelRepositoryPassword(); - - if (!password.isEmpty()) { + if (this.options.isModelEncryptionActive()) { + String password = this.options.getModelRepositoryPassword(); String plainPassword = String.valueOf(cryptoService.decryptAes(password.toCharArray())); String encryptedModelPath = TritonServerEncryptionUtils.getEncryptedModelPath(modelName, this.options.getModelRepositoryPath()); @@ -218,13 +217,13 @@ public void loadModel(String modelName, Optional modelPath) throws KuraE try { this.grpcStub.repositoryModelLoad(builder.build()); } catch (StatusRuntimeException e) { - if (!password.isEmpty() && !decryptionFolderPath.isEmpty()) { + if (this.options.isModelEncryptionActive()) { TritonServerEncryptionUtils.cleanRepository(decryptionFolderPath); } throw new KuraIOException(e, "Cannot load the model " + modelName); } - if (!password.isEmpty()) { + if (this.options.isModelEncryptionActive()) { int counter = 0; while (!isModelLoaded(modelName)) { if (counter++ >= 6) { diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java index dab81a92542..2c4ac116185 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java @@ -115,6 +115,10 @@ public String getBackendsPath() { return getStringProperty(PROPERTY_LOCAL_BACKENDS_PATH); } + public boolean isModelEncryptionActive() { + return !getModelRepositoryPassword().isEmpty(); + } + public List getBackendsConfigs() { List backendsConfigs = new ArrayList<>(); final Object propertyBackendsConfig = this.properties.get(PROPERTY_LOCAL_BACKENDS_CONFIG); From 1d5a10d9971b9192758c6d6ac479519a0af4d551 Mon Sep 17 00:00:00 2001 From: Mattia Dal Ben Date: Wed, 18 May 2022 10:17:17 +0200 Subject: [PATCH 6/7] refactor: rename method to modelsAreEcnrypted Signed-off-by: Mattia Dal Ben --- .../kura/ai/triton/server/TritonServerLocalManager.java | 2 +- .../kura/ai/triton/server/TritonServerServiceImpl.java | 8 ++++---- .../kura/ai/triton/server/TritonServerServiceOptions.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerLocalManager.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerLocalManager.java index f38d84c79e9..83d80478ddc 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerLocalManager.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerLocalManager.java @@ -139,7 +139,7 @@ protected static void sleepFor(long timeout) { private Command createServerCommand() { List commandString = new ArrayList<>(); commandString.add("tritonserver"); - if (!this.options.getModelRepositoryPassword().isEmpty()) { + if (this.options.modelsAreEncrypted()) { commandString.add("--model-repository=" + this.decryptionFolderPath); } else { commandString.add("--model-repository=" + this.options.getModelRepositoryPath()); diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java index 5df81f06bb4..4862884495e 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceImpl.java @@ -127,7 +127,7 @@ public void updated(Map properties) { } private void startLocalInstance() { - if (this.options.isModelEncryptionActive()) { + if (this.options.modelsAreEncrypted()) { try { decryptionFolderPath = TritonServerEncryptionUtils.createDecryptionFolder(TEMP_DIRECTORY_PREFIX); } catch (IOException e) { @@ -195,7 +195,7 @@ protected void loadModels() { @Override public void loadModel(String modelName, Optional modelPath) throws KuraException { - if (this.options.isModelEncryptionActive()) { + if (this.options.modelsAreEncrypted()) { String password = this.options.getModelRepositoryPassword(); String plainPassword = String.valueOf(cryptoService.decryptAes(password.toCharArray())); String encryptedModelPath = TritonServerEncryptionUtils.getEncryptedModelPath(modelName, @@ -217,13 +217,13 @@ public void loadModel(String modelName, Optional modelPath) throws KuraE try { this.grpcStub.repositoryModelLoad(builder.build()); } catch (StatusRuntimeException e) { - if (this.options.isModelEncryptionActive()) { + if (this.options.modelsAreEncrypted()) { TritonServerEncryptionUtils.cleanRepository(decryptionFolderPath); } throw new KuraIOException(e, "Cannot load the model " + modelName); } - if (this.options.isModelEncryptionActive()) { + if (this.options.modelsAreEncrypted()) { int counter = 0; while (!isModelLoaded(modelName)) { if (counter++ >= 6) { diff --git a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java index 2c4ac116185..1ef2f537222 100644 --- a/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java +++ b/kura/org.eclipse.kura.ai.triton.server/src/main/java/org/eclipse/kura/ai/triton/server/TritonServerServiceOptions.java @@ -115,7 +115,7 @@ public String getBackendsPath() { return getStringProperty(PROPERTY_LOCAL_BACKENDS_PATH); } - public boolean isModelEncryptionActive() { + public boolean modelsAreEncrypted() { return !getModelRepositoryPassword().isEmpty(); } From 7533539064ea031e81a631bbfcafaba9e973e061 Mon Sep 17 00:00:00 2001 From: Mattia Dal Ben Date: Wed, 18 May 2022 10:20:05 +0200 Subject: [PATCH 7/7] test: temporary path fix Signed-off-by: Mattia Dal Ben --- .../kura/ai/triton/server/TritonServerEncryptionUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kura/test/org.eclipse.kura.ai.triton.server.test/src/test/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtilsTest.java b/kura/test/org.eclipse.kura.ai.triton.server.test/src/test/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtilsTest.java index abb51a31b06..d4a517e75fb 100644 --- a/kura/test/org.eclipse.kura.ai.triton.server.test/src/test/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtilsTest.java +++ b/kura/test/org.eclipse.kura.ai.triton.server.test/src/test/java/org/eclipse/kura/ai/triton/server/TritonServerEncryptionUtilsTest.java @@ -38,7 +38,7 @@ public class TritonServerEncryptionUtilsTest { - private static final String WORKDIR = System.getProperty("java.io.tmpdir") + "decr_folder"; + private static final String WORKDIR = System.getProperty("java.io.tmpdir") + "/decr_folder"; private boolean exceptionOccurred = false; private String tempDirectoryPrefix; private String targetFolder;