Search in sources :

Example 1 with CuratorManager

use of com.zimbra.cs.zookeeper.CuratorManager in project zm-mailbox by Zimbra.

the class GetAllActiveServers method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
    Element response = zsc.createElement(AdminConstants.GET_ALL_ACTIVE_SERVERS_RESPONSE);
    CuratorManager curator = CuratorManager.getInstance();
    if (curator == null) {
        return response;
    }
    Set<String> serverIds;
    try {
        serverIds = curator.getActiveServers();
    } catch (Exception e) {
        throw ServiceException.FAILURE("error while getting active servers", e);
    }
    Provisioning prov = Provisioning.getInstance();
    List<Server> servers = new ArrayList<Server>();
    for (String serverId : serverIds) {
        Server server = prov.getServerById(serverId);
        servers.add(server);
    }
    AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
    for (Iterator<Server> it = servers.iterator(); it.hasNext(); ) {
        Server server = it.next();
        if (aac.hasRightsToList(server, Admin.R_listServer, null))
            GetServer.encodeServer(response, server, true, null, aac.getAttrRightChecker(server));
    }
    return response;
}
Also used : Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) CuratorManager(com.zimbra.cs.zookeeper.CuratorManager) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 2 with CuratorManager

use of com.zimbra.cs.zookeeper.CuratorManager in project zm-mailbox by Zimbra.

the class SetServerOffline method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
    Element response = zsc.createElement(AdminConstants.SET_SERVER_OFFLINE_RESPONSE);
    CuratorManager curator = CuratorManager.getInstance();
    if (curator == null) {
        return response;
    }
    Element d = request.getElement(AdminConstants.E_SERVER);
    String method = d.getAttribute(AdminConstants.A_BY);
    String name = d.getText();
    if (name == null || name.equals(""))
        throw ServiceException.INVALID_REQUEST("must specify a value for a server", null);
    Server server = Provisioning.getInstance().get(Key.ServerBy.fromString(method), name);
    try {
        curator.unregisterService(server.getId());
    } catch (Exception e) {
        throw ServiceException.FAILURE("error while unregistering the server", e);
    }
    return response;
}
Also used : Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) CuratorManager(com.zimbra.cs.zookeeper.CuratorManager) ServiceException(com.zimbra.common.service.ServiceException)

Example 3 with CuratorManager

use of com.zimbra.cs.zookeeper.CuratorManager in project zm-mailbox by Zimbra.

the class Zimbra method startup.

/**
 * Initialize the various subsystems at server/CLI startup time.
 * @param forMailboxd true if this is the mailboxd process; false for CLI processes
 * @throws ServiceException
 */
