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();
}
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);
}
}
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();
}
Aggregations