Skip to content

Commit

Permalink
Fixes #24515: Rudder should finish to migrate all techniques when boo…
Browse files Browse the repository at this point in the history
…ting instead of stopping on first error
  • Loading branch information
VinceMacBuche committed Mar 15, 2024
1 parent 228c36a commit ba2953b
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.normation.rudder.rest.RestExtractorService
import com.normation.utils.StringUuidGenerator
import com.normation.zio._
import zio._
import zio.syntax._

sealed trait NcfTechniqueUpgradeError extends RudderError {
def msg: String
Expand Down Expand Up @@ -95,11 +96,9 @@ class CheckNcfTechniqueUpdate(

def updateNcfTechniques = {
for {
_ <- BootstrapLogger.info("started")
_ <- BootstrapLogger.info("techniques - update")
_ <- BootstrapLogger.info("Started editor techniques update")
res <- techniqueReader.readTechniquesMetadataFile
(techniques, methods) = res
_ <- BootstrapLogger.info("techniques - read")
techniquesWithResources <-
ZIO.foreach(techniques) { technique =>
// Keep only non New Resources
Expand All @@ -111,19 +110,30 @@ class CheckNcfTechniqueUpdate(
written <- ZIO.foreach(techniquesWithResources) { t =>
techniqueWrite
.writeTechnique(t, methods, ModificationId(uuidGen.newUuid), EventActor(systemApiToken.name.value))
.chainError(s"An error occured while writing technique ${t.bundleName.value}")
.chainError(s"An error occurred while writing technique ${t.bundleName.value}")
.either
}
_ <- ZIO.foreach(written) {
case Right(_) => ().succeed
case Left(err) => BootstrapLogger.error(err.fullMsg)
}

_ <-
BootstrapLogger.info(
s"${written.filter(_.isRight).size} techniques migrated, ${$(written.filter(_.isLeft).size)} have an error. check errors above if any"
)
// Update technique library once all technique are updated
libUpdate <- techLibUpdate
.update(
ModificationId(uuidGen.newUuid),
EventActor(systemApiToken.name.value),
Some(s"Update Technique library after updating all techniques at start up")
)
.toIO
.chainError(s"An error occured during techniques update after update of all techniques from the editor")
libUpdate <- techLibUpdate
.update(
ModificationId(uuidGen.newUuid),
EventActor(systemApiToken.name.value),
Some(s"Update Technique library after updating all techniques at start up")
)
.toIO
.chainError(s"An error occurred during techniques update after update of all techniques from the editor")

flagDeleted <- IOResult.attempt(ncfTechniqueUpdateFlag.delete())
_ <- BootstrapLogger.info("Ended editor techniques update")
} yield {
techniques
}
Expand Down

0 comments on commit ba2953b

Please sign in to comment.