Skip to content

Commit d57b87c

Browse files
committed
Merge remote-tracking branch 'origin/master' into develop
2 parents faa7789 + 8fee797 commit d57b87c

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

docker-image/ror-entrypoint-es6x.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
INVOKE_ROR_TOOLS="$JAVA_HOME/bin/java -jar /usr/share/elasticsearch/plugins/readonlyrest/ror-tools.jar"
44

5-
if $INVOKE_ROR_TOOLS verify | grep -q "Elasticsearch is NOT patched"; then
5+
if ! $INVOKE_ROR_TOOLS verify; then
66

77
if [ -n "$I_UNDERSTAND_AND_ACCEPT_ES_PATCHING" ]; then
88
CONFIRMATION="$I_UNDERSTAND_AND_ACCEPT_ES_PATCHING"

docker-image/ror-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
INVOKE_ROR_TOOLS="/usr/share/elasticsearch/jdk/bin/java -jar /usr/share/elasticsearch/plugins/readonlyrest/ror-tools.jar"
44

5-
if $INVOKE_ROR_TOOLS verify | grep -q "Elasticsearch is NOT patched"; then
5+
if ! $INVOKE_ROR_TOOLS verify; then
66

77
if [ -n "$I_UNDERSTAND_AND_ACCEPT_ES_PATCHING" ]; then
88
CONFIRMATION="$I_UNDERSTAND_AND_ACCEPT_ES_PATCHING"

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
publishedPluginVersion=1.63.0
2-
pluginVersion=1.64.0
1+
publishedPluginVersion=1.64.1
2+
pluginVersion=1.64.1
33
pluginName=readonlyrest
44

55
org.gradle.jvmargs=-Xmx6144m

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatchExecutor.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package tech.beshu.ror.tools.core.patches.base
1818

19-
import just.semver.SemVer
2019
import tech.beshu.ror.tools.core.patches.base.EsPatchExecutor.EsPatchStatus
2120
import tech.beshu.ror.tools.core.patches.base.EsPatchExecutor.EsPatchStatus.*
2221
import tech.beshu.ror.tools.core.patches.base.EsPatchExecutor.PatchProblem.*
@@ -56,13 +55,14 @@ final class EsPatchExecutor(rorPluginDirectory: RorPluginDirectory,
5655
}
5756
}
5857

