Search in sources :

Example 6 with Mappings

use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.

the class RepositoryTransactionContext method clearContents.

@Override
public void clearContents() {
    final Index index = service(Index.class);
    final RevisionSearcher revisionSearcher = service(RevisionSearcher.class);
    final IndexAdmin indexAdmin = index.admin();
    final Mappings mappings = indexAdmin.mappings();
    final Stream<Class<?>> revisionTypes = mappings.getTypes().stream().filter(t -> Revision.class.isAssignableFrom(t));
    revisionTypes.forEach(type -> {
        Query.select(String.class).from(type).fields(Revision.Fields.ID).where(Expressions.matchAll()).build().stream(revisionSearcher).forEachOrdered(ids -> {
            final Iterable<?> revisions = fetchComponents(ids.getHits(), type);
            revisions.forEach(rev -> {
                final String revisionId = ((Revision) rev).getId();
                staging.stageRemove(revisionId, rev);
            });
        });
    });
}
Also used : IndexAdmin(com.b2international.index.admin.IndexAdmin) Mappings(com.b2international.index.mapping.Mappings) Index(com.b2international.index.Index)

Example 7 with Mappings

use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.

the class SnowOwlPlugin method preRun.

@Override
public void preRun(SnowOwlConfiguration configuration, Environment env) throws Exception {
    if (env.isServer()) {
        final ObjectMapper mapper = env.service(ObjectMapper.class);
        final Index resourceIndex = Indexes.createIndex(RESOURCES_INDEX, mapper, new Mappings(ResourceDocument.class, VersionDocument.class), env.service(IndexSettings.class).forIndex(env.service(RepositoryConfiguration.class).getIndexConfiguration(), RESOURCES_INDEX));
        final RevisionIndex revisionIndex = new DefaultRevisionIndex(resourceIndex, env.service(TimestampProvider.class), mapper);
        env.services().registerService(ResourceRepository.class, new ResourceRepository(revisionIndex));
    }
}
Also used : VersionDocument(com.b2international.snowowl.core.version.VersionDocument) TimestampProvider(com.b2international.index.revision.TimestampProvider) Mappings(com.b2international.index.mapping.Mappings) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) Index(com.b2international.index.Index) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with Mappings

use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.

the class LockPlugin method preRun.

