use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.
the class DeviceMepWebResource method getAllMepsForDevice.
/**
* Get all MEPs by Device Id. The device should support Meps
*
* @param deviceId The id of a device.
* @return 200 OK with a list of MEPS or 500 on error
*/
@GET
@Path("{device_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getAllMepsForDevice(@PathParam("device_id") String deviceId) {
DeviceId deviceIdObj = DeviceId.deviceId(deviceId);
log.debug("GET all Meps called for Device {}", deviceIdObj);
try {
Collection<Mep> mepCollection = get(CfmMepService.class).getAllMepsByDevice(deviceIdObj);
ArrayNode an = mapper().createArrayNode();
an.add(codec(Mep.class).encode(mepCollection, this));
return ok(mapper().createObjectNode().set("meps", an)).build();
} catch (CfmConfigException e) {
log.error("Get all Meps on device {} failed because of exception", deviceIdObj, e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.
the class MepWebResource method createMep.
/**
* Create MEP with MD name, MA name and Mep Json.
*
* @onos.rsModel MepCreate
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @param input A JSON formatted input stream specifying the Mep parameters
* @return 201 Created or 304 if already exists or 500 on error
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, InputStream input) {
log.debug("POST called to Create Mep");
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MaintenanceAssociation ma = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId).orElseThrow(() -> new IllegalArgumentException("MA " + mdName + "/" + maName + " not Found"));
ObjectMapper mapper = new ObjectMapper();
JsonNode cfg = readTreeFromStream(mapper(), input);
JsonCodec<Mep> mepCodec = codec(Mep.class);
Mep mep = ((MepCodec) mepCodec).decode((ObjectNode) cfg, this, mdName, maName);
Boolean didNotExist = get(CfmMepService.class).createMep(mdId, maId, mep);
if (!didNotExist) {
return Response.notModified(mdName + "/" + ma.maId() + "/" + mep.mepId() + " already exists").build();
}
return Response.created(new URI("md/" + mdName + "/ma/" + ma.maId() + "/mep/" + mep.mepId())).entity("{ \"success\":\"mep " + mdName + "/" + ma.maId() + "/" + mep.mepId() + " created\" }").build();
} catch (Exception | CfmConfigException e) {
log.error("Create Mep on " + mdName + "/" + maName + " failed because of exception {}", e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.
the class MepWebResourceTest method testCreateMep.
@Test
public void testCreateMep() throws CfmConfigException, IOException {
MepId mepId2 = MepId.valueOf((short) 2);
Mep mep2 = DefaultMep.builder(mepId2, DeviceId.deviceId("netconf:2.2.3.4:830"), PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
MaintenanceAssociation ma1 = DefaultMaintenanceAssociation.builder(MANAME1, MDNAME1.getNameLength()).build();
expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
replay(mdService);
expect(mepService.createMep(MDNAME1, MANAME1, mep2)).andReturn(true).anyTimes();
replay(mepService);
ObjectMapper mapper = new ObjectMapper();
CfmCodecContext context = new CfmCodecContext();
ObjectNode node = mapper.createObjectNode();
node.set("mep", context.codec(Mep.class).encode(mep2, context));
final WebTarget wt = target();
final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep").request().post(Entity.json(node.toString()));
assertEquals("Expecting 201", 201, response.getStatus());
}
Aggregations