JAMES-1902 split probes to prevent them to pull unwanted dependencies
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/793dae76 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/793dae76 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/793dae76 Branch: refs/heads/master Commit: 793dae76f8025f9f305e777bb06280944433d9ac Parents: ac56c42 Author: Matthieu Baechler <matthieu.baech...@gmail.com> Authored: Mon Jan 30 10:43:12 2017 +0100 Committer: benwa <btell...@linagora.com> Committed: Tue Mar 14 18:13:55 2017 +0700 ---------------------------------------------------------------------- .../store/mail/model/SerializableQuota.java | 49 +++ .../james/mailbox/store/probe/MailboxProbe.java | 55 +++ .../james/mailbox/store/probe/QuotaProbe.java | 49 +++ .../james/mailbox/store/probe/SieveProbe.java | 38 ++ .../smtp/host/CassandraJamesSmtpHostSystem.java | 9 +- .../java/org/apache/james/cli/ServerCmd.java | 89 +++-- .../org/apache/james/cli/probe/ServerProbe.java | 265 ------------- .../james/cli/probe/impl/JmxConnection.java | 62 ++++ .../james/cli/probe/impl/JmxDataProbe.java | 130 +++++++ .../james/cli/probe/impl/JmxMailboxProbe.java | 118 ++++++ .../apache/james/cli/probe/impl/JmxProbe.java | 28 ++ .../james/cli/probe/impl/JmxQuotaProbe.java | 100 +++++ .../james/cli/probe/impl/JmxServerProbe.java | 339 ----------------- .../james/cli/probe/impl/JmxSieveProbe.java | 78 ++++ .../org/apache/james/cli/ServerCmdTest.java | 96 ++--- .../apache/james/CassandraJamesServerMain.java | 4 +- .../java/org/apache/james/ESReporterTest.java | 4 +- .../java/org/apache/james/GuiceJamesServer.java | 5 - .../james/modules/CommonServicesModule.java | 4 +- .../org/apache/james/utils/DataProbeImpl.java | 130 +++++++ .../apache/james/utils/ExtendedServerProbe.java | 46 --- .../apache/james/utils/GuiceServerProbe.java | 367 ------------------- .../apache/james/AbstractJamesServerTest.java | 5 +- .../james/AbstractJmapJamesServerTest.java | 5 +- .../org/apache/james/JPAJamesServerMain.java | 6 +- .../org/apache/james/JPAJamesServerTest.java | 2 +- server/container/guice/mailbox/pom.xml | 21 +- .../org/apache/james/modules/MailboxModule.java | 33 ++ .../apache/james/modules/MailboxProbeImpl.java | 181 +++++++++ .../org/apache/james/MemoryJamesServerMain.java | 28 +- .../guice/protocols/managedsieve/pom.xml | 4 + .../protocols/ManageSieveServerModule.java | 2 + .../james/modules/protocols/SieveProbeImpl.java | 71 ++++ .../james/adapter/mailbox/QuotaManagement.java | 1 + .../adapter/mailbox/QuotaManagementMBean.java | 1 + .../adapter/mailbox/SerializableQuota.java | 49 --- .../java/org/apache/james/probe/DataProbe.java | 59 +++ .../mailets/CommonMailetConfigurationTest.java | 12 +- .../RecipientRewriteTableIntegrationTest.java | 34 +- .../org/apache/james/mailets/SieveDelivery.java | 19 +- .../james/mailets/TemporaryJamesServer.java | 9 +- .../crypto/SMIMEDecryptIntegrationTest.java | 10 +- .../crypto/SMIMESignIntegrationTest.java | 12 +- .../mailets/AmqpForwardAttachmentTest.java | 12 +- .../mailets/ICSAttachmentWorkflowTest.java | 12 +- .../transport/mailets/StripAttachmentTest.java | 12 +- .../james/jmap/JMAPAuthenticationTest.java | 5 +- .../jmap/UserProvisionningConcurrencyTest.java | 6 +- .../james/jmap/VacationIntegrationTest.java | 22 +- .../integration/GetMailboxesMethodTest.java | 72 ++-- .../integration/GetMessageListMethodTest.java | 291 ++++++++------- .../integration/GetVacationResponseTest.java | 8 +- .../integration/SetMailboxesMethodTest.java | 234 ++++++------ .../integration/SetMessagesMethodTest.java | 208 ++++++----- .../integration/SetVacationResponseTest.java | 5 +- .../integration/cucumber/DownloadStepdefs.java | 5 +- .../cucumber/GetMessagesMethodStepdefs.java | 13 +- .../cucumber/SetMailboxesMethodStepdefs.java | 13 +- .../cucumber/SetMessagesMethodStepdefs.java | 7 +- .../integration/cucumber/UserStepdefs.java | 8 +- .../WebAdminServerIntegrationTest.java | 39 +- 61 files changed, 1943 insertions(+), 1658 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuota.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuota.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuota.java new file mode 100644 index 0000000..100b609 --- /dev/null +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuota.java @@ -0,0 +1,49 @@ +/**************************************************************** + * 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.store.mail.model; + +import org.apache.james.mailbox.model.Quota; + +import java.io.Serializable; + +public class SerializableQuota implements Serializable { + + private final long max; + private final long used; + + public SerializableQuota(long max, long used) { + this.max = max; + this.used = used; + } + + public SerializableQuota(Quota quota) { + this.max = quota.getMax(); + this.used = quota.getUsed(); + } + + public long getMax() { + return max; + } + + public long getUsed() { + return used; + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/MailboxProbe.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/MailboxProbe.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/MailboxProbe.java new file mode 100644 index 0000000..2a64365 --- /dev/null +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/MailboxProbe.java @@ -0,0 +1,55 @@ +/**************************************************************** + * 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.store.probe; + +import java.io.InputStream; +import java.util.Collection; +import java.util.Date; + +import javax.mail.Flags; + +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.ComposedMessageId; +import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.store.mail.model.Mailbox; + +public interface MailboxProbe { + + void createMailbox(String namespace, String user, String name); + + Mailbox getMailbox(String namespace, String user, String name); + + Collection<String> listUserMailboxes(String user); + + void deleteMailbox(String namespace, String user, String name); + + ComposedMessageId appendMessage(String username, MailboxPath mailboxPath, InputStream message, Date internalDate, + boolean isRecent, Flags flags) throws MailboxException; + + void copyMailbox(String srcBean, String dstBean) throws Exception; + + void deleteUserMailboxesNames(String user) throws Exception; + + void reIndexMailbox(String namespace, String user, String name) throws Exception; + + void reIndexAll() throws Exception; + + Collection<String> listSubscriptions(String user) throws Exception; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java new file mode 100644 index 0000000..e5eec3f --- /dev/null +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java @@ -0,0 +1,49 @@ +/**************************************************************** + * 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.store.probe; + +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.store.mail.model.SerializableQuota; + +public interface QuotaProbe { + + String getQuotaRoot(String namespace, String user, String name) throws MailboxException; + + SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException; + + SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException; + + long getMaxMessageCount(String quotaRoot) throws MailboxException; + + long getMaxStorage(String quotaRoot) throws MailboxException; + + long getDefaultMaxMessageCount() throws MailboxException; + + long getDefaultMaxStorage() throws MailboxException; + + void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException; + + void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException; + + void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException; + + void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException; + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/SieveProbe.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/SieveProbe.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/SieveProbe.java new file mode 100644 index 0000000..9f3e18e --- /dev/null +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/SieveProbe.java @@ -0,0 +1,38 @@ +/**************************************************************** + * 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.store.probe; + +public interface SieveProbe { + + long getSieveQuota() throws Exception; + + void setSieveQuota(long quota) throws Exception; + + void removeSieveQuota() throws Exception; + + long getSieveQuota(String user) throws Exception; + + void setSieveQuota(String user, long quota) throws Exception; + + void removeSieveQuota(String user) throws Exception; + + void addActiveSieveScript(String user, String name, String script) throws Exception; + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java ---------------------------------------------------------------------- diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java index 65311c3..d0cad96 100644 --- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java +++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java @@ -34,6 +34,7 @@ import org.apache.james.mpt.monitor.SystemLoggingMonitor; import org.apache.james.mpt.session.ExternalSessionFactory; import org.apache.james.mpt.smtp.SmtpHostSystem; import org.apache.james.mpt.smtp.dns.InMemoryDNSService; +import org.apache.james.utils.DataProbeImpl; import org.junit.rules.TemporaryFolder; import com.google.common.base.Preconditions; @@ -61,19 +62,19 @@ public class CassandraJamesSmtpHostSystem extends ExternalSessionFactory impleme String domain = split.next(); createDomainIfNeeded(domain); - jamesServer.serverProbe().addUser(userAtDomain, password); + jamesServer.getProbe(DataProbeImpl.class).addUser(userAtDomain, password); return true; } private void createDomainIfNeeded(String domain) throws Exception { - if (!jamesServer.serverProbe().containsDomain(domain)) { - jamesServer.serverProbe().addDomain(domain); + if (!jamesServer.getProbe(DataProbeImpl.class).containsDomain(domain)) { + jamesServer.getProbe(DataProbeImpl.class).addDomain(domain); } } @Override public void addAddressMapping(String user, String domain, String address) throws Exception { - jamesServer.serverProbe().addAddressMapping(user, domain, address); + jamesServer.getProbe(DataProbeImpl.class).addAddressMapping(user, domain, address); } @Override http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java index 539f2be..402b0d2 100644 --- a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java +++ b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java @@ -34,17 +34,24 @@ import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.time.StopWatch; -import org.apache.james.adapter.mailbox.SerializableQuota; import org.apache.james.cli.exceptions.InvalidArgumentNumberException; import org.apache.james.cli.exceptions.InvalidPortException; import org.apache.james.cli.exceptions.JamesCliException; import org.apache.james.cli.exceptions.MissingCommandException; import org.apache.james.cli.exceptions.UnrecognizedCommandException; -import org.apache.james.cli.probe.ServerProbe; -import org.apache.james.cli.probe.impl.JmxServerProbe; +import org.apache.james.cli.probe.impl.JmxConnection; +import org.apache.james.cli.probe.impl.JmxDataProbe; +import org.apache.james.cli.probe.impl.JmxMailboxProbe; +import org.apache.james.cli.probe.impl.JmxQuotaProbe; +import org.apache.james.cli.probe.impl.JmxSieveProbe; import org.apache.james.cli.type.CmdType; import org.apache.james.cli.utils.ValueWithUnit; import org.apache.james.mailbox.model.Quota; +import org.apache.james.mailbox.store.mail.model.SerializableQuota; +import org.apache.james.mailbox.store.probe.MailboxProbe; +import org.apache.james.mailbox.store.probe.QuotaProbe; +import org.apache.james.mailbox.store.probe.SieveProbe; +import org.apache.james.probe.DataProbe; import org.apache.james.rrt.lib.Mappings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +70,7 @@ public class ServerCmd { private static final int DEFAULT_PORT = 9999; private static final Logger LOG = LoggerFactory.getLogger(ServerCmd.class); - + private static Options createOptions() { Options options = new Options(); Option optHost = new Option(HOST_OPT_SHORT, HOST_OPT_LONG, true, "node hostname or ip address"); @@ -73,12 +80,6 @@ public class ServerCmd { return options; } - private final ServerProbe probe; - - public ServerCmd(ServerProbe probe) { - this.probe = probe; - } - /** * Main method to initialize the class. * @@ -90,7 +91,13 @@ public class ServerCmd { StopWatch stopWatch = new StopWatch(); stopWatch.start(); CommandLine cmd = parseCommandLine(args); - CmdType cmdType =new ServerCmd(new JmxServerProbe(cmd.getOptionValue(HOST_OPT_LONG), getPort(cmd))) + JmxConnection jmxConnection = new JmxConnection(cmd.getOptionValue(HOST_OPT_LONG), getPort(cmd)); + CmdType cmdType = new ServerCmd( + new JmxDataProbe().connect(jmxConnection), + new JmxMailboxProbe().connect(jmxConnection), + new JmxQuotaProbe().connect(jmxConnection), + new JmxSieveProbe().connect(jmxConnection) + ) .executeCommandLine(cmd); stopWatch.split(); print(new String[] { Joiner.on(' ') @@ -111,6 +118,18 @@ public class ServerCmd { } + private final DataProbe probe; + private final MailboxProbe mailboxProbe; + private final QuotaProbe quotaProbe; + private final SieveProbe sieveProbe; + + public ServerCmd(DataProbe probe, MailboxProbe mailboxProbe, QuotaProbe quotaProbe, SieveProbe sieveProbe) { + this.probe = probe; + this.mailboxProbe = mailboxProbe; + this.quotaProbe = quotaProbe; + this.sieveProbe = sieveProbe; + } + @VisibleForTesting static CommandLine parseCommandLine(String[] args) throws ParseException { CommandLineParser parser = new PosixParser(); @@ -212,84 +231,84 @@ public class ServerCmd { probe.setPassword(arguments[1], arguments[2]); break; case COPYMAILBOX: - probe.copyMailbox(arguments[1], arguments[2]); + mailboxProbe.copyMailbox(arguments[1], arguments[2]); break; case DELETEUSERMAILBOXES: - probe.deleteUserMailboxesNames(arguments[1]); + mailboxProbe.deleteUserMailboxesNames(arguments[1]); break; case CREATEMAILBOX: - probe.createMailbox(arguments[1], arguments[2], arguments[3]); + mailboxProbe.createMailbox(arguments[1], arguments[2], arguments[3]); break; case LISTUSERMAILBOXES: - Collection<String> mailboxes = probe.listUserMailboxes(arguments[1]); + Collection<String> mailboxes = mailboxProbe.listUserMailboxes(arguments[1]); print(mailboxes.toArray(new String[0]), System.out); break; case DELETEMAILBOX: - probe.deleteMailbox(arguments[1], arguments[2], arguments[3]); + mailboxProbe.deleteMailbox(arguments[1], arguments[2], arguments[3]); break; case GETSTORAGEQUOTA: - printStorageQuota(arguments[1], probe.getStorageQuota(arguments[1])); + printStorageQuota(arguments[1], quotaProbe.getStorageQuota(arguments[1])); break; case GETMESSAGECOUNTQUOTA: - printMessageQuota(arguments[1], probe.getMessageCountQuota(arguments[1])); + printMessageQuota(arguments[1], quotaProbe.getMessageCountQuota(arguments[1])); break; case GETQUOTAROOT: - System.out.println("Quota Root : " + probe.getQuotaRoot(arguments[1], arguments[2], arguments[3])); + System.out.println("Quota Root : " + quotaProbe.getQuotaRoot(arguments[1], arguments[2], arguments[3])); break; case GETMAXSTORAGEQUOTA: System.out.println("Storage space allowed for Quota Root " + arguments[1] + " : " - + formatStorageValue(probe.getMaxStorage(arguments[1]))); + + formatStorageValue(quotaProbe.getMaxStorage(arguments[1]))); break; case GETMAXMESSAGECOUNTQUOTA: - System.out.println("MailboxMessage count allowed for Quota Root " + arguments[1] + " : " + formatMessageValue(probe.getMaxMessageCount(arguments[1]))); + System.out.println("MailboxMessage count allowed for Quota Root " + arguments[1] + " : " + formatMessageValue(quotaProbe.getMaxMessageCount(arguments[1]))); break; case SETMAXSTORAGEQUOTA: - probe.setMaxStorage(arguments[1], ValueWithUnit.parse(arguments[2]).getConvertedValue()); + quotaProbe.setMaxStorage(arguments[1], ValueWithUnit.parse(arguments[2]).getConvertedValue()); break; case SETMAXMESSAGECOUNTQUOTA: - probe.setMaxMessageCount(arguments[1], Long.parseLong(arguments[2])); + quotaProbe.setMaxMessageCount(arguments[1], Long.parseLong(arguments[2])); break; case SETDEFAULTMAXSTORAGEQUOTA: - probe.setDefaultMaxStorage(ValueWithUnit.parse(arguments[1]).getConvertedValue()); + quotaProbe.setDefaultMaxStorage(ValueWithUnit.parse(arguments[1]).getConvertedValue()); break; case SETDEFAULTMAXMESSAGECOUNTQUOTA: - probe.setDefaultMaxMessageCount(Long.parseLong(arguments[1])); + quotaProbe.setDefaultMaxMessageCount(Long.parseLong(arguments[1])); break; case GETDEFAULTMAXSTORAGEQUOTA: - System.out.println("Default Maximum Storage Quota : " + formatStorageValue(probe.getDefaultMaxStorage())); + System.out.println("Default Maximum Storage Quota : " + formatStorageValue(quotaProbe.getDefaultMaxStorage())); break; case GETDEFAULTMAXMESSAGECOUNTQUOTA: - System.out.println("Default Maximum message count Quota : " + formatMessageValue(probe.getDefaultMaxMessageCount())); + System.out.println("Default Maximum message count Quota : " + formatMessageValue(quotaProbe.getDefaultMaxMessageCount())); break; case REINDEXMAILBOX: - probe.reIndexMailbox(arguments[1], arguments[2], arguments[3]); + mailboxProbe.reIndexMailbox(arguments[1], arguments[2], arguments[3]); break; case REINDEXALL: - probe.reIndexAll(); + mailboxProbe.reIndexAll(); break; case SETSIEVEQUOTA: - probe.setSieveQuota(ValueWithUnit.parse(arguments[1]).getConvertedValue()); + sieveProbe.setSieveQuota(ValueWithUnit.parse(arguments[1]).getConvertedValue()); break; case SETSIEVEUSERQUOTA: - probe.setSieveQuota(arguments[1], ValueWithUnit.parse(arguments[2]).getConvertedValue()); + sieveProbe.setSieveQuota(arguments[1], ValueWithUnit.parse(arguments[2]).getConvertedValue()); break; case GETSIEVEQUOTA: System.out.println("Storage space allowed for Sieve scripts by default : " - + formatStorageValue(probe.getSieveQuota())); + + formatStorageValue(sieveProbe.getSieveQuota())); break; case GETSIEVEUSERQUOTA: System.out.println("Storage space allowed for " + arguments[1] + " Sieve scripts : " - + formatStorageValue(probe.getSieveQuota(arguments[1]))); + + formatStorageValue(sieveProbe.getSieveQuota(arguments[1]))); break; case REMOVESIEVEQUOTA: - probe.removeSieveQuota(); + sieveProbe.removeSieveQuota(); break; case REMOVESIEVEUSERQUOTA: - probe.removeSieveQuota(arguments[1]); + sieveProbe.removeSieveQuota(arguments[1]); break; default: throw new UnrecognizedCommandException(cmdType.getCommand()); http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java deleted file mode 100644 index 8ca3b15..0000000 --- a/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java +++ /dev/null @@ -1,265 +0,0 @@ -/**************************************************************** - * 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.cli.probe; - -import java.io.Closeable; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.apache.james.adapter.mailbox.SerializableQuota; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.rrt.lib.Mappings; - -public interface ServerProbe extends Closeable { - /** - * Add a user to this mail server. - * - * @param userName - * The name of the user being added. - * @param password - * The password of the user being added. - * @throws Exception - */ - void addUser(String userName, String password) throws Exception; - - /** - * Delete a user from this mail server. - * - * @param username - * The name of the user being deleted. - * @throws Exception - */ - void removeUser(String username) throws Exception; - - /** - * Get a List the names of all users. - * - * @return a List of all user names. - * @throws Exception - */ - String[] listUsers() throws Exception; - - /** - * Set a user's password. - * - * @param userName - * The name of the user whose password will be changed. - * @param password - * The new password. - * @throws Exception - */ - void setPassword(String userName, String password) throws Exception; - - /** - * Add domain to the service. - * - * @param domain - * The domain to add. - * @throws Exception - */ - void addDomain(String domain) throws Exception; - - /** - * Return true if the domain exists in the service - * - * @param domain - * The domain to remove. - * @throws Exception - */ - boolean containsDomain(String domain) throws Exception; - - String getDefaultDomain() throws Exception; - - /** - * Remove domain from the service - * - * @param domain - * The domain to remove. - * @throws Exception - */ - void removeDomain(String domain) throws Exception; - - /** - * Get a list of domains for the service. - * - * @return domains an array of domains, or null if no domains exist. - * @throws Exception - */ - List<String> listDomains() throws Exception; - - /** - * Get a Map which holds all mappings. The key is the user@domain and the - * value is a Collection which holds all mappings. - * - * @return a Map which holds all mappings. - * @throws Exception - */ - Map<String, Mappings> listMappings() throws Exception; - - /** - * Add address mapping. - * - * @param user - * The username, or null if no username should be used. - * @param domain - * The domain, or null if no domain should be used. - * @param toAddress - * The address. - * @throws Exception - */ - void addAddressMapping(String user, String domain, String toAddress) throws Exception; - - /** - * Remove address mapping. - * - * @param user - * The username, or null if no username should be used. - * @param domain - * The domain, or null if no domain should be used - * @param fromAddress - * The address. - * @throws Exception - */ - void removeAddressMapping(String user, String domain, String fromAddress) throws Exception; - - /** - * Return the explicit mapping stored for the given user and domain. Return - * null if no mapping was found - * - * @param user - * The username. - * @param domain - * The domain. - * @return the collection which holds the mappings, or null if no mapping is - * found. - * @throws Exception - */ - Mappings listUserDomainMappings(String user, String domain) throws Exception; - - /** - * Remove regex mapping. - * - * @param user - * The username, or null if no username should be used. - * @param domain - * The domain, or null if no domain should be used. - * @param regex - * The regex. - * @throws Exception - */ - void addRegexMapping(String user, String domain, String regex) throws Exception; - - /** - * Remove regex mapping. - * - * @param user - * The username, or null if no username should be used. - * @param domain - * The domain, or null if no domain should be used. - * @param regex - * The regex. - * @throws Exception - */ - void removeRegexMapping(String user, String domain, String regex) throws Exception; - - /** - * Copy Mailbox. - * - * @param srcBean - * The name of the bean that manages the source mailbox. - * @param dstBean - * The name of the bean that manages the destination mailbox. - * @throws Exception - */ - void copyMailbox(String srcBean, String dstBean) throws Exception; - - /** - * Delete mailboxes Belonging to #private:${user} - * - * @param user Username of the user we want to list mailboxes on - * @return Collection of the mailboxes names - * @throws Exception - */ - void deleteUserMailboxesNames(String user) throws Exception; - - /** - * Create a mailbox - * - * @param namespace Namespace of the created mailbox - * @param user User of the created mailbox - * @param name Name of the created mailbox - */ - void createMailbox(String namespace, String user, String name); - - /** - * List mailboxes belonging to the private namespace of a user - * - * @param user The given user - * @return List of mailboxes belonging to the private namespace of a user - */ - Collection<String> listUserMailboxes(String user); - - /** - * Delete the given mailbox - * - * @param namespace Namespace of the mailbox to delete - * @param user User the mailbox to delete belongs to - * @param name Name of the mailbox to delete - */ - void deleteMailbox(String namespace, String user, String name); - - String getQuotaRoot(String namespace, String user, String name) throws MailboxException; - - SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException; - - SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException; - - long getMaxMessageCount(String quotaRoot) throws MailboxException; - - long getMaxStorage(String quotaRoot) throws MailboxException; - - long getDefaultMaxMessageCount() throws MailboxException; - - long getDefaultMaxStorage() throws MailboxException; - - void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException; - - void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException; - - void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException; - - void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException; - - void reIndexMailbox(String namespace, String user, String name) throws Exception; - - void reIndexAll() throws Exception; - - long getSieveQuota() throws Exception; - - void setSieveQuota(long quota) throws Exception; - - void removeSieveQuota() throws Exception; - - long getSieveQuota(String user) throws Exception; - - void setSieveQuota(String user, long quota) throws Exception; - - void removeSieveQuota(String user) throws Exception; -} http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxConnection.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxConnection.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxConnection.java new file mode 100644 index 0000000..ed416f3 --- /dev/null +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxConnection.java @@ -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.cli.probe.impl; + +import java.io.Closeable; +import java.io.IOException; + +import javax.management.MBeanServerConnection; +import javax.management.MBeanServerInvocationHandler; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +public class JmxConnection implements Closeable { + + private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi"; + private static final int defaultPort = 9999; + + public static JmxConnection defaultJmxConnection(String host) throws IOException { + return new JmxConnection(host, defaultPort); + } + + private final JMXConnector jmxConnector; + + public JmxConnection(String host, int port) throws IOException { + JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port)); + jmxConnector = JMXConnectorFactory.connect(jmxUrl, null); + } + + @Override + public void close() throws IOException { + jmxConnector.close(); + } + + public <T> T retrieveBean(Class<T> mbeanType, String name) throws MalformedObjectNameException, IOException { + return MBeanServerInvocationHandler.newProxyInstance(getMBeanServerConnection(), new ObjectName(name), mbeanType, true); + } + + private MBeanServerConnection getMBeanServerConnection() throws IOException { + return jmxConnector.getMBeanServerConnection(); + } + + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxDataProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxDataProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxDataProbe.java new file mode 100644 index 0000000..1256f0c --- /dev/null +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxDataProbe.java @@ -0,0 +1,130 @@ +/**************************************************************** + * 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.cli.probe.impl; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import javax.management.MalformedObjectNameException; + +import org.apache.james.domainlist.api.DomainListManagementMBean; +import org.apache.james.probe.DataProbe; +import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean; +import org.apache.james.rrt.lib.Mappings; +import org.apache.james.user.api.UsersRepositoryManagementMBean; + +public class JmxDataProbe implements DataProbe, JmxProbe { + + private final static String DOMAINLIST_OBJECT_NAME = "org.apache.james:type=component,name=domainlist"; + private final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable"; + private final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository"; + + private DomainListManagementMBean domainListProxy; + private RecipientRewriteTableManagementMBean virtualUserTableProxy; + private UsersRepositoryManagementMBean usersRepositoryProxy; + + public JmxDataProbe connect(JmxConnection jmxc) throws IOException { + try { + domainListProxy = jmxc.retrieveBean(DomainListManagementMBean.class, DOMAINLIST_OBJECT_NAME); + virtualUserTableProxy = jmxc.retrieveBean(RecipientRewriteTableManagementMBean.class, VIRTUALUSERTABLE_OBJECT_NAME); + usersRepositoryProxy = jmxc.retrieveBean(UsersRepositoryManagementMBean.class, USERSREPOSITORY_OBJECT_NAME); + } catch (MalformedObjectNameException e) { + throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); + } + return this; + } + + @Override + public void addUser(String userName, String password) throws Exception { + usersRepositoryProxy.addUser(userName, password); + } + + @Override + public void removeUser(String username) throws Exception { + usersRepositoryProxy.deleteUser(username); + } + + @Override + public String[] listUsers() throws Exception { + return usersRepositoryProxy.listAllUsers(); + } + + @Override + public void setPassword(String userName, String password) throws Exception { + usersRepositoryProxy.setPassword(userName, password); + } + + @Override + public boolean containsDomain(String domain) throws Exception { + return domainListProxy.containsDomain(domain); + } + + @Override + public String getDefaultDomain() throws Exception { + return domainListProxy.getDefaultDomain(); + } + + @Override + public void addDomain(String domain) throws Exception { + domainListProxy.addDomain(domain); + } + + @Override + public void removeDomain(String domain) throws Exception { + domainListProxy.removeDomain(domain); + } + + @Override + public List<String> listDomains() throws Exception { + return domainListProxy.getDomains(); + } + + @Override + public Map<String, Mappings> listMappings() throws Exception { + return virtualUserTableProxy.getAllMappings(); + } + + @Override + public void addAddressMapping(String user, String domain, String toAddress) throws Exception { + virtualUserTableProxy.addAddressMapping(user, domain, toAddress); + } + + @Override + public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception { + virtualUserTableProxy.removeAddressMapping(user, domain, fromAddress); + } + + @Override + public Mappings listUserDomainMappings(String user, String domain) throws Exception { + return virtualUserTableProxy.getUserDomainMappings(user, domain); + } + + @Override + public void addRegexMapping(String user, String domain, String regex) throws Exception { + virtualUserTableProxy.addRegexMapping(user, domain, regex); + } + + @Override + public void removeRegexMapping(String user, String domain, String regex) throws Exception { + virtualUserTableProxy.removeRegexMapping(user, domain, regex); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java new file mode 100644 index 0000000..59ac40d --- /dev/null +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java @@ -0,0 +1,118 @@ +/**************************************************************** + * 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.cli.probe.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.Date; + +import javax.mail.Flags; +import javax.management.MalformedObjectNameException; + +import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean; +import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; +import org.apache.james.adapter.mailbox.ReIndexerManagementMBean; +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.ComposedMessageId; +import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.store.mail.model.Mailbox; +import org.apache.james.mailbox.store.probe.MailboxProbe; + +public class JmxMailboxProbe implements MailboxProbe, JmxProbe { + + private final static String MAILBOXCOPIER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxcopier"; + private final static String MAILBOXMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxmanagerbean"; + private final static String REINDEXER_OBJECT_NAME = "org.apache.james:type=component,name=reindexerbean"; + + private MailboxCopierManagementMBean mailboxCopierManagement; + private MailboxManagerManagementMBean mailboxManagerManagement; + private ReIndexerManagementMBean reIndexerManagement; + + public JmxMailboxProbe connect(JmxConnection jmxc) throws IOException { + try { + mailboxCopierManagement = jmxc.retrieveBean(MailboxCopierManagementMBean.class, MAILBOXCOPIER_OBJECT_NAME); + mailboxManagerManagement = jmxc.retrieveBean(MailboxManagerManagementMBean.class, MAILBOXMANAGER_OBJECT_NAME); + reIndexerManagement = jmxc.retrieveBean(ReIndexerManagementMBean.class, REINDEXER_OBJECT_NAME); + } catch (MalformedObjectNameException e) { + throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); + } + return this; + } + + + @Override + public void copyMailbox(String srcBean, String dstBean) throws Exception { + mailboxCopierManagement.copy(srcBean, dstBean); + } + + @Override + public void deleteUserMailboxesNames(String user) throws Exception { + mailboxManagerManagement.deleteMailboxes(user); + } + + @Override + public void createMailbox(String namespace, String user, String name) { + mailboxManagerManagement.createMailbox(namespace, user, name); + } + + @Override + public Collection<String> listUserMailboxes(String user) { + return mailboxManagerManagement.listMailboxes(user); + } + + @Override + public void deleteMailbox(String namespace, String user, String name) { + mailboxManagerManagement.deleteMailbox(namespace, user, name); + } + + @Override + public void reIndexMailbox(String namespace, String user, String name) throws Exception { + reIndexerManagement.reIndex(namespace, user, name); + } + + @Override + public void reIndexAll() throws Exception { + reIndexerManagement.reIndex(); + } + + + @Override + public Mailbox getMailbox(String namespace, String user, String name) { + // TODO Auto-generated method stub + return null; + } + + + @Override + public ComposedMessageId appendMessage(String username, MailboxPath mailboxPath, InputStream message, + Date internalDate, boolean isRecent, Flags flags) throws MailboxException { + // TODO Auto-generated method stub + return null; + } + + + @Override + public Collection<String> listSubscriptions(String user) throws Exception { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxProbe.java new file mode 100644 index 0000000..76b6552 --- /dev/null +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxProbe.java @@ -0,0 +1,28 @@ +/**************************************************************** + * 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.cli.probe.impl; + +import java.io.IOException; + +public interface JmxProbe { + + public JmxProbe connect(JmxConnection jmxc) throws IOException; + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java new file mode 100644 index 0000000..48191bb --- /dev/null +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java @@ -0,0 +1,100 @@ +/**************************************************************** + * 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.cli.probe.impl; + +import java.io.IOException; + +import javax.management.MalformedObjectNameException; + +import org.apache.james.adapter.mailbox.QuotaManagementMBean; +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.store.mail.model.SerializableQuota; +import org.apache.james.mailbox.store.probe.QuotaProbe; + +public class JmxQuotaProbe implements QuotaProbe, JmxProbe { + private final static String QUOTAMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=quotamanagerbean"; + + private QuotaManagementMBean quotaManagement; + + public JmxQuotaProbe connect(JmxConnection jmxc) throws IOException { + try { + quotaManagement = jmxc.retrieveBean(QuotaManagementMBean.class, QUOTAMANAGER_OBJECT_NAME); + } catch (MalformedObjectNameException e) { + throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); + } + return this; + } + + @Override + public String getQuotaRoot(String namespace, String user, String name) throws MailboxException { + return quotaManagement.getQuotaRoot(namespace, user, name); + } + + @Override + public SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException { + return quotaManagement.getMessageCountQuota(quotaRoot); + } + + @Override + public SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException { + return quotaManagement.getStorageQuota(quotaRoot); + } + + @Override + public long getMaxMessageCount(String quotaRoot) throws MailboxException { + return quotaManagement.getMaxMessageCount(quotaRoot); + } + + @Override + public long getMaxStorage(String quotaRoot) throws MailboxException { + return quotaManagement.getMaxStorage(quotaRoot); + } + + @Override + public long getDefaultMaxMessageCount() throws MailboxException { + return quotaManagement.getDefaultMaxMessageCount(); + } + + @Override + public long getDefaultMaxStorage() throws MailboxException { + return quotaManagement.getDefaultMaxStorage(); + } + + @Override + public void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException { + quotaManagement.setMaxMessageCount(quotaRoot, maxMessageCount); + } + + @Override + public void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException { + quotaManagement.setMaxStorage(quotaRoot, maxSize); + } + + @Override + public void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException { + quotaManagement.setDefaultMaxMessageCount(maxDefaultMessageCount); + } + + @Override + public void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException { + quotaManagement.setDefaultMaxStorage(maxDefaultSize); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java deleted file mode 100644 index a24724c..0000000 --- a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java +++ /dev/null @@ -1,339 +0,0 @@ -/**************************************************************** - * 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.cli.probe.impl; - -import java.io.IOException; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import javax.management.MBeanServerConnection; -import javax.management.MBeanServerInvocationHandler; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; -import javax.management.remote.JMXConnector; -import javax.management.remote.JMXConnectorFactory; -import javax.management.remote.JMXServiceURL; - -import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean; -import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; -import org.apache.james.adapter.mailbox.QuotaManagementMBean; -import org.apache.james.adapter.mailbox.ReIndexerManagementMBean; -import org.apache.james.adapter.mailbox.SerializableQuota; -import org.apache.james.cli.probe.ServerProbe; -import org.apache.james.domainlist.api.DomainListManagementMBean; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean; -import org.apache.james.rrt.lib.Mappings; -import org.apache.james.sieverepository.api.SieveRepositoryManagementMBean; -import org.apache.james.user.api.UsersRepositoryManagementMBean; - -public class JmxServerProbe implements ServerProbe { - - // TODO: Move this to somewhere else - private final static String DOMAINLIST_OBJECT_NAME = "org.apache.james:type=component,name=domainlist"; - private final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable"; - private final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository"; - private final static String MAILBOXCOPIER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxcopier"; - private final static String MAILBOXMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxmanagerbean"; - private final static String SIEVEMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=sievemanagerbean"; - private final static String QUOTAMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=quotamanagerbean"; - private final static String REINDEXER_OBJECT_NAME = "org.apache.james:type=component,name=reindexerbean"; - - private JMXConnector jmxc; - - private DomainListManagementMBean domainListProxy; - private RecipientRewriteTableManagementMBean virtualUserTableProxy; - private UsersRepositoryManagementMBean usersRepositoryProxy; - private MailboxCopierManagementMBean mailboxCopierManagement; - private MailboxManagerManagementMBean mailboxManagerManagement; - private QuotaManagementMBean quotaManagement; - private ReIndexerManagementMBean reIndexerManagement; - private SieveRepositoryManagementMBean sieveRepositoryManagement; - - private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi"; - private static final int defaultPort = 9999; - private final String host; - private final int port; - - /** - * Creates a ServerProbe using the specified JMX host and port. - * - * @param host hostname or IP address of the JMX agent - * @param port TCP port of the remote JMX agent - * @throws IOException on connection failures - */ - public JmxServerProbe(String host, int port) throws IOException { - this.host = host; - this.port = port; - connect(); - } - - /** - * Creates a NodeProbe using the specified JMX host and default port. - * - * @param host hostname or IP address of the JMX agent - * @throws IOException on connection failures - */ - public JmxServerProbe(String host) throws IOException { - this.host = host; - this.port = defaultPort; - connect(); - } - - /** - * Create a connection to the JMX agent and setup the M[X]Bean proxies. - * - * @throws IOException on connection failures - */ - private void connect() throws IOException { - JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port)); - jmxc = JMXConnectorFactory.connect(jmxUrl, null); - MBeanServerConnection mbeanServerConn = jmxc.getMBeanServerConnection(); - - try { - ObjectName name = new ObjectName(DOMAINLIST_OBJECT_NAME); - domainListProxy = MBeanServerInvocationHandler.newProxyInstance( - mbeanServerConn, name, DomainListManagementMBean.class, true); - name = new ObjectName(VIRTUALUSERTABLE_OBJECT_NAME); - virtualUserTableProxy = MBeanServerInvocationHandler - .newProxyInstance(mbeanServerConn, name, RecipientRewriteTableManagementMBean.class, true); - name = new ObjectName(USERSREPOSITORY_OBJECT_NAME); - usersRepositoryProxy = MBeanServerInvocationHandler.newProxyInstance( - mbeanServerConn, name, UsersRepositoryManagementMBean.class, true); - name = new ObjectName(MAILBOXCOPIER_OBJECT_NAME); - mailboxCopierManagement = MBeanServerInvocationHandler.newProxyInstance( - mbeanServerConn, name, MailboxCopierManagementMBean.class, true); - name = new ObjectName(MAILBOXMANAGER_OBJECT_NAME); - mailboxManagerManagement = MBeanServerInvocationHandler.newProxyInstance( - mbeanServerConn, name, MailboxManagerManagementMBean.class, true); - name = new ObjectName(QUOTAMANAGER_OBJECT_NAME); - quotaManagement = MBeanServerInvocationHandler.newProxyInstance( - mbeanServerConn, name, QuotaManagementMBean.class, true); - name = new ObjectName(REINDEXER_OBJECT_NAME); - reIndexerManagement = MBeanServerInvocationHandler.newProxyInstance( - mbeanServerConn, name, ReIndexerManagementMBean.class, true); - name = new ObjectName(SIEVEMANAGER_OBJECT_NAME); - sieveRepositoryManagement = MBeanServerInvocationHandler.newProxyInstance( - mbeanServerConn, name, SieveRepositoryManagementMBean.class, true); - } catch (MalformedObjectNameException e) { - throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); - } - } - - @Override - public void close() throws IOException { - jmxc.close(); - } - - @Override - public void addUser(String userName, String password) throws Exception { - usersRepositoryProxy.addUser(userName, password); - } - - @Override - public void removeUser(String username) throws Exception { - usersRepositoryProxy.deleteUser(username); - } - - @Override - public String[] listUsers() throws Exception { - return usersRepositoryProxy.listAllUsers(); - } - - @Override - public void setPassword(String userName, String password) throws Exception { - usersRepositoryProxy.setPassword(userName, password); - } - - @Override - public boolean containsDomain(String domain) throws Exception { - return domainListProxy.containsDomain(domain); - } - - @Override - public String getDefaultDomain() throws Exception { - return domainListProxy.getDefaultDomain(); - } - - @Override - public void addDomain(String domain) throws Exception { - domainListProxy.addDomain(domain); - } - - @Override - public void removeDomain(String domain) throws Exception { - domainListProxy.removeDomain(domain); - } - - @Override - public List<String> listDomains() throws Exception { - return domainListProxy.getDomains(); - } - - @Override - public Map<String, Mappings> listMappings() throws Exception { - return virtualUserTableProxy.getAllMappings(); - } - - @Override - public void addAddressMapping(String user, String domain, String toAddress) throws Exception { - virtualUserTableProxy.addAddressMapping(user, domain, toAddress); - } - - @Override - public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception { - virtualUserTableProxy.removeAddressMapping(user, domain, fromAddress); - } - - @Override - public Mappings listUserDomainMappings(String user, String domain) throws Exception { - return virtualUserTableProxy.getUserDomainMappings(user, domain); - } - - @Override - public void addRegexMapping(String user, String domain, String regex) throws Exception { - virtualUserTableProxy.addRegexMapping(user, domain, regex); - } - - @Override - public void removeRegexMapping(String user, String domain, String regex) throws Exception { - virtualUserTableProxy.removeRegexMapping(user, domain, regex); - } - - @Override - public void copyMailbox(String srcBean, String dstBean) throws Exception { - mailboxCopierManagement.copy(srcBean, dstBean); - } - - @Override - public void deleteUserMailboxesNames(String user) throws Exception { - mailboxManagerManagement.deleteMailboxes(user); - } - - @Override - public void createMailbox(String namespace, String user, String name) { - mailboxManagerManagement.createMailbox(namespace, user, name); - } - - @Override - public Collection<String> listUserMailboxes(String user) { - return mailboxManagerManagement.listMailboxes(user); - } - - @Override - public void deleteMailbox(String namespace, String user, String name) { - mailboxManagerManagement.deleteMailbox(namespace, user, name); - } - - @Override - public String getQuotaRoot(String namespace, String user, String name) throws MailboxException { - return quotaManagement.getQuotaRoot(namespace, user, name); - } - - @Override - public SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException { - return quotaManagement.getMessageCountQuota(quotaRoot); - } - - @Override - public SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException { - return quotaManagement.getStorageQuota(quotaRoot); - } - - @Override - public long getMaxMessageCount(String quotaRoot) throws MailboxException { - return quotaManagement.getMaxMessageCount(quotaRoot); - } - - @Override - public long getMaxStorage(String quotaRoot) throws MailboxException { - return quotaManagement.getMaxStorage(quotaRoot); - } - - @Override - public long getDefaultMaxMessageCount() throws MailboxException { - return quotaManagement.getDefaultMaxMessageCount(); - } - - @Override - public long getDefaultMaxStorage() throws MailboxException { - return quotaManagement.getDefaultMaxStorage(); - } - - @Override - public void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException { - quotaManagement.setMaxMessageCount(quotaRoot, maxMessageCount); - } - - @Override - public void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException { - quotaManagement.setMaxStorage(quotaRoot, maxSize); - } - - @Override - public void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException { - quotaManagement.setDefaultMaxMessageCount(maxDefaultMessageCount); - } - - @Override - public void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException { - quotaManagement.setDefaultMaxStorage(maxDefaultSize); - } - - @Override - public void reIndexMailbox(String namespace, String user, String name) throws Exception { - reIndexerManagement.reIndex(namespace, user, name); - } - - @Override - public void reIndexAll() throws Exception { - reIndexerManagement.reIndex(); - } - - @Override - public long getSieveQuota() throws Exception { - return sieveRepositoryManagement.getQuota(); - } - - @Override - public void setSieveQuota(long quota) throws Exception { - sieveRepositoryManagement.setQuota(quota); - } - - @Override - public void removeSieveQuota() throws Exception { - sieveRepositoryManagement.removeQuota(); - } - - @Override - public long getSieveQuota(String user) throws Exception { - return sieveRepositoryManagement.getQuota(user); - } - - @Override - public void setSieveQuota(String user, long quota) throws Exception { - sieveRepositoryManagement.setQuota(user, quota); - } - - @Override - public void removeSieveQuota(String user) throws Exception { - sieveRepositoryManagement.removeQuota(user); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/793dae76/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java new file mode 100644 index 0000000..acfcf7d --- /dev/null +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java @@ -0,0 +1,78 @@ +/**************************************************************** + * 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.cli.probe.impl; + +import java.io.IOException; + +import javax.management.MalformedObjectNameException; + +import org.apache.james.mailbox.store.probe.SieveProbe; +import org.apache.james.sieverepository.api.SieveRepositoryManagementMBean; + +public class JmxSieveProbe implements SieveProbe, JmxProbe { + + private final static String SIEVEMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=sievemanagerbean"; + + private SieveRepositoryManagementMBean sieveRepositoryManagement; + + public JmxSieveProbe connect(JmxConnection jmxc) throws IOException { + try { + jmxc.retrieveBean(SieveRepositoryManagementMBean.class, SIEVEMANAGER_OBJECT_NAME); + } catch (MalformedObjectNameException e) { + throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); + } + return this; + } + + @Override + public long getSieveQuota() throws Exception { + return sieveRepositoryManagement.getQuota(); + } + + @Override + public void setSieveQuota(long quota) throws Exception { + sieveRepositoryManagement.setQuota(quota); + } + + @Override + public void removeSieveQuota() throws Exception { + sieveRepositoryManagement.removeQuota(); + } + + @Override + public long getSieveQuota(String user) throws Exception { + return sieveRepositoryManagement.getQuota(user); + } + + @Override + public void setSieveQuota(String user, long quota) throws Exception { + sieveRepositoryManagement.setQuota(user, quota); + } + + @Override + public void removeSieveQuota(String user) throws Exception { + sieveRepositoryManagement.removeQuota(user); + } + + @Override + public void addActiveSieveScript(String user, String name, String script) throws Exception { + } + +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org