Skip to content

Commit

Permalink
feedback, remove more audits and exception catching
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-va committed Feb 8, 2025
1 parent 61fb0dc commit 61e4483
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import gov.nih.nci.evs.api.model.Audit;
import gov.nih.nci.evs.api.service.ElasticOperationsService;
import gov.nih.nci.evs.api.service.ElasticQueryService;
import gov.nih.nci.evs.api.util.TerminologyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -23,9 +22,6 @@ public class BaseController {
/* The terminology utils */
@Autowired TerminologyUtils termUtils;

/** The elastic query service. */
@Autowired ElasticQueryService elasticQueryService;

/** The elastic operations service. */
@Autowired ElasticOperationsService elasticOperationsService;

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/gov/nih/nci/evs/api/model/Audit.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,6 @@ public static void addAudit(
String details,
String logLevel)
throws Exception {
operationsService.deleteQuery(
"terminology:" + terminology + " AND logLevel:" + logLevel + " AND details:" + details,
ElasticOperationsService.AUDIT_INDEX);
Audit audit = new Audit(type, terminology, null, new Date(), process, details, logLevel);
operationsService.index(audit, ElasticOperationsService.AUDIT_INDEX, Audit.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void loadConceptsRealTime(
"loadConceptsRealTime",
terminology.getTerminology(),
"No concepts found!",
"warning");
"WARN");
return;
}

Expand Down Expand Up @@ -252,7 +252,7 @@ private void loadConceptsRealTime(
"loadConceptsRealTime",
terminology.getTerminology(),
"Error handling history for concept " + c.getCode(),
"error");
"ERROR");
} catch (Exception e1) {
logger.error(e1.getMessage(), e1);
}
Expand Down Expand Up @@ -338,7 +338,7 @@ private void loadConceptsRealTime(
"loadConceptsRealTime",
terminology.getTerminology(),
"UNABLE TO DELETE INDEX: " + NCIT_MAPS_TO + mapset.getKey() + " NOT FOUND!",
"warning");
"WARN");
}
Collections.sort(
mapset.getValue().getMaps(),
Expand Down Expand Up @@ -545,7 +545,7 @@ public void addExtraSubsets(List<Concept> existingSubsets, Terminology terminolo
"addExtraSubsets",
terminology.getTerminology(),
"Subset " + subsetCode + " not found as a concept, skipping.",
"warning");
"WARN");
continue;
}

Expand Down Expand Up @@ -577,7 +577,7 @@ public void addExtraSubsets(List<Concept> existingSubsets, Terminology terminolo
+ ": "
+ newSubsets.get(subsetCode)
+ " not found, skipping.",
"warning");
"WARN");
continue;
}

Expand Down Expand Up @@ -627,13 +627,15 @@ public void addExtraSubsets(List<Concept> existingSubsets, Terminology terminolo
// index subsetConcept
operationsService.index(subsetConcept, terminology.getIndexName(), Concept.class);
}
Audit.addAudit(
operationsService,
"Missing Subset Concepts",
"addExtraSubsets",
terminology.getTerminology(),
"Concepts " + missingConcepts + " not found for new subset " + subsetCode + ".",
"warning");
if (missingConcepts.size() > 0) {
Audit.addAudit(
operationsService,
"Missing Subset Concepts",
"addExtraSubsets",
terminology.getTerminology(),
"Concepts " + missingConcepts + " not found for new subset " + subsetCode + ".",
"WARN");
}
// explicitly set leaf since it defaults to false
newSubsetEntry.setLeaf(!newSubsets.containsValue(newSubsetEntry.getCode()));
// add extra relevant properties to new subset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public Set<String> cleanStaleIndexes(final Terminology terminology) throws Excep
logger.warn("Deleting concepts index {} failed!", indexName);
Audit.addAudit(
operationsService,
"warning",
"WARN",
"cleanStaleIndexes",
terminology.getTerminology(),
"Deleting concepts index " + objectIndexName + " failed!",
Expand Down Expand Up @@ -355,7 +355,7 @@ public void checkLoadStatus(int total, Terminology term) throws Exception {
Thread.sleep(2000);
} catch (InterruptedException e) {
logger.error("Error while checking load status: sleep interrupted - " + e.getMessage(), e);
throw new Exception(e);
throw e;
}

if (attempts == 15) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public static void main(String[] args) throws Exception {
Date endDate = new Date();
termAudit.setEndDate(endDate);
termAudit.setElapsedTime(endDate.getTime() - startDate.getTime());
termAudit.setLogLevel("INFO");
logger.info("Audit: {}", termAudit.toString());
// only add new audit if something major has actually happened
if (termAudit.getElapsedTime() > 10000) {
Expand All @@ -224,7 +225,7 @@ public static void main(String[] args) throws Exception {
e.getStackTrace()[0].getClassName(),
cmd.getOptionValue("t"),
e.getMessage(),
"error");
"ERROR");
int exitCode =
SpringApplication.exit(
app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ public List<Concept> getConcepts(
log.info(" finish main");
} catch (final Exception e) {
log.error("Unexpected error on main", e);
auditError(e, "getConcepts");
exceptions.add(e);
}
});
Expand All @@ -538,7 +537,6 @@ public List<Concept> getConcepts(
log.info(" finish roles");
} catch (final Exception e) {
log.error("Unexpected error on roles", e);
auditError(e, "getConcepts");
exceptions.add(e);
}
});
Expand All @@ -552,7 +550,6 @@ public List<Concept> getConcepts(
log.info(" finish inverse roles");
} catch (final Exception e) {
log.error("Unexpected error on inverse roles", e);
auditError(e, "getConcepts");
exceptions.add(e);
}
});
Expand All @@ -566,20 +563,14 @@ public List<Concept> getConcepts(
log.info(" finish axioms");
} catch (final Exception e) {
log.error("Unexpected error on axioms", e);
auditError(e, "getConcepts");
exceptions.add(e);
}
});
// Shutdown executor
executor.shutdown();

