Skip to content

Commit

Permalink
Fallback to no scenario labels in RemoteEnvironment for migrations to…
Browse files Browse the repository at this point in the history
… old NU versions (#7103)
  • Loading branch information
mateuszkp96 authored Oct 29, 2024
1 parent 13c7097 commit ac960f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package pl.touk.nussknacker.restmodel.scenariodetails

import io.circe.generic.JsonCodec
import io.circe.{Codec, Decoder, Encoder}
import pl.touk.nussknacker.engine.api.graph.ScenarioGraph
import pl.touk.nussknacker.engine.api.process.{ProcessName, ProcessingType, ScenarioVersion}
import pl.touk.nussknacker.restmodel.validation.ValidationResults
import pl.touk.nussknacker.restmodel.validation.ValidationResults.ValidationResult
import sttp.tapir.Schema

// It is a minimal set of information used by migration mechanism
@JsonCodec final case class ScenarioWithDetailsForMigrations(
final case class ScenarioWithDetailsForMigrations(
override val name: ProcessName,
override val isArchived: Boolean,
override val isFragment: Boolean,
Expand All @@ -30,6 +29,24 @@ import sttp.tapir.Schema
validationResult.getOrElse(throw new IllegalStateException("Missing validation result"))
}

object ScenarioWithDetailsForMigrations {

implicit val codec: Codec[ScenarioWithDetailsForMigrations] = {
implicit val labelsCodec: Codec[List[String]] = safeLabelsCodec
io.circe.generic.semiauto.deriveCodec
}

// labels field was introduced to BaseScenarioWithDetailsForMigrations in the 1.18 version and old versions do not provide it
// This fallback is needed to migrate the scenario to older versions of NU and can be removed in future releases
private lazy val safeLabelsCodec: Codec[List[String]] = {
Codec.from(
Decoder[Option[List[String]]].map(_.getOrElse(List.empty[String])),
Encoder[List[String]]
)
}

}

// This trait is extracted for easier monitoring changes in the /processes api that have an influence on the migration API
trait BaseScenarioWithDetailsForMigrations {
def name: ProcessName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import akka.http.scaladsl.model._
import akka.stream.Materializer
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport
import io.circe.parser
import io.circe.syntax.EncoderOps
import org.scalatest.BeforeAndAfterAll
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
Expand Down Expand Up @@ -350,9 +351,14 @@ class StandardRemoteEnvironmentSpec

(uri, method) match {
case GetProcessesDetailsWithoutScenarioGraph() =>
Marshal(allProcesses.map(_.copy(scenarioGraph = None))).to[ResponseEntity].map { entity =>
HttpResponse(entity = entity)
}
// response without labels to test decoder fallback
val response =
allProcesses.map(_.copy(scenarioGraph = None)).asJson.mapArray(_.map(_.mapObject(_.remove("labels"))))
Marshal(response)
.to[ResponseEntity]
.map { entity =>
HttpResponse(entity = entity)
}
case GetProcessesDetails(names) =>
Marshal(allProcesses.filter(p => names(p.name))).to[ResponseEntity].map { entity =>
HttpResponse(entity = entity)
Expand Down

0 comments on commit ac960f7

Please sign in to comment.