-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/ota 4175/director lite #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
simao
wants to merge
6
commits into
director-lite
Choose a base branch
from
feat/OTA-4175/director-lite
base: director-lite
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c4529f8
Implement backwards compatible API
simao f552eef
implement device listing endpoint
simao 009a945
Use director-v1 response format
simao 691df25
Add test to assert targets.json doesnt change after expire
simao 9b2ddec
New endpoint to force targets refresh
simao 0a5a4e2
Allow provision of device with same deviceId but different ecus
simao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/scala/com/advancedtelematic/director/http/LegacyRoutes.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.advancedtelematic.director.http | ||
|
|
||
| import java.time.Instant | ||
|
|
||
| import akka.http.scaladsl.model.StatusCodes | ||
| import akka.http.scaladsl.server.Directives.{complete, delete, path, put} | ||
| import akka.http.scaladsl.server.{Directive1, Route} | ||
| import com.advancedtelematic.libats.data.DataType.{MultiTargetUpdateId, Namespace} | ||
| import com.advancedtelematic.libats.messaging.MessageBusPublisher | ||
| import com.advancedtelematic.libats.messaging_datatype.DataType.{DeviceId, UpdateId} | ||
| import com.advancedtelematic.libats.messaging_datatype.Messages.{DeviceUpdateAssigned, DeviceUpdateEvent} | ||
| import slick.jdbc.MySQLProfile.api._ | ||
| import com.advancedtelematic.libats.http.UUIDKeyAkka._ | ||
| import akka.http.scaladsl.server.Directives._ | ||
|
|
||
| import scala.concurrent.{ExecutionContext, Future} | ||
| import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ | ||
| import PaginationParametersDirectives._ | ||
| import com.advancedtelematic.director.db.EcuRepositorySupport | ||
|
|
||
| // Implements routes provided by old director that ota-web-app still uses | ||
| class LegacyRoutes(extractNamespace: Directive1[Namespace])(implicit val db: Database, val ec: ExecutionContext, messageBusPublisher: MessageBusPublisher) | ||
| extends EcuRepositorySupport { | ||
| private val deviceAssignments = new DeviceAssignments() | ||
|
|
||
| private def createDeviceAssignment(ns: Namespace, deviceId: DeviceId, mtuId: UpdateId): Future[Unit] = { | ||
| val correlationId = MultiTargetUpdateId(mtuId.uuid) | ||
| val assignment = deviceAssignments.createForDevice(ns, correlationId, deviceId, mtuId) | ||
|
|
||
| assignment.map { a => | ||
| val msg: DeviceUpdateEvent = DeviceUpdateAssigned(ns, Instant.now(), correlationId, a.deviceId) | ||
| messageBusPublisher.publishSafe(msg) | ||
| } | ||
| } | ||
|
|
||
| val route: Route = | ||
| extractNamespace { ns => | ||
| path("admin" / "devices" / DeviceId.Path / "multi_target_update" / UpdateId.Path) { (deviceId, updateId) => | ||
| put { | ||
| val f = createDeviceAssignment(ns, deviceId, updateId).map(_ => StatusCodes.Created) | ||
| complete(f) | ||
| } | ||
| } ~ | ||
| path("assignments" / DeviceId.Path) { deviceId => | ||
| delete { | ||
| val a = deviceAssignments.cancel(ns, List(deviceId)) | ||
| complete(a.map(_.map(_.deviceId))) | ||
| } | ||
| } ~ | ||
| (path("admin" / "devices") & PaginationParameters) { (limit, offset) => | ||
| get { | ||
| complete(ecuRepository.findAllDeviceIds(ns, offset, limit)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/scala/com/advancedtelematic/director/http/PaginationParametersDirectives.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.advancedtelematic.director.http | ||
|
|
||
|
|
||
| import akka.http.scaladsl.server.Directive | ||
| import akka.http.scaladsl.server.Directives._ | ||
|
|
||
| object PaginationParametersDirectives { | ||
| val PaginationParameters: Directive[(Long, Long)] = | ||
| (parameters('limit.as[Long].?) & parameters('offset.as[Long].?)).tmap { case (mLimit, mOffset) => | ||
| val limit = mLimit.getOrElse(50L).min(1000) | ||
| val offset = mOffset.getOrElse(0L) | ||
| (limit, offset) | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/scala/com/advancedtelematic/director/http/RepositoryCreation.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.advancedtelematic.director.http | ||
|
|
||
| import com.advancedtelematic.director.db.{DeviceRepositorySupport, RepoNamespaceRepositorySupport} | ||
| import com.advancedtelematic.libats.data.DataType.Namespace | ||
| import com.advancedtelematic.libtuf.data.TufDataType.{Ed25519KeyType, RepoId} | ||
| import com.advancedtelematic.libtuf_server.keyserver.KeyserverClient | ||
| import slick.jdbc.MySQLProfile.api._ | ||
| import com.advancedtelematic.libats.http.UUIDKeyAkka._ | ||
|
|
||
| import scala.concurrent.{ExecutionContext, Future} | ||
|
|
||
| class RepositoryCreation(keyserverClient: KeyserverClient)(implicit val db: Database, val ec: ExecutionContext) | ||
| extends DeviceRepositorySupport with RepoNamespaceRepositorySupport { | ||
|
|
||
| def create(ns: Namespace): Future[Unit] = { | ||
| val repoId = RepoId.generate() | ||
|
|
||
| for { | ||
| _ <- keyserverClient.createRoot(repoId, Ed25519KeyType, forceSync = true) | ||
| _ <- repoNamespaceRepo.persist(repoId, ns) | ||
| } yield () | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.