Search in sources :

Example 1 with PingResponse

use of org.codelibs.fess.entity.PingResponse in project fess by codelibs.

the class PingEsJob method execute.

public String execute() {
    final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final StringBuilder resultBuf = new StringBuilder();
    final String notificationTo = fessConfig.getNotificationTo();
    final PingResponse ping = fessEsClient.ping();
    final int status = ping.getStatus();
    if (systemHelper.isChangedClusterState(status)) {
        if (StringUtil.isNotBlank(notificationTo)) {
            final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
            try {
                EsStatusPostcard.droppedInto(postbox, postcard -> {
                    postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
                    postcard.addReplyTo(fessConfig.getMailReturnPath());
                    postcard.addTo(notificationTo);
                    postcard.setHostname(systemHelper.getHostname());
                    postcard.setClustername(ping.getClusterName());
                    postcard.setClusterstatus(ping.getClusterStatus());
                });
            } catch (final Exception e) {
                logger.warn("Failed to send a test mail.", e);
            }
        }
        resultBuf.append("Status of ").append(ping.getClusterName()).append(" is changed to ").append(ping.getClusterStatus()).append('.');
    } else {
        if (status == 0) {
            resultBuf.append(ping.getClusterName()).append(" is alive.");
        } else {
            resultBuf.append(ping.getClusterName()).append(" is not available.");
        }
    }
    return resultBuf.toString();
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient) PingResponse(org.codelibs.fess.entity.PingResponse) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 2 with PingResponse

use of org.codelibs.fess.entity.PingResponse in project fess by codelibs.

the class JsonApiManager method processPingRequest.

protected void processPingRequest(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) {
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    int status;
    Exception err = null;
    try {
        final PingResponse pingResponse = searchEngineClient.ping();
        status = pingResponse.getStatus();
        writeJsonResponse(status, "\"message\":" + pingResponse.getMessage());
    } catch (final Exception e) {
        status = 9;
        err = e;
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to process a ping request.", e);
        }
        writeJsonResponse(status, null, err);
    }
}
Also used : SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) PingResponse(org.codelibs.fess.entity.PingResponse) IORuntimeException(org.codelibs.core.exception.IORuntimeException) ServletException(javax.servlet.ServletException) WebApiException(org.codelibs.fess.exception.WebApiException) IOException(java.io.IOException)

Example 3 with PingResponse

use of org.codelibs.fess.entity.PingResponse in project fess by codelibs.

the class PingSearchEngineJob method execute.

public String execute() {
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final StringBuilder resultBuf = new StringBuilder();
    final PingResponse ping = searchEngineClient.ping();
    final int status = ping.getStatus();
    if (systemHelper.isChangedClusterState(status)) {
        if (fessConfig.hasNotification()) {
            final String toStrs = fessConfig.getNotificationTo();
            final String[] toAddresses;
            if (StringUtil.isNotBlank(toStrs)) {
                toAddresses = toStrs.split(",");
            } else {
                toAddresses = StringUtil.EMPTY_STRINGS;
            }
            final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
            try {
                final NotificationHelper notificationHelper = ComponentUtil.getNotificationHelper();
                SMailCallbackContext.setPreparedMessageHookOnThread(notificationHelper::send);
                EsStatusPostcard.droppedInto(postbox, postcard -> {
                    postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
                    postcard.addReplyTo(fessConfig.getMailReturnPath());
                    if (toAddresses.length > 0) {
                        stream(toAddresses).of(stream -> stream.map(String::trim).forEach(address -> {
                            postcard.addTo(address);
                        }));
                    } else {
                        postcard.addTo(fessConfig.getMailFromAddress());
                        postcard.dryrun();
                    }
                    postcard.setHostname(systemHelper.getHostname());
                    postcard.setClustername(ping.getClusterName());
                    postcard.setClusterstatus(ping.getClusterStatus());
                });
            } catch (final Exception e) {
                logger.warn("Failed to send a test mail.", e);
            } finally {
                SMailCallbackContext.clearPreparedMessageHookOnThread();
            }
        }
        resultBuf.append("Status of ").append(ping.getClusterName()).append(" is changed to ").append(ping.getClusterStatus()).append('.');
    } else if (status == 0) {
        resultBuf.append(ping.getClusterName()).append(" is alive.");
    } else {
        resultBuf.append(ping.getClusterName()).append(" is not available.");
    }
    return resultBuf.toString();
}
Also used : StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) SMailCallbackContext(org.dbflute.mail.send.hook.SMailCallbackContext) NotificationHelper(org.codelibs.fess.helper.NotificationHelper) StringUtil(org.codelibs.core.lang.StringUtil) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) EsStatusPostcard(org.codelibs.fess.mylasta.mail.EsStatusPostcard) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) PingResponse(org.codelibs.fess.entity.PingResponse) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) LogManager(org.apache.logging.log4j.LogManager) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) PingResponse(org.codelibs.fess.entity.PingResponse) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SystemHelper(org.codelibs.fess.helper.SystemHelper) NotificationHelper(org.codelibs.fess.helper.NotificationHelper)

Aggregations

PingResponse (org.codelibs.fess.entity.PingResponse)3 SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)2 SystemHelper (org.codelibs.fess.helper.SystemHelper)2 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2 Postbox (org.lastaflute.core.mail.Postbox)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 IORuntimeException (org.codelibs.core.exception.IORuntimeException)1 StringUtil (org.codelibs.core.lang.StringUtil)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1 FessEsClient (org.codelibs.fess.es.client.FessEsClient)1 WebApiException (org.codelibs.fess.exception.WebApiException)1 NotificationHelper (org.codelibs.fess.helper.NotificationHelper)1 EsStatusPostcard (org.codelibs.fess.mylasta.mail.EsStatusPostcard)1 ComponentUtil (org.codelibs.fess.util.ComponentUtil)1 SMailCallbackContext (org.dbflute.mail.send.hook.SMailCallbackContext)1