Skip to content

Commit

Permalink
MAILBOX-332 Cassandra implementation for Quota Threshold Crossing not…
Browse files Browse the repository at this point in the history
…ification
  • Loading branch information
mbaechler authored and chibenwa committed May 10, 2018
1 parent a686c2b commit c3a1bda
Show file tree
Hide file tree
Showing 32 changed files with 1,488 additions and 23 deletions.
Expand Up @@ -56,6 +56,10 @@ public boolean supportsParameter(ParameterContext parameterContext, ExtensionCon
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
return dockerCassandra; return dockerCassandra;
} }

public DockerCassandra getDockerCassandra() {
return dockerCassandra;
}


public static class DockerCassandra { public static class DockerCassandra {


Expand Down
Expand Up @@ -30,7 +30,11 @@ public static QuotaCount unlimited() {
} }


public static QuotaCount count(long value) { public static QuotaCount count(long value) {
return new QuotaCount(Optional.of(value)); return count(Optional.of(value));
}

public static QuotaCount count(Optional<Long> value) {
return new QuotaCount(value);
} }


private final Optional<Long> value; private final Optional<Long> value;
Expand Down
Expand Up @@ -32,7 +32,11 @@ public static QuotaSize unlimited() {
} }


public static QuotaSize size(long value) { public static QuotaSize size(long value) {
return new QuotaSize(Optional.of(value)); return size(Optional.of(value));
}

public static QuotaSize size(Optional<Long> value) {
return new QuotaSize(value);
} }


private final Optional<Long> value; private final Optional<Long> value;
Expand Down
135 changes: 135 additions & 0 deletions mailbox/plugin/quota-mailing-cassandra/pom.xml
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>apache-james-mailbox</artifactId>
<groupId>org.apache.james</groupId>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>quota-mailing-cassandra</artifactId>
<name>Apache James :: Mailbox :: Plugin :: Quota Mailing :: Cassandra</name>
<description>Apache James Mailbox Cassandra implementation of Quota mailing listener</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apache-james-backends-cassandra</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apache-james-backends-cassandra</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apache-james-mailbox-api</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apache-james-mailbox-quota-mailing</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apache-james-mailbox-quota-mailing</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apache-james-mailbox-store</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apache-mailet-base</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>james-server-data-memory</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit</artifactId>
<version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-fluent</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,62 @@
/****************************************************************
* Licensed to the Apache Software Foundation (ASF) under one *
* or more contributor license agreements. See the NOTICE file *
* distributed with this work for additional information *
* regarding copyright ownership. The ASF licenses this file *
* to you under the Apache License, Version 2.0 (the *
* "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
* KIND, either express or implied. See the License for the *
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/

package org.apache.james.eventsourcing.cassandra;

import java.util.List;

import javax.inject.Inject;

import org.apache.james.eventsourcing.AggregateId;
import org.apache.james.eventsourcing.Event;
import org.apache.james.eventsourcing.EventStore;

import com.google.common.base.Preconditions;

public class CassandraEventStore implements EventStore {

private final EventStoreDao eventStoreDao;

@Inject
public CassandraEventStore(EventStoreDao eventStoreDao) {
this.eventStoreDao = eventStoreDao;
}

@Override
public void appendAll(List<Event> events) {
if (events.isEmpty()) {
return;
}
doAppendAll(events);
}

public void doAppendAll(List<Event> events) {
Preconditions.checkArgument(Event.belongsToSameAggregate(events));

boolean success = eventStoreDao.appendAll(events).join();
if (!success) {
throw new EventStoreFailedException();
}
}

@Override
public History getEventsOfAggregate(AggregateId aggregateId) {
return eventStoreDao.getEventsOfAggregate(aggregateId);
}
}
@@ -0,0 +1,62 @@
/****************************************************************
* Licensed to the Apache Software Foundation (ASF) under one *
* or more contributor license agreements. See the NOTICE file *
* distributed with this work for additional information *
* regarding copyright ownership. The ASF licenses this file *
* to you under the Apache License, Version 2.0 (the *
* "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
* KIND, either express or implied. See the License for the *
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/

package org.apache.james.eventsourcing.cassandra;

import java.util.List;

import org.apache.james.backends.cassandra.components.CassandraModule;
import org.apache.james.backends.cassandra.components.CassandraTable;
import org.apache.james.backends.cassandra.components.CassandraType;
import org.apache.james.backends.cassandra.utils.CassandraConstants;

import com.datastax.driver.core.DataType;
import com.datastax.driver.core.schemabuilder.SchemaBuilder;
import com.google.common.collect.ImmutableList;

public class CassandraEventStoreModule implements CassandraModule {
private final List<CassandraTable> tables;
private final List<CassandraType> types;

public CassandraEventStoreModule() {
tables = ImmutableList.of(
new CassandraTable(CassandraEventStoreTable.EVENTS_TABLE,
SchemaBuilder.createTable(CassandraEventStoreTable.EVENTS_TABLE)
.ifNotExists()
.addPartitionKey(CassandraEventStoreTable.AGGREGATE_ID, DataType.varchar())
.addClusteringColumn(CassandraEventStoreTable.EVENT_ID, DataType.cint())
.addColumn(CassandraEventStoreTable.EVENT, DataType.text())
.withOptions()
.comment("Store events of a EventSourcing aggregate")
.caching(SchemaBuilder.KeyCaching.ALL,
SchemaBuilder.rows(CassandraConstants.DEFAULT_CACHED_ROW_PER_PARTITION))));
types = ImmutableList.of();
}

@Override
public List<CassandraTable> moduleTables() {
return tables;
}

@Override
public List<CassandraType> moduleTypes() {
return types;
}

}
@@ -0,0 +1,27 @@
/****************************************************************
* Licensed to the Apache Software Foundation (ASF) under one *
* or more contributor license agreements. See the NOTICE file *
* distributed with this work for additional information *
* regarding copyright ownership. The ASF licenses this file *
* to you under the Apache License, Version 2.0 (the *
* "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
* KIND, either express or implied. See the License for the *
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/

package org.apache.james.eventsourcing.cassandra;

public interface CassandraEventStoreTable {
String EVENTS_TABLE = "eventStore";
String AGGREGATE_ID = "aggregateId";
String EVENT = "event";
String EVENT_ID = "eventId";
}

0 comments on commit c3a1bda

Please sign in to comment.