use of org.molgenis.data.index.meta.IndexAction in project molgenis by molgenis.
the class IndexActionRegisterServiceImpl method createIndexAction.
private IndexAction createIndexAction(IndexActionGroup indexActionGroup, Impact key, int actionOrder) {
IndexAction indexAction = indexActionFactory.create();
indexAction.setIndexStatus(PENDING);
if (key.getId() != null) {
indexAction.setEntityId(key.getId().toString());
}
indexAction.setEntityTypeId(key.getEntityTypeId());
indexAction.setIndexActionGroup(indexActionGroup);
indexAction.setActionOrder(actionOrder);
return indexAction;
}
use of org.molgenis.data.index.meta.IndexAction in project molgenis by molgenis.
the class IndexBootstrapperTest method testStartupFailedIndexJobsUnknownEntityType.
@Test
public void testStartupFailedIndexJobsUnknownEntityType() {
when(indexService.hasIndex(attributeMetadata)).thenReturn(true);
IndexJobExecution indexJobExecution = mock(IndexJobExecution.class);
when(indexJobExecution.getIndexActionJobID()).thenReturn("id");
IndexAction action = mock(IndexAction.class);
when(action.getEntityTypeId()).thenReturn("myEntityTypeName");
when(action.getEntityId()).thenReturn("1");
EntityType entityType = mock(EntityType.class);
when(dataService.findOneById(EntityTypeMetadata.ENTITY_TYPE_META_DATA, "myEntityTypeName", EntityType.class)).thenReturn(null);
Attribute idAttribute = mock(Attribute.class);
when(idAttribute.getDataType()).thenReturn(AttributeType.INT);
when(entityType.getIdAttribute()).thenReturn(idAttribute);
when(dataService.findAll(IndexJobExecutionMeta.INDEX_JOB_EXECUTION, new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED), IndexJobExecution.class)).thenReturn(Stream.of(indexJobExecution));
when(dataService.findAll(IndexActionMetaData.INDEX_ACTION, new QueryImpl<IndexAction>().eq(IndexActionMetaData.INDEX_ACTION_GROUP_ATTR, "id"), IndexAction.class)).thenReturn(Stream.of(action));
indexBootstrapper.bootstrap();
// verify that we are not passing through the "missing index" code
verify(metaDataService, never()).getRepositories();
// verify that a new job is registered for the failed one
verify(indexActionRegisterService, times(0)).register(entityType, 1);
}
use of org.molgenis.data.index.meta.IndexAction in project molgenis by molgenis.
the class IndexBootstrapperTest method testStartupFailedIndexJobs.
@Test
public void testStartupFailedIndexJobs() {
when(indexService.hasIndex(attributeMetadata)).thenReturn(true);
IndexJobExecution indexJobExecution = mock(IndexJobExecution.class);
when(indexJobExecution.getIndexActionJobID()).thenReturn("id");
IndexAction action = mock(IndexAction.class);
when(action.getEntityTypeId()).thenReturn("myEntityTypeName");
when(action.getEntityId()).thenReturn("1");
EntityType entityType = mock(EntityType.class);
when(dataService.findOneById(EntityTypeMetadata.ENTITY_TYPE_META_DATA, "myEntityTypeName", EntityType.class)).thenReturn(entityType);
Attribute idAttribute = mock(Attribute.class);
when(idAttribute.getDataType()).thenReturn(AttributeType.INT);
when(entityType.getIdAttribute()).thenReturn(idAttribute);
when(dataService.findAll(IndexJobExecutionMeta.INDEX_JOB_EXECUTION, new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED), IndexJobExecution.class)).thenReturn(Stream.of(indexJobExecution));
when(dataService.findAll(IndexActionMetaData.INDEX_ACTION, new QueryImpl<IndexAction>().eq(IndexActionMetaData.INDEX_ACTION_GROUP_ATTR, "id"), IndexAction.class)).thenReturn(Stream.of(action));
indexBootstrapper.bootstrap();
// verify that we are not passing through the "missing index" code
verify(metaDataService, never()).getRepositories();
// verify that a new job is registered for the failed one
verify(indexActionRegisterService).register(entityType, 1);
}
use of org.molgenis.data.index.meta.IndexAction in project molgenis by molgenis.
the class IndexActionRegisterServiceImpl method storeIndexActions.
@Override
@RunAsSystem
public void storeIndexActions(String transactionId) {
Set<Impact> changes = getChangesForCurrentTransaction();
if (changes.isEmpty()) {
return;
}
if (changes.stream().allMatch(impact -> excludedEntities.contains(impact.getEntityTypeId()))) {
return;
}
IndexActionGroup indexActionGroup = indexActionGroupFactory.create(transactionId);
IndexDependencyModel dependencyModel = createIndexDependencyModel(changes);
Stream<Impact> impactStream = indexingStrategy.determineImpact(changes, dependencyModel).stream().filter(key -> !excludedEntities.contains(key.getEntityTypeId()));
List<IndexAction> indexActions = mapWithIndex(impactStream, (key, actionOrder) -> createIndexAction(indexActionGroup, key, (int) actionOrder)).collect(toList());
if (indexActions.isEmpty()) {
return;
}
LOG.debug("Store index actions for transaction {}", transactionId);
dataService.add(INDEX_ACTION_GROUP, indexActionGroupFactory.create(transactionId).setCount(indexActions.size()));
dataService.add(INDEX_ACTION, indexActions.stream());
}
use of org.molgenis.data.index.meta.IndexAction in project molgenis by molgenis.
the class IndexJobService method performIndexActions.
/**
* Performs the IndexActions.
*
* @param progress {@link Progress} instance to log progress information to
*/
private void performIndexActions(Progress progress, String transactionId) {
List<IndexAction> indexActions = dataService.findAll(INDEX_ACTION, createQueryGetAllIndexActions(transactionId), IndexAction.class).collect(toList());
try {
boolean success = true;
int count = 0;
for (IndexAction indexAction : indexActions) {
success &= performAction(progress, count++, indexAction);
}
if (success) {
progress.progress(count, "Executed all index actions, cleaning up the actions...");
dataService.delete(INDEX_ACTION, indexActions.stream());
dataService.deleteById(INDEX_ACTION_GROUP, transactionId);
progress.progress(count, "Cleaned up the actions.");
}
} catch (Exception ex) {
LOG.error("Error performing index actions", ex);
throw ex;
} finally {
progress.status("Refresh index start");
indexService.refreshIndex();
progress.status("Refresh index done");
}
}
Aggregations