Skip to content

Commit

Permalink
Handle Time forced feature of hawkbit properly
Browse files Browse the repository at this point in the history
Signed-off-by: Saeed Rezaee <[email protected]>
  • Loading branch information
SaeedRe committed Feb 13, 2024
1 parent f2666d4 commit 5cec8b7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {

msg is Out.DeploymentInfo -> onDeployment(msg, state)

msg is DeploymentManager.Companion.Message.DownloadFailed -> {
msg is DownloadManager.Companion.Message.DownloadFailed -> {
become(defaultReceive(state.copy(deployment = null)))
child("deploymentManager")!!.close()
}

msg is DeploymentManager.Companion.Message.UpdateFailed ||
msg is DeploymentManager.Companion.Message.UpdateFinished -> {
msg is UpdateManager.Companion.Message.UpdateFailed ||
msg is UpdateManager.Companion.Message.UpdateFinished -> {
LOG.info(msg.javaClass.simpleName)
become(defaultReceive(state.copy(deployment = null)))
child("deploymentManager")!!.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {

private fun downloadingReceive(state: State): Receive = { msg ->
when (msg) {
is Message.DownloadFinished -> {
is DeploymentInfo -> {
//Send the new DeploymentInfo message to the download manager
become(downloadingReceive(state.copy(deplBaseResp = msg.info)))
child("downloadManager")!!.send(DeploymentInfo(msg.info))
}
is DownloadManager.Companion.Message.DownloadFinished -> {
become(updatingReceive())
child("updateManager")!!.send(DeploymentInfo(state.deplBaseResp!!))

}
is Message.DownloadFailed -> {
is DownloadManager.Companion.Message.DownloadFailed -> {
LOG.error("download failed")
parent!!.send(msg)
}
Expand All @@ -64,12 +68,17 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
private fun updatingReceive(): Receive = { msg ->
when (msg) {

is Message.UpdateFailed -> {
is DeploymentInfo -> {
//Send the new DeploymentInfo message to the update manager
child("updateManager")!!.send(DeploymentInfo(msg.info))
}

is UpdateManager.Companion.Message.UpdateFailed -> {
LOG.info("update failed")
parent!!.send(msg)
}

is Message.UpdateFinished -> {
is UpdateManager.Companion.Message.UpdateFinished -> {
LOG.info("update finished")
parent!!.send(msg)
}
Expand All @@ -86,6 +95,7 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
is CancelForced -> {
LOG.info("Force cancel ignored")
}
else -> unhandled(msg)
}
}

Expand Down Expand Up @@ -115,11 +125,5 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {

data class State(val deplBaseResp: DeploymentBaseResponse? = null)

sealed class Message {
object DownloadFinished : Message()
data class DownloadFailed(val details: List<String>) : Message()
object UpdateFailed : Message()
object UpdateFinished : Message()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import org.eclipse.hara.ddi.api.model.DeploymentFeedbackRequest.Status.Result.Fi
import org.eclipse.hara.ddi.api.model.DeploymentFeedbackRequest.Status.Result.Progress
import org.eclipse.hara.ddiclient.api.actors.ConnectionManager.Companion.Message.In.DeploymentFeedback
import org.eclipse.hara.ddiclient.api.actors.ConnectionManager.Companion.Message.Out.DeploymentInfo
import org.eclipse.hara.ddiclient.api.actors.DeploymentManager.Companion.Message.DownloadFailed
import org.eclipse.hara.ddiclient.api.actors.DeploymentManager.Companion.Message.DownloadFinished
import org.eclipse.hara.ddiclient.api.actors.DownloadManager.Companion.State.Download
import org.eclipse.hara.ddiclient.api.actors.DownloadManager.Companion.State.Download.State.Status
import org.eclipse.hara.ddiclient.api.actors.FileDownloader.Companion.FileToDownload
Expand Down Expand Up @@ -66,13 +64,13 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
}

msg.isDownloadSoft -> {
attemptDownloadingTheArtifact(State(msg.info), msg)
attemptDownloadingTheArtifact(msg)
}

msg.isDownloadSkip -> {
// todo implement download skip option
LOG.warn("skip download not yet implemented (used attempt)")
attemptDownloadingTheArtifact(State(msg.info), msg)
attemptDownloadingTheArtifact(msg)
}
}
}
Expand All @@ -91,11 +89,11 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
}
}

private suspend fun attemptDownloadingTheArtifact(state: State, msg: DeploymentInfo) {
private suspend fun attemptDownloadingTheArtifact(msg: DeploymentInfo) {
val message = "Waiting authorization to download"
LOG.info(message)
feedback(msg.info.id, proceeding, Progress(0, 0), none, message)
become(waitingDownloadAuthorization(state.copy(deplBaseResp = msg.info)))
become(waitingDownloadAuthorization(State(deplBaseResp = msg.info)))
notificationManager.send(MessageListener.Message.State
.WaitingDownloadAuthorization(false))
waitingAuthJob?.cancel()
Expand Down Expand Up @@ -242,7 +240,7 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
notificationManager.send(
MessageListener.Message.Event.UpdateFinished(successApply = false,
details = listOf(message)))
parent!!.send(DownloadFailed(listOf(message)))
parent!!.send(Message.DownloadFailed(listOf(message)))
}
else -> {
feedback(state.deplBaseResp.id, proceeding, progress, none, message)
Expand All @@ -255,7 +253,7 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
feedback(id, proceeding, progress, finished, message)
newState?.downloads?.values?.forEach { it.downloader.close() }
notificationManager.send(MessageListener.Message.Event.AllFilesDownloaded)
parent!!.send(DownloadFinished)
parent!!.send(Message.DownloadFinished)
channel.close()
}

Expand Down Expand Up @@ -352,6 +350,10 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {

sealed class Message {
object DownloadGranted : Message()

object DownloadFinished : Message()

data class DownloadFailed(val details: List<String>) : Message()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {

when{
updaters.all { it.softwareModules.isEmpty() } -> {
parent!!.send(DeploymentManager.Companion.Message.UpdateFinished)
parent!!.send(Message.UpdateFinished)
sendFeedback(msg.info.id, closed, Progress(0,0), success,
"No update applied"
)
Expand All @@ -144,14 +144,14 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {

updaterError.isNotEmpty() -> {
LOG.warn("update ${updaterError[0].first} failed!")
parent!!.send(DeploymentManager.Companion.Message.UpdateFailed)
parent!!.send(Message.UpdateFailed)
sendFeedback(msg.info.id, closed, Progress(updaters.size, updaterError[0].first),
failure, *details.toTypedArray())
notificationManager.send(MessageListener.Message.Event.UpdateFinished(successApply = false, details = details))
}

else -> {
parent!!.send(DeploymentManager.Companion.Message.UpdateFinished)
parent!!.send(Message.UpdateFinished)
sendFeedback(msg.info.id, closed, Progress(updaters.size, updaters.size),
success, *details.toTypedArray())
notificationManager.send(MessageListener.Message.Event.UpdateFinished(successApply = true, details = details))
Expand Down Expand Up @@ -236,6 +236,8 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
}
sealed class Message {
object UpdateGranted : Message()
object UpdateFailed : Message()
object UpdateFinished : Message()
}
}
}

0 comments on commit 5cec8b7

Please sign in to comment.