Search in sources :

Example 16 with MaIdShort

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort in project onos by opennetworkinglab.

the class DmWebResource method createDm.

/**
 * Create DM with MD name, MA name, Mep id and DM Json.
 *
 * @onos.rsModel DmCreate
 * @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 DM parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createDm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, InputStream input) {
    log.debug("POST called to Create Dm");
    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<DelayMeasurementCreate> dmCodec = codec(DelayMeasurementCreate.class);
        DelayMeasurementCreate dm = dmCodec.decode((ObjectNode) cfg, this);
        get(SoamService.class).createDm(mdId, maId, mepIdObj, dm);
        return Response.created(new URI("md/" + mdName + "/ma/" + maName + "/mep/" + mepId + "/dm")).entity("{ \"success\":\"dm " + mdName + "/" + maName + "/" + mepId + " created\" }").build();
    } catch (CfmConfigException | SoamConfigException | IllegalArgumentException | IOException | URISyntaxException e) {
        log.error("Create DM 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) DelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate) 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)

Example 17 with MaIdShort

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort in project onos by opennetworkinglab.

the class DmWebResource method abortDm.

/**
 * Abort DM by MD name, MA name, Mep Id and DM Id.
 * In the API the measurement is aborted, and not truly deleted. It still
 * remains so that its results may be read. Depending on the device it will
 * get overwritten on the creation of subsequent measurements.
 * Use clear stats to delete old results
 * measurements.
 *
 * @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
 * @param dmId The Id of the DM
 * @return 200 OK or 304 if not found, or 500 on error
 */
@DELETE
@Path("{dm_id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response abortDm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, @PathParam("dm_id") int dmId) {
    log.debug("DELETE called for DM {}", mdName + "/" + maName + "/" + mepId + "/" + dmId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        SoamId dmIdObj = SoamId.valueOf(dmId);
        get(SoamService.class).abortDm(mdId, maId, mepIdObj, dmIdObj);
        return ok("{ \"success\":\"deleted (aborted) " + mdName + "/" + maName + "/" + mepId + "/" + dmId + "\" }").build();
    } catch (CfmConfigException e) {
        log.error("Delete (abort) DM {} failed because of exception {}", mdName + "/" + maName + "/" + mepId + "/" + dmId, e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) 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) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) SoamId(org.onosproject.incubator.net.l2monitoring.soam.SoamId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 18 with MaIdShort

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort in project onos by opennetworkinglab.

the class LmWebResource method clearLmHistory.

/**
 * Clear LM history stats by MD name, MA name, Mep Id and LM 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
 * @param lmId The Id of the LM
 * @return 200 OK or 304 if not found, or 500 on error
 */
@PUT
@Path("{lm_id}/clear-history")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response clearLmHistory(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, @PathParam("lm_id") int lmId) {
    log.debug("clear-history called for LM {}", mdName + "/" + maName + "/" + mepId + "/" + lmId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        SoamId lmIdObj = SoamId.valueOf(lmId);
        get(SoamService.class).clearDelayHistoryStats(mdId, maId, mepIdObj, lmIdObj);
        return ok("{ \"success\":\"cleared LM history stats for " + mdName + "/" + maName + "/" + mepId + "/" + lmId + "\" }").build();
    } catch (CfmConfigException e) {
        log.error("Clear history stats for LM {} failed because of exception {}", mdName + "/" + maName + "/" + mepId + "/" + lmId, e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) 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) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) SoamId(org.onosproject.incubator.net.l2monitoring.soam.SoamId) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 19 with MaIdShort

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort in project onos by opennetworkinglab.

the class LmWebResource method abortLm.

/**
 * Abort LM by MD name, MA name, Mep Id and LM Id.
 * In the API the measurement is aborted, and not truly deleted. It still
 * remains so that its results may be read. Depending on the device it will
 * get overwritten on the creation of subsequent measurements.
 * Use clear stats to delete old results measurements.
 *
 * @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
 * @param lmId The Id of the LM
 * @return 200 OK or 304 if not found, or 500 on error
 */
@DELETE
@Path("{lm_id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response abortLm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, @PathParam("lm_id") int lmId) {
    log.debug("DELETE called for LM {}", mdName + "/" + maName + "/" + mepId + "/" + lmId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        SoamId lmIdObj = SoamId.valueOf(lmId);
        get(SoamService.class).abortLm(mdId, maId, mepIdObj, lmIdObj);
        return ok("{ \"success\":\"deleted (aborted) " + mdName + "/" + maName + "/" + mepId + "/" + lmId + "\" }").build();
    } catch (CfmConfigException e) {
        log.error("Delete (abort) LM {} failed because of exception {}", mdName + "/" + maName + "/" + mepId + "/" + lmId, e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) 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) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) SoamId(org.onosproject.incubator.net.l2monitoring.soam.SoamId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 20 with MaIdShort

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort 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();
    }
}
Also used : 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) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Aggregations

MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)26 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)23 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)23 Consumes (javax.ws.rs.Consumes)19 Produces (javax.ws.rs.Produces)19 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)15 Path (javax.ws.rs.Path)13 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)10 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 GET (javax.ws.rs.GET)7 CfmMdService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)7 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)6 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)6 SoamId (org.onosproject.incubator.net.l2monitoring.soam.SoamId)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 PUT (javax.ws.rs.PUT)5 DELETE (javax.ws.rs.DELETE)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3