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 boolean handleStateChangeEvent(AbstractNe ne, Map<String, String> values, CHANGE oper) throws Exception { String fromAid = values.get("AID1"); String[] aidMap = fromAid.split("-"); // Both equipment (STCHG-EQPT), and facility (STCHG-WAN, STCHG-OC192, ...) // state change reports are handle here. But we need to skip events that are // from the unsupported card like L2SS // Get the equipment type on this particular slot, assuming that it's a L2SS // if it's not, then continue // -------------- GGL2 ADDING L2SS SUPPORT; REMOVE THIS BELOW // ------------------ // Map<String, String> paramList = new HashMap<String, String>(); // paramList.put(ObjectElement.OPERATION_KEY, // Tl1CommandCode.RTRV_EQPT.toString()); // paramList.put("AID", "L2SS-1-" + aidMap[2]); // try // { // ArrayList<Map<String, String>> temp = new ArrayList<Map<String, // String>>(); // temp.add(new HashMap<String, String>()); // List<Map<String, String>> result = ((NetworkElement) // ne).getTl1Session().sendToNE(paramList); // if (result != null) // { // return false; // } // } // catch (Exception e) // { // } String command = values.get("COMMAND"); if (command.indexOf("STCHG-EQPT") >= 0) { // don't handle any thing, for now log.debug("Got the STCHG-EQPT report for " + fromAid); } else { log.debug("Handle state change " + command + " for " + fromAid); if (Facility.isWan(fromAid) && ne.slotIsL2SS(aidMap[1], aidMap[2])) { if (oper == CHANGE.DELETE) { try { DbNetworkElementFacility.INSTANCE.delete(ne, fromAid); // Do nothing (no event propagation please. The WAN is GONE). return false; } catch (Exception e) { log.error("Failed to delete " + fromAid + " from database.", e); } } // Choice to be made here: // // [1] // For L2SS, when a service tears down, a number of dbchg events are // emitted // from the backplane WAN associated with the L2SS service ... WANs that // were created 'on the fly' for the L2SS service. But by the time // the WAN events reach us here, the service is gone and the associated // WANs // deleted. This generates a few subsequent 'does not exist' TL1 errors // as // we try to retrieve the WAN in response to the events. // // [2] // But, if we want to support explicitly (user) provisioned // 'standalone' L2SS WANs // (which was a proposed scenario at Glif 2010), we'll want to ensure // full event handling for L2SS WANs. // // so: // - Keep event handling? ... then create a couple of TL1 retrieval // errors // - Silence TL1 errors? ... forego full support for standalone L2SS // WANs // else if (oper != CHANGE.ADD) // { // // Do nothing (avoid WAN RTRV errors). // return false; // } } // GGL2 if (fromAid.indexOf("VCE") >= 0 || fromAid.indexOf("VCS") >= 0) { // These entities are hidden from the user and application. Squelch // their events here. log.debug("Not processing event for " + fromAid); return false; } Map<String, String> aResult = getAndUpdateFacility(ne, Tl1CommandCode.fromString("RTRV_" + aidMap[0]), fromAid, oper); if (aResult != null) { getParameters().put(AbstractCommandlet.RESULT_KEY, dbchgEvent); return true; } } return false; }