Arsnael commented on code in PR #1706: URL: https://github.com/apache/james-project/pull/1706#discussion_r1309647218
########## mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManagerV2.java: ########## @@ -0,0 +1,332 @@ +/**************************************************************** + * 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.mailbox.cassandra.quota; + +import static org.apache.james.util.ReactorUtils.publishIfPresent; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.inject.Inject; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.james.backends.cassandra.components.CassandraQuotaLimitDao; +import org.apache.james.core.Domain; +import org.apache.james.core.quota.QuotaComponent; +import org.apache.james.core.quota.QuotaCountLimit; +import org.apache.james.core.quota.QuotaLimit; +import org.apache.james.core.quota.QuotaScope; +import org.apache.james.core.quota.QuotaSizeLimit; +import org.apache.james.core.quota.QuotaType; +import org.apache.james.mailbox.model.Quota; +import org.apache.james.mailbox.model.QuotaRoot; +import org.apache.james.mailbox.quota.MaxQuotaManager; + +import com.google.common.collect.ImmutableMap; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class CassandraPerUserMaxQuotaManagerV2 implements MaxQuotaManager { + + private static final String GLOBAL_IDENTIFIER = "global"; + + private final CassandraQuotaLimitDao cassandraQuotaLimitDao; + + @Inject + public CassandraPerUserMaxQuotaManagerV2(CassandraQuotaLimitDao cassandraQuotaLimitDao) { + this.cassandraQuotaLimitDao = cassandraQuotaLimitDao; + } + + @Override + public void setMaxStorage(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + setMaxStorageReactive(quotaRoot, maxStorageQuota).block(); + } + + @Override + public Mono<Void> setMaxStorageReactive(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(maxStorageQuota)).build()); + } + + @Override + public void setMaxMessage(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + setMaxMessageReactive(quotaRoot, maxMessageCount).block(); + } + + @Override + public Mono<Void> setMaxMessageReactive(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(maxMessageCount)).build()); + } + + @Override + public void setDomainMaxMessage(Domain domain, QuotaCountLimit count) { + setDomainMaxMessageReactive(domain, count).block(); + } + + @Override + public Mono<Void> setDomainMaxMessageReactive(Domain domain, QuotaCountLimit count) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.DOMAIN).identifier(domain.asString()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(count)).build()); + } + + @Override + public void setDomainMaxStorage(Domain domain, QuotaSizeLimit size) { + setDomainMaxStorageReactive(domain, size).block(); + } + + @Override + public Mono<Void> setDomainMaxStorageReactive(Domain domain, QuotaSizeLimit size) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.DOMAIN).identifier(domain.asString()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(size)).build()); + } + + @Override + public void removeDomainMaxMessage(Domain domain) { + removeDomainMaxMessageReactive(domain).block(); + } + + @Override + public Mono<Void> removeDomainMaxMessageReactive(Domain domain) { + return cassandraQuotaLimitDao.deleteQuotaLimit(CassandraQuotaLimitDao.QuotaLimitKey.of(QuotaComponent.MAILBOX, QuotaScope.DOMAIN, domain.asString(), QuotaType.COUNT)); Review Comment: static import on the QuotaLimitKey ? ########## mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManagerV2.java: ########## @@ -0,0 +1,332 @@ +/**************************************************************** + * 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.mailbox.cassandra.quota; + +import static org.apache.james.util.ReactorUtils.publishIfPresent; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.inject.Inject; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.james.backends.cassandra.components.CassandraQuotaLimitDao; +import org.apache.james.core.Domain; +import org.apache.james.core.quota.QuotaComponent; +import org.apache.james.core.quota.QuotaCountLimit; +import org.apache.james.core.quota.QuotaLimit; +import org.apache.james.core.quota.QuotaScope; +import org.apache.james.core.quota.QuotaSizeLimit; +import org.apache.james.core.quota.QuotaType; +import org.apache.james.mailbox.model.Quota; +import org.apache.james.mailbox.model.QuotaRoot; +import org.apache.james.mailbox.quota.MaxQuotaManager; + +import com.google.common.collect.ImmutableMap; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class CassandraPerUserMaxQuotaManagerV2 implements MaxQuotaManager { + + private static final String GLOBAL_IDENTIFIER = "global"; + + private final CassandraQuotaLimitDao cassandraQuotaLimitDao; + + @Inject + public CassandraPerUserMaxQuotaManagerV2(CassandraQuotaLimitDao cassandraQuotaLimitDao) { + this.cassandraQuotaLimitDao = cassandraQuotaLimitDao; + } + + @Override + public void setMaxStorage(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + setMaxStorageReactive(quotaRoot, maxStorageQuota).block(); + } + + @Override + public Mono<Void> setMaxStorageReactive(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(maxStorageQuota)).build()); + } + + @Override + public void setMaxMessage(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + setMaxMessageReactive(quotaRoot, maxMessageCount).block(); + } + + @Override + public Mono<Void> setMaxMessageReactive(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(maxMessageCount)).build()); Review Comment: idem ########## mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManagerV2.java: ########## @@ -0,0 +1,332 @@ +/**************************************************************** + * 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.mailbox.cassandra.quota; + +import static org.apache.james.util.ReactorUtils.publishIfPresent; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.inject.Inject; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.james.backends.cassandra.components.CassandraQuotaLimitDao; +import org.apache.james.core.Domain; +import org.apache.james.core.quota.QuotaComponent; +import org.apache.james.core.quota.QuotaCountLimit; +import org.apache.james.core.quota.QuotaLimit; +import org.apache.james.core.quota.QuotaScope; +import org.apache.james.core.quota.QuotaSizeLimit; +import org.apache.james.core.quota.QuotaType; +import org.apache.james.mailbox.model.Quota; +import org.apache.james.mailbox.model.QuotaRoot; +import org.apache.james.mailbox.quota.MaxQuotaManager; + +import com.google.common.collect.ImmutableMap; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class CassandraPerUserMaxQuotaManagerV2 implements MaxQuotaManager { + + private static final String GLOBAL_IDENTIFIER = "global"; + + private final CassandraQuotaLimitDao cassandraQuotaLimitDao; + + @Inject + public CassandraPerUserMaxQuotaManagerV2(CassandraQuotaLimitDao cassandraQuotaLimitDao) { + this.cassandraQuotaLimitDao = cassandraQuotaLimitDao; + } + + @Override + public void setMaxStorage(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + setMaxStorageReactive(quotaRoot, maxStorageQuota).block(); + } + + @Override + public Mono<Void> setMaxStorageReactive(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(maxStorageQuota)).build()); + } + + @Override + public void setMaxMessage(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + setMaxMessageReactive(quotaRoot, maxMessageCount).block(); + } + + @Override + public Mono<Void> setMaxMessageReactive(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(maxMessageCount)).build()); + } + + @Override + public void setDomainMaxMessage(Domain domain, QuotaCountLimit count) { + setDomainMaxMessageReactive(domain, count).block(); + } + + @Override + public Mono<Void> setDomainMaxMessageReactive(Domain domain, QuotaCountLimit count) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.DOMAIN).identifier(domain.asString()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(count)).build()); + } + + @Override + public void setDomainMaxStorage(Domain domain, QuotaSizeLimit size) { + setDomainMaxStorageReactive(domain, size).block(); + } + + @Override + public Mono<Void> setDomainMaxStorageReactive(Domain domain, QuotaSizeLimit size) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.DOMAIN).identifier(domain.asString()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(size)).build()); + } + + @Override + public void removeDomainMaxMessage(Domain domain) { + removeDomainMaxMessageReactive(domain).block(); + } + + @Override + public Mono<Void> removeDomainMaxMessageReactive(Domain domain) { + return cassandraQuotaLimitDao.deleteQuotaLimit(CassandraQuotaLimitDao.QuotaLimitKey.of(QuotaComponent.MAILBOX, QuotaScope.DOMAIN, domain.asString(), QuotaType.COUNT)); + } + + @Override + public void removeDomainMaxStorage(Domain domain) { + removeDomainMaxStorageReactive(domain).block(); + } + + @Override + public Mono<Void> removeDomainMaxStorageReactive(Domain domain) { + return cassandraQuotaLimitDao.deleteQuotaLimit(CassandraQuotaLimitDao.QuotaLimitKey.of(QuotaComponent.MAILBOX, QuotaScope.DOMAIN, domain.asString(), QuotaType.SIZE)); + } + + @Override + public Optional<QuotaCountLimit> getDomainMaxMessage(Domain domain) { + return getDomainMaxMessageReactive(domain).blockOptional(); + } + + @Override + public Mono<QuotaCountLimit> getDomainMaxMessageReactive(Domain domain) { + return getMaxMessageReactive(QuotaScope.DOMAIN, domain.asString()); + } + + @Override + public Optional<QuotaSizeLimit> getDomainMaxStorage(Domain domain) { + return getDomainMaxStorageReactive(domain).blockOptional(); + } + + @Override + public Mono<QuotaSizeLimit> getDomainMaxStorageReactive(Domain domain) { + return getMaxStorageReactive(QuotaScope.DOMAIN, domain.asString()); + } + + @Override + public void removeMaxMessage(QuotaRoot quotaRoot) { + removeMaxMessageReactive(quotaRoot).block(); + } + + @Override + public Mono<Void> removeMaxMessageReactive(QuotaRoot quotaRoot) { + return cassandraQuotaLimitDao.deleteQuotaLimit(CassandraQuotaLimitDao.QuotaLimitKey.of(QuotaComponent.MAILBOX, QuotaScope.USER, quotaRoot.getValue(), QuotaType.COUNT)); + } + + @Override + public void removeMaxStorage(QuotaRoot quotaRoot) { + removeMaxStorageReactive(quotaRoot).block(); + } + + @Override + public Mono<Void> removeMaxStorageReactive(QuotaRoot quotaRoot) { + return cassandraQuotaLimitDao.deleteQuotaLimit(CassandraQuotaLimitDao.QuotaLimitKey.of(QuotaComponent.MAILBOX, QuotaScope.USER, quotaRoot.getValue(), QuotaType.SIZE)); + } + + @Override + public void setGlobalMaxStorage(QuotaSizeLimit globalMaxStorage) { + setGlobalMaxStorageReactive(globalMaxStorage).block(); + } + + @Override + public Mono<Void> setGlobalMaxStorageReactive(QuotaSizeLimit globalMaxStorage) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.GLOBAL).identifier(GLOBAL_IDENTIFIER) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(globalMaxStorage)).build()); + } + + @Override + public void removeGlobalMaxStorage() { + removeGlobalMaxStorageReactive().block(); + } + + @Override + public Mono<Void> removeGlobalMaxStorageReactive() { + return cassandraQuotaLimitDao.deleteQuotaLimit(CassandraQuotaLimitDao.QuotaLimitKey.of(QuotaComponent.MAILBOX, QuotaScope.GLOBAL, GLOBAL_IDENTIFIER, QuotaType.SIZE)); + } + + @Override + public void setGlobalMaxMessage(QuotaCountLimit globalMaxMessageCount) { + setGlobalMaxMessageReactive(globalMaxMessageCount).block(); + } + + @Override + public Mono<Void> setGlobalMaxMessageReactive(QuotaCountLimit globalMaxMessageCount) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.GLOBAL).identifier(GLOBAL_IDENTIFIER) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(globalMaxMessageCount)).build()); Review Comment: Chaining builder ops indent ########## mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java: ########## @@ -102,7 +102,7 @@ static StoreMessageIdManager createMessageIdManager(CassandraMailboxSessionMappe } static MaxQuotaManager createMaxQuotaManager(CassandraCluster cassandra) { - return new CassandraPerUserMaxQuotaManager( + return new CassandraPerUserMaxQuotaManagerV1( Review Comment: Idem? ########## mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManagerV2.java: ########## @@ -0,0 +1,332 @@ +/**************************************************************** + * 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.mailbox.cassandra.quota; + +import static org.apache.james.util.ReactorUtils.publishIfPresent; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.inject.Inject; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.james.backends.cassandra.components.CassandraQuotaLimitDao; +import org.apache.james.core.Domain; +import org.apache.james.core.quota.QuotaComponent; +import org.apache.james.core.quota.QuotaCountLimit; +import org.apache.james.core.quota.QuotaLimit; +import org.apache.james.core.quota.QuotaScope; +import org.apache.james.core.quota.QuotaSizeLimit; +import org.apache.james.core.quota.QuotaType; +import org.apache.james.mailbox.model.Quota; +import org.apache.james.mailbox.model.QuotaRoot; +import org.apache.james.mailbox.quota.MaxQuotaManager; + +import com.google.common.collect.ImmutableMap; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class CassandraPerUserMaxQuotaManagerV2 implements MaxQuotaManager { + + private static final String GLOBAL_IDENTIFIER = "global"; + + private final CassandraQuotaLimitDao cassandraQuotaLimitDao; + + @Inject + public CassandraPerUserMaxQuotaManagerV2(CassandraQuotaLimitDao cassandraQuotaLimitDao) { + this.cassandraQuotaLimitDao = cassandraQuotaLimitDao; + } + + @Override + public void setMaxStorage(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + setMaxStorageReactive(quotaRoot, maxStorageQuota).block(); + } + + @Override + public Mono<Void> setMaxStorageReactive(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(maxStorageQuota)).build()); + } + + @Override + public void setMaxMessage(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + setMaxMessageReactive(quotaRoot, maxMessageCount).block(); + } + + @Override + public Mono<Void> setMaxMessageReactive(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(maxMessageCount)).build()); + } + + @Override + public void setDomainMaxMessage(Domain domain, QuotaCountLimit count) { + setDomainMaxMessageReactive(domain, count).block(); + } + + @Override + public Mono<Void> setDomainMaxMessageReactive(Domain domain, QuotaCountLimit count) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.DOMAIN).identifier(domain.asString()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(count)).build()); + } + + @Override + public void setDomainMaxStorage(Domain domain, QuotaSizeLimit size) { + setDomainMaxStorageReactive(domain, size).block(); + } + + @Override + public Mono<Void> setDomainMaxStorageReactive(Domain domain, QuotaSizeLimit size) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.DOMAIN).identifier(domain.asString()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(size)).build()); Review Comment: idem ########## mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java: ########## @@ -114,7 +114,7 @@ private static CassandraMailboxManager provideMailboxManager(CqlSession session, LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE); SessionProviderImpl sessionProvider = new SessionProviderImpl(noAuthenticator, noAuthorizator); - CassandraPerUserMaxQuotaManager maxQuotaManager = new CassandraPerUserMaxQuotaManager(new CassandraPerUserMaxQuotaDao(session), + CassandraPerUserMaxQuotaManagerV1 maxQuotaManager = new CassandraPerUserMaxQuotaManagerV1(new CassandraPerUserMaxQuotaDao(session), Review Comment: Shouldn't we use V2 for tests if this is deprecated? (it's nice I see I missed that in my own work as well) ########## mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManagerV2.java: ########## @@ -0,0 +1,332 @@ +/**************************************************************** + * 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.mailbox.cassandra.quota; + +import static org.apache.james.util.ReactorUtils.publishIfPresent; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.inject.Inject; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.james.backends.cassandra.components.CassandraQuotaLimitDao; +import org.apache.james.core.Domain; +import org.apache.james.core.quota.QuotaComponent; +import org.apache.james.core.quota.QuotaCountLimit; +import org.apache.james.core.quota.QuotaLimit; +import org.apache.james.core.quota.QuotaScope; +import org.apache.james.core.quota.QuotaSizeLimit; +import org.apache.james.core.quota.QuotaType; +import org.apache.james.mailbox.model.Quota; +import org.apache.james.mailbox.model.QuotaRoot; +import org.apache.james.mailbox.quota.MaxQuotaManager; + +import com.google.common.collect.ImmutableMap; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class CassandraPerUserMaxQuotaManagerV2 implements MaxQuotaManager { + + private static final String GLOBAL_IDENTIFIER = "global"; + + private final CassandraQuotaLimitDao cassandraQuotaLimitDao; + + @Inject + public CassandraPerUserMaxQuotaManagerV2(CassandraQuotaLimitDao cassandraQuotaLimitDao) { + this.cassandraQuotaLimitDao = cassandraQuotaLimitDao; + } + + @Override + public void setMaxStorage(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + setMaxStorageReactive(quotaRoot, maxStorageQuota).block(); + } + + @Override + public Mono<Void> setMaxStorageReactive(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(maxStorageQuota)).build()); Review Comment: Don't chain all build operations on the same line, return to the line for each, like for Reactor chains. Will be easier to read ########## mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManagerMigrationTest.java: ########## @@ -0,0 +1,135 @@ +/**************************************************************** + * 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.mailbox.cassandra.quota; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Optional; + +import org.apache.james.backends.cassandra.CassandraClusterExtension; +import org.apache.james.backends.cassandra.components.CassandraModule; +import org.apache.james.backends.cassandra.components.CassandraMutualizedQuotaModule; +import org.apache.james.core.Domain; +import org.apache.james.core.Username; +import org.apache.james.core.quota.QuotaCountLimit; +import org.apache.james.core.quota.QuotaSizeLimit; +import org.apache.james.domainlist.api.DomainList; +import org.apache.james.domainlist.api.mock.SimpleDomainList; +import org.apache.james.mailbox.cassandra.mail.utils.GuiceUtils; +import org.apache.james.mailbox.cassandra.modules.CassandraQuotaModule; +import org.apache.james.mailbox.model.QuotaRoot; +import org.apache.james.mailbox.quota.MaxQuotaManager; +import org.apache.james.mailbox.quota.UserQuotaRootResolver; +import org.apache.james.user.api.UsersRepository; +import org.apache.james.user.cassandra.CassandraUsersDAO; +import org.apache.james.user.cassandra.CassandraUsersRepositoryModule; +import org.apache.james.user.lib.UsersRepositoryImpl; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mockito.Mockito; + +import com.google.inject.Injector; + +public class CassandraPerUserMaxQuotaManagerMigrationTest { + + private static final Domain DOMAIN = Domain.of("domain.tld"); + private static final Username USERNAME = Username.of("bob"); + private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("#private&bob", Optional.empty()); + + @RegisterExtension + static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraModule.aggregateModules( + CassandraUsersRepositoryModule.MODULE, + CassandraQuotaModule.MODULE, + CassandraMutualizedQuotaModule.MODULE)); + + private static CassandraPerUserMaxQuotaManagerMigration migration; + private static MaxQuotaManager oldMaxQuotaManager; + private static MaxQuotaManager newMaxQuotaManager; + private static UsersRepository usersRepository; + + @BeforeAll + static void setup() throws Exception { + DomainList domainList = new SimpleDomainList(); + domainList.addDomain(DOMAIN); + CassandraUsersDAO usersDAO = new CassandraUsersDAO(cassandraCluster.getCassandraCluster().getConf()); + usersRepository = new UsersRepositoryImpl<>(domainList, usersDAO); + Injector testInjector = GuiceUtils.testInjector(cassandraCluster.getCassandraCluster()); + oldMaxQuotaManager = testInjector.getInstance(CassandraPerUserMaxQuotaManagerV1.class); + newMaxQuotaManager = testInjector.getInstance(CassandraPerUserMaxQuotaManagerV2.class); + UserQuotaRootResolver userQuotaRootResolver = Mockito.mock(UserQuotaRootResolver.class); + Mockito.when(userQuotaRootResolver.forUser(USERNAME)).thenReturn(QUOTA_ROOT); + migration = new CassandraPerUserMaxQuotaManagerMigration(usersRepository, + domainList, + oldMaxQuotaManager, + newMaxQuotaManager, + userQuotaRootResolver); + } + + @Test + void shouldMigrateGlobalLimit() throws Exception { + oldMaxQuotaManager.setGlobalMaxMessage(QuotaCountLimit.count(100)); + oldMaxQuotaManager.setGlobalMaxStorage(QuotaSizeLimit.size(100)); Review Comment: Could you use different values for message and storage? To enforce everythin is right. Also Those values are all Long, add the "L" at the end of each value For all tests ########## mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManagerV2.java: ########## @@ -0,0 +1,332 @@ +/**************************************************************** + * 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.mailbox.cassandra.quota; + +import static org.apache.james.util.ReactorUtils.publishIfPresent; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.inject.Inject; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.james.backends.cassandra.components.CassandraQuotaLimitDao; +import org.apache.james.core.Domain; +import org.apache.james.core.quota.QuotaComponent; +import org.apache.james.core.quota.QuotaCountLimit; +import org.apache.james.core.quota.QuotaLimit; +import org.apache.james.core.quota.QuotaScope; +import org.apache.james.core.quota.QuotaSizeLimit; +import org.apache.james.core.quota.QuotaType; +import org.apache.james.mailbox.model.Quota; +import org.apache.james.mailbox.model.QuotaRoot; +import org.apache.james.mailbox.quota.MaxQuotaManager; + +import com.google.common.collect.ImmutableMap; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class CassandraPerUserMaxQuotaManagerV2 implements MaxQuotaManager { + + private static final String GLOBAL_IDENTIFIER = "global"; + + private final CassandraQuotaLimitDao cassandraQuotaLimitDao; + + @Inject + public CassandraPerUserMaxQuotaManagerV2(CassandraQuotaLimitDao cassandraQuotaLimitDao) { + this.cassandraQuotaLimitDao = cassandraQuotaLimitDao; + } + + @Override + public void setMaxStorage(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + setMaxStorageReactive(quotaRoot, maxStorageQuota).block(); + } + + @Override + public Mono<Void> setMaxStorageReactive(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.SIZE).quotaLimit(QuotaCodec.quotaValueToLong(maxStorageQuota)).build()); + } + + @Override + public void setMaxMessage(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + setMaxMessageReactive(quotaRoot, maxMessageCount).block(); + } + + @Override + public Mono<Void> setMaxMessageReactive(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.USER).identifier(quotaRoot.getValue()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(maxMessageCount)).build()); + } + + @Override + public void setDomainMaxMessage(Domain domain, QuotaCountLimit count) { + setDomainMaxMessageReactive(domain, count).block(); + } + + @Override + public Mono<Void> setDomainMaxMessageReactive(Domain domain, QuotaCountLimit count) { + return cassandraQuotaLimitDao.setQuotaLimit(QuotaLimit.builder().quotaScope(QuotaScope.DOMAIN).identifier(domain.asString()) + .quotaComponent(QuotaComponent.MAILBOX).quotaType(QuotaType.COUNT).quotaLimit(QuotaCodec.quotaValueToLong(count)).build()); Review Comment: idem -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
