diff --git a/.gitignore b/.gitignore
index d10b76f..c181cbc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,3 +44,5 @@ build/
# hibernate-validator
.attach_pid*
+
+/mvn-release.sh
diff --git a/mvn-release.sh b/mvn-release.sh
deleted file mode 100755
index 6001579..0000000
--- a/mvn-release.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env bash
-
-if [[ $(git branch --show-current) != "development" ]]; then
- echo "Please move to development branch."
- exit 1
-fi
-
-VERSION=$(mvn -q \
- -Dexec.executable=echo \
- -Dexec.args='${project.version}' \
- --non-recursive \
- exec:exec)
-BASE=(${VERSION//-/ [0]})
-
-printf "Current version: $VERSION\n"
-printf "Releasing to ${BASE}\n"
-read -r -p "Proceed? (no push, only commit) [y/N] " response
-case "$response" in
-[yY][eE][sS] | [yY])
- mvn versions:set -DnewVersion=${BASE} &&
- git commit -m "Update version to ${BASE} for release." pom.xml &&
- git checkout master &&
- git merge -m "Merge branch 'development' for ${BASE}" development &&
- git tag -a ${BASE} -m "Tag for version ${BASE}"
- git checkout development &&
- read -r -p "New version for development: " new
- mvn versions:set -DnewVersion=${new} &&
- git commit -m "Update version to ${new}." pom.xml
- printf "Remember to push both development and master.\n"
- printf "git push --tags origin master\n"
- printf "git push origin development\n"
- ;;
-*)
- printf "Aborting release.\n"
- ;;
-esac
-exit 0
diff --git a/pom.xml b/pom.xml
index 7fdb260..e6185a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
it.cnit.blueprint
validator
- 0.0.6
+ 0.0.7
blueprint-validator
Simple validator for blueprints defined in 5G EVE
diff --git a/src/main/java/it/cnit/blueprint/validator/BlueprintValidatorApplication.java b/src/main/java/it/cnit/blueprint/validator/BlueprintValidatorApplication.java
index a089489..04f16a0 100644
--- a/src/main/java/it/cnit/blueprint/validator/BlueprintValidatorApplication.java
+++ b/src/main/java/it/cnit/blueprint/validator/BlueprintValidatorApplication.java
@@ -2,7 +2,11 @@
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator;
@@ -13,6 +17,15 @@
import it.nextworks.nfvmano.libs.ifa.common.DescriptorInformationElement;
import it.nextworks.nfvmano.libs.ifa.common.exceptions.MalformattedElementException;
import it.nextworks.nfvmano.libs.ifa.descriptors.nsd.Nsd;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.ArgumentParser;
@@ -27,134 +40,133 @@
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
-import javax.validation.ConstraintViolation;
-import javax.validation.Validation;
-import javax.validation.ValidatorFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.invoke.MethodHandles;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.Set;
-
@SpringBootApplication(exclude = {
- DataSourceAutoConfiguration.class,
- DataSourceTransactionManagerAutoConfiguration.class,
- HibernateJpaAutoConfiguration.class
+ DataSourceAutoConfiguration.class,
+ DataSourceTransactionManagerAutoConfiguration.class,
+ HibernateJpaAutoConfiguration.class
})
public class BlueprintValidatorApplication implements CommandLineRunner {
- enum TYPE {
- vsb,
- ctx,
- expb,
- tcb,
- nsd
- }
- private static final Logger LOG = LoggerFactory
- .getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
- private static ObjectMapper Y_OBJECT_MAPPER, J_OBJECT_MAPPER;
- private static javax.validation.Validator VALIDATOR;
+ enum TYPE {
+ vsb,
+ ctx,
+ expb,
+ tcb,
+ nsd
+ }
- public static void main(String[] args) {
- SpringApplication app = new SpringApplication(BlueprintValidatorApplication.class);
- app.setLogStartupInfo(false);
- app.run(args);
- }
+ private static final Logger LOG = LoggerFactory
+ .getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
+ private static ObjectMapper Y_OBJECT_MAPPER, J_OBJECT_MAPPER;
+ private static javax.validation.Validator VALIDATOR;
- private static Namespace parseArguments(String[] args) {
- ArgumentParser parser = ArgumentParsers.newFor("validator").build()
- .defaultHelp(true)
- .description("Simple tool to validate blueprints and NSD for the 5G EVE platform.");
+ public static void main(String[] args) {
+ SpringApplication app = new SpringApplication(BlueprintValidatorApplication.class);
+ app.setLogStartupInfo(false);
+ app.run(args);
+ }
- parser.addArgument("--debug").action(Arguments.storeTrue());
- parser.addArgument("-t", "--type").type(TYPE.class).required(true)
- .help("Specify the type of blueprint you want to validate.");
- parser.addArgument("-s", "--schema").action(Arguments.storeTrue())
- .help("Also generate JSON schema for the selected type");
- parser.addArgument("file").help("YAML blueprint file path");
+ private static Namespace parseArguments(String[] args) {
+ ArgumentParser parser = ArgumentParsers.newFor("validator").build()
+ .defaultHelp(true)
+ .description("Simple tool to validate blueprints and NSD for the 5G EVE platform.");
- Namespace ns = null;
- try {
- ns = parser.parseArgs(args);
- } catch (ArgumentParserException e) {
- parser.handleError(e);
- System.exit(1);
- }
- return ns;
+ parser.addArgument("--debug").action(Arguments.storeTrue());
+ parser.addArgument("-t", "--type").type(TYPE.class).required(true)
+ .help("Specify the type of blueprint you want to validate.");
+ parser.addArgument("-s", "--schema").action(Arguments.storeTrue())
+ .help("Also generate JSON schema for the selected type");
+ parser.addArgument("file").help("YAML blueprint file path");
+
+ Namespace ns = null;
+ try {
+ ns = parser.parseArgs(args);
+ } catch (ArgumentParserException e) {
+ parser.handleError(e);
+ System.exit(1);
}
+ return ns;
+ }
- /**
- * @param s string containing the blueprint to be validated
- * @param cls the specific blueprint class to use for validation (e.g. VsBlueprint.class)
- * @param schema if true, generate JSON schema for cls
- * @param The type of the class to be validated
- * @throws IOException if Jackson fails to deserialize the blueprint; it can be JsonParseException or JsonMappingException
- * @throws ViolationException if javax.validation fails
- * @throws MalformattedElementException if call to isValid() fails
- */
- private static void validate(String s, Class cls, boolean schema)
- throws IOException, ViolationException, MalformattedElementException {
- if (schema) {
- LOG.info("Schema:\n{}",
- J_OBJECT_MAPPER.writeValueAsString(new JsonSchemaGenerator(J_OBJECT_MAPPER).generateSchema(cls)));
- }
- T b = Y_OBJECT_MAPPER.readValue(s, cls);
- LOG.debug("Dump:\n{}", Y_OBJECT_MAPPER.writeValueAsString(b));
- Set> violations = VALIDATOR.validate(b);
- if (!violations.isEmpty()) {
- throw new ViolationException(violations);
- }
- b.isValid();
+ /**
+ * @param s string containing the blueprint to be validated
+ * @param cls the specific blueprint class to use for validation (e.g. VsBlueprint.class)
+ * @param schema if true, generate JSON schema for cls
+ * @param The type of the class to be validated
+ * @throws IOException if Jackson fails to deserialize the blueprint; it can be
+ * JsonParseException or JsonMappingException
+ * @throws ViolationException if javax.validation fails
+ * @throws MalformattedElementException if call to isValid() fails
+ */
+ private static void validate(String s, Class cls,
+ boolean schema)
+ throws IOException, ViolationException, MalformattedElementException {
+ if (schema) {
+ LOG.info("Schema:\n{}",
+ J_OBJECT_MAPPER
+ .writeValueAsString(new JsonSchemaGenerator(J_OBJECT_MAPPER).generateSchema(cls)));
+ }
+ T b = Y_OBJECT_MAPPER.readValue(s, cls);
+ LOG.debug("Dump:\n{}", Y_OBJECT_MAPPER.writeValueAsString(b));
+ Set> violations = VALIDATOR.validate(b);
+ if (!violations.isEmpty()) {
+ throw new ViolationException(violations);
}
+ b.isValid();
+ }
- @Override
- public void run(String... args) {
- Y_OBJECT_MAPPER = new ObjectMapper(new YAMLFactory().configure(Feature.SPLIT_LINES, false))
- .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
- J_OBJECT_MAPPER = new ObjectMapper(new JsonFactory()).enable(SerializationFeature.INDENT_OUTPUT);
+ @Override
+ public void run(String... args) {
+ Y_OBJECT_MAPPER = new ObjectMapper(new YAMLFactory().configure(Feature.SPLIT_LINES, false))
+ .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
+ J_OBJECT_MAPPER = new ObjectMapper(new JsonFactory())
+ .enable(SerializationFeature.INDENT_OUTPUT);
- ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
- VALIDATOR = factory.getValidator();
+ ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+ VALIDATOR = factory.getValidator();
- Namespace ns = parseArguments(args);
- LOG.info("Validating file {}", ns.getString("file"));
- try (InputStream is = Files.newInputStream(Paths.get(ns.getString("file")))) {
- JsonNode rootNode = Y_OBJECT_MAPPER.readTree(is);
- switch ((TYPE) ns.get("type")) {
- case vsb:
- LOG.info("Selected type: Vertical Service Blueprint");
- validate(rootNode.toString(), VsBlueprint.class, ns.getBoolean("schema"));
- break;
- case ctx:
- LOG.info("Selected type: Context Blueprint");
- validate(rootNode.toString(), CtxBlueprint.class, ns.getBoolean("schema"));
- break;
- case expb:
- LOG.info("Selected type: Experiment Blueprint");
- validate(rootNode.toString(), ExpBlueprint.class, ns.getBoolean("schema"));
- break;
- case tcb:
- LOG.info("Selected type: Test Case Blueprint");
- validate(rootNode.toString(), TestCaseBlueprint.class, ns.getBoolean("schema"));
- break;
- case nsd:
- LOG.info("Selected type: Network Service Descriptor");
- validate(rootNode.get(0).toString(), Nsd.class, ns.getBoolean("schema"));
- break;
- }
- LOG.info("Validation success");
- } catch (JsonParseException | JsonMappingException e) {
- LOG.error(e.getOriginalMessage());
- LOG.error("Error at line {}, column {}", e.getLocation().getLineNr(), e.getLocation().getColumnNr());
- } catch (ViolationException e) {
- for (String v : e.getViolationMessages()) {
- LOG.error(v);
- }
- } catch (MalformattedElementException e) {
- LOG.error(e.getMessage());
- } catch (IOException e) {
- LOG.error("Can't read input file {}", e.getMessage());
- }
+ Namespace ns = parseArguments(args);
+ LOG.info("Validating file {}", ns.getString("file"));
+ try (InputStream is = Files.newInputStream(Paths.get(ns.getString("file")))) {
+ JsonNode rootNode = Y_OBJECT_MAPPER.readTree(is);
+ if (!rootNode.isObject()) {
+ throw new IOException("Not a JSON object. Please remove array (-) if present.");
+ }
+ switch ((TYPE) ns.get("type")) {
+ case vsb:
+ LOG.info("Selected type: Vertical Service Blueprint");
+ validate(rootNode.toString(), VsBlueprint.class, ns.getBoolean("schema"));
+ break;
+ case ctx:
+ LOG.info("Selected type: Context Blueprint");
+ validate(rootNode.toString(), CtxBlueprint.class, ns.getBoolean("schema"));
+ break;
+ case expb:
+ LOG.info("Selected type: Experiment Blueprint");
+ validate(rootNode.toString(), ExpBlueprint.class, ns.getBoolean("schema"));
+ break;
+ case tcb:
+ LOG.info("Selected type: Test Case Blueprint");
+ validate(rootNode.toString(), TestCaseBlueprint.class, ns.getBoolean("schema"));
+ break;
+ case nsd:
+ LOG.info("Selected type: Network Service Descriptor");
+ validate(rootNode.toString(), Nsd.class, ns.getBoolean("schema"));
+ break;
+ }
+ LOG.info("Validation success");
+ } catch (JsonParseException | JsonMappingException e) {
+ LOG.error(e.getOriginalMessage());
+ LOG.error("Error at line {}, column {}", e.getLocation().getLineNr(),
+ e.getLocation().getColumnNr());
+ } catch (ViolationException e) {
+ for (String v : e.getViolationMessages()) {
+ LOG.error(v);
+ }
+ } catch (MalformattedElementException e) {
+ LOG.error(e.getMessage());
+ } catch (IOException e) {
+ LOG.error("Can't read input file. {}", e.getMessage());
}
+ }
}