private boolean updateFacilityAttribute( AbstractNe ne, Map<String, String> aResult, String aid, CHANGE oper) throws Exception { /* * TODO: Much of the logic here is a duplicate of what has to be done on * retrievals, in GetAllEthWanFacility. There should be one copy of this * processing code called from both retrievals and dbchg events. */ Map<String, String> facilityMap = null; int layer = 1; String layerStr; Element newFacElem = null; String changedFac = null; Map<String, String> currentNeAttrValue = new HashMap<String, String>(); if (Facility.isWan(aid)) { // If the WAN is a standalone, it is / will be explicitly stored in the // db. // If it's part of an EthWan EPL port, it'll be the ETH in our db. // Therefore, do the lookup based on shelf/slot/port // Note: For Eth/Wan EPL-like facility pairs, we rely on the ETH being // processed // ahead of the Wan. boolean wanIntoEthMapping = false; Element changedElement = null; String[] aidArr = aid.split("-"); changedFac = DbUtility.INSTANCE.retrieveAFacility(ne, aidArr[1], aidArr[2], aidArr[3]); if (changedFac != null) { changedElement = DbOpsHelper.xmlToElement(changedFac); String type = changedElement.getAttributeValue(FacilityConstants.TYPE_ATTR); if (Facility.isEth(type)) { wanIntoEthMapping = true; } } if (wanIntoEthMapping) { // A WAN that belongs to an Eth/Wan EPL port // Flip input "WAN" aid to found facility "ETHxxx" aid aid = changedElement.getAttributeValue(AbstractFacilityXml.AID_ATTR); layer = 2; layerStr = AbstractFacilityXml.LAYER2_ELEMENT; newFacElem = new Element(layerStr); facilityMap = OmeFacilityXML.wanToEthEPLNeToXmlMapping; // DRAC FLAG: to indicate this ETH is actually a WAN-backed ETH (see // GetAllEthWanFacility) newFacElem.setAttribute(FacilityConstants.IS_EPL, "true"); currentNeAttrValue.put(FacilityConstants.IS_EPL, "true"); } else { // Standalone WAN // WAN as Layer2 selectable UNI layer = 2; layerStr = AbstractFacilityXml.LAYER2_ELEMENT; newFacElem = new Element(layerStr); facilityMap = OmeFacilityXML.wanNeToXmlMapping; } } else if (Facility.isEth(aid)) { layer = 2; layerStr = AbstractFacilityXml.LAYER2_ELEMENT; newFacElem = new Element(layerStr); facilityMap = OmeFacilityXML.ethNeToXmlMapping; // Nov.1, 2010 // At the time of writing, the OME R7 load was not emitting a dbchange // report // for FE (ETH100) in such a way that the primary state could be parsed. // The ETH100 would only appear on toggling association (thereby learning // of // of the ETH100 via retrievals. // TEMPORARY FIX: assume worst case 'OOS' if (aid.startsWith("ETH100") && oper == CHANGE.ADD) { newFacElem.setAttribute(FacilityConstants.PRISTATE_ATTR, "OOS"); } } else { layer = 1; layerStr = AbstractFacilityXml.LAYER1_ELEMENT; newFacElem = new Element(layerStr); facilityMap = OmeFacilityXML.commonNeToXmlMapping; } // DRAC FLAG: for L2SS-based facilities String[] aidArr = aid.split("-"); if (ne.slotIsL2SS(aidArr[1], aidArr[2])) { newFacElem.setAttribute(FacilityConstants.IS_L2SS_FACILITY, "true"); currentNeAttrValue.put(FacilityConstants.IS_L2SS_FACILITY, "true"); } // Build the list of XML attributes based on the NE key/value. Iterator<String> keyIr = facilityMap.keySet().iterator(); while (keyIr.hasNext()) { String neKey = keyIr.next(); String xmlKey = facilityMap.get(neKey); String aValue = aResult.get(neKey); if (aValue != null) { if (aid.indexOf("ETH10G") >= 0 && xmlKey.equals(AbstractFacilityXml.SPEED_ATTR)) { // Only one value is reported: always 10G. Normalize to Mb/s ... aValue = "10000"; } currentNeAttrValue.put(xmlKey, aValue); newFacElem.setAttribute(xmlKey, aValue); } } if (changedFac == null) { changedFac = DbUtility.INSTANCE.retrieveAFacility(ne, aid); } XMLOutputter outXml = new XMLOutputter(Format.getCompactFormat()); if (changedFac == null) { // Create new entry and setup the data for the event as well HashMap<String, String> eventData = new HashMap<String, String>(); eventData.put(AbstractFacilityXml.AID_ATTR, aid); eventData.put("operation", CHANGE.ADD.asString()); eventData.put(AbstractFacilityXml.ID_ATTR, Integer.toString(layer)); newFacElem.setAttribute(AbstractFacilityXml.VALID_ATTR, "true"); newFacElem.setAttribute(AbstractFacilityXml.ID_ATTR, Integer.toString(layer)); newFacElem.setAttribute(AbstractFacilityXml.AID_ATTR, aid); List<Attribute> staticAttr = OmeFacilityXML.getStaticAttributes(); for (int i = 0; i < staticAttr.size(); i++) { Attribute anAttr = staticAttr.get(i); if (newFacElem.getAttributeValue(anAttr.getName()) == null) { newFacElem.setAttribute(anAttr.getName(), anAttr.getValue()); } eventData.put(anAttr.getName(), anAttr.getValue()); } String[] aidMap = aid.split("-"); eventData.put(AbstractFacilityXml.PORT_ATTR, aidMap[3]); eventData.put(AbstractFacilityXml.SHELF_ATTR, aidMap[1]); eventData.put(AbstractFacilityXml.SLOT_ATTR, aidMap[2]); eventData.put(AbstractFacilityXml.TYPE_ATTR, aidMap[0]); newFacElem.setAttribute(AbstractFacilityXml.PORT_ATTR, aidMap[3]); newFacElem.setAttribute(AbstractFacilityXml.SHELF_ATTR, aidMap[1]); newFacElem.setAttribute(AbstractFacilityXml.SLOT_ATTR, aidMap[2]); newFacElem.setAttribute(AbstractFacilityXml.TYPE_ATTR, aidMap[0]); // PREPARE THE EVENT FOR LPCP_PORT dbchgEvent.addDataElement(eventData); dbchgEvent.addDataElement(currentNeAttrValue); String newFacStr = outXml.outputString(newFacElem); if (oper == CHANGE.ADD) { log.debug("Create new Facility: " + newFacStr); DbUtility.INSTANCE.addNewFacility(ne, newFacStr); } } else { OmeFacilityXML changedFacXML = new OmeFacilityXML(changedFac); Map<String, String> updateList = changedFacXML.updateFacilityAttr(aid, currentNeAttrValue); if (updateList != null || oper != CHANGE.MODIFY) { // If there are no changes and the operation is ADD or DELETE, then // we still want to update the Valid field accordingly if (updateList == null) { updateList = new HashMap<String, String>(); } if (oper == CHANGE.ADD) { updateList.put(AbstractFacilityXml.VALID_ATTR, "true"); } else if (oper == CHANGE.DELETE) { updateList.put(AbstractFacilityXml.VALID_ATTR, "false"); } updateList.put(AbstractFacilityXml.AID_ATTR, aid); updateList.put("operation", oper.asString()); dbchgEvent.addDataElement(updateList); // // DbUtility.INSTANCE.updateAFacility(ne, updateList, aid); // Add missing attributes here. This will be the case when an // an Eth/Wan pair enrol; when the Wan enrols, its attributes of // interest will be added to its associated Eth: boolean addNewAttributes = true; DbUtility.INSTANCE.updateAFacility(ne, updateList, aid, addNewAttributes); } else { return false; } } return true; }
private void checkForEplWanDbChange( AbstractNe ne, Tl1CommandCode mod, String wanType, String ethType, String shelf, String slot, String port) { // ethType can vary: ETH, ETH10G, ETH100, etc. String wanAid = wanType + "-" + shelf + "-" + slot + "-" + port; String ethAid = ethType + "-" + shelf + "-" + slot + "-" + port; log.debug("Checking for change in DB due to Connection event: aid: " + wanAid); Map<String, String> paramList = new HashMap<String, String>(); paramList.put(ObjectElement.OPERATION_KEY, mod.toString()); paramList.put("AID", wanAid); try { ArrayList<Map<String, String>> temp = new ArrayList<Map<String, String>>(); temp.add(new HashMap<String, String>()); List<Map<String, String>> wanResult = ((NetworkElement) ne).getTl1Session().sendToNE(paramList); if (wanResult != null) { Map<String, String> aWanResult = wanResult.get(0); String ethEplFac = DbUtility.INSTANCE.retrieveAFacility(ne, shelf, slot, port); if (ethEplFac == null) { return; } OmeFacilityXML eplFacXML = new OmeFacilityXML(ethEplFac); // Build the list of EPL WAN->ETH*** XML attributes based on the NE // key/value. Map<String, String> currentNeAttrValue = new HashMap<String, String>(); Iterator<String> keyIr = OmeFacilityXML.wanToEthEPLNeToXmlMapping.keySet().iterator(); while (keyIr.hasNext()) { String neKey = keyIr.next(); String xmlKey = OmeFacilityXML.wanToEthEPLNeToXmlMapping.get(neKey); String aValue = aWanResult.get(neKey); if (aValue != null) { currentNeAttrValue.put(xmlKey, aValue); } } Map<String, String> updateList = eplFacXML.updateFacilityAttr(ethAid, currentNeAttrValue); if (updateList != null) { // TODO: The WAN event from here up to LPCP_PORT should be screened // first... // to evaluate whether or not the updated attributes are of interest // to LPCP_PORT. WAN attributes of interest currently are: // - VCAT // - Basic Rate (?) log.debug("Facility's attr to update in checkForDbChange:" + updateList); DbUtility.INSTANCE.updateAFacility(ne, updateList, ethAid); updateList.put("operation", "modify"); updateList.put("aid", ethAid); Tl1XmlDbChangeEvent additionalEvent = new Tl1XmlDbChangeEvent(ne); additionalEvent.setOccurrentDate(dbchgEvent.getOccurrentDate()); additionalEvent.setOccurrentTime(dbchgEvent.getOccurrentTime()); additionalEvent.setEventId(ne.getNeId() + "_" + System.currentTimeMillis()); additionalEvent.setOwnerId(ne.getTerminalId()); additionalEvent.setNotificationType("facility"); additionalEvent.updateDescription("PROXY_GEN"); additionalEvent.addDataElement(updateList); getParameters().put(AbstractCommandlet.ADDITIONALEVENT_KEY, additionalEvent); } else { } } else { log.error("Got empty result from querying new state of " + wanAid + " from NE"); } } catch (Exception e) { log.error("Failed to perform " + mod + " from " + ne.getNeName(), e); } }