@Override
public void preRun(SnowOwlConfiguration configuration, Environment env) throws Exception {
    if (env.isServer()) {
        final Index locksIndex = Indexes.createIndex(LOCKS_INDEX, env.service(ObjectMapper.class), new Mappings(DatastoreLockIndexEntry.class), env.service(IndexSettings.class).forIndex(env.service(RepositoryConfiguration.class).getIndexConfiguration(), LOCKS_INDEX));
        final DefaultOperationLockManager lockManager = new DefaultOperationLockManager(locksIndex);
        final RemoteLockTargetListener remoteLockTargetListener = new RemoteLockTargetListener();
        lockManager.addLockTargetListener(new Slf4jOperationLockTargetListener());
        lockManager.addLockTargetListener(remoteLockTargetListener);
        env.services().registerService(IOperationLockManager.class, lockManager);
        final RpcSession session = RpcUtil.getInitialServerSession(env.container());
        session.registerClassLoader(IOperationLockManager.class, DefaultOperationLockManager.class.getClassLoader());
    } else {
        env.services().registerService(IOperationLockManager.class, RpcUtil.createProxy(env.container(), IOperationLockManager.class));
    }
}
Also used : Mappings(com.b2international.index.mapping.Mappings) DatastoreLockIndexEntry(com.b2international.snowowl.core.locks.DatastoreLockIndexEntry) RpcSession(com.b2international.snowowl.rpc.RpcSession) Index(com.b2international.index.Index) IOperationLockManager(com.b2international.snowowl.core.locks.IOperationLockManager) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) DefaultOperationLockManager(com.b2international.snowowl.core.locks.DefaultOperationLockManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with Mappings

use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.

the class JobRequestsTest method setup.

@Before
public void setup() {
    mapper = JsonSupport.getDefaultObjectMapper();
    final Index index = Indexes.createIndex("jobs", mapper, new Mappings(RemoteJobEntry.class));
    this.bus = EventBusUtil.getBus();
    this.tracker = new RemoteJobTracker(index, bus, mapper, 200);
    this.context = ServiceProvider.EMPTY.inject().bind(ObjectMapper.class, mapper).bind(RemoteJobTracker.class, tracker).bind(IdentityProvider.class, IdentityProvider.NOOP).bind(User.class, User.SYSTEM).build();
    this.bus.registerHandler(SystemNotification.ADDRESS, message -> {
        try {
            notifications.offer(message.body(RemoteJobNotification.class), 1, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            throw new RuntimeException();
        }
    });
}
Also used : Mappings(com.b2international.index.mapping.Mappings) Index(com.b2international.index.Index) IdentityProvider(com.b2international.snowowl.core.identity.IdentityProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 10 with Mappings

use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.

the class ValidationPlugin method preRun.

@Override
public void preRun(SnowOwlConfiguration configuration, Environment env) throws Exception {
    if (env.isServer()) {
        final ObjectMapper mapper = env.service(ObjectMapper.class);
        final Index validationIndex = Indexes.createIndex(VALIDATIONS_INDEX, mapper, new Mappings(ValidationIssue.class, ValidationRule.class, ValidationWhiteList.class), env.service(IndexSettings.class).forIndex(env.service(RepositoryConfiguration.class).getIndexConfiguration(), VALIDATIONS_INDEX));
        final ValidationRepository repository = new ValidationRepository(validationIndex);
        env.services().registerService(ValidationRepository.class, repository);
        // register always available validation rule evaluators
        ValidationRuleEvaluator.Registry.register(new GroovyScriptValidationRuleEvaluator(env.getConfigPath()));
        // initialize validation thread pool
        final ValidationConfiguration validationConfig = configuration.getModuleConfig(ValidationConfiguration.class);
        int numberOfValidationThreads = validationConfig.getNumberOfValidationThreads();
        int maxConcurrentExpensiveJobs = validationConfig.getMaxConcurrentExpensiveJobs();
        int maxConcurrentNormalJobs = validationConfig.getMaxConcurrentNormalJobs();
        env.services().registerService(ValidationConfiguration.class, validationConfig);
        env.services().registerService(ValidationThreadPool.class, new ValidationThreadPool(numberOfValidationThreads, maxConcurrentExpensiveJobs, maxConcurrentNormalJobs));
        env.services().registerService(ValidationIssueDetailExtensionProvider.class, new ValidationIssueDetailExtensionProvider(env.service(ClassPathScanner.class)));
        final List<File> listOfFiles = Arrays.asList(env.getConfigPath().toFile().listFiles());
        final Set<File> validationRuleFiles = Sets.newHashSet();
        final Pattern validationFilenamePattern = Pattern.compile("(validation-rules)-(\\w+).(json)");
        for (File file : listOfFiles) {
            final String fileName = file.getName();
            final Matcher match = validationFilenamePattern.matcher(fileName);
            if (match.matches()) {
                validationRuleFiles.add(file);
            }
        }
        final List<ValidationRule> availableRules = Lists.newArrayList();
        for (File validationRulesFile : validationRuleFiles) {
            LOG.info("Synchronizing validation rules from file: " + validationRulesFile);
            availableRules.addAll(mapper.readValue(validationRulesFile, new TypeReference<List<ValidationRule>>() {
            }));
        }
        repository.write(writer -> {
            final Map<String, ValidationRule> existingRules = Maps.uniqueIndex(ValidationRequests.rules().prepareSearch().all().buildAsync().getRequest().execute(env), ValidationRule::getId);
            // index all rules from the file, this will update existing rules as well
            final Set<String> ruleIds = newHashSet();
            for (ValidationRule rule : availableRules) {
                writer.put(rule);
                ruleIds.add(rule.getId());
            }
            // delete rules and associated issues
            Set<String> rulesToDelete = Sets.difference(existingRules.keySet(), ruleIds);
            if (!rulesToDelete.isEmpty()) {
                final Set<String> issuesToDelete = newHashSet(writer.searcher().search(Query.select(String.class).from(ValidationIssue.class).fields(ValidationIssue.Fields.ID).where(Expressions.builder().filter(Expressions.matchAny(ValidationIssue.Fields.RULE_ID, rulesToDelete)).build()).limit(Integer.MAX_VALUE).build()).getHits());
                writer.removeAll(ImmutableMap.<Class<?>, Set<String>>of(ValidationRule.class, rulesToDelete, ValidationIssue.class, issuesToDelete));
            }
            writer.commit();
            return null;
        });
    }
}
Also used : GroovyScriptValidationRuleEvaluator(com.b2international.snowowl.core.validation.eval.GroovyScriptValidationRuleEvaluator) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Index(com.b2international.index.Index) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) ValidationWhiteList(com.b2international.snowowl.core.validation.whitelist.ValidationWhiteList) ValidationRule(com.b2international.snowowl.core.validation.rule.ValidationRule) Mappings(com.b2international.index.mapping.Mappings) ValidationIssueDetailExtensionProvider(com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Mappings (com.b2international.index.mapping.Mappings)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Index (com.b2international.index.Index)13 Before (org.junit.Before)7 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)5 ValidationRepository (com.b2international.snowowl.core.internal.validation.ValidationRepository)4 ValidationRule (com.b2international.snowowl.core.validation.rule.ValidationRule)4 ValidationIssue (com.b2international.snowowl.core.validation.issue.ValidationIssue)3 ValidationWhiteList (com.b2international.snowowl.core.validation.whitelist.ValidationWhiteList)3 ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)3 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)3 DefaultRevisionIndex (com.b2international.index.revision.DefaultRevisionIndex)2 RevisionIndex (com.b2international.index.revision.RevisionIndex)2 ClassPathScanner (com.b2international.snowowl.core.plugin.ClassPathScanner)2 ValidationIssueDetailExtensionProvider (com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider)2 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)2 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)2 SequentialItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy)2 SnomedIdentifierReservationServiceImpl (com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl)2 CompareUtils (com.b2international.commons.CompareUtils)1