Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create JMX bean command handlers for system commands #115

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
[Semantic Versioning](http://semver.org/).

## [Unreleased]
## [2.0.0-M33] - 2019-06-05
### Changed
- Catchup and rebuild now use the new System Command jmx architecture
- Events for catchup and rebuild moved in from framework-api
- Catchup and rebuild moved to a new 'event-store-management' module

## [2.0.0-M32] - 2019-05-30
### Fixed
- Added component column to processed_event table to allow Event Listener and Indexer to create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import uk.gov.justice.services.jdbc.persistence.JdbcResultSetStreamer;
import uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper;
import uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapperFactory;
import uk.gov.justice.services.jmx.command.SystemCommandStore;
import uk.gov.justice.services.messaging.DefaultJsonObjectEnvelopeConverter;
import uk.gov.justice.services.messaging.JsonEnvelope;
import uk.gov.justice.services.messaging.JsonObjectEnvelopeConverter;
Expand Down Expand Up @@ -163,7 +164,8 @@ public void initializeDatabase() throws Exception {
PublishedEventRepository.class,
PrePublishRepository.class,
PublishedEventQueries.class,
StopWatchFactory.class
StopWatchFactory.class,
SystemCommandStore.class
})
public WebApp war() {
return new WebApp()
Expand Down
4 changes: 4 additions & 0 deletions event-sourcing/subscription-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<artifactId>subscription-event-tracking</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>jmx</artifactId>
</dependency>

<!--Test Dependencies-->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import uk.gov.justice.services.event.sourcing.subscription.catchup.consumer.task.ConsumeEventQueueBean;
import uk.gov.justice.services.event.sourcing.subscription.catchup.consumer.util.DummyTransactionalEventProcessor;
import uk.gov.justice.services.event.sourcing.subscription.catchup.consumer.util.TestCatchupBean;
import uk.gov.justice.services.jmx.command.SystemCommandStore;
import uk.gov.justice.services.messaging.JsonEnvelope;
import uk.gov.justice.services.test.utils.core.messaging.Poller;

Expand Down Expand Up @@ -48,7 +49,8 @@ public class EventStreamCatchupIT {
EventStreamsInProgressList.class,
ConsumeEventQueueBean.class,
EventQueueConsumerFactory.class,
LoggerProducer.class
LoggerProducer.class,
SystemCommandStore.class
})
public WebApp war() {
return new WebApp()
Expand Down
58 changes: 58 additions & 0 deletions event-store-management/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>event-store</artifactId>
<groupId>uk.gov.justice.event-store</groupId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>event-store-management</artifactId>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.utils</groupId>
<artifactId>utilities-core</artifactId>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>published-event-processor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>jmx</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>subscription-manager</artifactId>
<version>${project.version}</version>
</dependency>

<!--Test Dependencies-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>test-utils-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package uk.gov.justice.services.eventstore.management.catchup.commands;

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

public class CatchupCommand extends BaseSystemCommand {

public static final String CATCHUP = "CATCHUP";

public CatchupCommand() {
super(CATCHUP);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package uk.gov.justice.services.eventstore.management.catchup.commands;

import static uk.gov.justice.services.eventstore.management.catchup.commands.CatchupCommand.CATCHUP;

import uk.gov.justice.services.common.util.UtcClock;
import uk.gov.justice.services.eventstore.management.catchup.events.CatchupRequestedEvent;
import uk.gov.justice.services.jmx.command.HandlesSystemCommand;

import javax.enterprise.event.Event;
import javax.inject.Inject;

public class CatchupCommandHandler {

@Inject
private UtcClock utcClock;

@Inject
private Event<CatchupRequestedEvent> catchupRequestedEventFirer;

@HandlesSystemCommand(CATCHUP)
public void doCatchup() {
catchupRequestedEventFirer.fire(new CatchupRequestedEvent(new CatchupCommand(), utcClock.now()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package uk.gov.justice.services.eventstore.management.catchup.events;

import java.time.ZonedDateTime;
import java.util.Objects;

public class CatchupCompletedEvent {

private final ZonedDateTime completedAt;

public CatchupCompletedEvent(final ZonedDateTime completedAt) {
this.completedAt = completedAt;
}

public ZonedDateTime getCompletedAt() {
return completedAt;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof CatchupCompletedEvent)) return false;
final CatchupCompletedEvent that = (CatchupCompletedEvent) o;
return Objects.equals(completedAt, that.completedAt);
}

@Override
public int hashCode() {
return Objects.hash(completedAt);
}

@Override
public String toString() {
return "CatchupCompletedEvent{" +
"completedAt=" + completedAt +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package uk.gov.justice.services.eventstore.management.catchup.events;

import java.time.ZonedDateTime;
import java.util.Objects;

public class CatchupCompletedForSubscriptionEvent {

private final String eventSourceName;
private final ZonedDateTime catchupCompletedAt;
private final int totalNumberOfEvents;

public CatchupCompletedForSubscriptionEvent(
final String eventSourceName,
final int totalNumberOfEvents,
final ZonedDateTime catchupCompletedAt) {

this.eventSourceName = eventSourceName;
this.catchupCompletedAt = catchupCompletedAt;
this.totalNumberOfEvents = totalNumberOfEvents;
}

public String getEventSourceName() {
return eventSourceName;
}

public ZonedDateTime getCatchupCompletedAt() {
return catchupCompletedAt;
}

public int getTotalNumberOfEvents() {
return totalNumberOfEvents;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof CatchupCompletedForSubscriptionEvent)) return false;
final CatchupCompletedForSubscriptionEvent that = (CatchupCompletedForSubscriptionEvent) o;
return totalNumberOfEvents == that.totalNumberOfEvents &&
Objects.equals(eventSourceName, that.eventSourceName) &&
Objects.equals(catchupCompletedAt, that.catchupCompletedAt);
}

@Override
public int hashCode() {
return Objects.hash(eventSourceName, catchupCompletedAt, totalNumberOfEvents);
}

@Override
public String toString() {
return "CatchupCompletedForSubscriptionEvent{" +
"eventSourceName='" + eventSourceName + '\'' +
", catchupCompletedAt=" + catchupCompletedAt +
", totalNumberOfEvents=" + totalNumberOfEvents +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package uk.gov.justice.services.eventstore.management.catchup.events;

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

import java.time.ZonedDateTime;
import java.util.Objects;

public class CatchupRequestedEvent {

private final SystemCommand cause;
private final ZonedDateTime catchupRequestedAt;

public CatchupRequestedEvent(final SystemCommand cause, final ZonedDateTime catchupRequestedAt) {
this.cause = cause;
this.catchupRequestedAt = catchupRequestedAt;
}

public SystemCommand getCause() {
return cause;
}

public ZonedDateTime getCatchupRequestedAt() {
return catchupRequestedAt;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof CatchupRequestedEvent)) return false;
final CatchupRequestedEvent that = (CatchupRequestedEvent) o;
return Objects.equals(cause, that.cause) &&
Objects.equals(catchupRequestedAt, that.catchupRequestedAt);
}

@Override
public int hashCode() {
return Objects.hash(cause, catchupRequestedAt);
}

@Override
public String toString() {
return "CatchupRequestedEvent{" +
"cause=" + cause +
", catchupRequestedAt=" + catchupRequestedAt +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package uk.gov.justice.services.eventstore.management.catchup.events;

import java.time.ZonedDateTime;
import java.util.Objects;

public class CatchupStartedEvent {

private final ZonedDateTime catchupStartedAt;

public CatchupStartedEvent(final ZonedDateTime catchupStartedAt) {
this.catchupStartedAt = catchupStartedAt;
}

public ZonedDateTime getCatchupStartedAt() {
return catchupStartedAt;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof CatchupStartedEvent)) return false;
final CatchupStartedEvent that = (CatchupStartedEvent) o;
return Objects.equals(catchupStartedAt, that.catchupStartedAt);
}

@Override
public int hashCode() {
return Objects.hash(catchupStartedAt);
}

@Override
public String toString() {
return "CatchupStartedEvent{" +
"catchupStartedAt=" + catchupStartedAt +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.justice.services.eventstore.management.catchup.events;

import java.time.ZonedDateTime;
import java.util.Objects;

public class CatchupStartedForSubscriptionEvent {

private final String subscriptionName;
private final ZonedDateTime catchupStartedAt;

public CatchupStartedForSubscriptionEvent(final String subscriptionName, final ZonedDateTime catchupStartedAt) {
this.subscriptionName = subscriptionName;
this.catchupStartedAt = catchupStartedAt;
}

public String getSubscriptionName() {
return subscriptionName;
}

public ZonedDateTime getCatchupStartedAt() {
return catchupStartedAt;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof CatchupStartedForSubscriptionEvent)) return false;
final CatchupStartedForSubscriptionEvent that = (CatchupStartedForSubscriptionEvent) o;
return Objects.equals(subscriptionName, that.subscriptionName) &&
Objects.equals(catchupStartedAt, that.catchupStartedAt);
}

@Override
public int hashCode() {
return Objects.hash(subscriptionName, catchupStartedAt);
}

@Override
public String toString() {
return "CatchupStartedForSubscriptionEvent{" +
"eventSourceName='" + subscriptionName + '\'' +
", catchupStartedAt=" + catchupStartedAt +
'}';
}
}
Loading