private static synchronized void startup(boolean forMailboxd) throws ServiceException {
    if (sInited)
        return;
    sIsMailboxd = forMailboxd;
    if (sIsMailboxd) {
        FirstServlet.waitForInitialization();
    }
    Provisioning prov = Provisioning.getInstance();
    Server server = prov.getLocalServer();
    alwaysOnClusterId = server.getAlwaysOnClusterId();
    setSystemProperties();
    validateJavaOptions();
    logVersionAndSysInfo();
    SoapTransport.setDefaultUserAgent("ZCS", BuildInfo.VERSION);
    checkForClasses();
    ZimbraApplication app = ZimbraApplication.getInstance();
    ZimbraPerf.prepare(ZimbraPerf.ServerID.ZIMBRA);
    DbPool.startup();
    app.initializeZimbraDb(forMailboxd);
    if (!Versions.checkVersions()) {
        Zimbra.halt("Data version mismatch.  Reinitialize or upgrade the backend data store.");
    }
    DbPool.loadSettings();
    String tzFilePath = LC.timezone_file.value();
    try {
        File tzFile = new File(tzFilePath);
        WellKnownTimeZones.loadFromFile(tzFile);
    } catch (Throwable t) {
        Zimbra.halt("Unable to load timezones from " + tzFilePath, t);
    }
    if (prov instanceof LdapProv) {
        ((LdapProv) prov).waitForLdapServer();
        if (forMailboxd) {
            AttributeManager.loadLdapSchemaExtensionAttrs((LdapProv) prov);
        }
    }
    if (server.isMailSSLClientCertOCSPEnabled()) {
        // Activate OCSP
        Security.setProperty("ocsp.enable", "true");
        // Activate CRLDP
        System.setProperty("com.sun.security.enableCRLDP", "true");
    } else {
        // Disable OCSP
        Security.setProperty("ocsp.enable", "false");
        // Disable CRLDP
        System.setProperty("com.sun.security.enableCRLDP", "false");
    }
    try {
        RightManager.getInstance();
    } catch (ServiceException e) {
        Util.halt("cannot initialize RightManager", e);
    }
    ZimbraHttpConnectionManager.startReaperThread();
    EphemeralStore.registerFactory("ldap", LdapEphemeralStore.Factory.class.getName());
    ExtensionUtil.initAll();
    try {
        StoreManager.getInstance().startup();
    } catch (IOException e) {
        throw ServiceException.FAILURE("Unable to initialize StoreManager.", e);
    }
    MailboxManager.getInstance();
    app.startup();
    if (app.supports(MemcachedConnector.class.getName())) {
        MemcachedConnector.startup();
    }
    if (app.supports(EhcacheManager.class.getName())) {
        EhcacheManager.getInstance().startup();
    }
    // ZimletUtil.loadZimlets();
    MailboxIndex.startup();
    RedoLogProvider redoLog = RedoLogProvider.getInstance();
    if (sIsMailboxd) {
        redoLog.startup();
    } else {
        redoLog.initRedoLogManager();
    }
    System.setProperty("ical4j.unfolding.relaxed", "true");
    MailboxManager.getInstance().startup();
    app.initialize(sIsMailboxd);
    if (sIsMailboxd) {
        SessionCache.startup();
        AuthTokenRegistry.startup(prov.getConfig(Provisioning.A_zimbraAuthTokenNotificationInterval).getIntAttr(Provisioning.A_zimbraAuthTokenNotificationInterval, 60000));
        dbSessionCleanup();
        if (!redoLog.isSlave()) {
            boolean useDirectBuffers = server.isMailUseDirectBuffers();
            IoBuffer.setUseDirectBuffer(useDirectBuffers);
            ZimbraLog.misc.info("MINA setUseDirectBuffers(" + useDirectBuffers + ")");
            ServerManager.getInstance().startServers();
        }
        if (app.supports(WaitSetMgr.class.getName())) {
            WaitSetMgr.startup();
        }
        if (app.supports(MemoryStats.class.getName())) {
            MemoryStats.startup();
        }
        if (app.supports(ScheduledTaskManager.class.getName())) {
            ScheduledTaskManager.startup();
        }
        if (app.supports(PurgeThread.class.getName())) {
            PurgeThread.startup();
        }
        if (app.supports(AutoProvisionThread.class.getName())) {
            AutoProvisionThread.switchAutoProvThreadIfNecessary();
        }
        if (LC.smtp_to_lmtp_enabled.booleanValue()) {
            int smtpPort = LC.smtp_to_lmtp_port.intValue();
            int lmtpPort = Provisioning.getInstance().getLocalServer().getLmtpBindPort();
            SmtpToLmtp smtpServer = SmtpToLmtp.startup(smtpPort, "localhost", lmtpPort);
            smtpServer.setRecipientValidator(new SmtpRecipientValidator());
        }
        if (app.supports(AclPushTask.class)) {
            long pushInterval = server.getSharingUpdatePublishInterval();
            sTimer.schedule(new AclPushTask(), pushInterval, pushInterval);
        }
        if (app.supports(ExternalAccountManagerTask.class)) {
            long interval = server.getExternalAccountStatusCheckInterval();
            sTimer.schedule(new ExternalAccountManagerTask(), interval, interval);
        }
        Server localServer = Provisioning.getInstance().getLocalServer();
        String provPort = localServer.getAttr(Provisioning.A_zimbraMailPort);
        String lcPort = LC.zimbra_mail_service_port.value();
        if (!lcPort.equals(provPort)) {
            LocalConfig lc;
            try {
                lc = new LocalConfig(null);
                lc.set(LC.zimbra_mail_service_port.key(), provPort);
                lc.save();
                LC.reload();
            } catch (DocumentException | ConfigException | IOException e) {
                ZimbraLog.misc.warn("Cannot set LC zimbra_mail_service_port", e);
            }
        }
        // should be last, so that other subsystems can add dynamic stats counters
        if (app.supports(ZimbraPerf.class.getName())) {
            ZimbraPerf.initialize(ZimbraPerf.ServerID.ZIMBRA);
        }
    }
    ExtensionUtil.postInitAll();
    // Register the service with ZooKeeper
    if (sIsMailboxd && isAlwaysOn()) {
        try {
            CuratorManager curatorManager = CuratorManager.getInstance();
            if (curatorManager == null) {
                throw ServiceException.FAILURE("ZooKeeper addresses not configured.", null);
            }
            curatorManager.start();
        } catch (Exception e) {
            throw ServiceException.FAILURE("Unable to start Distributed Lock service.", e);
        }
    }
    sInited = true;
}
Also used : PurgeThread(com.zimbra.cs.mailbox.PurgeThread) Server(com.zimbra.cs.account.Server) AclPushTask(com.zimbra.cs.mailbox.acl.AclPushTask) ConfigException(com.zimbra.common.localconfig.ConfigException) Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv) AutoProvisionThread(com.zimbra.cs.account.AutoProvisionThread) ScheduledTaskManager(com.zimbra.cs.mailbox.ScheduledTaskManager) RedoLogProvider(com.zimbra.cs.redolog.RedoLogProvider) DocumentException(org.dom4j.DocumentException) ExternalAccountManagerTask(com.zimbra.cs.account.ExternalAccountManagerTask) SmtpToLmtp(com.zimbra.common.lmtp.SmtpToLmtp) MemcachedConnector(com.zimbra.cs.memcached.MemcachedConnector) LocalConfig(com.zimbra.common.localconfig.LocalConfig) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException) ConfigException(com.zimbra.common.localconfig.ConfigException) WaitSetMgr(com.zimbra.cs.session.WaitSetMgr) ServiceException(com.zimbra.common.service.ServiceException) ZimbraPerf(com.zimbra.cs.stats.ZimbraPerf) CuratorManager(com.zimbra.cs.zookeeper.CuratorManager) File(java.io.File)

