use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId in project onos by opennetworkinglab.
the class CfmMdAddCommand method doExecute.
@Override
protected void doExecute() {
CfmMdService service = get(CfmMdService.class);
MdId mdId = CfmMdListMdCommand.parseMdName(name + "(" + nameType + ")");
MaintenanceDomain.MdLevel levelEnum = MaintenanceDomain.MdLevel.valueOf(level);
try {
MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain.builder(mdId).mdLevel(levelEnum);
if (numericId != null) {
builder = builder.mdNumericId(numericId);
}
boolean created = service.createMaintenanceDomain(builder.build());
print("Maintenance Domain with id %s is successfully %s.", mdId, created ? "updated" : "created");
} catch (CfmConfigException e) {
throw new IllegalArgumentException(e);
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId in project onos by opennetworkinglab.
the class MaWebResource method getMa.
/**
* Get Maintenance Association by MD and MA name.
*
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @return 200 OK with details of MA or 500 on Error
*/
@GET
@Path("{ma_name}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getMa(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName) {
log.debug("GET called for MA {}/{}", mdName, maName);
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MaintenanceAssociation ma = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId).orElseThrow(() -> new IllegalArgumentException("MA " + maName + " not Found"));
ObjectNode node = mapper().createObjectNode();
node.set("ma", codec(MaintenanceAssociation.class).encode(ma, this));
return ok(node).build();
} catch (IllegalArgumentException e) {
log.error("Get MA {} failed", mdName + "/" + maName, e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId in project onos by opennetworkinglab.
the class MaWebResource method createMaintenanceAssociation.
/**
* Create Maintenance Association by MD and MA name.
*
* @onos.rsModel MaCreate
* @param mdName The name of a Maintenance Domain
* @param input A JSON formatted input stream specifying the MA parameters
* @return 200 OK or 500 on error
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMaintenanceAssociation(@PathParam("md_name") String mdName, InputStream input) {
log.debug("POST called to Create MA");
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
Optional<MaintenanceDomain> md = get(CfmMdService.class).getMaintenanceDomain(mdId);
if (!md.isPresent()) {
return Response.serverError().entity("{ \"failure\":\"md " + mdName + " does not exist\" }").build();
}
ObjectMapper mapper = new ObjectMapper();
JsonNode cfg = readTreeFromStream(mapper, input);
JsonCodec<MaintenanceAssociation> maCodec = codec(MaintenanceAssociation.class);
MaintenanceAssociation ma;
try {
ma = ((MaintenanceAssociationCodec) maCodec).decode((ObjectNode) cfg, this, mdId.getNameLength());
} catch (Exception e) {
log.error("Create MaintenanceAssociation on MD {} failed", mdName, e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
Boolean alreadyExists = get(CfmMdService.class).createMaintenanceAssociation(mdId, ma);
if (alreadyExists) {
return Response.notModified(mdName + "/" + ma.maId() + " already exists").build();
}
return Response.created(new URI("md/" + mdName + "/ma/" + ma.maId())).entity("{ \"success\":\"" + mdName + "/" + ma.maId() + " created\" }").build();
} catch (Exception | CfmConfigException e) {
log.error("Create MaintenanceAssociation on MD {} failed", mdName, e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId in project onos by opennetworkinglab.
the class MdWebResource method deleteMd.
/**
* Delete Maintenance Domain by name.
*
* @param mdName The name of a Maintenance Domain
* @return 200 OK, or 304 if not found or 500 on error
*/
@DELETE
@Path("{md_name}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteMd(@PathParam("md_name") String mdName) {
log.debug("DELETE called for MD {}", mdName);
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
boolean deleted = get(CfmMdService.class).deleteMaintenanceDomain(mdId);
if (!deleted) {
return Response.notModified(mdName + " did not exist").build();
} else {
return ok("{ \"success\":\"deleted " + mdName + "\" }").build();
}
} catch (CfmConfigException e) {
log.error("Delete Maintenance Domain {} failed", mdName, e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId in project onos by opennetworkinglab.
the class MepWebResource method transmitLinktrace.
/**
* Transmit Linktrace on MEP with MD name, MA name and Mep Id.
*
* @onos.rsModel MepLtTransmit
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @param mepIdShort The id of a MEP belonging to the MA
* @param input A JSON formatted input stream specifying the Linktrace parameters
* @return 202 Received with success message or 500 on error
*/
@PUT
@Path("{mep_id}/transmit-linktrace")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transmitLinktrace(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort, InputStream input) {
log.debug("PUT called to Transmit Linktrace on Mep");
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MaintenanceDomain md;
Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
if (mdOpt.isPresent()) {
md = mdOpt.get();
} else {
return Response.serverError().entity("{ \"failure\":\"" + mdName + " does not exist\" }").build();
}
MaintenanceAssociation ma;
Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId);
if (maOpt.isPresent()) {
ma = maOpt.get();
} else {
return Response.serverError().entity("{ \"failure\":\"" + maName + " does not exist\" }").build();
}
MepId mepId = MepId.valueOf(mepIdShort);
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode cfg = readTreeFromStream(mapper, input);
JsonCodec<MepLtCreate> mepLtCreateCodec = codec(MepLtCreate.class);
MepLtCreate ltCreate = mepLtCreateCodec.decode((ObjectNode) cfg, this);
get(CfmMepService.class).transmitLinktrace(md.mdId(), ma.maId(), mepId, ltCreate);
} catch (Exception | CfmConfigException e) {
log.error("Transmit Linktrace on " + mdName + "/" + maName + "/{} failed", String.valueOf(mepIdShort), e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
return Response.accepted().entity("{ \"success\":\"Linktrace on MEP " + mdName + "/" + ma.maId() + "/" + mepId.id() + " started\" }").build();
}
Aggregations