diff --git a/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/ActionManager.kt b/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/ActionManager.kt index bdb143b..3e60f76 100644 --- a/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/ActionManager.kt +++ b/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/ActionManager.kt @@ -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() diff --git a/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DeploymentManager.kt b/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DeploymentManager.kt index 727bf53..442329f 100644 --- a/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DeploymentManager.kt +++ b/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DeploymentManager.kt @@ -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) } @@ -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) } @@ -86,6 +95,7 @@ private constructor(scope: ActorScope) : AbstractActor(scope) { is CancelForced -> { LOG.info("Force cancel ignored") } + else -> unhandled(msg) } } @@ -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) : Message() - object UpdateFailed : Message() - object UpdateFinished : Message() - } } } diff --git a/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DownloadManager.kt b/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DownloadManager.kt index 71e7a89..e8cb10f 100644 --- a/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DownloadManager.kt +++ b/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DownloadManager.kt @@ -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 @@ -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) } } } @@ -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() @@ -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) @@ -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() } @@ -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) : Message() } } } diff --git a/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/UpdateManager.kt b/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/UpdateManager.kt index b36ba28..850f090 100644 --- a/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/UpdateManager.kt +++ b/src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/UpdateManager.kt @@ -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" ) @@ -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)) @@ -236,6 +236,8 @@ private constructor(scope: ActorScope) : AbstractActor(scope) { } sealed class Message { object UpdateGranted : Message() + object UpdateFailed : Message() + object UpdateFinished : Message() } } }