From ef7251e557e9e5551529ec36ef83fd52c04c23d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ko=C5=82odziejczyk?= Date: Thu, 27 Jun 2024 20:38:39 +0200 Subject: [PATCH] [RORDEV-1222] patcher invalid state detection improvements (#1026) --- gradle.properties | 2 +- .../base/TransportNetty4AwareEsPatch.scala | 14 ++++++++++++-- .../tools/core/patches/internal/FilePatch.scala | 3 +++ .../patches/internal/RorPluginDirectory.scala | 16 +++++++++------- .../ElasticsearchJarPatchCreator.scala | 2 +- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 80df8f960d..06660136f1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ publishedPluginVersion=1.57.3 -pluginVersion=1.58.0-pre4 +pluginVersion=1.58.0-pre5 pluginName=readonlyrest org.gradle.jvmargs=-Xmx6144m diff --git a/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/TransportNetty4AwareEsPatch.scala b/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/TransportNetty4AwareEsPatch.scala index 9b7e0b9a4e..939612005c 100644 --- a/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/TransportNetty4AwareEsPatch.scala +++ b/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/TransportNetty4AwareEsPatch.scala @@ -35,10 +35,20 @@ private [patches] abstract class TransportNetty4AwareEsPatch(rorPluginDirectory: ) override def isPatched: IsPatched = { - if (rorPluginDirectory.doesBackupFolderExist && rorPluginDirectory.isTransportNetty4PresentInRorPluginPath) { + val backupExists = rorPluginDirectory.doesBackupFolderExist + val transportNetty4FoundInRorDir = rorPluginDirectory.isTransportNetty4PresentInRorPluginPath + if (backupExists && transportNetty4FoundInRorDir) { checkWithPatchedByFile(rorPluginDirectory) - } else { + } else if (!backupExists && !transportNetty4FoundInRorDir) { No(Cause.NotPatchedAtAll) + } else { + val possiblyCorruptedEsFiles = filePatches.files.filterNot(rorPluginDirectory.isRorPluginPath).map(_.toIO) + throw new IllegalStateException( + s""" + |ES Corrupted! Something went wrong during patching/unpatching and the current state of ES installation is corrupted. + |To recover from this state, please uninstall ReadonlyREST plugin and copy the corrupted files from ES sources (https://www.elastic.co/downloads/elasticsearch): + |${possiblyCorruptedEsFiles.map(_.toString).map(f => s"- $f").mkString("\n")} + |""".stripMargin) } } diff --git a/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/FilePatch.scala b/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/FilePatch.scala index b8e7c7e26f..dce5a19384 100644 --- a/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/FilePatch.scala +++ b/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/FilePatch.scala @@ -60,6 +60,9 @@ private [patches] class MultiFilePatch(filePatches: FilePatch*) { def restore(): Unit = { filePatches.foreach(_.restore()) } + + def files: Seq[Path] = filePatches.map(_.fileToPatchPath) + } private [patches] class OptionalFilePatchDecorator[FP <: FilePatch](underlying: FP) diff --git a/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/RorPluginDirectory.scala b/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/RorPluginDirectory.scala index 01afc08a72..06d02f6a23 100644 --- a/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/RorPluginDirectory.scala +++ b/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/RorPluginDirectory.scala @@ -22,12 +22,12 @@ import tech.beshu.ror.tools.core.utils.EsUtil.{findTransportNetty4JarIn, readonl private [patches] class RorPluginDirectory(val esDirectory: EsDirectory) { - private val path: Path = readonlyrestPluginPath(esDirectory.path) - private val backupFolderPath: Path = path / "patch_backup" + private val rorPath: Path = readonlyrestPluginPath(esDirectory.path) + private val backupFolderPath: Path = rorPath / "patch_backup" private val patchedByFilePath: Path = backupFolderPath / "patched_by" - private val pluginPropertiesFilePath = path / "plugin-descriptor.properties" + private val pluginPropertiesFilePath = rorPath / "plugin-descriptor.properties" - val securityPolicyPath: Path = path / "plugin-security.policy" + val securityPolicyPath: Path = rorPath / "plugin-security.policy" def doesBackupFolderExist: Boolean = { os.exists(backupFolderPath) @@ -50,15 +50,15 @@ private [patches] class RorPluginDirectory(val esDirectory: EsDirectory) { } def copyToPluginPath(file: Path): Unit = { - os.copy(from = file, to = path / file.last) + os.copy(from = file, to = rorPath / file.last) } def isTransportNetty4PresentInRorPluginPath: Boolean = { - findTransportNetty4JarIn(path).isDefined + findTransportNetty4JarIn(rorPath).isDefined } def findTransportNetty4Jar: Option[Path] = { - findTransportNetty4JarIn(path) + findTransportNetty4JarIn(rorPath) } def readPatchedByRorVersion(): Option[String] = { @@ -83,4 +83,6 @@ private [patches] class RorPluginDirectory(val esDirectory: EsDirectory) { .headOption .getOrElse(throw new IllegalStateException(s"Cannot read ROR version from ${pluginPropertiesFilePath}")) } + + def isRorPluginPath(path: Path): Boolean = path.startsWith(rorPath) } diff --git a/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/ElasticsearchJarPatchCreator.scala b/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/ElasticsearchJarPatchCreator.scala index c63a8c7639..5cd8d2cf56 100644 --- a/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/ElasticsearchJarPatchCreator.scala +++ b/ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/internal/filePatchers/ElasticsearchJarPatchCreator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.tools.core.patches.internal.filePatchers import just.semver.SemVer import tech.beshu.ror.tools.core.patches.internal.modifiers.FileModifier -import tech.beshu.ror.tools.core.patches.internal.{FileModifiersBasedPatch, FilePatch, RorPluginDirectory} +import tech.beshu.ror.tools.core.patches.internal.{FileModifiersBasedPatch, RorPluginDirectory} private[patches] class ElasticsearchJarPatchCreator(patchingSteps: FileModifier*) extends FilePatchCreator[ElasticsearchJarPatch] {