Skip to content

Commit

Permalink
Layerscan is now using --layername
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenplieger committed Dec 18, 2019
1 parent c477dd8 commit cdc62b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -5,7 +5,7 @@

<groupId>nl.knmi.adagucservices</groupId>
<artifactId>adaguc-services</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>

<name>adaguc-services</name>
<description>Backend for adaguc-server and adaguc-viewer</description>
Expand Down
27 changes: 20 additions & 7 deletions src/main/java/nl/knmi/adaguc/cron/AdagucServerScanLayers.java
Expand Up @@ -65,13 +65,14 @@ public void readAdagucServerDatasetConfig(File file) throws JsonProcessingExcept
*/
private void takeLayer(JSONObject layer, File datasetConfigFile) {
try {
JSONObject filePath = layer.getJSONObject("FilePath");
// JSONObject filePath = layer.getJSONObject("FilePath");
JSONObject autoScan = layer.getJSONObject("AutoScan");
JSONObject autoScanAttributes = autoScan.getJSONObject("attr");
String autoScanAttrEnabled = autoScanAttributes.getString("enabled");
String autoScanAttrDirPattern = null;
String autoScanAttrDuration = null;
String autoScanAttrStep = null;
String layerName = null;
try {
autoScanAttrDirPattern = autoScanAttributes.getString("dirpattern");
Debug.println("autoScanAttrDirPattern" + autoScanAttrDirPattern);
Expand All @@ -90,15 +91,22 @@ private void takeLayer(JSONObject layer, File datasetConfigFile) {
} catch (Exception e) {
}


try {
layerName = layer.getJSONObject("Name").getString("value");
Debug.println("layerName" + layerName);
} catch (Exception e) {
}

if ("true".equals(autoScanAttrEnabled)) {
if (autoScanAttrDuration == null || autoScanAttrDirPattern == null) {
/* Will update all files, no tailpath */
scanAllFilesForLayer(datasetConfigFile, null);
scanAllFilesForLayer(datasetConfigFile, null, layerName);
} else {
/*
* Will scan only files configured using tailpath based on duration and pattern
*/
scanFilesForLayerUsingTailPath(datasetConfigFile, autoScanAttrDuration, autoScanAttrDirPattern, autoScanAttrStep);
scanFilesForLayerUsingTailPath(datasetConfigFile, autoScanAttrDuration, autoScanAttrDirPattern, autoScanAttrStep, layerName);
}
}
} catch (Exception e) {
Expand All @@ -115,7 +123,7 @@ private void takeLayer(JSONObject layer, File datasetConfigFile) {
* @throws IOException
* @throws InterruptedException
*/
private void scanFilesForLayerUsingTailPath(File datasetConfigFile, String duration, String dirpattern, String step) throws ElementNotFoundException, IOException, InterruptedException {
private void scanFilesForLayerUsingTailPath(File datasetConfigFile, String duration, String dirpattern, String step, String layerName) throws ElementNotFoundException, IOException, InterruptedException {
try {
Debug.println("scanFilesForLayerUsingTailPath");
java.time.Period d = java.time.Period.parse(duration);
Expand All @@ -126,7 +134,7 @@ private void scanFilesForLayerUsingTailPath(File datasetConfigFile, String durat
do {

String tailPath = date1.format(DateTimeFormatter.ofPattern(dirpattern));
scanAllFilesForLayer(datasetConfigFile, tailPath);
scanAllFilesForLayer(datasetConfigFile, tailPath, layerName);
date1 = date1.minus(s);
maxIter--;
if (maxIter<0){
Expand All @@ -146,7 +154,7 @@ private void scanFilesForLayerUsingTailPath(File datasetConfigFile, String durat
* @throws IOException
* @throws InterruptedException
*/
private void scanAllFilesForLayer(File datasetConfigFile, String tailpath) throws ElementNotFoundException, IOException, InterruptedException {
private void scanAllFilesForLayer(File datasetConfigFile, String tailpath, String layerName) throws ElementNotFoundException, IOException, InterruptedException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String[] configEnv = ADAGUCConfigurator.getADAGUCEnvironment();
String configFile = null;
Expand All @@ -163,11 +171,16 @@ private void scanAllFilesForLayer(File datasetConfigFile, String tailpath) throw
args.add("--tailpath");
args.add(tailpath);
}
if (layerName!=null) {
args.add("--layername");
args.add(layerName);
}
String[] commands = args.toArray(new String[0]);
Debug.println(String.join(" ", commands));
ADAGUCServer.runADAGUC("/tmp/", commands, outputStream);
outputStream.flush();
String getCapabilities = new String(outputStream.toByteArray());
Debug.println(getCapabilities);
Debug.println("\n" + getCapabilities);
outputStream.close();
}
}

0 comments on commit cdc62b5

Please sign in to comment.