Example #1
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;
  }
Example #2
0
  private boolean handleConnectionEvent(
      AbstractNe ne, Map<String, String> values, Tl1XmlDbChangeEvent dbchgEvent) {
    Map<String, String> data = new HashMap<String, String>();
    String neId = ne.getNeId();
    String command = values.get("COMMAND");
    String cktid = values.get("CKTID");
    String fromAid = values.get("AID1"); // STS3C-1-1-1-1
    String toAid = values.get("AID2"); // STS3C-1-12-1-1
    String swmateAid = null;

    try {
      /*
       * Notice that, in deleting case, the CKTID is null, so we have to compare
       * the AIDs in the database. The AID coming from OME doesn't contain the
       * type of facility (ie. STS1-1-4-1-2) so extra database querying has to
       * be done.
       */

      // Notify the internal utility that keeps track of all Xconnections
      // being created, not deleted
      if (command.startsWith("ENT")) {
        CheckAllComplete.INSTANCE.iAmDone(cktid);
      }

      // SOURCE
      String[] fromAidArr = fromAid.split("-");
      String fromShelf = fromAidArr[1];
      String fromSlot = fromAidArr[2];
      String fromPort = fromAidArr[3];
      @SuppressWarnings("unused")
      boolean fromSideIsL2SS = ne.slotIsL2SS(fromShelf, fromSlot);
      String fromFacilityRecord =
          DbUtility.INSTANCE.retrieveAFacility(ne, fromShelf, fromSlot, fromPort);
      int startTypeIndex = fromFacilityRecord.indexOf("type=") + 6;
      int endTypeIndex = fromFacilityRecord.indexOf('"', startTypeIndex);
      String fromFacilityType = fromFacilityRecord.substring(startTypeIndex, endTypeIndex);
      StringBuilder tempBuff = new StringBuilder(fromFacilityType);
      for (int i = 1; i < fromAidArr.length; i++) {
        tempBuff.append("-" + fromAidArr[i]);
      }
      fromAid = tempBuff.toString();

      // Rate
      getParameters().put("replaceRate", fromAidArr[0]);
      data.put(NetworkElementConnectionCols.RATE, fromAidArr[0]);

      // TARGET
      String[] toAidArr = toAid.split("-");
      String toShelf = toAidArr[1];
      String toSlot = toAidArr[2];
      String toPort = toAidArr[3];
      @SuppressWarnings("unused")
      boolean toSideIsL2SS = ne.slotIsL2SS(toAidArr[1], toAidArr[2]);
      String toFacilityRecord = DbUtility.INSTANCE.retrieveAFacility(ne, toShelf, toSlot, toPort);
      startTypeIndex = toFacilityRecord.indexOf("type=") + 6;
      endTypeIndex = toFacilityRecord.indexOf('"', startTypeIndex);
      String toFacilityType = toFacilityRecord.substring(startTypeIndex, endTypeIndex);
      tempBuff = new StringBuilder(toFacilityType);
      for (int i = 1; i < toAidArr.length; i++) {
        tempBuff.append("-" + toAidArr[i]);
      }
      toAid = tempBuff.toString();

      // Validation of the case
      String existConnection = DbUtility.INSTANCE.retrieveAXConnect(ne, fromAid, toAid);
      if (existConnection != null) {
        if (command.startsWith("ENT")) {
          log.error(ne.getNeName() + ": connection " + fromAid + ":" + toAid + " already exists");
          return false;
        }
      } else if (!command.startsWith("ENT")) {
        log.warn(ne.getNeName() + ": connection " + fromAid + ":" + toAid + " doesn't exist");
        log.debug("Trying the switched values: " + toAid + " to" + fromAid);
        existConnection = DbUtility.INSTANCE.retrieveAXConnect(ne, toAid, fromAid);
        if (existConnection == null) {
          log.error(ne.getNeName() + ": connection " + toAid + ":" + fromAid + " doesn't exist");
          return false;
        }
        String temp = fromAid;
        fromAid = toAid;
        toAid = temp;
      }

      if (cktid == null) {
        cktid = "N/A";
      }

      // SWMATE
      String swMate = null;
      Object tempSwmate = values.get("KEYWORDPARAMS");
      if (tempSwmate != null) {
        String[] keyWords = ((String) tempSwmate).split(",");
        for (String keyWord : keyWords) {
          if (keyWord.indexOf("SWMATE") >= 0) {
            swMate = keyWord.split("=")[1];
            break;
          }
        }
      }

      String[] swmateAidArr = null;
      String swmateFacilityRecord = null;
      String swmateShelf = null;
      String swmateSlot = null;
      String swmatePort = null;
      String swmateFacilityType = null;
      if (swMate != null && swMate.length() > 0) {
        swmateAidArr = swMate.split("-");
        swmateShelf = swmateAidArr[1];
        swmateSlot = swmateAidArr[2];
        swmatePort = swmateAidArr[3];
        swmateFacilityRecord =
            DbUtility.INSTANCE.retrieveAFacility(ne, swmateShelf, swmateSlot, swmatePort);
        startTypeIndex = swmateFacilityRecord.indexOf("type=") + 6;
        endTypeIndex = swmateFacilityRecord.indexOf('"', startTypeIndex);
        swmateFacilityType = swmateFacilityRecord.substring(startTypeIndex, endTypeIndex);
        tempBuff = new StringBuilder(swmateFacilityType);
        for (int i = 1; i < swmateAidArr.length; i++) {
          tempBuff.append("-" + swmateAidArr[i]);
        }
        swmateAid = tempBuff.toString();
      }

      log.debug("Handling DRAC's connection event CKTID: " + cktid);

      getParameters().put("replaceSourceAddress", neId);
      getParameters().put("replaceTargetAddress", neId);
      getParameters().put("replaceId", cktid);
      getParameters().put("replaceType", values.get("POS1"));
      getParameters().put("replaceCommitted", "true");

      data.put(NetworkElementConnectionCols.ID, cktid);

      data.put(NetworkElementConnectionCols.SOURCEAID, fromAid);
      getParameters().put("replaceSourceAid", fromAid);

      data.put(NetworkElementConnectionCols.TARGETAID, toAid);
      getParameters().put("replaceTargetAid", toAid);

      data.put(NetworkElementConnectionCols.SWMATEAID, swmateAid);
      getParameters().put("replaceSwmate", swmateAid);

      // Update the database and re-use the "parameters"
      if (command.startsWith("ENT")) {
        data.put(NetworkElementEventXML.OPERATION_ATTR, OperationType.OPERATION_ADD.toString());
        DbUtility.INSTANCE.addOneXConnect(ne, getParameters());
      } else {
        data.put(NetworkElementEventXML.OPERATION_ATTR, OperationType.OPERATION_DELETE.toString());

        ByteArrayInputStream aByteStream = new ByteArrayInputStream(existConnection.getBytes());
        SAXBuilder builder = new SAXBuilder();
        Document aDoc = builder.build(aByteStream);
        Element root = aDoc.getRootElement();
        data.put(NetworkElementConnectionCols.ID, root.getAttributeValue("id"));

        DbUtility.INSTANCE.deleteXConnect(ne, fromAid, toAid);
      }
      dbchgEvent.addDataElement(data);

      // *** FOR an Eth/Wan EPL port ***
      //
      // The act of cross-connecting can change some of the WAN attributes, such
      // as provUnits,
      // state, and most importantly, the RATE (e.g. for WAN port pairs,
      // connecting to one
      // port at STS1 requires that the other take only STS1 ... same for
      // STS3C).
      //
      // So, with the connection provisioned, check for db changes on the WAN
      // (...the NE doesn't emit a dbchange report?!)

      // Ignoring L2SS-based WAN facilities for state changes

      Element fromElement = DbOpsHelper.xmlToElement(fromFacilityRecord);
      String eplFlag = fromElement.getAttributeValue(FacilityConstants.IS_EPL);
      if (eplFlag != null && Boolean.parseBoolean(eplFlag)) {
        // The found fromFacilityRecord is an EthXXX/Wan EPL port
        checkForEplWanDbChange(
            ne,
            Tl1CommandCode.RTRV_WAN,
            FacilityConstants.WAN,
            fromFacilityType,
            fromShelf,
            fromSlot,
            fromPort);
      }

      Element toElement = DbOpsHelper.xmlToElement(toFacilityRecord);
      eplFlag = toElement.getAttributeValue(FacilityConstants.IS_EPL);
      if (eplFlag != null && Boolean.parseBoolean(eplFlag)) {
        // The found toFacilityRecord is an EthXXX/Wan EPL port
        tempBuff = new StringBuilder(FacilityConstants.WAN);
        for (int i = 1; i < toAidArr.length; i++) {
          tempBuff.append("-" + toAidArr[i]);
        }
        // String wanAid = tempBuff.toString();

        checkForEplWanDbChange(
            ne,
            Tl1CommandCode.RTRV_WAN,
            FacilityConstants.WAN,
            toFacilityType,
            toShelf,
            toSlot,
            toPort);
      }

      if (swmateFacilityRecord != null) {
        Element swmateElement = DbOpsHelper.xmlToElement(swmateFacilityRecord);
        eplFlag = swmateElement.getAttributeValue(FacilityConstants.IS_EPL);
        if (eplFlag != null && Boolean.parseBoolean(eplFlag)) {
          // The found swmateFacilityRecord is an EthXXX/Wan EPL port
          tempBuff = new StringBuilder(FacilityConstants.WAN);
          for (int i = 1; i < swmateAidArr.length; i++) {
            tempBuff.append("-" + swmateAidArr[i]);
          }
          // String wanAid = tempBuff.toString();

          checkForEplWanDbChange(
              ne,
              Tl1CommandCode.RTRV_WAN,
              FacilityConstants.WAN,
              swmateFacilityType,
              swmateShelf,
              swmateSlot,
              swmatePort);
        }
      }
    } catch (Exception e) {
      log.error(
          "Failed to handle connection db change event from ne:"
              + ne.getNeId()
              + " values:"
              + values,
          e);
      return false;
    }
    getParameters().put(AbstractCommandlet.RESULT_KEY, dbchgEvent);

    // LPCP_PORT connection event handling only considers OSS connections (i.e.
    // connections whose
    // IDs don't begin with 'DRAC-1'. Connection events for DRAC services is
    // handled
    // elsewhere.
    if (CrossConnection.isDracConnection(cktid)) {
      return false;
    }

    return true;
  }