Skip to content

Commit

Permalink
[RORDEV-1222] patcher invalid state detection improvements (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
coutoPL authored Jun 27, 2024
1 parent af8d70f commit ef7251e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
publishedPluginVersion=1.57.3
pluginVersion=1.58.0-pre4
pluginVersion=1.58.0-pre5
pluginName=readonlyrest

org.gradle.jvmargs=-Xmx6144m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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] = {
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down

0 comments on commit ef7251e

Please sign in to comment.