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