Search in sources :

Example 1 with YangModel

use of org.onosproject.yang.model.YangModel 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 YangModel

use of org.onosproject.yang.model.YangModel 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)

Example 3 with YangModel

use of org.onosproject.yang.model.YangModel in project onos by opennetworkinglab.

the class YangWebResource method getModels.

/**
 * Returns all models registered with YANG runtime. 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 YangModelsGet
 * @return HTTP response
 */
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getModels() {
    modelRegistry = getService(YangModelRegistry.class);
    ObjectNode result = mapper().createObjectNode();
    Set<YangModel> models = modelRegistry.getModels();
    ArrayNode ids = result.putArray("model_ids");
    for (YangModel m : models) {
        ids.add(m.getYangModelId());
    }
    return Response.ok(result.toString()).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) YangModel(org.onosproject.yang.model.YangModel) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) YangModelRegistry(org.onosproject.yang.runtime.YangModelRegistry) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

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