Search in sources :

Example 1 with IndexAction

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;
}
Also used : IndexAction(org.molgenis.data.index.meta.IndexAction)

Example 2 with 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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) IndexJobExecution(org.molgenis.data.index.job.IndexJobExecution) IndexAction(org.molgenis.data.index.meta.IndexAction) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 3 with IndexAction

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) IndexJobExecution(org.molgenis.data.index.job.IndexJobExecution) IndexAction(org.molgenis.data.index.meta.IndexAction) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 4 with IndexAction

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());
}
Also used : Impact.createSingleEntityImpact(org.molgenis.data.index.Impact.createSingleEntityImpact) PENDING(org.molgenis.data.index.meta.IndexActionMetaData.IndexStatus.PENDING) LoggerFactory(org.slf4j.LoggerFactory) Fetch(org.molgenis.data.Fetch) QueryImpl(org.molgenis.data.support.QueryImpl) IndexActionFactory(org.molgenis.data.index.meta.IndexActionFactory) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) TRANSACTION_ID_RESOURCE_NAME(org.molgenis.data.transaction.TransactionManager.TRANSACTION_ID_RESOURCE_NAME) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) HashMultimap(com.google.common.collect.HashMultimap) EntityKey(org.molgenis.data.EntityKey) Impact.createSingleEntityImpact(org.molgenis.data.index.Impact.createSingleEntityImpact) Objects.requireNonNull(java.util.Objects.requireNonNull) ATTRIBUTE_META_DATA(org.molgenis.data.meta.model.AttributeMetadata.ATTRIBUTE_META_DATA) REF_ENTITY_TYPE(org.molgenis.data.meta.model.AttributeMetadata.REF_ENTITY_TYPE) Multimaps.synchronizedSetMultimap(com.google.common.collect.Multimaps.synchronizedSetMultimap) Collectors.toSet(java.util.stream.Collectors.toSet) INDEX_ACTION(org.molgenis.data.index.meta.IndexActionMetaData.INDEX_ACTION) Streams.mapWithIndex(com.google.common.collect.Streams.mapWithIndex) IndexActionGroup(org.molgenis.data.index.meta.IndexActionGroup) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Collections.emptyList(java.util.Collections.emptyList) INDEX_ACTION_GROUP(org.molgenis.data.index.meta.IndexActionGroupMetaData.INDEX_ACTION_GROUP) IndexAction(org.molgenis.data.index.meta.IndexAction) Set(java.util.Set) TransactionInformation(org.molgenis.data.transaction.TransactionInformation) EntityType(org.molgenis.data.meta.model.EntityType) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) Component(org.springframework.stereotype.Component) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) IndexActionGroupFactory(org.molgenis.data.index.meta.IndexActionGroupFactory) DataService(org.molgenis.data.DataService) Optional(java.util.Optional) ENTITY_TYPE_FETCH(org.molgenis.data.index.IndexDependencyModel.ENTITY_TYPE_FETCH) Transactional(org.springframework.transaction.annotation.Transactional) IndexActionGroup(org.molgenis.data.index.meta.IndexActionGroup) IndexAction(org.molgenis.data.index.meta.IndexAction) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 5 with IndexAction

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");
    }
}
Also used : IndexAction(org.molgenis.data.index.meta.IndexAction)

Aggregations

IndexAction (org.molgenis.data.index.meta.IndexAction)5 EntityType (org.molgenis.data.meta.model.EntityType)3 QueryImpl (org.molgenis.data.support.QueryImpl)3 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)2 IndexJobExecution (org.molgenis.data.index.job.IndexJobExecution)2 Attribute (org.molgenis.data.meta.model.Attribute)2 Test (org.testng.annotations.Test)2 HashMultimap (com.google.common.collect.HashMultimap)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Multimaps.synchronizedSetMultimap (com.google.common.collect.Multimaps.synchronizedSetMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Sets (com.google.common.collect.Sets)1 Streams.mapWithIndex (com.google.common.collect.Streams.mapWithIndex)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptySet (java.util.Collections.emptySet)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1