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();
}
}
Aggregations