use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException 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.service.CfmConfigException in project onos by opennetworkinglab.
the class MaintenanceAssociationCodec method decode.
/**
* Decodes the MaintenanceAssociation entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @param mdNameLen the length of the corresponding MD's name
* @return decoded MaintenanceAssociation
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
public MaintenanceAssociation decode(ObjectNode json, CodecContext context, int mdNameLen) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode maNode = json.get(MA);
String maName = nullIsIllegal(maNode.get(MA_NAME), "maName is required").asText();
String maNameType = MaIdShort.MaIdType.CHARACTERSTRING.name();
if (maNode.get(MA_NAME_TYPE) != null) {
maNameType = maNode.get(MA_NAME_TYPE).asText();
}
try {
MaIdShort maId = MdMaNameUtil.parseMaName(maNameType, maName);
MaBuilder builder = DefaultMaintenanceAssociation.builder(maId, mdNameLen);
JsonNode maNumericIdNode = maNode.get(MA_NUMERIC_ID);
if (maNumericIdNode != null) {
short mdNumericId = (short) maNumericIdNode.asInt();
builder = builder.maNumericId(mdNumericId);
}
if (maNode.get(CCM_INTERVAL) != null) {
builder.ccmInterval(CcmInterval.valueOf(maNode.get(CCM_INTERVAL).asText()));
}
List<Component> componentList = (new ComponentCodec()).decode((ArrayNode) nullIsIllegal(maNode.get(COMPONENT_LIST), "component-list is required"), context);
for (Component component : componentList) {
builder = builder.addToComponentList(component);
}
JsonNode rmepListJson = maNode.get(RMEP_LIST);
if (rmepListJson != null) {
List<MepId> remoteMeps = (new RMepCodec()).decode((ArrayNode) rmepListJson, context);
for (MepId remoteMep : remoteMeps) {
builder = builder.addToRemoteMepIdList(remoteMep);
}
}
return builder.build();
} catch (CfmConfigException e) {
throw new IllegalArgumentException(e);
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException 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);
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.
the class MepCodec method decode.
/**
* Decodes the Mep entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @param mdName The MD name
* @param maName The MA name
* @return decoded Mep
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
public Mep decode(ObjectNode json, CodecContext context, String mdName, String maName) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode mepNode = json.get("mep");
int mepId = Integer.parseInt(nullIsIllegal(mepNode.get("mepId"), "mepId is required").asText());
DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(mepNode.get("deviceId"), "deviceId is required").asText());
PortNumber port = PortNumber.portNumber(Long.parseLong(nullIsIllegal(mepNode.get("port"), "port is required").asText()));
MepDirection direction = MepDirection.valueOf(nullIsIllegal(mepNode.get("direction"), "direction is required").asText());
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MepBuilder mepBuilder = DefaultMep.builder(MepId.valueOf((short) mepId), deviceId, port, direction, mdId, maId);
if (mepNode.get(PRIMARY_VID) != null) {
mepBuilder.primaryVid(VlanId.vlanId((short) mepNode.get(PRIMARY_VID).asInt(0)));
}
if (mepNode.get(ADMINISTRATIVE_STATE) != null) {
mepBuilder.administrativeState(mepNode.get(ADMINISTRATIVE_STATE).asBoolean());
}
if (mepNode.get(CCM_LTM_PRIORITY) != null) {
mepBuilder.ccmLtmPriority(Priority.values()[mepNode.get(CCM_LTM_PRIORITY).asInt(0)]);
}
if (mepNode.get(CCI_ENABLED) != null) {
mepBuilder.cciEnabled(mepNode.get(CCI_ENABLED).asBoolean());
}
if (mepNode.get(LOWEST_FAULT_PRIORITY_DEFECT) != null) {
mepBuilder.lowestFaultPriorityDefect(Mep.LowestFaultDefect.values()[mepNode.get(LOWEST_FAULT_PRIORITY_DEFECT).asInt()]);
}
if (mepNode.get(DEFECT_ABSENT_TIME) != null) {
mepBuilder.defectAbsentTime(Duration.parse(mepNode.get(DEFECT_ABSENT_TIME).asText()));
}
if (mepNode.get(DEFECT_PRESENT_TIME) != null) {
mepBuilder.defectPresentTime(Duration.parse(mepNode.get(DEFECT_PRESENT_TIME).asText()));
}
if (mepNode.get(FNG_ADDRESS) != null) {
mepBuilder.fngAddress((new FngAddressCodec()).decode((ObjectNode) mepNode, context));
}
return mepBuilder.build();
} catch (CfmConfigException e) {
throw new IllegalArgumentException(e);
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.
the class CfmMepListCommand method doExecute.
@Override
protected void doExecute() {
CfmMepService mepService = get(CfmMepService.class);
CfmMdService mdService = get(CfmMdService.class);
if (mdStr != null && !mdStr.isEmpty()) {
MdId mdId = parseMdName(mdStr);
print(printMdId(mdId));
if (maStr != null && !maStr.isEmpty()) {
MaIdShort maId = parseMaName(maStr);
print(printMaId(maId));
if (mepStr != null && !mepStr.isEmpty()) {
MepId mepId = MepId.valueOf(Short.parseShort(mepStr));
try {
MepEntry mep = mepService.getMep(mdId, maId, mepId);
if (mep != null) {
print(printMepEntry(mep));
}
} catch (CfmConfigException e) {
log.error("Error retrieving Mep details {}", new MepKeyId(mdId, maId, mepId), e);
}
// MD, MA and MEP given
} else {
// MD and MA given but no MEP given
try {
mepService.getAllMeps(mdId, maId).forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}", mdId.mdName(), maId.maName(), e);
}
}
} else {
// MD given but no MA given
mdService.getAllMaintenanceAssociation(mdId).forEach(ma -> {
print(printMaId(ma.maId()));
try {
mepService.getAllMeps(mdId, ma.maId()).forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}", mdId.mdName(), ma.maId().maName(), e);
}
});
}
} else {
mdService.getAllMaintenanceDomain().forEach(md -> {
print(printMdId(md.mdId()));
mdService.getAllMaintenanceAssociation(md.mdId()).forEach(ma -> {
print(printMaId(ma.maId()));
try {
mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}", md.mdId().mdName(), ma.maId().maName(), e);
}
});
});
}
}
Aggregations