[RORDEV-1435] Improved patching algorithm#1095
Conversation
52965d0 to
67157a1
Compare
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/utils/RorToolsError.scala
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
docker-envs/base-ror-docker/es/Dockerfile-build-for-from-sources
Outdated
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatch.scala
Outdated
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatch.scala
Outdated
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/SimpleEsPatch.scala
Show resolved
Hide resolved
...core/src/main/scala/tech/beshu/ror/tools/core/patches/base/TransportNetty4AwareEsPatch.scala
Outdated
Show resolved
Hide resolved
...core/src/main/scala/tech/beshu/ror/tools/core/patches/base/TransportNetty4AwareEsPatch.scala
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/utils/RorToolsError.scala
Show resolved
Hide resolved
coutoPL
left a comment
There was a problem hiding this comment.
Great! It seems all the important things we already have here. Only small minor things left
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/PatchingVerifier.scala
Outdated
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala
Outdated
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala
Outdated
Show resolved
Hide resolved
...ools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/RorPluginDirectory.scala
Outdated
Show resolved
Hide resolved
...main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/JarManifestModifier.scala
Show resolved
Hide resolved
ror-tools/src/test/scala/tech/beshu/ror/tools/RorToolsAppSuite.scala
Outdated
Show resolved
Hide resolved
ror-tools/src/test/scala/tech/beshu/ror/tools/RorToolsAppSuite.scala
Outdated
Show resolved
Hide resolved
ror-tools/src/test/scala/tech/beshu/ror/tools/RorToolsAppSuite.scala
Outdated
Show resolved
Hide resolved
…5-improved-patching-algorithm # Conflicts: # gradle.properties
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala
Outdated
Show resolved
Hide resolved
|
|
||
| def addPatchedByRorVersionProperty(file: File, rorVersion: String): Unit = { | ||
| Using(new JarFile(file.toJava)) { jarFile => | ||
| val tempJarFile = File(s"temp-${UUID.randomUUID()}.jar") |
There was a problem hiding this comment.
I had to revert that change. Using temporary file break the patcher - I did not investigate it, but probably some kind of permissions problem. Temp file is created in /temp directory, but then in this part of code we copy and replace the original jar with this temp file.
There was a problem hiding this comment.
ok, let's leave the comment
...main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/JarManifestModifier.scala
Outdated
Show resolved
Hide resolved
ror-tools/src/test/scala/tech/beshu/ror/tools/RorToolsAppSuite.scala
Outdated
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala
Show resolved
Hide resolved
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/JarManifestModifier.scala (1)
33-33: Consider using temporary file utilitiesThe current implementation creates a temporary file in the working directory rather than using better-files' temporary file utilities that would handle cleanup automatically.
- val tempJarFile = File(s"temp-${UUID.randomUUID()}.jar") + val tempJarFile = File.newTemporaryFile("temp-", ".jar")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala(1 hunks)ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/JarManifestModifier.scala(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: ror (Run all tests IT_es67x)
- GitHub Check: ror (Run all tests IT_es70x)
- GitHub Check: ror (Run all tests IT_es80x)
- GitHub Check: ror (Run all tests IT_es710x)
- GitHub Check: ror (Run all tests IT_es810x)
- GitHub Check: ror (Run all tests IT_es717x)
- GitHub Check: ror (Run all tests IT_es818x)
- GitHub Check: ror (Run all tests UNIT)
- GitHub Check: ror (Run all tests IT_es90x)
- GitHub Check: ror (Run all tests LICENSE)
- GitHub Check: ror (CVE check Job)
🔇 Additional comments (9)
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/JarManifestModifier.scala (3)
31-41: Well-implemented resource management with Using blocksThe code correctly uses Scala's
Usingconstruct to ensure proper resource management for both the JarFile and JarOutputStream, preventing resource leaks.
43-51: Clean implementation of findPatchedFiles with proper resource handlingThis implementation properly manages resources and handles potential exceptions when scanning JAR files for the ROR version property. The flatMap with Using.toOption.flatten pattern is a clean way to filter out JARs that don't contain the property.
55-64: Efficient and resource-safe JAR content copyingThe method correctly handles streaming JAR entries and ensures all resources are properly closed via the inner Using block for the input stream.
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala (6)
36-46: Clear patch logic with proper error handlingThe patch method follows a good pattern by checking state first and then performing actions, with clear error handling using Either for domain errors.
73-85: Inconsistent error handling in doPatchWhile domain errors are properly returned as
Either[RorToolsError, Unit], technical errors fromesPatch.performPatching()are thrown as exceptions. This is inconsistent with the functional approach used elsewhere.Based on past review discussions, this appears to be an intentional design decision to distinguish between expected domain errors and unexpected technical failures.
Confirm that exceptions are meant to be thrown for technical failures only (like file I/O issues), while business logic errors like "already patched" should be returned as Either values.
108-127: Comprehensive patch status detection logicThe method thoroughly checks for various patch states, considering both metadata version compatibility and file integrity. This ensures reliable detection of patched, unpatched, and corrupted states.
129-148: Well-documented corruption detection for legacy patchesThe additional checking for corrupted patch states without valid metadata is well-commented and handles an important edge case where JAR files might have been patched but metadata is missing.
154-157: Exhaustive pattern matching in validatePatchedFilesThe pattern matching now properly handles all possible cases, including when both lists are empty (
case _ => Right(())). This prevents potential MatchError during runtime.
193-204: Clean pattern for converting domain errors to user-facing errorsThe
PatchProblemOpsimplicit class provides a clean way to convert internal patch problems to user-facing error messages, enhancing separation of concerns.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/JarManifestModifier.scala (2)
31-42: Improve temp file creation and cleanupThe temp file creation uses a UUID-based approach that creates the file in the current directory, which may have permission issues in some environments. Consider using
java.io.File.createTempFile()instead to create the file in the system's temp directory.Also, consider adding explicit cleanup for the temp file in case the move operation fails.
- val tempJarFile = File(s"temp-${UUID.randomUUID()}.jar") + val tempFile = java.io.File.createTempFile("ror-jar-modifier-", ".jar") + tempFile.deleteOnExit() // Ensure cleanup + val tempJarFile = File(tempFile)
44-52: Consider limiting directory traversal depthThe
directory.walk()call will recursively scan all subdirectories, which could potentially process a large number of files in a deep directory structure. Consider adding a depth limit or more specific filtering to improve performance.- directory.walk().filter(_.name.endsWith(".jar")).toList.flatMap { file => + directory.walk(maxDepth = 2).filter(_.name.endsWith(".jar")).toList.flatMap { file =>
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/JarManifestModifier.scala(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: ror (Run all tests IT_es67x)
- GitHub Check: ror (Run all tests IT_es70x)
- GitHub Check: ror (Run all tests IT_es80x)
- GitHub Check: ror (Run all tests IT_es710x)
- GitHub Check: ror (Run all tests IT_es810x)
- GitHub Check: ror (Run all tests IT_es717x)
- GitHub Check: ror (CVE check Job)
- GitHub Check: ror (Run all tests IT_es90x)
- GitHub Check: ror (Run all tests IT_es818x)
- GitHub Check: ror (Run all tests UNIT)
- GitHub Check: ror (Run all tests LICENSE)
🔇 Additional comments (2)
ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/JarManifestModifier.scala (2)
56-65: Good implementation of jar content copyingThe implementation correctly addresses previous review comments by properly handling resource management and fixing the JAR entry copying issue. Each entry's input stream is now properly obtained and closed.
47-50: Robust error handling for jar file processingGood use of the
UsingandOptionpattern to safely handle JAR files and gracefully manage potential issues. The flattening of the option ensures that only valid patched JARs are returned.
🧐Enhancement (ES) Patcher - more robust Elasticsearch patcher + better logs messages
Summary by CodeRabbit
Chores
New Features
Bug Fixes
Refactor