Permalink
Browse files

Refactored Profile model, added id to update actions

  • Loading branch information...
lefou committed Nov 26, 2018
1 parent c3f783c commit cd0e57d19be98b4b9a3ea1b048678c0ac9c63532
Showing with 282 additions and 161 deletions.
  1. +1 −1 blended.mgmt.agent/src/main/scala/blended/mgmt/agent/internal/OsgiMgmtReporter.scala
  2. +8 −8 blended.mgmt.mock/src/main/scala/blended/mgmt/mock/MockObjects.scala
  3. +3 −3 blended.mgmt.mock/src/main/scala/blended/mgmt/mock/server/MgmtMockServer.scala
  4. +4 −0 blended.mgmt.rest/src/main/scala/blended/mgmt/rest/internal/CollectorService.scala
  5. +3 −3 blended.mgmt.rest/src/test/scala/blended/mgmt/rest/internal/CollectorServiceSpec.scala
  6. +2 −1 blended.mgmt.ws/src/test/scala/blended/mgmt/ws/internal/MgmtWebSocketSpec.scala
  7. +5 −3 blended.updater.config/shared/src/main/scala/blended/updater/config/ContainerInfo.scala
  8. +33 −7 blended.updater.config/shared/src/main/scala/blended/updater/config/Mapper.scala
  9. +5 −15 blended.updater.config/shared/src/main/scala/blended/updater/config/Profile.scala
  10. +25 −0 blended.updater.config/shared/src/main/scala/blended/updater/config/ProfileGroup.scala
  11. +1 −1 blended.updater.config/shared/src/main/scala/blended/updater/config/ProfileInfo.scala
  12. +7 −4 blended.updater.config/shared/src/main/scala/blended/updater/config/RolloutProfile.scala
  13. +0 −9 blended.updater.config/shared/src/main/scala/blended/updater/config/SingleProfile.scala
  14. +21 −1 blended.updater.config/shared/src/main/scala/blended/updater/config/UpdateAction.scala
  15. +1 −0 blended.updater.config/shared/src/test/scala/blended/updater/config/MapperSpec.scala
  16. +11 −9 blended.updater.config/shared/src/test/scala/blended/updater/config/PrickleSpec.scala
  17. +4 −4 blended.updater.config/shared/src/test/scala/blended/updater/config/ProfileSpec.scala
  18. +16 −11 blended.updater.config/shared/src/test/scala/blended/updater/config/TestData.scala
  19. +2 −1 blended.updater.remote/src/main/scala/blended/updater/remote/ContainerState.scala
  20. +1 −1 blended.updater.remote/src/main/scala/blended/updater/remote/Mapper.scala
  21. +29 −27 blended.updater.remote/src/main/scala/blended/updater/remote/RemoteUpdater.scala
  22. +8 −8 blended.updater.remote/src/main/scala/blended/updater/remote/internal/RemoteCommands.scala
  23. +75 −27 blended.updater.remote/src/test/scala/blended/updater/remote/RemoteUpdaterTest.scala
  24. +3 −3 blended.updater/src/main/scala/blended/updater/LocalProfile.scala
  25. +14 −14 blended.updater/src/main/scala/blended/updater/Updater.scala
