Exemplo n.º 1
0
  private boolean handleProtectionChangeEvent(
      AbstractNe ne, Map<String, String> values, CHANGE oper) {
    try {
      String workingAid = values.get("AID1");
      String protectionAid = values.get("AID2");
      NetworkElement omeNe = (NetworkElement) ne;

      // Set up the data for event
      HashMap<String, String> eventData = new HashMap<String, String>();
      eventData.put("workingAid", workingAid);
      eventData.put("proctectingAid", protectionAid);
      eventData.put("operation", oper.asString());
      dbchgEvent.addDataElement(eventData);
      getParameters().put(AbstractCommandlet.RESULT_KEY, dbchgEvent);
      // String command = values.get("COMMAND");
      if (oper == CHANGE.DELETE) {
        // don't handle any thing, for now
        log.debug("Got the DLT-FFP report for " + workingAid + ":" + protectionAid);

        DbUtility.INSTANCE.updateOrAddFacilityAttr(
            ne, workingAid, AbstractFacilityXml.PROTECTIONSCHEME_ATTR, "N/A");
        DbUtility.INSTANCE.updateOrAddFacilityAttr(
            ne, protectionAid, AbstractFacilityXml.PROTECTIONSCHEME_ATTR, "N/A");
        omeNe.getProtectionAid().remove(workingAid);
        omeNe.getProtectionAid().remove(protectionAid);
        eventData.put(AbstractFacilityXml.PROTECTIONSCHEME_ATTR, "N/A");
        return true;
      }
      log.debug("Got the ENT-FFP report for " + workingAid + ":" + protectionAid);
      String[] aidMap = workingAid.split("-");
      Map<String, String> paramList = new HashMap<String, String>();
      paramList.put(ObjectElement.OPERATION_KEY, "RTRV-FFP-" + aidMap[0]);
      paramList.put("WRKGAID", aidMap[0] + "-1-ALL");

      List<Map<String, String>> result = omeNe.getTl1Session().sendToNE(paramList);
      if (result != null) {
        Iterator<Map<String, String>> ir = result.iterator();
        while (ir.hasNext()) {
          Map<String, String> aResult = ir.next();
          String protectionScheme = aResult.get("PS");
          omeNe.getProtectionAid().add(workingAid);
          omeNe.getProtectionAid().add(protectionAid);

          DbUtility.INSTANCE.updateOrAddFacilityAttr(
              ne, workingAid, AbstractFacilityXml.PROTECTIONSCHEME_ATTR, protectionScheme);
          DbUtility.INSTANCE.updateOrAddFacilityAttr(
              ne, protectionAid, AbstractFacilityXml.PROTECTIONSCHEME_ATTR, protectionScheme);
          eventData.put(AbstractFacilityXml.PROTECTIONSCHEME_ATTR, protectionScheme);
        }
        return true;
      }
    } catch (Exception e) {
      log.error("Failed to handle FFP event", e);
    }
    return false;
  }
Exemplo n.º 2
0
  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;
  }
Exemplo n.º 3
0
  private boolean handleBlsrChangeEvent(AbstractNe ne, Map<String, String> values, CHANGE oper) {
    try {
      String workingAid = values.get("AID1");
      String protectionAid = values.get("AID2");
      NetworkElement omeNe = (NetworkElement) ne;

      // Set up the data for event
      HashMap<String, String> eventData = new HashMap<String, String>();
      eventData.put("workingAid", workingAid);
      eventData.put("proctectingAid", protectionAid);
      eventData.put("operation", oper.asString());
      dbchgEvent.addDataElement(eventData);
      getParameters().put(AbstractCommandlet.RESULT_KEY, dbchgEvent);
      // String command = values.get("COMMAND");
      if (oper == CHANGE.DELETE) {
        // don't handle any thing, for now
        log.debug("Got the DLT-BLSRMAP report for " + workingAid + ":" + protectionAid);

        DbUtility.INSTANCE.updateOrAddFacilityAttr(
            ne, workingAid, AbstractFacilityXml.APSID_ATTR, "N/A");
        DbUtility.INSTANCE.updateOrAddFacilityAttr(
            ne, protectionAid, AbstractFacilityXml.APSID_ATTR, "N/A");
        omeNe.getRingName().remove(workingAid);
        omeNe.getRingName().remove(protectionAid);
        omeNe.setApsId(null);
        eventData.put(AbstractFacilityXml.APSID_ATTR, "N/A");
        return true;
      }

      log.debug("Got the ENT-BLSRMAP report for " + workingAid + ":" + protectionAid);
      Map<String, String> paramList = new HashMap<String, String>();
      paramList.put(ObjectElement.OPERATION_KEY, Tl1CommandCode.RTRV_BLSRMAP.toString());
      paramList.put("WRKGAID", workingAid);
      paramList.put("PROTAID", protectionAid);

      List<Map<String, String>> result = omeNe.getTl1Session().sendToNE(paramList);
      if (result != null) {
        Iterator<Map<String, String>> ir = result.iterator();
        while (ir.hasNext()) {
          Map<String, String> blsrResult = ir.next();
          String ringName = blsrResult.get("LABEL");
          omeNe.getRingName().put(workingAid, ringName);
          omeNe.getRingName().put(protectionAid, ringName);

          // ringMap is expected to have the following format
          // "3:3/0:0/1:1/2:2/3:3"
          try {
            String ringMap = blsrResult.get("RINGMAP");
            log.debug("got ringMap info for " + ringName + " in " + ringMap);

            String apsIdStr = ringMap.split("/")[0].split(":")[0];
            omeNe.setApsId(Integer.valueOf(apsIdStr));

            // update the facility in the database with the apsId.
            DbUtility.INSTANCE.updateOrAddFacilityAttr(
                ne, workingAid, AbstractFacilityXml.APSID_ATTR, apsIdStr);
            DbUtility.INSTANCE.updateOrAddFacilityAttr(
                ne, protectionAid, AbstractFacilityXml.APSID_ATTR, apsIdStr);
            eventData.put(AbstractFacilityXml.APSID_ATTR, apsIdStr);
          } catch (Exception ex) {
            log.error("Fail to obtain the ring information", ex);
          }
        }
        return true;
      }

    } catch (Exception e) {
      log.error("Failed to handle BLSRMAP event", e);
    }
    return false;
  }