59-
def verify(): Either[RorToolsError, Unit] = {
58+
def verify(): Either[RorToolsError, Boolean] = {
6059
checkWithPatchedByFileAndEsPatch() match {
6160
case NotPatched =>
62-
Left(EsNotPatchedError)
61+
inOut.println(EsNotPatchedError.message)
62+
Right(false)
6363
case PatchedWithCurrentRorVersion(_) =>
6464
inOut.println("Elasticsearch is patched! ReadonlyREST can be used")
65-
Right(())
65+
Right(true)
6666
case PatchProblemDetected(patchProblem) =>
6767
Left(patchProblem.rorToolsError)
6868
}

ror-tools/src/main/scala/tech/beshu/ror/tools/RorToolsApp.scala

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ import scopt.*
2121
import tech.beshu.ror.tools.RorTools.*
2222
import tech.beshu.ror.tools.core.patches.base.EsPatchExecutor
2323
import tech.beshu.ror.tools.core.utils.InOut.ConsoleInOut
24+
import tech.beshu.ror.tools.core.utils.RorToolsError.EsNotPatchedError
2425
import tech.beshu.ror.tools.core.utils.{EsDirectory, InOut, RorToolsError, RorToolsException}
2526

2627
import scala.util.{Failure, Success, Try}
2728

2829
object RorToolsApp extends RorTools {
2930

30-
// todo:
31-
// 1. option: return success when already patched/unpatched
32-
// 2. restore backup when fails to patch
3331
def main(args: Array[String]): Unit = {
3432
run(args)(ConsoleInOut) match {
3533
case Result.Success =>
@@ -80,10 +78,10 @@ trait RorTools {
8078
}
8179
} match {
8280
case Failure(ex: RorToolsException) =>
83-
inOut.println(s"ERROR: ${ex.getMessage()}\n${ex.printStackTrace()}")
81+
inOut.println(s"ERROR: ${ex.getMessage}\n${ex.printStackTrace()}")
8482
Result.Failure
8583
case Failure(ex: Throwable) =>
86-
inOut.println(s"UNEXPECTED ERROR: ${ex.getMessage()}\n${ex.printStackTrace()}")
84+
inOut.println(s"UNEXPECTED ERROR: ${ex.getMessage}\n${ex.printStackTrace()}")
8785
Result.Failure
8886
case Success(result) =>
8987
result
@@ -110,7 +108,10 @@ trait RorTools {
110108

111109
private def performPatching(customESPath: Option[Path]): Result = {
112110
val esDirectory = esDirectoryFrom(customESPath)
113-
handleResult(EsPatchExecutor.create(esDirectory).patch())
111+
EsPatchExecutor.create(esDirectory).patch() match {
112+
case Right(()) => Result.Success
113+
case Left(error) => failureCausedByRorToolsError(error)
114+
}
114115
}
115116

116117
private def abortPatchingBecauseUserDidNotAcceptConsequences(): Result = {
@@ -139,32 +140,34 @@ trait RorTools {
139140
private class UnpatchCommandHandler(implicit inOut: InOut) {
140141
def handle(command: Command.Unpatch): Result = {
141142
val esDirectory = esDirectoryFrom(command.customEsPath)
142-
handleResult(EsPatchExecutor.create(esDirectory).restore())
143+
EsPatchExecutor.create(esDirectory).restore() match {
144+
case Right(()) => Result.Success
145+
case Left(error) => failureCausedByRorToolsError(error)
146+
}
143147
}
144148
}
145149

146150
private class VerifyCommandHandler(implicit inOut: InOut) {
147151
def handle(command: Command.Verify): Result = {
148152
val esDirectory = esDirectoryFrom(command.customEsPath)
149-
handleResult(EsPatchExecutor.create(esDirectory).verify())
150-
}
151-
}
152-
153-
private def handleResult(result: Either[RorToolsError, Unit])
154-
(implicit inOut: InOut): Result = {
155-
result match {
156-
case Left(error) =>
157-
inOut.printlnErr("ERROR: " + error.message)
158-
Result.Failure
159-
case Right(()) =>
160-
Result.Success
153+
EsPatchExecutor.create(esDirectory).verify() match {
154+
case Right(true) => Result.Success
155+
case Right(false) => Result.Failure
156+
case Left(error) => failureCausedByRorToolsError(error)
157+
}
161158
}
162159
}
163160

164161
private def esDirectoryFrom(esPath: Option[os.Path]) = {
165162
esPath.map(EsDirectory.from).getOrElse(EsDirectory.default)
166163
}
167164

165+
private def failureCausedByRorToolsError(error: RorToolsError)
166+
(implicit inOut: InOut) = {
167+
inOut.printlnErr(s"ERROR: ${error.message}")
168+
Result.Failure
169+
}
170+
168171
private val builder = OParser.builder[Arguments]
169172

170173
import builder.*

ror-tools/src/test/scala/tech/beshu/ror/tools/RorToolsAppSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class RorToolsAppSuite
280280
verifyResult should equal(Result.Failure)
281281
verifyOutput should include(
282282
"""Checking if Elasticsearch is patched ...
283-
|ERROR: Elasticsearch is NOT patched. ReadonlyREST cannot be used yet. For patching instructions see our docs: https://docs.readonlyrest.com/elasticsearch#id-3.-patch-elasticsearch"""
283+
|Elasticsearch is NOT patched. ReadonlyREST cannot be used yet. For patching instructions see our docs: https://docs.readonlyrest.com/elasticsearch#id-3.-patch-elasticsearch"""
284284
.stripMargin
285285
)
286286
}

0 commit comments

Comments
 (0)