add daoconfig

This commit is contained in:
Ken Stevens 2021-11-07 12:19:25 -05:00
parent 8e27b85094
commit ed9dac5b1a
4 changed files with 71 additions and 10 deletions

View File

@ -300,6 +300,7 @@ public class FhirValidator {
* @return the results of validation
* @since 4.0.0
*/
// FIXME KHS consolidate this method with the other one that calls applyDefaultValidators()
public ValidationResult validateWithResult(String theResource, ValidationOptions theOptions) {
Validate.notNull(theResource, "theResource must not be null");
@ -307,6 +308,10 @@ public class FhirValidator {
IValidationContext<IBaseResource> ctx = ValidationContext.forText(myContext, theResource, theOptions);
if (ctx.getResource() instanceof IBaseBundle && myContext.getValidationSupport().isConcurrentBundleValidation()) {
return validateBundleEntriesConcurrently((IBaseBundle) ctx.getResource(), theOptions);
}
for (IValidatorModule next : myValidators) {
next.validateResource(ctx);
}

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.config;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.dao.JpaPersistedResourceValidationSupport;
import ca.uhn.fhir.jpa.dao.ObservationLastNIndexPersistSvc;
import ca.uhn.fhir.jpa.term.TermCodeSystemStorageSvcImpl;
@ -65,8 +66,11 @@ public abstract class BaseConfigDstu3Plus extends BaseConfig {
public abstract ITermVersionAdapterSvc terminologyVersionAdapterSvc();
@Bean(name = "myDefaultProfileValidationSupport")
public DefaultProfileValidationSupport defaultProfileValidationSupport() {
return new DefaultProfileValidationSupport(fhirContext());
public DefaultProfileValidationSupport defaultProfileValidationSupport(DaoConfig theDaoConfig) {
DefaultProfileValidationSupport retval = new DefaultProfileValidationSupport(fhirContext());
retval.setConcurrentBundleValidation(theDaoConfig.isConcurrentBundleValidation());
retval.setBundleValidationThreadCount(theDaoConfig.getBundleValidationThreadCount());
return retval;
}
@Bean(name = JPA_VALIDATION_SUPPORT_CHAIN)

View File

@ -1,5 +1,6 @@
package ca.uhn.fhir.jpa.api.config;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.api.model.HistoryCountModeEnum;
import ca.uhn.fhir.jpa.api.model.WarmCacheEntry;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
@ -278,6 +279,18 @@ public class DaoConfig {
*/
private boolean myAdvancedLuceneIndexing = false;
/**
* @see IValidationSupport#getBundleValidationThreadCount()
* @since 5.6.0
*/
private int myBundleValidationThreadCount = IValidationSupport.DEFAULT_BUNDLE_VALIDATION_THREADCOUNT;
/**
* @see IValidationSupport#isConcurrentBundleValidation()
* @since 5.6.0
*/
private boolean myConcurrentBundleValidation;
/**
* Constructor
*/
@ -2672,6 +2685,40 @@ public class DaoConfig {
myElasicSearchIndexPrefix = thePrefix;
}
/**
* @see IValidationSupport#getBundleValidationThreadCount()
* @since 5.6.0
*/
public int getBundleValidationThreadCount() {
return myBundleValidationThreadCount;
}
/**
* @see IValidationSupport#getBundleValidationThreadCount()
* @since 5.6.0
*/
public DaoConfig setBundleValidationThreadCount(int theBundleValidationThreadCount) {
myBundleValidationThreadCount = theBundleValidationThreadCount;
return this;
}
/**
* @see IValidationSupport#isConcurrentBundleValidation()
* @since 5.6.0
*/
public boolean isConcurrentBundleValidation() {
return myConcurrentBundleValidation;
}
/**
* @see IValidationSupport#isConcurrentBundleValidation()
* @since 5.6.0
*/
public DaoConfig setConcurrentBundleValidation(boolean theConcurrentBundleValidation) {
myConcurrentBundleValidation = theConcurrentBundleValidation;
return this;
}
public enum StoreMetaSourceInformationEnum {
NONE(false, false),
SOURCE_URI(true, false),

View File

@ -82,6 +82,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat;
@ -1505,7 +1506,9 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
myStructureDefinitionMap.put("https://example.com/StructureDefinition/Patient-v1", sd);
int entriesCount = 300;
Bundle bundle = buildBundle(entriesCount);
// We deliberately create an invalid bundle to confirm we are indeed running multithreaded
Bundle bundle = buildBundle(entriesCount, false);
assertThat(bundle.getEntry(), hasSize(entriesCount));
try {
myDefaultValidationSupport.setConcurrentBundleValidation(true);
@ -1527,18 +1530,20 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
}
}
private Bundle buildBundle(int theSize) throws IOException {
private Bundle buildBundle(int theSize, boolean theValidBundle) throws IOException {
BundleBuilder bundleBuilder = new BundleBuilder(ourCtx);
Patient p = ourCtx.newJsonParser().parseResource(Patient.class, loadResource("/r4/multithread/patient.json"));
for (int i = 0; i < theSize; ++i) {
bundleBuilder.addTransactionCreateEntry(p);
}
if (theValidBundle) {
Bundle retval = (Bundle) bundleBuilder.getBundle();
AtomicInteger count = new AtomicInteger(1);
retval.getEntry().stream().forEach(entry -> entry.setFullUrl("urn:uuid:" + count.getAndIncrement()));
return retval;
} else {
return (Bundle) bundleBuilder.getBundle();
// We deliberately omit setting unique fullUrls on the bundle to validate that the bundle was validated concurrently
// Bundle retval = (Bundle) bundleBuilder.getBundle();
// AtomicInteger count = new AtomicInteger(1);
// retval.getEntry().stream().forEach(entry -> entry.setFullUrl("urn:uuid:" + count.getAndIncrement()));
// return retval;
}
}
@AfterAll