Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
Merge 6caf38a into 58f0a44
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmckenzie committed Nov 12, 2019
2 parents 58f0a44 + 6caf38a commit 732fea7
Show file tree
Hide file tree
Showing 61 changed files with 1,316 additions and 1,313 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
[Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- SHUTTER command renamed to SUSPEND
- UNSHUTTER command renamed to UNSUSPEND

## [6.3.0] - 2019-11-07
### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.gov.justice.services.management.hibernation.api;

import uk.gov.justice.services.management.hibernation.commands.SuspensionCommand;

import java.util.UUID;

public interface Suspendable {

default String getName() {
return this.getClass().getSimpleName();
}

default boolean shouldSuspend() {
return false;
}

default boolean shouldUnsuspend() {
return false;
}

default SuspensionResult suspend(final UUID commandId, final SuspensionCommand suspensionCommand) throws SuspensionFailedException {
throw new UnsupportedOperationException("Method not implemented");
}

default SuspensionResult unsuspend(final UUID commandId, final SuspensionCommand suspensionCommand) throws SuspensionFailedException {
throw new UnsupportedOperationException("Method not implemented");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package uk.gov.justice.services.management.hibernation.api;

public class SuspensionFailedException extends Exception {

public SuspensionFailedException(final String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.justice.services.management.shuttering.api;
package uk.gov.justice.services.management.hibernation.api;

import static java.util.Optional.empty;
import static java.util.Optional.of;
Expand All @@ -12,7 +12,7 @@
import java.util.Optional;
import java.util.UUID;

public class ShutteringResult {
public class SuspensionResult {

private final String shutteringExecutorName;
private final String message;
Expand All @@ -21,7 +21,7 @@ public class ShutteringResult {
private final SystemCommand systemCommand;
private final Optional<Throwable> exception;

private ShutteringResult(
private SuspensionResult(
final String shutteringExecutorName,
final String message,
final CommandState commandState,
Expand All @@ -36,13 +36,13 @@ private ShutteringResult(
this.exception = exception;
}

public static ShutteringResult shutteringSucceeded(
public static SuspensionResult shutteringSucceeded(
final String shutteringExecutorName,
final UUID commandId,
final String message,
final SystemCommand systemCommand) {

return new ShutteringResult(
return new SuspensionResult(
shutteringExecutorName,
message,
COMMAND_COMPLETE,
Expand All @@ -52,13 +52,13 @@ public static ShutteringResult shutteringSucceeded(
);
}

public static ShutteringResult shutteringFailed(
public static SuspensionResult shutteringFailed(
final String shutteringExecutorName,
final UUID commandId,
final String message,
final SystemCommand systemCommand) {

return new ShutteringResult(
return new SuspensionResult(
shutteringExecutorName,
message,
COMMAND_FAILED,
Expand All @@ -68,14 +68,14 @@ public static ShutteringResult shutteringFailed(
);
}

public static ShutteringResult shutteringFailed(
public static SuspensionResult shutteringFailed(
final String shutteringExecutorName,
final UUID commandId,
final String message,
final SystemCommand systemCommand,
final Throwable exception) {

return new ShutteringResult(
return new SuspensionResult(
shutteringExecutorName,
message,
COMMAND_FAILED,
Expand Down Expand Up @@ -112,8 +112,8 @@ public Optional<Throwable> getException() {
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof ShutteringResult)) return false;
final ShutteringResult that = (ShutteringResult) o;
if (!(o instanceof SuspensionResult)) return false;
final SuspensionResult that = (SuspensionResult) o;
return Objects.equals(shutteringExecutorName, that.shutteringExecutorName) &&
Objects.equals(message, that.message) &&
commandState == that.commandState &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package uk.gov.justice.services.management.hibernation.commands;

import uk.gov.justice.services.jmx.api.command.BaseSystemCommand;

public class SuspendCommand extends BaseSystemCommand implements SuspensionCommand {

public static final String SUSPEND = "SUSPEND";
private static final String DESCRIPTION = "Suspends the application to allow for maintenance.";

public SuspendCommand() {
super(SUSPEND, DESCRIPTION);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package uk.gov.justice.services.management.hibernation.commands;

import static uk.gov.justice.services.management.hibernation.commands.SuspendCommand.SUSPEND;
import static uk.gov.justice.services.management.hibernation.commands.UnsuspendCommand.UNSUSPEND;

import uk.gov.justice.services.jmx.api.command.SystemCommand;

public interface SuspensionCommand extends SystemCommand {

default boolean isSuspendCommand() {
return SUSPEND.equals(getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package uk.gov.justice.services.management.hibernation.commands;

import uk.gov.justice.services.jmx.api.command.BaseSystemCommand;

public class UnsuspendCommand extends BaseSystemCommand implements SuspensionCommand {

public static final String UNSUSPEND = "UNSUSPEND";
private static final String DESCRIPTION = "Unsuspends the application.";

public UnsuspendCommand() {
super(UNSUSPEND, DESCRIPTION);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package uk.gov.justice.services.management.hibernation.executors;

import static uk.gov.justice.services.management.hibernation.api.SuspensionResult.shutteringSucceeded;

import uk.gov.justice.services.management.hibernation.api.Suspendable;
import uk.gov.justice.services.management.hibernation.api.SuspensionResult;
import uk.gov.justice.services.management.hibernation.commands.SuspensionCommand;

import java.util.UUID;

import javax.inject.Inject;

import org.slf4j.Logger;

public class CommandApiSuspender implements Suspendable {

@Inject
private CommandApiSuspensionBean commandApiSuspensionBean;

@Inject
private Logger logger;

@Override
public boolean shouldSuspend() {
return true;
}

@Override
public boolean shouldUnsuspend() {
return true;
}

@Override
public SuspensionResult suspend(final UUID commandId, final SuspensionCommand suspensionCommand) {

logger.info("Suspending Command API");

commandApiSuspensionBean.suspend();

logger.info("Suspension of Command API complete");

return shutteringSucceeded(
getName(),
commandId,
"Command API suspended with no errors",
suspensionCommand
);
}

@Override
public SuspensionResult unsuspend(final UUID commandId, final SuspensionCommand suspensionCommand) {

logger.info("Unsuspending Command API");

commandApiSuspensionBean.unsuspend();

logger.info("Unsuspension of Command API complete");

return shutteringSucceeded(
getName(),
commandId,
"Command API unsuspended with no errors",
suspensionCommand
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.justice.services.management.shuttering.executors;
package uk.gov.justice.services.management.hibernation.executors;

import static javax.transaction.Transactional.TxType.REQUIRED;

Expand All @@ -15,7 +15,7 @@
import javax.transaction.Transactional;

@Stateless
public class CommandApiShutteringBean {
public class CommandApiSuspensionBean {

private static final int POLLER_RETRY_COUNT = 2;
private static final long POLLER_DELAY_INTERVAL_MILLIS = 100;
Expand All @@ -35,16 +35,16 @@ public class CommandApiShutteringBean {
@Inject
private MultiIteratingPollerFactory multiIteratingPollerFactory;

public void shutter() {
envelopeSenderSelector.setShuttered(true);
public void suspend() {
envelopeSenderSelector.setSuspended(true);
}

@Transactional(REQUIRED)
public void unshutter() {
public void unsuspend() {

getCommandsAndSend();

envelopeSenderSelector.setShuttered(false);
envelopeSenderSelector.setSuspended(false);

final MultiIteratingPoller multiIteratingPoller = multiIteratingPollerFactory.create(
POLLER_RETRY_COUNT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.justice.services.management.shuttering.executors;
package uk.gov.justice.services.management.hibernation.executors;

import static javax.transaction.Transactional.TxType.REQUIRES_NEW;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.justice.services.management.shuttering.handler;
package uk.gov.justice.services.management.hibernation.handler;

import static java.lang.String.format;
import static javax.transaction.Transactional.TxType.REQUIRED;
Expand All @@ -7,11 +7,11 @@
import uk.gov.justice.services.common.util.UtcClock;
import uk.gov.justice.services.jmx.logging.MdcLoggerInterceptor;
import uk.gov.justice.services.jmx.state.events.SystemCommandStateChangedEvent;
import uk.gov.justice.services.management.shuttering.api.ShutteringResult;
import uk.gov.justice.services.management.shuttering.commands.ApplicationShutteringCommand;
import uk.gov.justice.services.management.shuttering.process.ShutteringExecutorsRunner;
import uk.gov.justice.services.management.shuttering.process.ShutteringPostProcess;
import uk.gov.justice.services.management.shuttering.process.ShutteringResultsMapper;
import uk.gov.justice.services.management.hibernation.api.SuspensionResult;
import uk.gov.justice.services.management.hibernation.commands.SuspensionCommand;
import uk.gov.justice.services.management.hibernation.process.SuspendablesRunner;
import uk.gov.justice.services.management.hibernation.process.SuspensionPostProcess;
import uk.gov.justice.services.management.hibernation.process.SuspensionResultsMapper;

import java.util.List;
import java.util.UUID;
Expand All @@ -25,16 +25,16 @@
import org.slf4j.Logger;

@Stateless
public class RunShutteringBean {
public class SuspensionBean {

@Inject
private ShutteringExecutorsRunner shutteringExecutorsRunner;
private SuspendablesRunner suspendablesRunner;

@Inject
private ShutteringResultsMapper shutteringResultsMapper;
private SuspensionResultsMapper suspensionResultsMapper;

@Inject
private ShutteringPostProcess shutteringPostProcess;
private SuspensionPostProcess suspensionPostProcess;

@Inject
private Event<SystemCommandStateChangedEvent> systemCommandStateChangedEventFirer;
Expand All @@ -47,26 +47,26 @@ public class RunShutteringBean {

@Interceptors(MdcLoggerInterceptor.class)
@Transactional(REQUIRED)
public void runShuttering(final UUID commandId, final ApplicationShutteringCommand applicationShutteringCommand) {
final String systemCommandName = applicationShutteringCommand.getName();
public void runSuspension(final UUID commandId, final SuspensionCommand suspensionCommand) {
final String systemCommandName = suspensionCommand.getName();

logger.info(format("Running %s", systemCommandName));

systemCommandStateChangedEventFirer.fire(new SystemCommandStateChangedEvent(
commandId,
applicationShutteringCommand,
suspensionCommand,
COMMAND_IN_PROGRESS,
clock.now(),
format("%s started", systemCommandName)
));

final List<ShutteringResult> results = shutteringExecutorsRunner.findAndRunShutteringExecutors(
final List<SuspensionResult> results = suspendablesRunner.findAndRunSuspendables(
commandId,
applicationShutteringCommand
suspensionCommand
);

final List<ShutteringResult> failureResults = shutteringResultsMapper.getFailedResults(results);
final List<ShutteringResult> successfulResults = shutteringResultsMapper.getSuccessfulResults(results);
final List<SuspensionResult> failureResults = suspensionResultsMapper.getFailedResults(results);
final List<SuspensionResult> successfulResults = suspensionResultsMapper.getSuccessfulResults(results);

logger.info(format(
"%s ran with %s success(es) and %s error(s)",
Expand All @@ -75,9 +75,9 @@ public void runShuttering(final UUID commandId, final ApplicationShutteringComma
failureResults.size()));

if (failureResults.isEmpty()) {
shutteringPostProcess.completeShutteringSuccessfully(successfulResults, commandId, applicationShutteringCommand);
suspensionPostProcess.completeSuspensionSuccessfully(successfulResults, commandId, suspensionCommand);
} else {
shutteringPostProcess.completeShutteringWithFailures(failureResults, commandId, applicationShutteringCommand);
suspensionPostProcess.completeSuspensionWithFailures(failureResults, commandId, suspensionCommand);
}
}
}
Loading

0 comments on commit 732fea7

Please sign in to comment.