From d6c76c69aa5c08a741550b04964108d63a8a0289 Mon Sep 17 00:00:00 2001 From: Christian Sailer Date: Tue, 23 Oct 2018 08:51:09 +0100 Subject: [PATCH] ENT-2553 Serialisation warnings in notary healthcheck (#1497) * Visibility settings and annotations to stop warnings when running notary healthcheck. * Add progress trackers so the warnings about unstarted progress trackers disappear. --- .../notaryhealthcheck/cordapp/CheckStates.kt | 12 +++++++++--- .../cordapp/HealthCheckFlow.kt | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/notary-healthcheck/cordapp/src/main/kotlin/net/corda/notaryhealthcheck/cordapp/CheckStates.kt b/tools/notary-healthcheck/cordapp/src/main/kotlin/net/corda/notaryhealthcheck/cordapp/CheckStates.kt index bc2a27c401..be99c72236 100644 --- a/tools/notary-healthcheck/cordapp/src/main/kotlin/net/corda/notaryhealthcheck/cordapp/CheckStates.kt +++ b/tools/notary-healthcheck/cordapp/src/main/kotlin/net/corda/notaryhealthcheck/cordapp/CheckStates.kt @@ -3,6 +3,7 @@ package net.corda.notaryhealthcheck.cordapp import net.corda.core.contracts.* import net.corda.core.flows.FlowLogicRefFactory import net.corda.core.identity.AbstractParty +import net.corda.notaryhealthcheck.contract.SchedulingContract import net.corda.notaryhealthcheck.utils.Monitorable import java.time.Instant import kotlin.reflect.jvm.jvmName @@ -20,15 +21,16 @@ import kotlin.reflect.jvm.jvmName * @param waitTimeSeconds How long to wait for the next check (i.e. time to add to the current time for the next states startTime) * @param waitForOutstandingFlowsSeconds How long to wait before running another notary check if the previous one is still outstanding. */ +@BelongsToContract(SchedulingContract::class) class ScheduledCheckState( override val participants: List, override val linearId: UniqueIdentifier, val statesToCheck: List, val target: Monitorable, - private val startTime: Instant, + val startTime: Instant, val lastSuccessTime: Instant, - private val waitTimeSeconds: Int, - private val waitForOutstandingFlowsSeconds: Int) : SchedulableState, LinearState { + val waitTimeSeconds: Int, + val waitForOutstandingFlowsSeconds: Int) : SchedulableState, LinearState { override fun nextScheduledActivity(thisStateRef: StateRef, flowLogicRefFactory: FlowLogicRefFactory): ScheduledActivity? { val logicRef = flowLogicRefFactory.create(ScheduledCheckFlow::class.jvmName, thisStateRef, waitTimeSeconds, waitForOutstandingFlowsSeconds) return ScheduledActivity(logicRef, startTime) @@ -39,18 +41,21 @@ class ScheduledCheckState( * State to mark a running notary health check. The ScheduleCheckFlow evolves a ScheduleCheckState into this when it * runs the healthcheck flow for its target. */ +@BelongsToContract(SchedulingContract::class) class RunningCheckState(override val linearId: UniqueIdentifier, override val participants: List, val startTime: Instant) : LinearState /** * State to mark a successful health check. The ScheduleCheckFlow evolves a RunningCheckState into this if the healthcheck * flow returns successfully. */ +@BelongsToContract(SchedulingContract::class) class SuccessfulCheckState(override val linearId: UniqueIdentifier, override val participants: List, val finishTime: Instant) : LinearState /** * State to mark a failed health check. The ScheduleCheckFlow evolves a RunningCheckState into this if the healthcheck * flow fails */ +@BelongsToContract(SchedulingContract::class) class FailedCheckState(override val linearId: UniqueIdentifier, override val participants: List) : LinearState /** @@ -58,5 +63,6 @@ class FailedCheckState(override val linearId: UniqueIdentifier, override val par * if there was still one or more healthcheck flows outstanding and the last one had been started less than waitForOutstandingFlowsSeconds * ago. */ +@BelongsToContract(SchedulingContract::class) class AbandonnedCheckState(override val linearId: UniqueIdentifier, override val participants: List) : LinearState diff --git a/tools/notary-healthcheck/cordapp/src/main/kotlin/net/corda/notaryhealthcheck/cordapp/HealthCheckFlow.kt b/tools/notary-healthcheck/cordapp/src/main/kotlin/net/corda/notaryhealthcheck/cordapp/HealthCheckFlow.kt index 7067584f71..d7252b4457 100644 --- a/tools/notary-healthcheck/cordapp/src/main/kotlin/net/corda/notaryhealthcheck/cordapp/HealthCheckFlow.kt +++ b/tools/notary-healthcheck/cordapp/src/main/kotlin/net/corda/notaryhealthcheck/cordapp/HealthCheckFlow.kt @@ -12,6 +12,7 @@ import net.corda.core.transactions.ContractUpgradeWireTransaction import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.WireTransaction +import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.UntrustworthyData import net.corda.notaryhealthcheck.contract.NullContract import net.corda.notaryhealthcheck.utils.Monitorable @@ -23,14 +24,25 @@ class HealthCheckFlow(monitorable: Monitorable) : FlowLogic) : ContractState + companion object { + object PREPARING : ProgressTracker.Step("Preparing") + object CHECKING : ProgressTracker.Step("Checking") + } + + override val progressTracker = ProgressTracker(PREPARING, CHECKING) + @Suspendable override fun call(): List { + progressTracker.currentStep = PREPARING val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary).apply { addOutputState(State(listOf(ourIdentity)), NullContract::class.java.name, AlwaysAcceptAttachmentConstraint) addCommand(NullCommand(), listOf(ourIdentity.owningKey)) }) + progressTracker.currentStep = CHECKING return subFlow(NotaryClientFlow(stx, party, notary)) } @@ -53,11 +65,14 @@ class HealthCheckFlow(monitorable: Monitorable) : FlowLogic { val session = initiateFlow(party) val requestSignature = NotarisationRequest(stx.inputs, stx.id).generateSignature(serviceHub) - return validateResponse(if (serviceHub.networkMapCache.isValidatingNotary(notaryParty)) { + progressTracker.currentStep = REQUESTING + val result = if (serviceHub.networkMapCache.isValidatingNotary(notaryParty)) { sendAndReceiveValidating(session, requestSignature) } else { sendAndReceiveNonValidating(notaryParty, session, requestSignature) - }, notaryParty) + } + progressTracker.currentStep = VALIDATING + return validateResponse(result, notaryParty) }