/*
   * Remove Meter to the southbound plugin and our internal database
   *
   * @param path
   *
   * @param dataObject
   */
  private Status removeMeter(InstanceIdentifier<?> path, Meter meterRemoveDataObject) {
    MeterKey meterKey = meterRemoveDataObject.getKey();

    if (null != meterKey && validateMeter(meterRemoveDataObject).isSuccess()) {
      RemoveMeterInputBuilder meterBuilder = new RemoveMeterInputBuilder();
      meterBuilder.fieldsFrom(meterRemoveDataObject);
      meterBuilder.setNode(meterRemoveDataObject.getNode());
      meterBuilder.setMeterId(new MeterId(meterRemoveDataObject.getId()));
      meterService.removeMeter(meterBuilder.build());
    } else {
      return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
    }

    return new Status(StatusCode.SUCCESS);
  }
  /*
   * Update Meter to the southbound plugin and our internal database
   *
   * @param path
   *
   * @param dataObject
   */
  private Status updateMeter(InstanceIdentifier<?> path, Meter updatedMeter, Meter originalMeter) {
    UpdatedMeterBuilder updateMeterBuilder = null;

    if (validateMeter(updatedMeter).isSuccess()) {
      UpdateMeterInputBuilder updateMeterInputBuilder = new UpdateMeterInputBuilder();
      updateMeterInputBuilder.setNode(updatedMeter.getNode());
      updateMeterBuilder = new UpdatedMeterBuilder();
      updateMeterBuilder.fieldsFrom(updatedMeter);
      updateMeterBuilder.setMeterId(new MeterId(updatedMeter.getId()));
      updateMeterInputBuilder.setUpdatedMeter(updateMeterBuilder.build());
      OriginalMeterBuilder originalMeterBuilder = new OriginalMeterBuilder(originalMeter);
      updateMeterInputBuilder.setOriginalMeter(originalMeterBuilder.build());
      meterService.updateMeter(updateMeterInputBuilder.build());
    } else {
      return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
    }

    return new Status(StatusCode.SUCCESS);
  }
  public Status validateMeter(Meter meter) {
    String meterName;
    Status returnStatus = null;

    if (null != meter) {
      meterName = meter.getMeterName();
      if (!FRMUtil.isNameValid(meterName)) {
        logger.error("Meter Name is invalid %s" + meterName);
        returnStatus = new Status(StatusCode.BADREQUEST, "Meter Name is invalid");
        return returnStatus;
      }

      for (int i = 0; i < meter.getMeterBandHeaders().getMeterBandHeader().size(); i++) {
        if (null != meter.getFlags() && !meter.getFlags().isMeterBurst()) {
          if (0 < meter.getMeterBandHeaders().getMeterBandHeader().get(i).getBurstSize()) {
            logger.error("Burst size should only be associated when Burst FLAG is set");
            returnStatus =
                new Status(
                    StatusCode.BADREQUEST,
                    "Burst size should only be associated when Burst FLAG is set");
            break;
          }
        }
      }

      if (null != returnStatus && !returnStatus.isSuccess()) {
        return returnStatus;
      } else if (null != meter.getMeterBandHeaders()) {
        BandType setBandType = null;
        DscpRemark dscpRemark = null;
        for (int i = 0; i < meter.getMeterBandHeaders().getMeterBandHeader().size(); i++) {
          setBandType = meter.getMeterBandHeaders().getMeterBandHeader().get(i).getBandType();
          if (setBandType instanceof DscpRemark) {
            dscpRemark = (DscpRemark) setBandType;
            if (0 > dscpRemark.getRate()) {}

          } else if (setBandType instanceof Drop) {
            if (0 < dscpRemark.getPercLevel()) {
              logger.error("Number of drop Precedence level");
            }
          } else if (setBandType instanceof Experimenter) {

          }
        }
      }
    }
    return new Status(StatusCode.SUCCESS);
  }