- try {
- ruleMgtWrapper.deployRule2Engine(rule, ip);
- correlationRuleDao.updateRule(rule);
- } catch (CorrelationException e) {
- throw new CorrelationException(String.format("Failed to allocate rule <%s> to <%s>",
- rule.getName(), ip), e);
+ // Retry for a couple of times in case of deployment failure
+ // due to unfinished initialization procedures of engine instances.
+ for (int i = 0; i <= RETRY_TIMES; ++i) {
+ try {
+ ruleMgtWrapper.deployRule2Engine(rule, ip);
+ correlationRuleService.updateRule(rule);
+ // If the codes reach here, it means everything's okay. There's no need to run the loop more.
+ break;
+ } catch (CorrelationException e) {
+ LOGGER.warn(String.format("Failed to allocate rule <%s> to <%s>. Retry: %d.",
+ rule.getName(), ip, i), e);
+ if (i == RETRY_TIMES) {
+ throw new CorrelationException(String.format("Failed to allocate rule <%s> to <%s>",
+ rule.getName(), ip), e);
+ }
+ try {
+ SECONDS.sleep(RETRY_INTERVAL_SEC * (i + 1));
+ } catch (InterruptedException interruptedException) {
+ LOGGER.info(interruptedException.getMessage(), interruptedException);
+ }
+ }