Search in sources :

Example 1 with YangModule

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) YangModel(org.onosproject.yang.model.YangModel) YangModule(org.onosproject.yang.model.YangModule) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) YangModelRegistry(org.onosproject.yang.runtime.YangModelRegistry) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with YangModule

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;
}
Also used : YangModule(org.onosproject.yang.model.YangModule) DefaultYangModuleId(org.onosproject.yang.model.DefaultYangModuleId) IOException(java.io.IOException) YangModelRegistry(org.onosproject.yang.runtime.YangModelRegistry) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with YangModule

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) YangModel(org.onosproject.yang.model.YangModel) YangModule(org.onosproject.yang.model.YangModule) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

YangModule (org.onosproject.yang.model.YangModule)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 YangModel (org.onosproject.yang.model.YangModel)2 YangModelRegistry (org.onosproject.yang.runtime.YangModelRegistry)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 DefaultYangModuleId (org.onosproject.yang.model.DefaultYangModuleId)1