use of org.onosproject.yang.model.YangModule in project onos by opennetworkinglab.
the class YangWebResource method getModules.
/**
* Returns all modules registered with YANG runtime under given model
* identifier.If the operation is successful, the JSON presentation of the
* resource plus HTTP status code "200 OK" is returned. Otherwise,
* HTTP error status code "400 Bad Request" is returned.
*
* @onos.rsModel YangModulesGet
* @param id for model
* @return HTTP response
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}")
public Response getModules(@PathParam("id") String id) {
modelRegistry = getService(YangModelRegistry.class);
ObjectNode result = mapper().createObjectNode();
YangModel model = modelRegistry.getModel(id);
if (model == null) {
return Response.status(NOT_FOUND).build();
}
Set<YangModule> modules = model.getYangModules();
ArrayNode ids = result.putArray(id);
for (YangModule m : modules) {
ids.add(m.getYangModuleId().moduleName() + "@" + m.getYangModuleId().revision());
}
return Response.ok(result).build();
}
use of org.onosproject.yang.model.YangModule in project onos by opennetworkinglab.
the class YangWebResource method getModule.
/**
* Returns module registered with YANG runtime with given module
* identifier.
* If the operation is successful, the JSON presentation of the resource
* plus HTTP status code "200 OK" is returned. Otherwise,
* HTTP error status code "400 Bad Request" is returned.
*
* @param n for module name
* @param r for module revision
* @return HTTP response
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
@Path("/{name}@{revision}")
public String getModule(@PathParam("name") String n, @PathParam("revision") String r) {
modelRegistry = getService(YangModelRegistry.class);
YangModule m = modelRegistry.getModule(new DefaultYangModuleId(n, r));
if (m == null) {
return Response.status(NOT_FOUND).build().toString();
}
String x;
try {
x = IOUtils.toString(m.getYangSource(), StandardCharsets.UTF_8);
} catch (IOException e) {
log.error("ERROR: handleModuleGetRequest", e.getMessage());
log.debug("Exception in handleModuleGetRequest:", e);
return e.getMessage();
}
return x;
}
use of org.onosproject.yang.model.YangModule in project onos by opennetworkinglab.
the class YangModelsListCommand method json.
// Produces JSON structure.
private JsonNode json(YangModelRegistry service) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode result = mapper.createObjectNode();
for (YangModel model : service.getModels()) {
ArrayNode modelNode = mapper.createArrayNode();
result.set(model.getYangModelId(), modelNode);
for (YangModule module : model.getYangModules()) {
ObjectNode moduleNode = mapper.createObjectNode();
modelNode.add(moduleNode);
moduleNode.put(MODULE_NAME, module.getYangModuleId().moduleName());
moduleNode.put(MODULE_REVISION, module.getYangModuleId().revision());
}
}
return result;
}
Aggregations