Issue 3450 there is no way to recreate freetext indexes for terminology entities (#3481)
* Add reindex-terminology batch command * Handle number of thread throttling and concurrency with other terminology batch operations * Add required dbcp2 dependency * Fix test * Improve ConnectionPoolInfoProvider setup. Handle maximum connections. * Remove java higher version construction * Remove unused config * Add reindex terminology integration test. Reset termConcept counters before pre-expanding, which otherwise accumulate if it was pre-expanded before. * Address MR comments * Adjust test to tested class change * Adjust test to tested class change Co-authored-by: juan.marchionatto <juan.marchionatto@smilecdr.com>
This commit is contained in:
parent
e45f7ee9cb
commit
f518f30506
|
@ -91,7 +91,7 @@ public class ReindexTerminologyCommand extends BaseRequestGeneratingCommand {
|
|||
ParametersUtil.addParameterToParametersBoolean(myFhirCtx, response, RESP_PARAM_SUCCESS, false);
|
||||
ParametersUtil.addParameterToParametersString(myFhirCtx, response, "message",
|
||||
"Internal error. Command result unknown. Check system logs for details");
|
||||
ourLog.info("Response:{}{}", NL, myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||
ourLog.error("Response:{}{}", NL, myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ class ReindexTerminologyCommandTest {
|
|||
new RestfulServerExtension(myContext, myProvider);
|
||||
|
||||
|
||||
private final PrintStream standardOut = System.out;
|
||||
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
|
||||
|
||||
static {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
type: fix
|
||||
type: add
|
||||
issue: 3450
|
||||
title: "There was no way to recreate freetext indexes for terminology entities. Command line operation
|
||||
reindex-terminology was added for this purpose."
|
||||
title: "Previously there was no way to recreate freetext indexes for terminology entities. A new CLI operation,
|
||||
reindex-terminology now exists for this purpose."
|
||||
|
|
|
@ -15,22 +15,22 @@ import java.util.Optional;
|
|||
public class ConnectionPoolInfoProvider implements IConnectionPoolInfoProvider {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(ConnectionPoolInfoProvider.class);
|
||||
|
||||
private IConnectionPoolInfoProvider provider;
|
||||
private IConnectionPoolInfoProvider myProvider;
|
||||
|
||||
|
||||
public ConnectionPoolInfoProvider(DataSource theDataSource) {
|
||||
if (theDataSource.getClass().isAssignableFrom(BasicDataSource.class)) {
|
||||
provider = new BasicDataSourceConnectionPoolInfoProvider((BasicDataSource) theDataSource);
|
||||
myProvider = new BasicDataSourceConnectionPoolInfoProvider((BasicDataSource) theDataSource);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( theDataSource.getClass().isAssignableFrom(ProxyDataSource.class)) {
|
||||
boolean basiDataSourceWrapped = false;
|
||||
boolean basiDataSourceWrapped;
|
||||
try {
|
||||
basiDataSourceWrapped = theDataSource.isWrapperFor(BasicDataSource.class);
|
||||
if (basiDataSourceWrapped) {
|
||||
BasicDataSource basicDataSource = theDataSource.unwrap(BasicDataSource.class);
|
||||
provider = new BasicDataSourceConnectionPoolInfoProvider(basicDataSource);
|
||||
myProvider = new BasicDataSourceConnectionPoolInfoProvider(basicDataSource);
|
||||
}
|
||||
} catch (SQLException ignored) { }
|
||||
}
|
||||
|
@ -39,17 +39,17 @@ public class ConnectionPoolInfoProvider implements IConnectionPoolInfoProvider {
|
|||
|
||||
@Override
|
||||
public Optional<Integer> getTotalConnectionSize() {
|
||||
return provider == null ? Optional.empty() : provider.getTotalConnectionSize();
|
||||
return myProvider == null ? Optional.empty() : myProvider.getTotalConnectionSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Integer> getActiveConnections() {
|
||||
return provider == null ? Optional.empty() : provider.getActiveConnections();
|
||||
return myProvider == null ? Optional.empty() : myProvider.getActiveConnections();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Long> getMaxWaitMillis() {
|
||||
return provider == null ? Optional.empty() : provider.getMaxWaitMillis();
|
||||
return myProvider == null ? Optional.empty() : myProvider.getMaxWaitMillis();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
|||
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
|
||||
import ca.uhn.fhir.util.ParametersUtil;
|
||||
import ca.uhn.fhir.util.StopWatch;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -142,7 +143,8 @@ public class BaseJpaSystemProvider<T, MT> extends BaseJpaProvider implements IJp
|
|||
|
||||
} catch (Exception theE) {
|
||||
throw new InternalErrorException(Msg.code(2072) +
|
||||
"Re-creating terminology freetext indexes failed with exception: " + theE.getMessage());
|
||||
"Re-creating terminology freetext indexes failed with exception: " + theE.getMessage() +
|
||||
NL + "With trace:" + NL + ExceptionUtils.getStackTrace(theE));
|
||||
}
|
||||
|
||||
IBaseParameters retVal = ParametersUtil.newInstance(getContext());
|
||||
|
@ -161,6 +163,6 @@ public class BaseJpaSystemProvider<T, MT> extends BaseJpaProvider implements IJp
|
|||
}
|
||||
|
||||
|
||||
|
||||
public static final String NL = System.getProperty("line.separator");
|
||||
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ class ConnectionPoolInfoProviderTest {
|
|||
IConnectionPoolInfoProvider provider = new ConnectionPoolInfoProvider(ds);
|
||||
|
||||
IConnectionPoolInfoProvider instantiatedProvider =
|
||||
(IConnectionPoolInfoProvider) ReflectionTestUtils.getField(provider, "provider");
|
||||
(IConnectionPoolInfoProvider) ReflectionTestUtils.getField(provider, "myProvider");
|
||||
|
||||
assertNotNull(instantiatedProvider);
|
||||
assertTrue(instantiatedProvider.getClass().isAssignableFrom(BasicDataSourceConnectionPoolInfoProvider.class));
|
||||
|
@ -115,7 +115,7 @@ class ConnectionPoolInfoProviderTest {
|
|||
IConnectionPoolInfoProvider provider = new ConnectionPoolInfoProvider(proxyDs);
|
||||
|
||||
IConnectionPoolInfoProvider instantiatedProvider =
|
||||
(IConnectionPoolInfoProvider) ReflectionTestUtils.getField(provider, "provider");
|
||||
(IConnectionPoolInfoProvider) ReflectionTestUtils.getField(provider, "myProvider");
|
||||
assertNotNull(instantiatedProvider);
|
||||
assertTrue(instantiatedProvider.getClass().isAssignableFrom(BasicDataSourceConnectionPoolInfoProvider.class));
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class ConnectionPoolInfoProviderTest {
|
|||
|
||||
IConnectionPoolInfoProvider provider = new ConnectionPoolInfoProvider(proxyDs);
|
||||
IConnectionPoolInfoProvider instantiatedProvider =
|
||||
(IConnectionPoolInfoProvider) ReflectionTestUtils.getField(provider, "provider");
|
||||
(IConnectionPoolInfoProvider) ReflectionTestUtils.getField(provider, "myProvider");
|
||||
assertNull(instantiatedProvider);
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ class ConnectionPoolInfoProviderTest {
|
|||
IConnectionPoolInfoProvider provider = new ConnectionPoolInfoProvider(unknownDataSource);
|
||||
|
||||
IConnectionPoolInfoProvider instantiatedProvider =
|
||||
(IConnectionPoolInfoProvider) ReflectionTestUtils.getField(provider, "provider");
|
||||
(IConnectionPoolInfoProvider) ReflectionTestUtils.getField(provider, "myProvider");
|
||||
assertNull(instantiatedProvider);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,15 +88,15 @@ public class TerminologyFreetextIndexingProviderTest {
|
|||
|
||||
|
||||
@Test
|
||||
void testServiceThroes() throws InterruptedException {
|
||||
void testServiceThrows() throws InterruptedException {
|
||||
String exceptionMsg = "some msg";
|
||||
when(myTermReadSvc.reindexTerminology()).thenThrow(new InterruptedException(exceptionMsg));
|
||||
|
||||
InternalErrorException thrown = assertThrows(InternalErrorException.class,
|
||||
() -> testedProvider.reindexTerminology(myRequestDetails));
|
||||
|
||||
assertEquals(Msg.code(2072) + "Re-creating terminology freetext indexes " +
|
||||
"failed with exception: " + exceptionMsg, thrown.getMessage());
|
||||
assertTrue(thrown.getMessage().startsWith(Msg.code(2072) + "Re-creating terminology freetext indexes " +
|
||||
"failed with exception: " + exceptionMsg));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
,ReindexTerminologyFreetextR4Test.NoopMandatoryTransactionListener.class
|
||||
})
|
||||
public class ReindexTerminologyFreetextR4Test extends BaseJpaR4Test {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(ReindexTerminologyFreetextR4Test.class);
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(ReindexTerminologyFreetextR4Test.class);
|
||||
|
||||
public static final String LOINC_URL = "http://loinc.org";
|
||||
public static final String TEST_FILES_CLASSPATH = "loinc-reindex/";
|
||||
|
@ -180,7 +180,7 @@ public class ReindexTerminologyFreetextR4Test extends BaseJpaR4Test {
|
|||
myTermConceptDao.countByCodeSystemVersion(termCodeSystemVersionWithNoVersionId) );
|
||||
assertEquals(CS_CONCEPTS_NUMBER, dbTermConceptCountForNullVersion);
|
||||
|
||||
long termConceptCountNullVersion = searchAllIndexedTermConceptCount(termCodeSystemVersionWithVersionId);
|
||||
long termConceptCountNullVersion = searchAllIndexedTermConceptCount(termCodeSystemVersionWithNoVersionId);
|
||||
ourLog.info("=================> Number of freetext found concepts after re-indexing for version {}: {}",
|
||||
NULL, termConceptCountNullVersion);
|
||||
assertEquals(CS_CONCEPTS_NUMBER, termConceptCountNullVersion);
|
||||
|
|
Loading…
Reference in New Issue