Search in sources :

Example 41 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException 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();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 42 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException 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();
    }
}
Also used : MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 43 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.

the class MdWebResource method createMaintenanceDomain.

/**
 * Create Maintenance Domain.
 *
 * @onos.rsModel MdCreate
 * @param input A JSON formatted input stream specifying the MA parameters
 * @return 200 OK, 304 if MD already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMaintenanceDomain(InputStream input) {
    log.debug("POST called to Create MD");
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper, input);
        MaintenanceDomain md = codec(MaintenanceDomain.class).decode((ObjectNode) cfg, this);
        if (get(CfmMdService.class).createMaintenanceDomain(md)) {
            return Response.notModified(md.mdId().toString() + " already exists").build();
        }
        return Response.created(new URI("md/" + md.mdId())).entity("{ \"success\":\"" + md.mdId() + " created\" }").build();
    } catch (Exception | CfmConfigException e) {
        log.error("Create MaintenanceDomain", e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) JsonNode(com.fasterxml.jackson.databind.JsonNode) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) URI(java.net.URI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 44 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException 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();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 45 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.

the class MepWebResource method getMep.

/**
 * Get MEP by MD name, MA name and Mep Id.
 *
 * @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
 * @return 200 OK with details of the MEP or 500 on error
 */
@GET
@Path("{mep_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId) {
    log.debug("GET called for MEP {}", mdName + "/" + maName + "/" + mepId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepEntry mepEntry = get(CfmMepService.class).getMep(mdId, maId, MepId.valueOf(mepId));
        if (mepEntry == null) {
            return Response.serverError().entity("{ \"failure\":\"MEP " + mdName + "/" + maName + "/" + mepId + " not found\" }").build();
        }
        ObjectNode node = mapper().createObjectNode();
        node.set("mep", codec(MepEntry.class).encode(mepEntry, this));
        return ok(node).build();
    } catch (CfmConfigException e) {
        log.error("Get Mep {} failed because of exception", mdName + "/" + maName + "/" + mepId, e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Aggregations

CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)50 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)27 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)23 Consumes (javax.ws.rs.Consumes)22 Produces (javax.ws.rs.Produces)22 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)17 Path (javax.ws.rs.Path)14 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)14 CfmMdService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)13 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)12 DeviceId (org.onosproject.net.DeviceId)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)10 MepEntry (org.onosproject.incubator.net.l2monitoring.cfm.MepEntry)9 CfmMepProgrammable (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 GET (javax.ws.rs.GET)7 MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)7 MepKeyId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)7 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)6