Search in sources :

Example 11 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class ValidationThreadPoolTest method testConcurrentFastJobsWithExpensiveOnes.

@Test
public void testConcurrentFastJobsWithExpensiveOnes() {
    final IJobManager manager = Job.getJobManager();
    final List<Promise<Object>> validationPromises = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        validationPromises.add(pool.submit(CheckType.FAST, createValidatableRunnable(CheckType.FAST, manager)));
        if (i % 3 == 0) {
            validationPromises.add(pool.submit(CheckType.EXPENSIVE, createValidatableRunnable(CheckType.EXPENSIVE, manager)));
        }
    }
    Promise.all(validationPromises).getSync();
}
Also used : Promise(com.b2international.snowowl.core.events.util.Promise) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Test(org.junit.Test)

Example 12 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class ValidationThreadPoolTest method testConcurrentExpensiveJobs.

@Test
public void testConcurrentExpensiveJobs() {
    final IJobManager manager = Job.getJobManager();
    final Runnable expensiveRunnable = createValidatableRunnable(CheckType.EXPENSIVE, manager);
    final List<Promise<Object>> validationPromises = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        validationPromises.add(pool.submit(CheckType.EXPENSIVE, expensiveRunnable));
    }
    Promise.all(validationPromises).getSync();
}
Also used : Promise(com.b2international.snowowl.core.events.util.Promise) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Test(org.junit.Test)

Example 13 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class LdapIdentityProvider method searchUsers.

@Override
public Promise<Users> searchUsers(Collection<String> usernames, int limit) {
    final ImmutableList.Builder<User> resultBuilder = ImmutableList.builder();
    final String uidProp = conf.getUserIdProperty();
    InitialLdapContext context = null;
    NamingEnumeration<SearchResult> searchResultEnumeration = null;
    try {
        context = createLdapContext();
        Collection<LdapRole> ldapRoles = getAllLdapRoles(context);
        searchResultEnumeration = context.search(conf.getBaseDn(), conf.getUserFilter(), createSearchControls(ATTRIBUTE_DN, uidProp));
        for (final SearchResult searchResult : ImmutableList.copyOf(Iterators.forEnumeration(searchResultEnumeration))) {
            final Attributes attributes = searchResult.getAttributes();
            if (hasAttribute(attributes, uidProp)) {
                final String userName = (String) attributes.get(uidProp).get();
                final List<Role> userRoles = ldapRoles.stream().filter(role -> role.getUniqueMembers().contains(searchResult.getNameInNamespace())).map(role -> new Role(role.getName(), role.getPermissions())).collect(Collectors.toList());
                resultBuilder.add(new User(userName, userRoles));
            }
        }
        final List<User> users = resultBuilder.build().stream().sorted((u1, u2) -> u1.getUsername().compareTo(u2.getUsername())).filter(user -> usernames.isEmpty() || usernames.contains(user.getUsername())).limit(limit).collect(Collectors.toList());
        return Promise.immediate(new Users(users, limit, users.size()));
    } catch (final NamingException e) {
        LOG.error("Couldn't search users/roles due to LDAP communication error: {}", e.getMessage(), e);
        throw new SnowowlRuntimeException(e);
    } finally {
        closeNamingEnumeration(searchResultEnumeration);
        closeLdapContext(context);
    }
}
Also used : Iterables(com.google.common.collect.Iterables) InitialLdapContext(javax.naming.ldap.InitialLdapContext) Promise(com.b2international.snowowl.core.events.util.Promise) LoggerFactory(org.slf4j.LoggerFactory) NamingException(javax.naming.NamingException) SearchControls(javax.naming.directory.SearchControls) Iterators(com.google.common.collect.Iterators) Attribute(javax.naming.directory.Attribute) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Permission(com.b2international.snowowl.core.identity.Permission) Context(javax.naming.Context) NoSuchElementException(java.util.NoSuchElementException) Hashtable(java.util.Hashtable) IdentityProvider(com.b2international.snowowl.core.identity.IdentityProvider) Logger(org.slf4j.Logger) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) DirContext(javax.naming.directory.DirContext) Role(com.b2international.snowowl.core.identity.Role) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TreeMap(java.util.TreeMap) Attributes(javax.naming.directory.Attributes) Users(com.b2international.snowowl.core.identity.Users) NamingEnumeration(javax.naming.NamingEnumeration) User(com.b2international.snowowl.core.identity.User) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) SearchResult(javax.naming.directory.SearchResult) User(com.b2international.snowowl.core.identity.User) ImmutableList(com.google.common.collect.ImmutableList) Attributes(javax.naming.directory.Attributes) SearchResult(javax.naming.directory.SearchResult) Users(com.b2international.snowowl.core.identity.Users) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Role(com.b2international.snowowl.core.identity.Role) InitialLdapContext(javax.naming.ldap.InitialLdapContext) NamingException(javax.naming.NamingException)

Example 14 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class RepositoryValidationRestService method getValidationResults.

