Search in sources :

Example 1 with ClassificationTracker

use of com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker in project snow-owl by b2ihealthcare.

the class SaveJobRequest method execute.

@Override
public Boolean execute(final BranchContext context) {
    final IProgressMonitor monitor = context.service(IProgressMonitor.class);
    final ClassificationTracker tracker = context.service(ClassificationTracker.class);
    final String user = !Strings.isNullOrEmpty(userId) ? userId : context.service(User.class).getUsername();
    try (Locks locks = Locks.on(context).user(user).lock(DatastoreLockContextDescriptions.SAVE_CLASSIFICATION_RESULTS, parentLockContext)) {
        return persistChanges(context, monitor);
    } catch (final LockedException e) {
        tracker.classificationFailed(classificationId);
        throw new ReasonerApiException("Couldn't acquire exclusive access to terminology store for persisting classification changes; %s", e.getMessage(), e);
    } catch (final Exception e) {
        LOG.error("Unexpected error while persisting classification changes.", e);
        tracker.classificationSaveFailed(classificationId);
        throw new ReasonerApiException("Error while persisting classification changes on '%s'.", context.path(), e);
    } finally {
        monitor.done();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LockedException(com.b2international.commons.exceptions.LockedException) ReasonerApiException(com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException) Locks(com.b2international.snowowl.core.locks.Locks) ClassificationTracker(com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker) BadRequestException(com.b2international.commons.exceptions.BadRequestException) LockedException(com.b2international.commons.exceptions.LockedException) ReasonerApiException(com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException)

Example 2 with ClassificationTracker

use of com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker in project snow-owl by b2ihealthcare.

the class SaveJobRequest method persistChanges.

private Boolean persistChanges(final BranchContext context, final IProgressMonitor monitor) {
    // Repeat the same checks as in ClassificationSaveRequest, now within the lock
    final ClassificationTask classification = ClassificationRequests.prepareGetClassification(classificationId).build().execute(context);
    final String branchPath = classification.getBranch();
    final Branch branch = RepositoryRequests.branching().prepareGet(branchPath).build().execute(context);
    if (!ClassificationSaveRequest.SAVEABLE_STATUSES.contains(classification.getStatus())) {
        throw new BadRequestException("Classification '%s' is not in the expected state to start saving changes.", classificationId);
    }
    if (classification.getTimestamp() < branch.headTimestamp()) {
        throw new BadRequestException("Classification '%s' on branch '%s' is stale (classification timestamp: %s, head timestamp: %s).", classificationId, branchPath, classification.getTimestamp(), branch.headTimestamp());
    }
    final ClassificationTracker classificationTracker = context.service(ClassificationTracker.class);
    // Signal the state change
    classificationTracker.classificationSaving(classificationId);
    final SubMonitor subMonitor = SubMonitor.convert(monitor, "Persisting changes", 6);
    final BulkRequestBuilder<TransactionContext> bulkRequestBuilder = BulkRequest.create();
    applyChanges(subMonitor, context, bulkRequestBuilder);
    long resultTimeStamp = Commit.NO_COMMIT_TIMESTAMP;
    for (List<Request<TransactionContext, ?>> partition : Iterables.partition(bulkRequestBuilder.build().getRequests(), getCommitLimit(context))) {
        final BulkRequestBuilder<TransactionContext> batchRequest = BulkRequest.create();
        partition.forEach(request -> batchRequest.add(request));
        final Request<BranchContext, CommitResult> commitRequest = SnomedRequests.prepareCommit().setBody(batchRequest.build()).setCommitComment(commitComment).setParentContextDescription(DatastoreLockContextDescriptions.SAVE_CLASSIFICATION_RESULTS).setAuthor(userId).build();
        final CommitResult commitResult = new IdRequest<>(commitRequest).execute(context);
        resultTimeStamp = commitResult.getCommitTimestamp();
    }
    if (Commit.NO_COMMIT_TIMESTAMP == resultTimeStamp) {
        classificationTracker.classificationSaveFailed(classificationId);
        return Boolean.FALSE;
    } else {
        classificationTracker.classificationSaved(classificationId, resultTimeStamp);
        return Boolean.TRUE;
    }
}
Also used : CommitResult(com.b2international.snowowl.core.request.CommitResult) SubMonitor(org.eclipse.core.runtime.SubMonitor) Request(com.b2international.snowowl.core.events.Request) BulkRequest(com.b2international.snowowl.core.events.bulk.BulkRequest) Branch(com.b2international.snowowl.core.branch.Branch) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) BranchContext(com.b2international.snowowl.core.domain.BranchContext) BadRequestException(com.b2international.commons.exceptions.BadRequestException) ClassificationTracker(com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker)

Example 3 with ClassificationTracker

use of com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker in project snow-owl by b2ihealthcare.

the class ClassificationCreateRequest method execute.

@Override
public String execute(final BranchContext context) {
    final String repositoryId = context.info().id();
    final Branch branch = context.branch();
    final ClassificationTracker tracker = context.service(ClassificationTracker.class);
    final SnomedCoreConfiguration config = context.service(SnomedCoreConfiguration.class);
    final String user = !Strings.isNullOrEmpty(userId) ? userId : context.service(User.class).getUsername();
    tracker.classificationScheduled(classificationId, reasonerId, user, branch.path());
    final AsyncRequest<Boolean> jobRequest = new ClassificationJobRequestBuilder().setReasonerId(reasonerId).setParentLockContext(parentLockContext).addAllConcepts(additionalConcepts).build(branch.path());
    final ClassificationSchedulingRule rule = ClassificationSchedulingRule.create(config.getMaxReasonerCount(), repositoryId, branch.path());
    JobRequests.prepareSchedule().setKey(classificationId).setUser(user).setRequest(jobRequest).setDescription(String.format("Classifying the ontology on %s", branch.path())).setSchedulingRule(rule).buildAsync().get(context, SCHEDULE_TIMEOUT_MILLIS);
    return classificationId;
}
Also used : Branch(com.b2international.snowowl.core.branch.Branch) SnomedCoreConfiguration(com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration) ClassificationSchedulingRule(com.b2international.snowowl.snomed.reasoner.classification.ClassificationSchedulingRule) ClassificationTracker(com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker)

Example 4 with ClassificationTracker

use of com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker in project snow-owl by b2ihealthcare.

the class ClassificationDeleteRequest method execute.

@Override
public Boolean execute(final RepositoryContext context) {
    final ClassificationTracker tracker = context.service(ClassificationTracker.class);
    tracker.classificationDeleted(classificationId);
    return Boolean.TRUE;
}
Also used : ClassificationTracker(com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker)

Example 5 with ClassificationTracker

use of com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker in project snow-owl by b2ihealthcare.

the class ClassificationJobRequest method execute.

@Override
public Boolean execute(final BranchContext context) {
    final RemoteJob job = context.service(RemoteJob.class);
    final String classificationId = job.getKey();
    final Branch branch = context.branch();
    final long headTimestamp = branch.headTimestamp();
    final ClassificationTracker tracker = context.service(ClassificationTracker.class);
    tracker.classificationRunning(classificationId, headTimestamp);
    try {
        executeClassification(context, classificationId, tracker);
    } catch (final ReasonerApiException e) {
        tracker.classificationFailed(classificationId);
        throw e;
    } catch (final Exception e) {
        LOGGER.error("Unexpected error encountered while running classification job.", e);
        tracker.classificationFailed(classificationId);
        throw new ReasonerApiException("Exception caught while running classification.", e);
    }
    return Boolean.TRUE;
}
Also used : RemoteJob(com.b2international.snowowl.core.jobs.RemoteJob) Branch(com.b2international.snowowl.core.branch.Branch) ReasonerApiException(com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException) ClassificationTracker(com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) ReasonerInterruptedException(org.semanticweb.owlapi.reasoner.ReasonerInterruptedException) OWLReasonerRuntimeException(org.semanticweb.owlapi.reasoner.OWLReasonerRuntimeException) LockedException(com.b2international.commons.exceptions.LockedException) ReasonerApiException(com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException)

Aggregations

ClassificationTracker (com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker)6 Branch (com.b2international.snowowl.core.branch.Branch)3 BadRequestException (com.b2international.commons.exceptions.BadRequestException)2 LockedException (com.b2international.commons.exceptions.LockedException)2 SnomedCoreConfiguration (com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration)2 ReasonerApiException (com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException)2 Index (com.b2international.index.Index)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 TransactionContext (com.b2international.snowowl.core.domain.TransactionContext)1 Request (com.b2international.snowowl.core.events.Request)1 BulkRequest (com.b2international.snowowl.core.events.bulk.BulkRequest)1 RemoteJob (com.b2international.snowowl.core.jobs.RemoteJob)1 Locks (com.b2international.snowowl.core.locks.Locks)1 CommitResult (com.b2international.snowowl.core.request.CommitResult)1 ClassificationSchedulingRule (com.b2international.snowowl.snomed.reasoner.classification.ClassificationSchedulingRule)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLReasonerRuntimeException (org.semanticweb.owlapi.reasoner.OWLReasonerRuntimeException)1 ReasonerInterruptedException (org.semanticweb.owlapi.reasoner.ReasonerInterruptedException)1