Search in sources :

Example 1 with IndexActionGroup

use of org.molgenis.data.index.meta.IndexActionGroup in project molgenis by molgenis.

the class IndexJobSchedulerImpl method scheduleIndexJob.

@Override
@RunAsSystem
public void scheduleIndexJob(String transactionId) {
    LOG.trace("Index transaction with id {}...", transactionId);
    IndexActionGroup indexActionGroup = dataService.findOneById(INDEX_ACTION_GROUP, transactionId, IndexActionGroup.class);
    if (indexActionGroup != null) {
        Stream<Entity> indexActions = dataService.findAll(INDEX_ACTION, new QueryImpl<>().eq(INDEX_ACTION_GROUP_ATTR, indexActionGroup));
        Map<String, Long> numberOfActionsPerEntity = indexActions.collect(groupingBy(indexAction -> indexAction.getString(ENTITY_TYPE_ID), counting()));
        indexStatus.addActionCounts(numberOfActionsPerEntity);
        IndexJobExecution indexJobExecution = indexJobExecutionFactory.create();
        indexJobExecution.setUser("admin");
        indexJobExecution.setIndexActionJobID(transactionId);
        jobExecutor.submit(indexJobExecution, executorService).whenComplete((a, b) -> indexStatus.removeActionCounts(numberOfActionsPerEntity));
    } else {
        LOG.debug("No index job found for id [{}].", transactionId);
    }
}
Also used : JobExecutor(org.molgenis.jobs.JobExecutor) STATUS(org.molgenis.jobs.model.JobExecutionMetaData.STATUS) LoggerFactory(org.slf4j.LoggerFactory) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) QueryImpl(org.molgenis.data.support.QueryImpl) Scheduled(org.springframework.scheduling.annotation.Scheduled) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) SUCCESS(org.molgenis.jobs.model.JobExecution.Status.SUCCESS) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ExecutorService(java.util.concurrent.ExecutorService) IndexActionGroup(org.molgenis.data.index.meta.IndexActionGroup) Logger(org.slf4j.Logger) INDEX_ACTION_GROUP(org.molgenis.data.index.meta.IndexActionGroupMetaData.INDEX_ACTION_GROUP) END_DATE(org.molgenis.jobs.model.JobExecutionMetaData.END_DATE) IndexActionMetaData(org.molgenis.data.index.meta.IndexActionMetaData) Instant(java.time.Instant) EntityType(org.molgenis.data.meta.model.EntityType) Executors(java.util.concurrent.Executors) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) DataService(org.molgenis.data.DataService) Entity(org.molgenis.data.Entity) IndexActionGroup(org.molgenis.data.index.meta.IndexActionGroup) Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 2 with IndexActionGroup

use of org.molgenis.data.index.meta.IndexActionGroup 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 3 with IndexActionGroup

use of org.molgenis.data.index.meta.IndexActionGroup in project molgenis by molgenis.

the class IndexJobService method executeJob.

public Void executeJob(Progress progress, String transactionId) {
    requireNonNull(progress);
    IndexActionGroup indexActionGroup = dataService.findOneById(INDEX_ACTION_GROUP, transactionId, IndexActionGroup.class);
    if (indexActionGroup != null && indexActionGroup.getCount() > 0) {
        progress.setProgressMax(indexActionGroup.getCount());
        progress.status(format("Start indexing for transaction id: [{0}]", transactionId));
        performIndexActions(progress, transactionId);
        progress.status(format("Finished indexing for transaction id: [{0}]", transactionId));
    } else {
        progress.status(format("No index actions found for transaction id: [{0}]", transactionId));
    }
    return null;
}
Also used : IndexActionGroup(org.molgenis.data.index.meta.IndexActionGroup)

Aggregations

IndexActionGroup (org.molgenis.data.index.meta.IndexActionGroup)3 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Stream (java.util.stream.Stream)2 DataService (org.molgenis.data.DataService)2 INDEX_ACTION_GROUP (org.molgenis.data.index.meta.IndexActionGroupMetaData.INDEX_ACTION_GROUP)2 EntityType (org.molgenis.data.meta.model.EntityType)2 QueryImpl (org.molgenis.data.support.QueryImpl)2 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)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 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptySet (java.util.Collections.emptySet)1