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;
}
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));
}
}
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));
}
}
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();
}
});
}
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;
});
}
}
Aggregations