-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from CJSCommonPlatform/fix-failure-status-of-…
…verify-catchup Status of VERIFY_CATCHUP command now correctly set to COMMAND_FAILED …
- Loading branch information
Showing
30 changed files
with
717 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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
74 changes: 74 additions & 0 deletions
74
...justice/services/eventstore/management/validation/commands/VerificationCommandResult.java
This file contains 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,74 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.commands; | ||
|
||
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_COMPLETE; | ||
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_FAILED; | ||
|
||
import uk.gov.justice.services.jmx.api.domain.CommandState; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
public class VerificationCommandResult { | ||
|
||
private final UUID commandId; | ||
private final String message; | ||
private final CommandState commandState; | ||
|
||
private VerificationCommandResult(final UUID commandId, final String message, final CommandState commandState) { | ||
this.commandId = commandId; | ||
this.message = message; | ||
this.commandState = commandState; | ||
} | ||
|
||
public static VerificationCommandResult success(final UUID commandId, final String message) { | ||
return new VerificationCommandResult( | ||
commandId, | ||
message, | ||
COMMAND_COMPLETE | ||
); | ||
} | ||
|
||
public static VerificationCommandResult failure(final UUID commandId, final String message) { | ||
return new VerificationCommandResult( | ||
commandId, | ||
message, | ||
COMMAND_FAILED | ||
); | ||
} | ||
|
||
public UUID getCommandId() { | ||
return commandId; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public CommandState getCommandState() { | ||
return commandState; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof VerificationCommandResult)) return false; | ||
final VerificationCommandResult that = (VerificationCommandResult) o; | ||
return Objects.equals(commandId, that.commandId) && | ||
Objects.equals(message, that.message) && | ||
commandState == that.commandState; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(commandId, message, commandState); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "VerificationResult{" + | ||
"commandId=" + commandId + | ||
", message='" + message + '\'' + | ||
", commandState=" + commandState + | ||
'}'; | ||
} | ||
} |
This file contains 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
53 changes: 24 additions & 29 deletions
53
...justice/services/eventstore/management/validation/process/CatchupVerificationProcess.java
This file contains 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 |
---|---|---|
@@ -1,50 +1,45 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.process; | ||
|
||
import static java.lang.String.format; | ||
import static java.util.stream.Collectors.toList; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.VerificationResult.VerificationResultType.ERROR; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.VerificationResult.VerificationResultType.SUCCESS; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.VerificationResult.VerificationResultType.WARNING; | ||
import uk.gov.justice.services.eventstore.management.validation.commands.VerificationCommandResult; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.slf4j.Logger; | ||
|
||
public class CatchupVerificationProcess { | ||
|
||
@Inject | ||
private Logger logger; | ||
private VerificationRunner verificationRunner; | ||
|
||
@Inject | ||
private VerifierProvider verifierProvider; | ||
private VerificationResultFilter verificationResultFilter; | ||
|
||
public void runVerification() { | ||
@Inject | ||
private VerificationResultsLogger verificationResultsLogger; | ||
|
||
final List<VerificationResult> verificationResults = verifierProvider.getVerifiers().stream() | ||
.map(Verifier::verify) | ||
.flatMap(Collection::stream) | ||
.collect(toList()); | ||
@Inject | ||
private CommandResultGenerator commandResultGenerator; | ||
|
||
final List<VerificationResult> errorResults = filter(verificationResults, ERROR); | ||
final List<VerificationResult> warningResults = filter(verificationResults, WARNING); | ||
final List<VerificationResult> successfulResults = filter(verificationResults, SUCCESS); | ||
public VerificationCommandResult runVerification(final UUID commandId) { | ||
|
||
logger.info(format("Verification of Catchup completed with %d Errors, %d Warnings and %d Successes", errorResults.size(), warningResults.size(), successfulResults.size())); | ||
final List<VerificationResult> verificationResults = verificationRunner.runVerifiers(); | ||
|
||
errorResults.forEach(verificationResult -> logger.error("ERROR: " + verificationResult.getMessage())); | ||
warningResults.forEach(verificationResult -> logger.warn("WARNING: " + verificationResult.getMessage())); | ||
successfulResults.forEach(verificationResult -> logger.info("SUCCESS: " + verificationResult.getMessage())); | ||
} | ||
final List<VerificationResult> successResults = verificationResultFilter.findSuccesses(verificationResults); | ||
final List<VerificationResult> warningResults = verificationResultFilter.findWarnings(verificationResults); | ||
final List<VerificationResult> errorResults = verificationResultFilter.findErrors(verificationResults); | ||
|
||
private List<VerificationResult> filter( | ||
final List<VerificationResult> verificationResults, | ||
final VerificationResult.VerificationResultType verificationResultType) { | ||
verificationResultsLogger.logResults( | ||
successResults, | ||
warningResults, | ||
errorResults | ||
); | ||
|
||
return verificationResults.stream() | ||
.filter(verificationResult -> verificationResult.getVerificationResultType() == verificationResultType) | ||
.collect(toList()); | ||
return commandResultGenerator.createCommandResult( | ||
commandId, | ||
successResults, | ||
warningResults, | ||
errorResults | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...gov/justice/services/eventstore/management/validation/process/CommandResultGenerator.java
This file contains 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,43 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.process; | ||
|
||
import static java.lang.String.format; | ||
import static uk.gov.justice.services.eventstore.management.validation.commands.VerificationCommandResult.failure; | ||
import static uk.gov.justice.services.eventstore.management.validation.commands.VerificationCommandResult.success; | ||
|
||
import uk.gov.justice.services.eventstore.management.validation.commands.VerificationCommandResult; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class CommandResultGenerator { | ||
|
||
public VerificationCommandResult createCommandResult( | ||
final UUID commandId, | ||
final List<VerificationResult> successfulResults, | ||
final List<VerificationResult> warningResults, | ||
final List<VerificationResult> errorResults) { | ||
|
||
|
||
if (errorResults.isEmpty()) { | ||
final String message = format( | ||
"Verification of Catchup completed successfully with %d Error(s), %d Warning(s) and %d Success(es)", | ||
errorResults.size(), | ||
warningResults.size(), | ||
successfulResults.size()); | ||
|
||
return success(commandId, message); | ||
} | ||
|
||
final String message = format( | ||
"Verification of Catchup failed with %d Error(s), %d Warning(s) and %d Success(es)", | ||
errorResults.size(), | ||
warningResults.size(), | ||
successfulResults.size()); | ||
|
||
return failure( | ||
commandId, | ||
message | ||
); | ||
|
||
} | ||
} |
This file contains 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
32 changes: 32 additions & 0 deletions
32
...v/justice/services/eventstore/management/validation/process/VerificationResultFilter.java
This file contains 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,32 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.process; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.VerificationResult.VerificationResultType.ERROR; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.VerificationResult.VerificationResultType.SUCCESS; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.VerificationResult.VerificationResultType.WARNING; | ||
|
||
import java.util.List; | ||
|
||
public class VerificationResultFilter { | ||
|
||
public List<VerificationResult> findSuccesses(final List<VerificationResult> verificationResults) { | ||
return filter(SUCCESS, verificationResults); | ||
} | ||
|
||
public List<VerificationResult> findWarnings(final List<VerificationResult> verificationResults) { | ||
return filter(WARNING, verificationResults); | ||
} | ||
|
||
public List<VerificationResult> findErrors(final List<VerificationResult> verificationResults) { | ||
return filter(ERROR, verificationResults); | ||
} | ||
|
||
private List<VerificationResult> filter( | ||
final VerificationResult.VerificationResultType verificationResultType, | ||
final List<VerificationResult> verificationResults) { | ||
|
||
return verificationResults.stream() | ||
.filter(verificationResult -> verificationResult.getVerificationResultType() == verificationResultType) | ||
.collect(toList()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.../justice/services/eventstore/management/validation/process/VerificationResultsLogger.java
This file contains 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,27 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.process; | ||
|
||
import static java.lang.String.format; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.slf4j.Logger; | ||
|
||
public class VerificationResultsLogger { | ||
|
||
@Inject | ||
private Logger logger; | ||
|
||
public void logResults( | ||
final List<VerificationResult> successfulResults, | ||
final List<VerificationResult> warningResults, | ||
final List<VerificationResult> errorResults) { | ||
|
||
logger.info(format("Verification of Catchup completed with %d Errors, %d Warnings and %d Successes", errorResults.size(), warningResults.size(), successfulResults.size())); | ||
|
||
errorResults.forEach(verificationResult -> logger.error("ERROR: " + verificationResult.getMessage())); | ||
warningResults.forEach(verificationResult -> logger.warn("WARNING: " + verificationResult.getMessage())); | ||
successfulResults.forEach(verificationResult -> logger.info("SUCCESS: " + verificationResult.getMessage())); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../uk/gov/justice/services/eventstore/management/validation/process/VerificationRunner.java
This file contains 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,22 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.process; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class VerificationRunner { | ||
|
||
@Inject | ||
private VerifierProvider verifierProvider; | ||
|
||
public List<VerificationResult> runVerifiers() { | ||
|
||
return verifierProvider.getVerifiers().stream() | ||
.map(Verifier::verify) | ||
.flatMap(Collection::stream) | ||
.collect(toList()); | ||
} | ||
} |
This file contains 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
5 changes: 4 additions & 1 deletion
5
.../process/ProcessedEventCountVerifier.java → ...erifiers/ProcessedEventCountVerifier.java
This file contains 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 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 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.