@Operation(summary = "Retrieve the validation issues from a completed validation on a branch. Output may differ by the chosen content type.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Branch not found") })
@RequestMapping(value = "/validations/{validationId}/issues", method = RequestMethod.GET, produces = { AbstractRestService.JSON_MEDIA_TYPE, AbstractRestService.CSV_MEDIA_TYPE })
@ResponseBody
public Promise<Collection<Object>> getValidationResults(@Parameter(description = "The unique validation identifier.") @PathVariable(value = "validationId") final String validationId, @Parameter(description = "The search key to use for retrieving the next page of results") @RequestParam(value = "searchAfter", required = false) final String searchAfter, @Parameter(description = "The maximum number of items to return") @RequestParam(value = "limit", defaultValue = "50", required = false) final int limit, @Parameter(hidden = true) @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = AbstractRestService.JSON_MEDIA_TYPE, required = false) final String contentType) {
    final IEventBus bus = getBus();
    return getValidationRun(validationId).thenWith(validationJob -> {
        final ResourceURI codeSystemURI = getCodeSystemURIFromJob(validationJob);
        if (AbstractRestService.CSV_MEDIA_TYPE.equals(contentType)) {
            return ValidationRequests.issues().prepareSearch().isWhitelisted(false).all().filterByResourceUri(codeSystemURI).sortBy(Sort.fieldAsc(ValidationIssue.Fields.RULE_ID)).buildAsync().execute(bus).then(issues -> {
                final Set<String> rulesToFetch = issues.stream().map(ValidationIssue::getRuleId).collect(Collectors.toSet());
                final Map<String, String> ruleDescriptionById = ValidationRequests.rules().prepareSearch().all().filterByIds(rulesToFetch).buildAsync().execute(bus).getSync(1, TimeUnit.MINUTES).stream().collect(Collectors.toMap(ValidationRule::getId, ValidationRule::getMessageTemplate));
                return issues.stream().map(issue -> {
                    final String ruleId = issue.getRuleId();
                    final String ruleDescription = ruleDescriptionById.get(ruleId);
                    final String affectedComponentLabel = Iterables.getFirst(issue.getAffectedComponentLabels(), "No label found");
                    final String affectedComponentId = issue.getAffectedComponent().getComponentId();
                    return new ValidationIssueReport(ruleId, ruleDescription, affectedComponentId, affectedComponentLabel);
                }).collect(Collectors.toList());
            });
        } else {
            return ValidationRequests.issues().prepareSearch().isWhitelisted(false).setLimit(limit).setSearchAfter(searchAfter).filterByResourceUri(codeSystemURI).buildAsync().execute(bus).then(issues -> issues.getItems().stream().collect(Collectors.toList()));
        }
    });
}
Also used : Iterables(com.google.common.collect.Iterables) AbstractRestService(com.b2international.snowowl.core.rest.AbstractRestService) Promise(com.b2international.snowowl.core.events.util.Promise) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) Operation(io.swagger.v3.oas.annotations.Operation) HttpHeaders(com.google.common.net.HttpHeaders) Map(java.util.Map) RemoteJobs(com.b2international.snowowl.core.jobs.RemoteJobs) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) ResourceURI(com.b2international.snowowl.core.ResourceURI) ValidationRule(com.b2international.snowowl.core.validation.rule.ValidationRule) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Collectors(java.util.stream.Collectors) IDs(com.b2international.snowowl.core.id.IDs) TimeUnit(java.util.concurrent.TimeUnit) Parameter(io.swagger.v3.oas.annotations.Parameter) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) JobRequests(com.b2international.snowowl.core.jobs.JobRequests) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) Tag(io.swagger.v3.oas.annotations.tags.Tag) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ValidationConfiguration(com.b2international.snowowl.core.internal.validation.ValidationConfiguration) ResponseEntity(org.springframework.http.ResponseEntity) ValidationRequests(com.b2international.snowowl.core.validation.ValidationRequests) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) ResourceURI(com.b2international.snowowl.core.ResourceURI) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 15 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class ValidationThreadPoolTest method testConcurrentFastJobs.

@Test
public void testConcurrentFastJobs() {
    final IJobManager manager = Job.getJobManager();
    final Runnable fastRunnable = createValidatableRunnable(CheckType.FAST, manager);
    final List<Promise<Object>> validationPromises = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        validationPromises.add(pool.submit(CheckType.FAST, fastRunnable));
    }
    Promise.all(validationPromises).getSync();
}
Also used : Promise(com.b2international.snowowl.core.events.util.Promise) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Test(org.junit.Test)

Aggregations

Promise (com.b2international.snowowl.core.events.util.Promise)22 ResourceURI (com.b2international.snowowl.core.ResourceURI)10 TimeUnit (java.util.concurrent.TimeUnit)10 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)9 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)9 IOException (java.io.IOException)9 List (java.util.List)9 Test (org.junit.Test)9 BranchContext (com.b2international.snowowl.core.domain.BranchContext)8 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)7 IEventBus (com.b2international.snowowl.eventbus.IEventBus)7 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)7 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)7 Trees (com.b2international.snowowl.snomed.core.tree.Trees)7 Function (com.google.common.base.Function)7 Collection (java.util.Collection)7