Skip to content

Commit

Permalink
#1741 : correction post Anthony review
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckflipXYZ committed Feb 26, 2025
1 parent 45dd300 commit 951accc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 41 deletions.
10 changes: 2 additions & 8 deletions docker-compose/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
locales \
locales-all

RUN apt-get install -y iputils-ping


# take care of path
ENV PATH /opt/dcm4che/bin:$PATH
ENV LC_ALL en_US.UTF-8
Expand All @@ -101,21 +98,18 @@ ENV LANGUAGE en_US.UTF-8

# install the files from the 'dowloader' stage
COPY --link --from=datasets-download /target/. /
COPY --link datasets/shanoir-ng-datasets.jar shanoir-ng-datasets.jar



COPY --link datasets/entrypoint /usr/bin/
COPY --link datasets/wait-for-solr.sh /usr/bin/
COPY --link datasets/shanoir-ng-datasets.jar shanoir-ng-datasets.jar

# Use the below line for remote debugging
# Use the below line for remote debugging
#CMD ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:9914", "-jar", "/shanoir-ng-datasets.jar"]
CMD ["-jar", "/shanoir-ng-datasets.jar"]





################ import ####################################################

FROM base-microservice as import
Expand Down
2 changes: 0 additions & 2 deletions docker-compose/datasets/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ handle_microservice_migration

abort_if_error

/usr/bin/wait-for-solr.sh

run_microservice "$@"
20 changes: 0 additions & 20 deletions docker-compose/datasets/wait-for-solr.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.shanoir.ng.solr.service.SolrServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Profile;
Expand All @@ -18,24 +20,42 @@
@Profile("!test")
public class ShanoirDatasetIndexation implements ApplicationRunner {

@Autowired
private SolrClient solrClient;

@Autowired
private SolrServiceImpl solrServiceImpl;

@Value("${spring.data.solr.host}")
private String solrUrl;

private static final int RETRY_INTERVAL_MS = 5000;

private static final int MAX_WAIT_TIME_MS = 10 * 60 * 1000;

private static final Logger LOG = LoggerFactory.getLogger(ShanoirDatasetIndexation.class);

@Override
public void run(ApplicationArguments args) throws Exception {
SolrQuery q = new SolrQuery("*:*");
q.setRows(0); // don't actually request any data
if(Objects.nonNull(solrClient.query(q)) && Objects.equals(0L, solrClient.query(q).getResults().getNumFound())){
LOG.info("Solr index empty. Re-indexing...");
solrServiceImpl.indexAllNoAuth();
LOG.info("Solr indexation complete.");
} else {
LOG.info("Solr index already complete, no re-indexation required.");
SolrClient solrClient = null;
long startTime = System.currentTimeMillis();

while (Objects.isNull(solrClient) && (System.currentTimeMillis() - startTime) < MAX_WAIT_TIME_MS) {
try {
solrClient = new HttpSolrClient.Builder(solrUrl).build();
} catch (Exception ignored) {
Thread.sleep(RETRY_INTERVAL_MS);
}
}

if(Objects.nonNull(solrClient)){
SolrQuery q = new SolrQuery("*:*");
q.setRows(0); // don't actually request any data
if (Objects.nonNull(solrClient.query(q)) && Objects.equals(0L, solrClient.query(q).getResults().getNumFound())) {
LOG.info("Solr index empty. Re-indexing...");
solrServiceImpl.indexAllNoAuth();
LOG.info("Solr indexation complete.");
} else {
LOG.info("Solr index already complete, no re-indexation required.");
}
}
}
}

0 comments on commit 951accc

Please sign in to comment.