Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' for 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWall89 committed Oct 24, 2019
2 parents ba23a50 + 512c925 commit baf1393
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 41 deletions.
44 changes: 9 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>it.cnit.blueprint</groupId>
<artifactId>validator</artifactId>
<version>0.0.2</version>
<version>0.0.3</version>
<name>blueprint-validator</name>
<description>Simple validator for blueprints defined in 5G EVE</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ConstraintViolation<VsBlueprint>> violations = VALIDATOR.validate(vsb);
if (!violations.isEmpty()) {
Expand All @@ -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<ConstraintViolation<CtxBlueprint>> violations = VALIDATOR.validate(ctx);
if (!violations.isEmpty()) {
Expand All @@ -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<ConstraintViolation<ExpBlueprint>> violations = VALIDATOR.validate(expb);
if (!violations.isEmpty()) {
Expand All @@ -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<ConstraintViolation<TestCaseBlueprint>> violations = VALIDATOR.validate(tcb);
if (!violations.isEmpty()) {
Expand All @@ -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));
}

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit baf1393

Please sign in to comment.