summaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src/main/java
diff options
context:
space:
mode:
authorLianhao Lu <lianhao.lu@intel.com>2018-11-09 14:57:30 +0800
committerLianhao Lu <lianhao.lu@intel.com>2018-11-12 15:55:37 +0800
commit70f9f24e6ed39a6ddb4afef02516af624f50079d (patch)
treecf1ecb8bff087d757f41bb31f6921dd6f17dc63c /plugins/reception-plugins/src/main/java
parent789f09f2430440d6be44a5fad26715d002aff757 (diff)
Make FileSystemReceptionHandler more tolerant
Make FileSystemReceptionHandler tolerant of exceptions thrown when parsing tosca template and be able to handle new incoming csar. Also added the unit test for FileSystemReceptionHandler. Change-Id: I0f1647f6f952576a8e61adca4d027990706d1411 Issue-ID: POLICY-837 Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Diffstat (limited to 'plugins/reception-plugins/src/main/java')
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java25
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java10
2 files changed, 24 insertions, 11 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java
index 9ac21550..b1a95fac 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java
@@ -23,6 +23,7 @@ package org.onap.policy.distribution.reception.handling.sdc;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import java.io.File;
+import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -52,9 +53,10 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler {
final FileSystemReceptionHandlerConfigurationParameterGroup handlerParameters =
ParameterService.get(parameterGroupName);
main(handlerParameters.getWatchPath());
- } catch (final PolicyDecodingException ex) {
- LOGGER.debug(ex);
+ } catch (final Exception ex) {
+ LOGGER.error(ex);
}
+ LOGGER.debug("FileSystemReceptionHandler main loop exited...");
}
@Override
@@ -67,10 +69,9 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler {
* Main entry point.
*
* @param watchPath Path to watch
- * @throws PolicyDecodingException Decoding exception
*/
@SuppressWarnings("unchecked")
- public void main(String watchPath) throws PolicyDecodingException {
+ public void main(String watchPath) {
try (final WatchService watcher = FileSystems.getDefault().newWatchService()) {
final Path dir = Paths.get(watchPath);
@@ -85,25 +86,31 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler {
Thread.currentThread().interrupt();
return;
}
+
for (final WatchEvent<?> event : key.pollEvents()) {
final WatchEvent.Kind<?> kind = event.kind();
final WatchEvent<Path> ev = (WatchEvent<Path>) event;
final Path fileName = ev.context();
- LOGGER.debug("new CSAR found: " + kind.name() + ": " + fileName);
- createPolicyInputAndCallHandler(dir.toString() + File.separator + fileName.toString());
- LOGGER.debug("CSAR complete: " + kind.name() + ": " + fileName);
+ try {
+ LOGGER.debug("new CSAR found: " + kind.name() + ": " + fileName);
+ createPolicyInputAndCallHandler(dir.toString() + File.separator + fileName.toString());
+ LOGGER.debug("CSAR complete: " + kind.name() + ": " + fileName);
+ } catch (final PolicyDecodingException ex) {
+ LOGGER.error(ex);
+ }
}
final boolean valid = key.reset();
if (!valid) {
+ LOGGER.error("Watch key no longer valid!");
break;
}
}
- } catch (final Exception ex) {
+ } catch (final IOException ex) {
LOGGER.error(ex);
}
}
- private void createPolicyInputAndCallHandler(final String fileName) throws PolicyDecodingException {
+ protected void createPolicyInputAndCallHandler(final String fileName) throws PolicyDecodingException {
final Csar csarObject = new Csar(fileName);
inputReceived(csarObject);
}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java
index 98f3c6a4..457cd5ea 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java
@@ -68,8 +68,14 @@ public class FileSystemReceptionHandlerConfigurationParameterGroup extends Recep
*/
private void validatePathElement(final GroupValidationResult validationResult, final String element,
final String elementName) {
- File file = new File(element);
- if (!(file.exists() && file.isDirectory())) {
+ boolean valid = false;
+ if (element != null) {
+ File file = new File(element);
+ if (file.exists() && file.isDirectory()) {
+ valid = true;
+ }
+ }
+ if (!valid) {
validationResult.setResult(elementName, ValidationStatus.INVALID,
elementName + " must be a valid directory");
}