@@ -44,7 +44,7 @@ class OsgiMgmtReporter(cfg: OSGIActorConfig) extends OSGIActor(cfg) with MgmtRep
private[this] val idSvc = cfg.idSvc
protected def createContainerInfo: ContainerInfo =
ContainerInfo(idSvc.uuid, idSvc.properties, serviceInfos.values.toList, profileInfo.profiles, System.currentTimeMillis())
ContainerInfo(idSvc.uuid, idSvc.properties, serviceInfos.values.toList, profileInfo.profiles, System.currentTimeMillis(), Nil)
}
@@ -70,11 +70,11 @@ object MockObjects {
reason = Some("Incorrect artifact checksums")
)
lazy val validProfiles = List(
Profile(name = "blended-demo", "1.0", List(noOverlays)),
Profile(name = "blended-simple", "1.0", List(noOverlays, someOverlays, invalid)),
Profile(name = "blended-simple", "1.1", List(noOverlays, someOverlays, invalid))
)
lazy val validProfiles: List[Profile] = List(
ProfileGroup(name = "blended-demo", "1.0", List(noOverlays)),
ProfileGroup(name = "blended-simple", "1.0", List(noOverlays, someOverlays, invalid)),
ProfileGroup(name = "blended-simple", "1.1", List(noOverlays, someOverlays, invalid))
).flatMap(_.toSingle)
def createContainer(numContainers: Integer) = 1.to(numContainers).map { i =>
@@ -87,7 +87,8 @@ object MockObjects {
properties = containerProps(containerCount.incrementAndGet()),
serviceInfos = pickOne(serviceSeqs),
profiles = validProfiles,
timestampMsec = System.currentTimeMillis()
timestampMsec = System.currentTimeMillis(),
appliedUpdateActionIds = Nil
)
}.toList
@@ -103,7 +104,7 @@ object MockObjects {
Pickle.intoString(result)
}
def profilesList(l: List[Profile]) = Pickle.intoString(l)
def profilesList(l: List[ProfileGroup]) = Pickle.intoString(l)
// Define some test environments here
@@ -141,4 +142,3 @@ object MockObjects {
}
@@ -3,8 +3,8 @@ package blended.mgmt.mock.server
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.options
import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.http.{ HttpHeader, HttpHeaders }
import blended.updater.config.ContainerInfo
import com.github.tomakehurst.wiremock.http.{HttpHeader, HttpHeaders}
import blended.updater.config.{ContainerInfo, ProfileGroup}
import blended.mgmt.mock.MockObjects
object MgmtMockServer {
@@ -40,7 +40,7 @@ object MgmtMockServer {
)
stubFor(
get(urlEqualTo("/mgmt/profiles")).willReturn(response(profilesList(validProfiles)))
get(urlEqualTo("/mgmt/profiles")).willReturn(response(profilesList(ProfileGroup.fromSingleProfiles(validProfiles))))
)
stubFor(
@@ -1,6 +1,7 @@
package blended.mgmt.rest.internal
import java.io.File
import java.util.UUID
import scala.collection.{immutable => sci}
import scala.concurrent.duration._
@@ -193,6 +194,7 @@ trait CollectorService {
addUpdateAction(
containerId = containerId,
updateAction = AddRuntimeConfig(
UUID.randomUUID().toString(),
runtimeConfig = rc
)
)
@@ -204,6 +206,7 @@ trait CollectorService {
addUpdateAction(
containerId = containerId,
updateAction = AddOverlayConfig(
UUID.randomUUID().toString(),
overlay = oc
)
)
@@ -213,6 +216,7 @@ trait CollectorService {
addUpdateAction(
containerId = containerId,
updateAction = StageProfile(
UUID.randomUUID().toString(),
profileName = rolloutProfile.profileName,
profileVersion = rolloutProfile.profileVersion,
overlays = rolloutProfile.overlays
@@ -30,15 +30,15 @@ class CollectorServiceSpec
"The Management collector routes" - {
"should POST /container returns a registry response" in {
Post("/container", ContainerInfo("uuid", Map("foo" -> "bar"), List(), List(), 1L)) ~> collectorRoute ~> check {
Post("/container", ContainerInfo("uuid", Map("foo" -> "bar"), List(), List(), 1L, List())) ~> collectorRoute ~> check {
responseAs[ContainerRegistryResponseOK].id should be("uuid")
}
processContainerInfoLatch.isOpen should be(true)
}
"should GET /container return container infos" in {
Get("/container") ~> infoRoute ~> check {
responseAs[Seq[RemoteContainerState]] should be(Seq(RemoteContainerState(ContainerInfo("uuid", Map("foo" -> "bar"), List(), List(), 1L), List())))
responseAs[Seq[RemoteContainerState]] should be(Seq(RemoteContainerState(ContainerInfo("uuid", Map("foo" -> "bar"), List(), List(), 1L, List()), List())))
}
getCurrentStateLatch.isOpen should be(true)
}
@@ -62,7 +62,7 @@ class CollectorServiceSpec
override def getCurrentState(): sci.Seq[RemoteContainerState] = {
getCurrentStateLatch.countDown()
List(RemoteContainerState(ContainerInfo("uuid", Map("foo" -> "bar"), List(), List(), 1L), List()))
List(RemoteContainerState(ContainerInfo("uuid", Map("foo" -> "bar"), List(), List(), 1L, List()), List()))
}
override def version: String = "TEST"
@@ -114,7 +114,8 @@ class MgmtWebSocketSpec extends SimplePojoContainerSpec
properties = Map("country" -> country),
List.empty,
List.empty,
System.currentTimeMillis()
System.currentTimeMillis(),
List.empty
)
private[this] val containers : Seq[ContainerInfo] = {
@@ -1,4 +1,5 @@
package blended.updater.config
import blended.security.{BlendedPermission, GrantableObject}
import scala.collection.{immutable => sci}
@@ -8,14 +9,15 @@ case class ContainerInfo(
properties: Map[String, String],
serviceInfos: List[ServiceInfo],
profiles: List[Profile],
timestampMsec: Long
timestampMsec: Long,
appliedUpdateActionIds: List[String]
) extends GrantableObject {
override def permission: BlendedPermission = BlendedPermission(
permissionClass = Some("container"),
properties = properties.map { case (k,v) => k -> sci.Seq(v) }
properties = properties.map { case (k, v) => k -> sci.Seq(v) }
)
override def toString(): String = s"${getClass().getSimpleName()}(containerId=${containerId},properties=${properties},serviceInfos=${serviceInfos},profiles=${profiles},timestampMsec=${timestampMsec})"
override def toString(): String = s"${getClass().getSimpleName()}(containerId=${containerId},properties=${properties},serviceInfos=${serviceInfos},profiles=${profiles},timestampMsec=${timestampMsec},appliedUpdateActionIds=${appliedUpdateActionIds})"
}
@@ -78,26 +78,30 @@ trait Mapper {
).asJava
def mapUpdateAction(a: UpdateAction): java.util.Map[String, AnyRef] = a match {
case AddRuntimeConfig(rc) =>
case AddRuntimeConfig(id, rc) =>
Map(
"kind" -> UpdateAction.KindAddRuntimeConfig,
"id" -> id,
"runtimeConfig" -> mapRuntimeConfig(rc)
).asJava
case AddOverlayConfig(oc) =>
case AddOverlayConfig(id, oc) =>
Map(
"kind" -> UpdateAction.KindAddOverlayConfig,
"id" ->id,
"overlay" -> mapOverlayConfig(oc)
).asJava
case ActivateProfile(profileName, profileVersion, overlays) =>
case ActivateProfile(id, profileName, profileVersion, overlays) =>
Map(
"kind" -> UpdateAction.KindActivateProfile,
"id" -> id,
"profileName" -> profileName,
"profileVersion" -> profileVersion,
"overlays" -> overlays.map(o => mapOverlayRef(o)).asJava
).asJava
case StageProfile(profileName, profileVersion, overlays) =>
case StageProfile(id, profileName, profileVersion, overlays) =>
Map(
"kind" -> UpdateAction.KindStageProfile,
"id" -> id,
"profileName" -> profileName,
"profileVersion" -> profileVersion,
"overlays" -> overlays.map(o => mapOverlayRef(o)).asJava
@@ -118,13 +122,21 @@ trait Mapper {
"config" -> c.config
).asJava
def mapProfile(p: Profile): java.util.Map[String, AnyRef] =
def mapProfileGroup(p: ProfileGroup): java.util.Map[String, AnyRef] =
Map[String, AnyRef](
"name" -> p.name,
"version" -> p.version,
"overlays" -> p.overlays.map(o => mapOverlaySet(o)).asJava
).asJava
def mapProfile(p: Profile): java.util.Map[String, AnyRef] =
Map[String, AnyRef](
"name" -> p.name,
"version" -> p.version,
"overlays" -> mapOverlaySet(p.overlaySet)
).asJava
def mapOverlaySet(o: OverlaySet): java.util.Map[String, AnyRef] =
Map[String, AnyRef](
"overlays" -> o.overlays.map(o => mapOverlayRef(o)).asJava,
@@ -160,20 +172,24 @@ trait Mapper {
a("kind") match {
case UpdateAction.KindAddRuntimeConfig =>
AddRuntimeConfig(
id = a("id").asInstanceOf[String],
runtimeConfig = unmapRuntimeConfig(a("runtimeConfig")).get
)
case UpdateAction.KindAddOverlayConfig =>
AddOverlayConfig(
id = a("id").asInstanceOf[String],
overlay = unmapOverlayConfig(a("overlay")).get
)
case UpdateAction.KindActivateProfile =>
ActivateProfile(
id = a("id").asInstanceOf[String],
profileName = a("profileName").asInstanceOf[String],
profileVersion = a("profileVersion").asInstanceOf[String],
overlays = a("overlays").asInstanceOf[java.util.Collection[AnyRef]].asScala.map(o => unmapOverlayRef(o).get).toSet
)
case UpdateAction.KindStageProfile =>
StageProfile(
id = a("id").asInstanceOf[String],
profileName = a("profileName").asInstanceOf[String],
profileVersion = a("profileVersion").asInstanceOf[String],
overlays = a("overlays").asInstanceOf[java.util.Collection[AnyRef]].asScala.map(o => unmapOverlayRef(o).get).toSet
@@ -189,7 +205,8 @@ trait Mapper {
properties = ci("properties").asInstanceOf[java.util.Map[String, String]].asScala.toMap,
serviceInfos = ci("serviceInfos").asInstanceOf[java.util.Collection[AnyRef]].asScala.toList.map(si => unmapServiceInfo(si).get),
profiles = ci("profiles").asInstanceOf[java.util.Collection[AnyRef]].asScala.toList.map(p => unmapProfile(p).get),
timestampMsec = ci("timestampMsec").asInstanceOf[java.lang.Long].longValue()
timestampMsec = ci("timestampMsec").asInstanceOf[java.lang.Long].longValue(),
appliedUpdateActionIds = Nil
)
}
@@ -204,12 +221,21 @@ trait Mapper {
)
}
def unmapProfileGroup(map: AnyRef): Try[ProfileGroup] = Try {
val p = map.asInstanceOf[java.util.Map[String, AnyRef]].asScala
ProfileGroup(
name = p("name").asInstanceOf[String],
version = p("version").asInstanceOf[String],
overlays = p("overlays").asInstanceOf[java.util.Collection[AnyRef]].asScala.toList.map(o => unmapOverlaySet(o).get)
)
}
def unmapProfile(map: AnyRef): Try[Profile] = Try {
val p = map.asInstanceOf[java.util.Map[String, AnyRef]].asScala
Profile(
name = p("name").asInstanceOf[String],
version = p("version").asInstanceOf[String],
overlays = p("overlays").asInstanceOf[java.util.Collection[AnyRef]].asScala.toList.map(o => unmapOverlaySet(o).get)
overlaySet = unmapOverlaySet(p("overlays")).get
)
}
@@ -1,19 +1,9 @@
package blended.updater.config
@deprecated("To be used only be the updater and will be renamed. Use SingleProfile instead.")
case class Profile(name: String, version: String, overlays: List[OverlaySet]) {
require(!overlays.isEmpty, "A Profile must have at least one OverlaySet.")
def toSingle: List[SingleProfile] = overlays.map(o => SingleProfile(name, version, o))
override def toString(): String = s"${getClass().getSimpleName()}(name=${name},version=${version},overlays=${overlays})"
}
object Profile {
def fromSingleProfiles(singleProfiles: Seq[SingleProfile]): List[Profile] = {
val grouped = singleProfiles.groupBy(p => (p.name, p.version))
grouped.toList.map { case ((n, v), p) => Profile(n, v, p.toList.map(_.overlaySet)) }
}
case class Profile(name: String, version: String, overlaySet: OverlaySet) {
// convenience getters
def overlays: Set[OverlayRef] = overlaySet.overlays
def state: OverlayState = overlaySet.state
override def toString(): String = s"${getClass().getSimpleName()}(name=${name},version=${version},overlaySet=${overlaySet})}"
}
@@ -0,0 +1,25 @@
package blended.updater.config
/**
* A group of [[Profile]]s, that share the same name and version.
* Hence, all profiles in the same group reprent the same runtimeConfig, but different overlays.
* @param name
* @param version
* @param overlays
*/
case class ProfileGroup(name: String, version: String, overlays: List[OverlaySet]) {
require(!overlays.isEmpty, "A ProfileGroup must have at least one OverlaySet.")
def toSingle: List[Profile] = overlays.map(o => Profile(name, version, o))
override def toString(): String = s"${getClass().getSimpleName()}(name=${name},version=${version},overlays=${overlays})"
}
object ProfileGroup {
def fromSingleProfiles(singleProfiles: Seq[Profile]): List[ProfileGroup] = {
val grouped = singleProfiles.groupBy(p => (p.name, p.version))
grouped.toList.map { case ((n, v), p) => ProfileGroup(n, v, p.toList.map(_.overlaySet)) }
}
}
@@ -3,4 +3,4 @@ package blended.updater.config
case class ProfileInfo (
timeStamp: Long,
profiles: List[Profile]
)
)
@@ -4,17 +4,20 @@ case class RolloutProfile(
profileName: String,
profileVersion: String,
overlays: Set[OverlayRef],
containerIds: List[String])
containerIds: List[String]
)
object RolloutProfile {
def apply(
profile: SingleProfile,
containerIds: List[String]): RolloutProfile =
profile: Profile,
containerIds: List[String]
): RolloutProfile =
RolloutProfile(
profileName = profile.name,
profileVersion = profile.version,
overlays = profile.overlaySet.overlays,
containerIds = containerIds)
containerIds = containerIds
)
}

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit cd0e57d

Please sign in to comment.