diff options
Diffstat (limited to 'framework/src/onos/tools')
6 files changed, 92 insertions, 28 deletions
diff --git a/framework/src/onos/tools/package/maven-plugin/pom.xml b/framework/src/onos/tools/package/maven-plugin/pom.xml index 54839b11..c2b5d8ae 100644 --- a/framework/src/onos/tools/package/maven-plugin/pom.xml +++ b/framework/src/onos/tools/package/maven-plugin/pom.xml @@ -85,6 +85,11 @@ <artifactId>jackson-annotations</artifactId> <version>2.4.2</version> </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + </dependency> </dependencies> <build> diff --git a/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java b/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java index 5558b13a..09cf4dd9 100644 --- a/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java +++ b/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java @@ -163,7 +163,7 @@ public class OnosAppMojo extends AbstractMojo { origin = origin != null ? origin : DEFAULT_ORIGIN; requiredApps = (String) project.getProperties().get(ONOS_APP_REQUIRES); - requiredApps = requiredApps == null ? "" : requiredApps; + requiredApps = requiredApps == null ? "" : requiredApps.replaceAll("[\\s]", ""); if (appFile.exists()) { loadAppFile(appFile); diff --git a/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosSwaggerMojo.java b/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosSwaggerMojo.java index ea847459..a75127a3 100644 --- a/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosSwaggerMojo.java +++ b/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosSwaggerMojo.java @@ -18,6 +18,7 @@ package org.onosproject.maven; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.base.Charsets; import com.google.common.io.ByteStreams; import com.google.common.io.Files; import com.thoughtworks.qdox.JavaProjectBuilder; @@ -124,11 +125,13 @@ public class OnosSwaggerMojo extends AbstractMojo { ObjectNode root = initializeRoot(); ArrayNode tags = mapper.createArrayNode(); ObjectNode paths = mapper.createObjectNode(); + ObjectNode definitions = mapper.createObjectNode(); root.set("tags", tags); root.set("paths", paths); + root.set("definitions", definitions); - builder.getClasses().forEach(jc -> processClass(jc, paths, tags)); + builder.getClasses().forEach(jc -> processClass(jc, paths, tags, definitions)); if (paths.size() > 0) { getLog().info("Generating ONOS REST API documentation..."); @@ -172,7 +175,7 @@ public class OnosSwaggerMojo extends AbstractMojo { // Checks whether javaClass has a path tag associated with it and if it does // processes its methods and creates a tag for the class on the root - void processClass(JavaClass javaClass, ObjectNode paths, ArrayNode tags) { + void processClass(JavaClass javaClass, ObjectNode paths, ArrayNode tags, ObjectNode definitions) { // If the class does not have a Path tag then ignore it JavaAnnotation annotation = getPathAnnotation(javaClass); if (annotation == null) { @@ -199,7 +202,7 @@ public class OnosSwaggerMojo extends AbstractMojo { ArrayNode tagArray = mapper.createArrayNode(); tagArray.add(tagPath); - processAllMethods(javaClass, resourcePath, paths, tagArray); + processAllMethods(javaClass, resourcePath, paths, tagArray, definitions); } private JavaAnnotation getPathAnnotation(JavaClass javaClass) { @@ -211,7 +214,7 @@ public class OnosSwaggerMojo extends AbstractMojo { // Checks whether a class's methods are REST methods and then places all the // methods under a specific path into the paths node private void processAllMethods(JavaClass javaClass, String resourcePath, - ObjectNode paths, ArrayNode tagArray) { + ObjectNode paths, ArrayNode tagArray, ObjectNode definitions) { // map of the path to its methods represented by an ObjectNode Map<String, ObjectNode> pathMap = new HashMap<>(); @@ -221,7 +224,7 @@ public class OnosSwaggerMojo extends AbstractMojo { if (name.equals(POST) || name.equals(GET) || name.equals(DELETE) || name.equals(PUT)) { // substring(12) removes "javax.ws.rs." String method = annotation.getType().toString().substring(12).toLowerCase(); - processRestMethod(javaMethod, method, pathMap, resourcePath, tagArray); + processRestMethod(javaMethod, method, pathMap, resourcePath, tagArray, definitions); } }); }); @@ -236,9 +239,10 @@ public class OnosSwaggerMojo extends AbstractMojo { private void processRestMethod(JavaMethod javaMethod, String method, Map<String, ObjectNode> pathMap, - String resourcePath, ArrayNode tagArray) { + String resourcePath, ArrayNode tagArray, ObjectNode definitions) { String fullPath = resourcePath, consumes = "", produces = "", comment = javaMethod.getComment(); + DocletTag tag = javaMethod.getTagByName("rsModel"); for (JavaAnnotation annotation : javaMethod.getAnnotations()) { String name = annotation.getType().getName(); if (name.equals(PATH)) { @@ -256,12 +260,19 @@ public class OnosSwaggerMojo extends AbstractMojo { methodNode.set("tags", tagArray); addSummaryDescriptions(methodNode, comment); - processParameters(javaMethod, methodNode); + addJsonSchemaDefinition(definitions, tag); + addJsonSchemaDefinition(definitions, tag); + + processParameters(javaMethod, methodNode, method, tag); processConsumesProduces(methodNode, "consumes", consumes); processConsumesProduces(methodNode, "produces", produces); - - addResponses(methodNode); + if (tag == null || ((method.toLowerCase().equals("post") || method.toLowerCase().equals("put")) + && !(tag.getParameters().size() > 1))) { + addResponses(methodNode, tag, false); + } else { + addResponses(methodNode, tag, true); + } ObjectNode operations = pathMap.get(fullPath); if (operations == null) { @@ -273,6 +284,24 @@ public class OnosSwaggerMojo extends AbstractMojo { } } + private void addJsonSchemaDefinition(ObjectNode definitions, DocletTag tag) { + File definitionsDirectory = new File(srcDirectory + "/src/main/resources/definitions"); + if (tag != null) { + tag.getParameters().stream().forEach(param -> { + try { + File config = new File(definitionsDirectory.getAbsolutePath() + "/" + + param + ".json"); + String lines = Files.readLines(config, Charsets.UTF_8).stream().reduce((t, u) -> t + u). + get(); + definitions.putPOJO(param, lines); + } catch (IOException e) { + e.printStackTrace(); + } + }); + + } + } + private void processConsumesProduces(ObjectNode methodNode, String type, String io) { if (!io.equals("")) { ArrayNode array = mapper.createArrayNode(); @@ -299,13 +328,19 @@ public class OnosSwaggerMojo extends AbstractMojo { // Temporary solution to add responses to a method // TODO Provide annotations in the web resources for responses and parse them - private void addResponses(ObjectNode methodNode) { + private void addResponses(ObjectNode methodNode, DocletTag tag, boolean responseJson) { ObjectNode responses = mapper.createObjectNode(); methodNode.set("responses", responses); ObjectNode success = mapper.createObjectNode(); success.put("description", "successful operation"); responses.set("200", success); + if (tag != null && responseJson) { + ObjectNode schema = mapper.createObjectNode(); + tag.getParameters().stream().forEach( + param -> schema.put("$ref", "#/definitions/" + param)); + success.set("schema", schema); + } ObjectNode defaultObj = mapper.createObjectNode(); defaultObj.put("description", "Unexpected error"); @@ -329,7 +364,7 @@ public class OnosSwaggerMojo extends AbstractMojo { } // Processes parameters of javaMethod and enters the proper key-values into the methodNode - private void processParameters(JavaMethod javaMethod, ObjectNode methodNode) { + private void processParameters(JavaMethod javaMethod, ObjectNode methodNode, String method, DocletTag tag) { ArrayNode parameters = mapper.createArrayNode(); methodNode.set("parameters", parameters); boolean required = true; @@ -346,7 +381,8 @@ public class OnosSwaggerMojo extends AbstractMojo { if (pathType != null) { //the parameter is a path or query parameter individualParameterNode.put("name", - pathType.getNamedParameter("value").toString().replace("\"", "")); + pathType.getNamedParameter("value") + .toString().replace("\"", "")); if (pathType.getType().getName().equals(PATH_PARAM)) { individualParameterNode.put("in", "path"); } else if (pathType.getType().getName().equals(QUERY_PARAM)) { @@ -357,10 +393,16 @@ public class OnosSwaggerMojo extends AbstractMojo { individualParameterNode.put("name", annotationName); individualParameterNode.put("in", "body"); - // TODO add actual hardcoded schemas and a type - // body parameters must have a schema associated with them - ArrayNode schema = mapper.createArrayNode(); - individualParameterNode.set("schema", schema); + // Adds the reference to the Json model for the input + // that goes in the post or put operation + if (tag != null && (method.toLowerCase().equals("post") || + method.toLowerCase().equals("put"))) { + ObjectNode schema = mapper.createObjectNode(); + tag.getParameters().stream().forEach(param -> { + schema.put("$ref", "#/definitions/" + param); + }); + individualParameterNode.set("schema", schema); + } } for (DocletTag p : javaMethod.getTagsByName("param")) { if (p.getValue().contains(annotationName)) { diff --git a/framework/src/onos/tools/test/bin/onos-check-apps b/framework/src/onos/tools/test/bin/onos-check-apps index dfd6b4ef..5d83e416 100755 --- a/framework/src/onos/tools/test/bin/onos-check-apps +++ b/framework/src/onos/tools/test/bin/onos-check-apps @@ -24,7 +24,7 @@ for attempt in {1..3}; do # Check for differences case ${3:-equals} in equals) diff $aux.1 $aux.2;; - includes) [ $(egrep -c -f $aux.2 $aux.1) -eq $(wc -l $aux.2 | sed "s|$aux.2||g") ];; + includes) [ $(egrep -c -f $aux.2 $aux.1) -ge $(wc -l $aux.2 | sed "s|$aux.2||g") ];; excludes) ! egrep -f $aux.2 $aux.1;; esac diff --git a/framework/src/onos/tools/test/scenarios/setup.xml b/framework/src/onos/tools/test/scenarios/setup.xml index c26c0dea..071db8b9 100644 --- a/framework/src/onos/tools/test/scenarios/setup.xml +++ b/framework/src/onos/tools/test/scenarios/setup.xml @@ -40,7 +40,7 @@ <step name="Check-Components-${#}" exec="onos-check-components ${OC#}" requires="~Wait-for-Start-${#},"/> - <step name="Check-Apps-${#}" exec="onos-check-apps ${OC#}" + <step name="Check-Apps-${#}" exec="onos-check-apps ${OC#} ${ONOS_APPS} includes" requires="~Wait-for-Start-${#}"/> </parallel> </group> diff --git a/framework/src/onos/tools/test/topos/opticalUtils.py b/framework/src/onos/tools/test/topos/opticalUtils.py index 5d955e51..87903cc5 100644 --- a/framework/src/onos/tools/test/topos/opticalUtils.py +++ b/framework/src/onos/tools/test/topos/opticalUtils.py @@ -58,7 +58,7 @@ import os from time import sleep import urllib2 -from mininet.node import Switch, RemoteController +from mininet.node import Switch, OVSSwitch, RemoteController from mininet.topo import Topo from mininet.util import quietRun from mininet.net import Mininet @@ -356,8 +356,18 @@ class LINCSwitch(OpticalSwitch): return configDict @staticmethod - def bootOE(net): - "Start the LINC optical emulator within a mininet instance" + def bootOE(net, domain=None): + """ + Start the LINC optical emulator within a mininet instance + + This involves 1. converting the information stored in Linc* to configs + for both LINC and the network config system, 2. starting Linc, 3. connecting + cross-connects, and finally pushing the network configs to ONOS. + + Inevitably, there are times when we have OVS switches that should not be + under the control of the controller in charge of the Linc switches. We + hint at these by passing domain information. + """ LINCSwitch.opticalJSON = {} linkConfig = [] devices = [] @@ -365,9 +375,11 @@ class LINCSwitch(OpticalSwitch): LINCSwitch.controllers = net.controllers for switch in net.switches: + if domain and switch not in domain: + continue if isinstance(switch, OpticalSwitch): devices.append(switch.json()) - else: + elif isinstance(switch, OVSSwitch): devices.append(LINCSwitch.switchJSON(switch)) LINCSwitch.opticalJSON[ 'devices' ] = devices @@ -450,18 +462,21 @@ class LINCSwitch(OpticalSwitch): opener = urllib2.build_opener(handler) opener.open(url) urllib2.install_opener(opener) + # focus on just checking the state of devices we're interested in + devlist = map( lambda x: x['uri'], devices ) while True: response = json.load(urllib2.urlopen(url)) devs = response.get('devices') - # Wait for all devices to be registered - if (len(devices) != len(devs)): + # Wait for all devices to be registered. There is a chance that this is only a subgraph. + if (len(devices) > len(devs)): continue # Wait for all devices to available available = True for d in devs: - available &= d['available'] + if d['id'] in devlist: + available &= d['available'] if available: break @@ -615,9 +630,11 @@ class LINCSwitch(OpticalSwitch): if isinstance(link, LINCLink): if link.annotations[ 'optical.type' ] == 'cross-connect': tapCount += 1 - while True: - if str(tapCount) == quietRun('ip addr | grep tap | wc -l', shell=True).strip('\n'): + # tapCount can be less than the actual number of taps if the optical network + # is a subgraph of a larger multidomain network. + tapNum = int(quietRun('ip addr | grep tap | wc -l', shell=True).strip('\n')) + if tapCount <= tapNum: return True if timeout: if time >= TIMEOUT: |