Skip to content

Commit

Permalink
Do not allow multiple ingestion packages to be loaded concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
weisenje authored and GitHub Enterprise committed Apr 25, 2023
1 parent 2425815 commit b037229
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.zip.ZipInputStream;

import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -82,6 +84,8 @@ public class UtilityServiceRestController {

private static final String SERVICE_NAME = "utilityService";

private ReentrantLock lock;

@Autowired
private AuthorizationProperties auth_prop;
@Autowired
Expand Down Expand Up @@ -111,6 +115,8 @@ public void init() {
query_prop.validateWithExit();
query_credentials_prop.validateWithExit();
servicesgraph_prop.validateWithExit();

lock = new ReentrantLock();
}

/**
Expand Down Expand Up @@ -421,25 +427,25 @@ public void loadIngestionPackage( @RequestParam("serverAndPort") String serverAn
throw new Exception("Cannot find a top-level manifest in " + ingestionPackageZipFile.getOriginalFilename());
}
ManifestConfig manifest = new ManifestConfig(manifestFile, defaultModelGraph, defaultDataGraph);
manifest.load(serverAndPort, serverType, clear, true, ingest_prop.getClient(), ngexec_prop.getClient(), ngstore_prop.getClient(), getSparqlQueryClient(), responseLogger);

if(lock.tryLock(30, TimeUnit.SECONDS)) { // don't allow multiple loads to be performed at once. Wait a short time to acquire the lock
manifest.load(serverAndPort, serverType, clear, true, ingest_prop.getClient(), ngexec_prop.getClient(), ngstore_prop.getClient(), getSparqlQueryClient(), responseLogger);
}else {
throw new Exception("Another ingestion package load is in progress");
}
responseLogger.info("Load complete");
LocalLogger.logToStdOut(SERVICE_NAME + " " + ENDPOINT_NAME + " completed");

} catch (Exception e){
responseLogger.error(e.getMessage());
LocalLogger.printStackTrace(e);
}finally {
if(lock.isHeldByCurrentThread()) {
lock.unlock(); // release the lock
}
try {
if(responseWriter != null) {
responseWriter.close();
}
if(zipInputStream != null) {
zipInputStream.close();
}
if(tempDir != null) {
FileUtils.deleteDirectory(tempDir);
}
if(responseWriter != null) { responseWriter.close(); }
if(zipInputStream != null) { zipInputStream.close(); }
if(tempDir != null) { FileUtils.deleteDirectory(tempDir); }
}catch(Exception e) {
LocalLogger.printStackTrace(e);
}
Expand Down

0 comments on commit b037229

Please sign in to comment.