Skip to content

Commit

Permalink
Merge c6ca388 into 70ad4e9
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmckenzie committed Oct 9, 2019
2 parents 70ad4e9 + c6ca388 commit 10b2d73
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 331 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## [Unreleased]

## [2.2.0-M3] - 2018-10-09
### Changed
- Updated framework t0 6.2.0-M3
- Converted ShutteringExecutors to use the new ShutteringExecutor interface

## [2.2.0-M2] - 2018-10-02
### Added
- Added commandId to all SystemEvents
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package uk.gov.justice.services.eventstore.management.shuttering.observers;

import static java.lang.String.format;
import static uk.gov.justice.services.management.shuttering.api.ShutteringResult.shutteringFailed;
import static uk.gov.justice.services.management.shuttering.api.ShutteringResult.shutteringSucceeded;

import uk.gov.justice.services.eventsourcing.util.jee.timer.StopWatchFactory;
import uk.gov.justice.services.eventstore.management.shuttering.process.CommandHandlerQueueInterrogator;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.management.shuttering.api.ShutteringExecutor;
import uk.gov.justice.services.management.shuttering.api.ShutteringResult;

import java.util.UUID;

import javax.inject.Inject;

import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;

public class CommandHandlerQueueDrainedShutteringExecutor implements ShutteringExecutor {

@Inject
private CommandHandlerQueueInterrogator commandHandlerQueueInterrogator;

@Inject
private StopWatchFactory stopWatchFactory;

@Inject
private Logger logger;

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

@Override
public ShutteringResult shutter(final UUID commandId, final SystemCommand systemCommand) {

logger.info("Shuttering Command Handler. Waiting for queue to drain");

final StopWatch stopWatch = stopWatchFactory.createStartedStopWatch();

try {
final boolean queueEmpty = commandHandlerQueueInterrogator.pollUntilEmptyHandlerQueue();

if (queueEmpty) {

final String message = "Command Handler Queue drained successfully";
logger.info(message);

return shutteringSucceeded(
getName(),
commandId,
message,
systemCommand
);
}

stopWatch.stop();

final String message = format("Failed to drain command handler queue in %d milliseconds", stopWatch.getTime());
logger.error(message);

return shutteringFailed(
getName(),
commandId,
message,
systemCommand
);
} finally {
stopWatch.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package uk.gov.justice.services.eventstore.management.shuttering.observers;

import static java.lang.String.format;
import static uk.gov.justice.services.management.shuttering.api.ShutteringResult.shutteringFailed;
import static uk.gov.justice.services.management.shuttering.api.ShutteringResult.shutteringSucceeded;

import uk.gov.justice.services.eventsourcing.util.jee.timer.StopWatchFactory;
import uk.gov.justice.services.eventstore.management.shuttering.process.PublishQueueInterrogator;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.management.shuttering.api.ShutteringExecutor;
import uk.gov.justice.services.management.shuttering.api.ShutteringResult;

import java.util.UUID;

import javax.inject.Inject;

import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;

public class PublishQueueDrainedShutteringExecutor implements ShutteringExecutor {

@Inject
private PublishQueueInterrogator publishQueueInterrogator;

@Inject
private StopWatchFactory stopWatchFactory;

@Inject
private Logger logger;

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

@Override
public ShutteringResult shutter(final UUID commandId, final SystemCommand systemCommand) {

logger.info("Waiting for Publish Queue to empty");
final StopWatch stopWatch = stopWatchFactory.createStartedStopWatch();

try {
final boolean queueEmpty = publishQueueInterrogator.pollUntilPublishQueueEmpty();

if (queueEmpty) {
final String message = "Publish Queue drained successfully";
logger.info(message);

return shutteringSucceeded(
getName(),
commandId,
message,
systemCommand
);
}

stopWatch.stop();

final String message = format("PublishQueue failed to drain after %d milliseconds", stopWatch.getTime());

logger.error(message);

return shutteringFailed(
getName(),
commandId,
message,
systemCommand
);

} finally {
stopWatch.stop();
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import uk.gov.justice.services.common.util.UtcClock;
import uk.gov.justice.services.eventstore.management.events.rebuild.RebuildRequestedEvent;
import uk.gov.justice.services.jmx.api.command.RebuildCommand;
import uk.gov.justice.services.management.shuttering.events.ShutteringRequestedEvent;
import uk.gov.justice.services.management.shuttering.events.UnshutteringRequestedEvent;

import java.time.ZonedDateTime;
import java.util.UUID;
Expand Down
Loading

0 comments on commit 10b2d73

Please sign in to comment.