Search in sources :

Example 1 with LossMeasurementCreate

use of org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate in project onos by opennetworkinglab.

the class LmWebResource method createLm.

/**
 * Create LM with MD name, MA name, Mep id and LM Json.
 *
 * @onos.rsModel LmCreate
 * @param mdName The name of a Maintenance Domain
 * @param maName The name of a Maintenance Association belonging to the MD
 * @param mepId The Id of the MEP belonging to the MEP
 * @param input A JSON formatted input stream specifying the LM parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createLm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, InputStream input) {
    log.debug("POST called to Create Lm");
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        Mep mep = get(CfmMepService.class).getMep(mdId, maId, mepIdObj);
        if (mep == null) {
            return Response.serverError().entity("{ \"failure\":\"mep " + mdName + "/" + maName + "/" + mepId + " does not exist\" }").build();
        }
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper, input);
        JsonCodec<LossMeasurementCreate> lmCodec = codec(LossMeasurementCreate.class);
        LossMeasurementCreate lm = lmCodec.decode((ObjectNode) cfg, this);
        get(SoamService.class).createLm(mdId, maId, mepIdObj, lm);
        return Response.created(new URI("md/" + mdName + "/ma/" + maName + "/mep/" + mepId + "/lm")).entity("{ \"success\":\"lm " + mdName + "/" + maName + "/" + mepId + " created\" }").build();
    } catch (CfmConfigException | SoamConfigException | IllegalArgumentException | IOException | URISyntaxException e) {
        log.error("Create LM on " + mdName + "/" + maName + "/" + mepId + " failed because of exception {}", e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) LossMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)1 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)1 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)1 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)1 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)1 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)1 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)1 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)1 LossMeasurementCreate (org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate)1