// Wait up to 10 min for processes to stop
try {
executor.awaitTermination(10, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
auditError(e, "getConcepts");
throw new RuntimeException(e);
}
executor.awaitTermination(10, TimeUnit.MINUTES);

if (axiomMap.isEmpty()) {
// This likely occurs if the 10 minute awaitTermination isn't long enough
Expand Down Expand Up @@ -2448,12 +2439,7 @@ public List<Concept> getAllConceptsWithCode(final Terminology terminology) throw
final String queryPrefix = queryBuilderService.constructPrefix(terminology);
final String query = queryBuilderService.constructQuery("all.concepts.with.code", terminology);
String res = null;
try {
res = restUtils.runSPARQL(queryPrefix + query, getQueryURL());
} catch (final Exception e) {
auditError(e, "getAllConceptsWithCode");
e.printStackTrace();
}
res = restUtils.runSPARQL(queryPrefix + query, getQueryURL());

final ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Expand Down Expand Up @@ -2489,12 +2475,7 @@ public List<Concept> getAllConceptsWithoutCode(final Terminology terminology) th
final String query =
queryBuilderService.constructQuery("all.concepts.without.code", terminology);
String res = null;
try {
res = restUtils.runSPARQL(queryPrefix + query, getQueryURL());
} catch (final Exception e) {
auditError(e, "getAllConceptsWithoutCode");
e.printStackTrace();
}
res = restUtils.runSPARQL(queryPrefix + query, getQueryURL());

final ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Expand Down Expand Up @@ -2577,29 +2558,20 @@ private void getSubsetsHelper(
/* see superclass */
@Override
public List<AssociationEntry> getAssociationEntries(
final Terminology terminology, final Concept association) {
final Terminology terminology, final Concept association) throws Exception {
final String queryPrefix = queryBuilderService.constructPrefix(terminology);
final String query =
queryBuilderService.constructQuery(
"association.entries", terminology, association.getCode());
String res = null;
try {
res = restUtils.runSPARQL(queryPrefix + query, getQueryURL());
} catch (final Exception e1) {
auditError(e1, "getAssociationEntries");
e1.printStackTrace();
}
res = restUtils.runSPARQL(queryPrefix + query, getQueryURL());

final ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final List<AssociationEntry> entries = new ArrayList<>();
Sparql sparqlResult = null;
try {
sparqlResult = mapper.readValue(res, Sparql.class);
} catch (final Exception e) {
log.error("Mapper could not read value in Association Entries");
auditError(e, "getAssociationEntries");
e.printStackTrace();
}
sparqlResult = mapper.readValue(res, Sparql.class);

if (sparqlResult != null) {
final Bindings[] bindings = sparqlResult.getResults().getBindings();
for (final Bindings b : bindings) {
Expand Down Expand Up @@ -2647,11 +2619,7 @@ private List<String> getIgnoreSourceUrls() {
return Collections.emptyList();
}

private void auditError(Exception e, String function) {
try {
Audit.addAudit(operationsService, "Exception", function, null, e.getMessage(), "error");
} catch (Exception e1) {
log.error("Error adding audit", e1);
}
private void auditError(Exception e, String function) throws Exception {
Audit.addAudit(operationsService, "Exception", function, null, e.getMessage(), "ERROR");
}
}

0 comments on commit 61e4483

Please sign in to comment.