Search in sources :

Example 11 with MaintenanceDomain

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

the class MdWebResource method getMd.

/**
 * Get Maintenance Domain by name.
 *
 * @param mdName The name of a Maintenance Domain
 * @return 200 OK with the details of the MD and its children or 500 on error
 */
@GET
@Path("{md_name}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getMd(@PathParam("md_name") String mdName) {
    log.debug("GET called for MD {}", mdName);
    try {
        MaintenanceDomain md = get(CfmMdService.class).getMaintenanceDomain(MdIdCharStr.asMdId(mdName)).orElseThrow(() -> new IllegalArgumentException("MD " + mdName + " not Found"));
        ObjectNode result = mapper().createObjectNode();
        result.set("md", codec(MaintenanceDomain.class).encode(md, this));
        return ok(result.toString()).build();
    } catch (IllegalArgumentException e) {
        log.error("Get MD {} failed", mdName, e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 12 with MaintenanceDomain

use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain 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 13 with MaintenanceDomain

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

the class MdWebResource method getMds.

/**
 * Get all Maintenance Domains.
 *
 * @return 200 OK with a list of MDs and their children
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getMds() {
    log.debug("GET called for all MDs");
    Collection<MaintenanceDomain> mdMap = get(CfmMdService.class).getAllMaintenanceDomain();
    ArrayNode arrayNode = mapper().createArrayNode();
    arrayNode.add(codec(MaintenanceDomain.class).encode(mdMap, this));
    return ok(mapper().createObjectNode().set("mds", arrayNode)).build();
}
Also used : MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 14 with MaintenanceDomain

use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain 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 15 with MaintenanceDomain

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

the class MaintenanceDomainCodec method decode.

/**
 * Decodes the MaintenanceDomain entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @return decoded MaintenanceDomain
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
@Override
public MaintenanceDomain decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode mdNode = json.get(MD);
    String mdName = nullIsIllegal(mdNode.get(MD_NAME), "mdName is required").asText();
    String mdNameType = MdId.MdNameType.CHARACTERSTRING.name();
    if (mdNode.get(MD_NAME_TYPE) != null) {
        mdNameType = mdNode.get(MD_NAME_TYPE).asText();
    }
    try {
        MdId mdId = MdMaNameUtil.parseMdName(mdNameType, mdName);
        MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain.builder(mdId);
        JsonNode mdLevelNode = mdNode.get(MD_LEVEL);
        if (mdLevelNode != null) {
            MdLevel mdLevel = MdLevel.valueOf(mdLevelNode.asText());
            builder = builder.mdLevel(mdLevel);
        }
        JsonNode mdNumericIdNode = mdNode.get(MD_NUMERIC_ID);
        if (mdNumericIdNode != null) {
            short mdNumericId = (short) mdNumericIdNode.asInt();
            builder = builder.mdNumericId(mdNumericId);
        }
        return builder.build();
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) JsonNode(com.fasterxml.jackson.databind.JsonNode) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MdLevel(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain.MdLevel)

Aggregations

MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)25 DefaultMaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain)18 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)6 CfmMdService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5 DefaultMaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation)5 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)5 Path (javax.ws.rs.Path)4 CfmCodecContext (org.onosproject.cfm.CfmCodecContext)4 PUT (javax.ws.rs.PUT)3