Example 4 with CuratorManager

use of com.zimbra.cs.zookeeper.CuratorManager in project zm-mailbox by Zimbra.

the class Zimbra method shutdown.

public static synchronized void shutdown() throws ServiceException {
    if (!sInited)
        return;
    sInited = false;
    if (sIsMailboxd) {
        PurgeThread.shutdown();
        AutoProvisionThread.shutdown();
    }
    ZimbraApplication app = ZimbraApplication.getInstance();
    app.shutdown();
    if (sIsMailboxd) {
        if (app.supports(MemoryStats.class.getName())) {
            MemoryStats.shutdown();
        }
        if (app.supports(WaitSetMgr.class.getName())) {
            WaitSetMgr.shutdown();
        }
    }
    RedoLogProvider redoLog = RedoLogProvider.getInstance();
    if (sIsMailboxd) {
        if (!redoLog.isSlave()) {
            ServerManager.getInstance().stopServers();
        }
        dbSessionCleanup();
        SessionCache.shutdown();
        CuratorManager curatorManager = CuratorManager.getInstance();
        if (curatorManager != null) {
            curatorManager.stop();
        }
    }
    MailboxIndex.shutdown();
    if (sIsMailboxd) {
        redoLog.shutdown();
    }
    if (app.supports(ExtensionUtil.class.getName())) {
        ExtensionUtil.destroyAll();
    }
    if (app.supports(MemcachedConnector.class.getName())) {
        MemcachedConnector.shutdown();
    }
    if (app.supports(EhcacheManager.class.getName())) {
        EhcacheManager.getInstance().shutdown();
    }
    MailboxManager.getInstance().shutdown();
    if (sIsMailboxd) {
        StoreManager.getInstance().shutdown();
    }
    ZimbraHttpConnectionManager.shutdownReaperThread();
    sTimer.cancel();
    try {
        DbPool.shutdown();
    } catch (Exception ignored) {
    }
    EphemeralStore.getFactory().shutdown();
}
Also used : WaitSetMgr(com.zimbra.cs.session.WaitSetMgr) MemcachedConnector(com.zimbra.cs.memcached.MemcachedConnector) RedoLogProvider(com.zimbra.cs.redolog.RedoLogProvider) CuratorManager(com.zimbra.cs.zookeeper.CuratorManager) ServiceException(com.zimbra.common.service.ServiceException) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException) ConfigException(com.zimbra.common.localconfig.ConfigException) ExtensionUtil(com.zimbra.cs.extension.ExtensionUtil)

Example 5 with CuratorManager

use of com.zimbra.cs.zookeeper.CuratorManager in project zm-mailbox by Zimbra.

the class SetLocalServerOnline method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
    Element response = zsc.createElement(AdminConstants.SET_LOCAL_SERVER_ONLINE_RESPONSE);
    CuratorManager curator = CuratorManager.getInstance();
    if (curator == null) {
        return response;
    }
    try {
        curator.registerLocalService();
    } catch (Exception e) {
        throw ServiceException.FAILURE("error while register the local server", e);
    }
    return response;
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) CuratorManager(com.zimbra.cs.zookeeper.CuratorManager) ServiceException(com.zimbra.common.service.ServiceException)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)5 CuratorManager (com.zimbra.cs.zookeeper.CuratorManager)5 Element (com.zimbra.common.soap.Element)3 Server (com.zimbra.cs.account.Server)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 ConfigException (com.zimbra.common.localconfig.ConfigException)2 Provisioning (com.zimbra.cs.account.Provisioning)2 MemcachedConnector (com.zimbra.cs.memcached.MemcachedConnector)2 RedoLogProvider (com.zimbra.cs.redolog.RedoLogProvider)2 WaitSetMgr (com.zimbra.cs.session.WaitSetMgr)2 IOException (java.io.IOException)2 DocumentException (org.dom4j.DocumentException)2 SmtpToLmtp (com.zimbra.common.lmtp.SmtpToLmtp)1 LocalConfig (com.zimbra.common.localconfig.LocalConfig)1 AutoProvisionThread (com.zimbra.cs.account.AutoProvisionThread)1 ExternalAccountManagerTask (com.zimbra.cs.account.ExternalAccountManagerTask)1 LdapProv (com.zimbra.cs.account.ldap.LdapProv)1 ExtensionUtil (com.zimbra.cs.extension.ExtensionUtil)1 PurgeThread (com.zimbra.cs.mailbox.PurgeThread)1 ScheduledTaskManager (com.zimbra.cs.mailbox.ScheduledTaskManager)1