Search in sources :

Example 6 with Index

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

the class TerminologyRepository method initIndex.

private RevisionIndex initIndex(final ServiceProvider context, Mappings mappings) {
    final ObjectMapper mapper = context.service(ObjectMapper.class);
    IndexConfiguration indexConfiguration = context.service(RepositoryConfiguration.class).getIndexConfiguration();
    final IndexClient indexClient = Indexes.createIndexClient(repositoryId, mapper, mappings, context.service(IndexSettings.class).forIndex(indexConfiguration, repositoryId));
    final Index index = new DefaultIndex(indexClient);
    final RevisionIndex revisionIndex = new DefaultRevisionIndex(index, context.service(TimestampProvider.class), mapper);
    revisionIndex.branching().addBranchChangeListener(path -> {
        new BranchChangedEvent(repositoryId, path).publish(context.service(IEventBus.class));
    });
    // register IndexClient per terminology
    bind(IndexClient.class, indexClient);
    // register index and revision index access, the underlying index is the same
    bind(Index.class, index);
    bind(RevisionIndex.class, revisionIndex);
    // register branching services
    bind(BaseRevisionBranching.class, revisionIndex.branching());
    return revisionIndex;
}
Also used : DefaultIndex(com.b2international.index.DefaultIndex) TimestampProvider(com.b2international.index.revision.TimestampProvider) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) IndexClient(com.b2international.index.IndexClient) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) Index(com.b2international.index.Index) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) DefaultIndex(com.b2international.index.DefaultIndex) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BranchChangedEvent(com.b2international.snowowl.core.branch.BranchChangedEvent) IEventBus(com.b2international.snowowl.eventbus.IEventBus) IndexConfiguration(com.b2international.snowowl.core.config.IndexConfiguration)

Example 7 with Index

use of com.b2international.index.Index 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 Index

use of com.b2international.index.Index 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 Index

use of com.b2international.index.Index 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 Index

use of com.b2international.index.Index 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

Index (com.b2international.index.Index)17 Mappings (com.b2international.index.mapping.Mappings)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)6 Before (org.junit.Before)6 ValidationRepository (com.b2international.snowowl.core.internal.validation.ValidationRepository)4 ValidationRule (com.b2international.snowowl.core.validation.rule.ValidationRule)4 RevisionIndex (com.b2international.index.revision.RevisionIndex)3 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 TimestampProvider (com.b2international.index.revision.TimestampProvider)2 ClassPathScanner (com.b2international.snowowl.core.plugin.ClassPathScanner)2 ValidationIssueDetailExtensionProvider (com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider)2 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)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