use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.
the class HandleFailedMessagesTest method before.
@Before
public void before() {
MockitoAnnotations.initMocks(this);
TargetProxyHelper.injectIntoProxy(h, "manager", mock_manager);
TargetProxyHelper.injectIntoProxy(h, "jmsTemplate", mock_jmsTemplate);
TargetProxyHelper.injectIntoProxy(h, "maxFailuresBeforeNotify", 3);
List<RecordStatusEntity> elements = new ArrayList<RecordStatusEntity>();
for (int i = 0; i < 10; i++) {
RecordStatusEntity r = new RecordStatusEntity();
r.setDateCreated(new Date());
r.setDumpStatus12Api(i);
r.setDumpStatus20Api(0);
r.setSolrStatus20Api(0);
r.setId("0000-0000-0000-000" + i);
elements.add(r);
}
when(mock_manager.getFailedElements(Matchers.anyInt())).thenReturn(elements);
}
use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.
the class RecordStatusManagerTest method markAsFailedTest.
@Test
public void markAsFailedTest() {
String orcid = "0000-0000-0000-0002";
assertFalse(recordStatusDao.exists(orcid));
recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
assertTrue(recordStatusDao.exists(orcid));
RecordStatusEntity entity = recordStatusDao.get(orcid);
assertNotNull(entity);
assertEquals(orcid, entity.getId());
assertEquals(Integer.valueOf(1), entity.getDumpStatus12Api());
recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
entity = recordStatusDao.get(orcid);
assertNotNull(entity);
assertEquals(orcid, entity.getId());
assertEquals(Integer.valueOf(2), entity.getDumpStatus12Api());
recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
entity = recordStatusDao.get(orcid);
assertNotNull(entity);
assertEquals(orcid, entity.getId());
assertEquals(Integer.valueOf(3), entity.getDumpStatus12Api());
}
use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.
the class HandleFailedMessages method buildNotificationMessage.
private String buildNotificationMessage(List<RecordStatusEntity> elements) {
StringBuilder sb = new StringBuilder("The following records failed to be processed in the message listener: ");
sb.append(System.lineSeparator() + System.lineSeparator());
for (RecordStatusEntity element : elements) {
sb.append("*ORCID: '").append(element.getId()).append("':* ");
if (element.getDumpStatus12Api() > maxFailuresBeforeNotify) {
sb.append(" (1.2 API Dump: ");
sb.append(element.getDumpStatus12Api());
sb.append(" failures)");
}
if (element.getDumpStatus20Api() > maxFailuresBeforeNotify) {
sb.append(" (2.0 API Dump: ");
sb.append(element.getDumpStatus20Api());
sb.append(" failures)");
}
if (element.getSolrStatus20Api() > maxFailuresBeforeNotify) {
sb.append(" (2.0 Solr indexing: ");
sb.append(element.getSolrStatus20Api());
sb.append(" failures)");
}
sb.append(System.lineSeparator());
}
return sb.toString();
}
use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.
the class RecordStatusDao method create.
public void create(String orcid, AvailableBroker broker, Integer status) {
RecordStatusEntity entity = new RecordStatusEntity();
entity.setId(orcid);
switch(broker) {
case DUMP_STATUS_1_2_API:
entity.setDumpStatus12Api(status);
break;
case DUMP_STATUS_2_0_API:
entity.setDumpStatus20Api(status);
break;
case SOLR:
entity.setSolrStatus20Api(status);
break;
}
Date now = new Date();
entity.setDateCreated(now);
entity.setLastModified(now);
entityManager.persist(entity);
}
use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.
the class HandleFailedMessages method resendFailedElements.
@Scheduled(cron = "${org.orcid.cron.reindex-failed}")
public void resendFailedElements() {
List<RecordStatusEntity> failedElements = manager.getFailedElements(BATCH_SIZE);
List<RecordStatusEntity> elementsToNotify = new ArrayList<RecordStatusEntity>();
for (RecordStatusEntity element : failedElements) {
try {
// Send RetryMessage for 1.2 dump
if (element.getDumpStatus12Api() > 0) {
RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_1_2_API.value());
jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
}
// Send RetryMessage for 2.0 dump
if (element.getDumpStatus20Api() > 0) {
RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_2_0_API.value());
jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
}
// Send RetryMessage for solr indexing
if (element.getSolrStatus20Api() > 0) {
RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.SOLR.value());
jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
}
// Should we notify about this element?
if ((element.getDumpStatus12Api() > maxFailuresBeforeNotify) || (element.getDumpStatus20Api() > maxFailuresBeforeNotify) || (element.getSolrStatus20Api() > maxFailuresBeforeNotify)) {
elementsToNotify.add(element);
}
} catch (JmsException e) {
LOGGER.warn("Unable to resend message for " + element.getId());
}
}
// Send summary
if (!elementsToNotify.isEmpty()) {
String message = buildNotificationMessage(elementsToNotify);
sendSystemAlert(message);
}
}
Aggregations