From 41f5dc33a90718fae58bedce4229a1d7e6fc59c8 Mon Sep 17 00:00:00 2001 From: Matteo Pergolesi Date: Wed, 16 Oct 2019 15:44:18 +0200 Subject: [PATCH 1/4] Update version to 0.0.3-SNAPSHOT. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 851e24f..62ba99b 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.cnit.blueprint validator - 0.0.2 + 0.0.3-SNAPSHOT blueprint-validator Simple validator for blueprints defined in 5G EVE From 3f4be7f682d0972a45f55b454f4c57b231532bef Mon Sep 17 00:00:00 2001 From: Matteo Pergolesi Date: Thu, 24 Oct 2019 16:41:59 +0200 Subject: [PATCH 2/4] Using the `isValid()` method provided by NXW and handling excpetion. --- .../BlueprintValidatorApplication.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/it/cnit/blueprint/validator/BlueprintValidatorApplication.java b/src/main/java/it/cnit/blueprint/validator/BlueprintValidatorApplication.java index 60266e7..21e100c 100644 --- a/src/main/java/it/cnit/blueprint/validator/BlueprintValidatorApplication.java +++ b/src/main/java/it/cnit/blueprint/validator/BlueprintValidatorApplication.java @@ -9,6 +9,7 @@ import it.nextworks.nfvmano.catalogue.blueprint.elements.ExpBlueprint; import it.nextworks.nfvmano.catalogue.blueprint.elements.TestCaseBlueprint; import it.nextworks.nfvmano.catalogue.blueprint.elements.VsBlueprint; +import it.nextworks.nfvmano.libs.ifa.common.exceptions.MalformattedElementException; import java.io.IOException; import java.io.InputStream; import java.lang.invoke.MethodHandles; @@ -71,7 +72,8 @@ private static Namespace parseArguments(String[] args) { return ns; } - private static void validateVSB(InputStream is) throws ValidationException, IOException { + private static void validateVSB(InputStream is) + throws ValidationException, IOException, MalformattedElementException { VsBlueprint vsb = OBJECT_MAPPER.readValue(is, VsBlueprint.class); Set> violations = VALIDATOR.validate(vsb); if (!violations.isEmpty()) { @@ -80,10 +82,12 @@ private static void validateVSB(InputStream is) throws ValidationException, IOEx } throw new ValidationException(); } + vsb.isValid(); LOG.debug("Dump:\n{}", OBJECT_MAPPER.writeValueAsString(vsb)); } - private static void validateCtx(InputStream is) throws ValidationException, IOException { + private static void validateCtx(InputStream is) + throws ValidationException, IOException, MalformattedElementException { CtxBlueprint ctx = OBJECT_MAPPER.readValue(is, CtxBlueprint.class); Set> violations = VALIDATOR.validate(ctx); if (!violations.isEmpty()) { @@ -92,10 +96,12 @@ private static void validateCtx(InputStream is) throws ValidationException, IOEx } throw new ValidationException(); } + ctx.isValid(); LOG.debug("Dump:\n{}", OBJECT_MAPPER.writeValueAsString(ctx)); } - private static void validateExpB(InputStream is) throws ValidationException, IOException { + private static void validateExpB(InputStream is) + throws ValidationException, IOException, MalformattedElementException { ExpBlueprint expb = OBJECT_MAPPER.readValue(is, ExpBlueprint.class); Set> violations = VALIDATOR.validate(expb); if (!violations.isEmpty()) { @@ -104,10 +110,12 @@ private static void validateExpB(InputStream is) throws ValidationException, IOE } throw new ValidationException(); } + expb.isValid(); LOG.debug("Dump:\n{}", OBJECT_MAPPER.writeValueAsString(expb)); } - private static void validateTcB(InputStream is) throws ValidationException, IOException { + private static void validateTcB(InputStream is) + throws ValidationException, IOException, MalformattedElementException { TestCaseBlueprint tcb = OBJECT_MAPPER.readValue(is, TestCaseBlueprint.class); Set> violations = VALIDATOR.validate(tcb); if (!violations.isEmpty()) { @@ -116,6 +124,7 @@ private static void validateTcB(InputStream is) throws ValidationException, IOEx } throw new ValidationException(); } + tcb.isValid(); LOG.debug("Dump:\n{}", OBJECT_MAPPER.writeValueAsString(tcb)); } @@ -156,7 +165,8 @@ public void run(String... args) throws Exception { LOG.error("Error at line {}, column {} of YAML file", e.getLocation().getLineNr(), e.getLocation().getColumnNr()); LOG.error("Validation failed"); - } catch (ValidationException e) { + } catch (ValidationException | MalformattedElementException e) { + LOG.error(e.getMessage()); LOG.error("Validation failed"); } catch (IOException e) { LOG.error("Can't read input file {}", e.getMessage()); From f0bcd6f9be3249fb9e2fe63d067ed41d616b33fd Mon Sep 17 00:00:00 2001 From: Matteo Pergolesi Date: Thu, 24 Oct 2019 16:46:40 +0200 Subject: [PATCH 3/4] Update README. --- README.md | 44 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 842680f..29ecbf2 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,23 @@ # blueprint-validator A simple validator for blueprints used in 5G EVE Portal -# Old readme. TODO update - -# 5g-blueprint-libs -Definitions and POJO mappings of Vertical Service Blueprints for 5G EVE - -## Developer guide - -POJO classes for all blueprints and sub-components are included in -[blueprint](src/test/java/eu/_5geve/blueprint) package. - -## User Guide - -### Blueprint examples in YAML - -Some blueprint examples are included in this project. You can find them in -[blueprint-examples](src/main/resources/blueprint-examples/) folder. - -### Importing and using POJOs in your Java project - -To understand how to use the generated Java classes, please refer to the test -classes in [test](src/test/java/eu/_5geve/blueprint) - -To parse YAML files you can use jackson's `ObjectMapper`. -The `ObjectMapper` behavior can be configured with various options and an -example of this is shown in the `testSetup()` method in the test classes. - -To validate the generated object you can use -[Hibernate Validator](https://hibernate.org/validator/) provided as a -dependency, or any other validator that you like. -Please refer again to the `testSetup()` method for how to initialize it. - -### Command line +### Command line usage The jar file produced by `mvn package` is executable and you can use it to validate blueprints. The jar file is also available for download from -[releases](https://github.com/5GEVE/5geve-blueprint-libs/releases). +[releases](https://github.com/TheWall89/blueprint-validator/releases). Usage example: ``` # print help and exit -java -jar 5geve-blueprint-libs-VERSION.jar --help +java -jar validator-VERSION.jar --help # validate a VSB -java -jar 5geve-blueprint-libs-VERSION.jar --type vsb ./vsb_asti_agv.yaml +java -jar validator-VERSION.jar --type vsb ./vsb_asti_agv.yaml ``` + +### Blueprint examples in YAML + +Some blueprint examples are provided in [blueprint-yaml](link-coming-soon). + From 512c925774d9d3b6e30657b9fec6f7ff5d495b7d Mon Sep 17 00:00:00 2001 From: Matteo Pergolesi Date: Thu, 24 Oct 2019 16:49:37 +0200 Subject: [PATCH 4/4] Update version to 0.0.3 for release. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 62ba99b..2efb101 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.cnit.blueprint validator - 0.0.3-SNAPSHOT + 0.0.3 blueprint-validator Simple validator for blueprints defined in 5G EVE