private void updateStorageVolume(
      CIMInstance volumeInstance, Volume storageVolume, Map<String, Object> keyMap)
      throws IOException {
    storageVolume.setAllocatedCapacity(
        Long.parseLong(getCIMPropertyValue(volumeInstance, EMC_ALLOCATED_CAPACITY)));
    storageVolume.setProvisionedCapacity(returnProvisionedCapacity(volumeInstance, keyMap));

    // If meta volume was ingested prior to upgrade to 2.2 it won't have
    // 'isComposite' set. We need to check
    // cim instance here to see if the volume is meta volume and set it in
    // the volume instance.
    if (isComposite(volumeInstance) && !storageVolume.getIsComposite()) {
      storageVolume.setIsComposite(true);
      _logger.info("Set volume {} to composite (meta volume)", storageVolume.getId());
    }
    _updateVolumes.add(storageVolume);
  }
  /**
   * Called to update the job status when the volume expand job completes.
   *
   * @param jobContext The job context.
   */
  public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMObjectPath> associatorIterator = null;
    CloseableIterator<CIMInstance> instanceIterator = null;
    JobStatus jobStatus = getJobStatus();

    try {
      if (jobStatus == JobStatus.IN_PROGRESS) {
        return;
      }

      DbClient dbClient = jobContext.getDbClient();
      CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
      WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);

      // If terminal state update storage pool capacity and remove reservation for volume capacity
      // from pool's reserved capacity map.
      if (jobStatus == JobStatus.SUCCESS
          || jobStatus == JobStatus.FAILED
          || jobStatus == JobStatus.FATAL_ERROR) {
        SmisUtils.updateStoragePoolCapacity(dbClient, client, _storagePoolURI);

        StoragePool pool = dbClient.queryObject(StoragePool.class, _storagePoolURI);
        StringMap reservationMap = pool.getReservedCapacityMap();
        URI volumeId = getTaskCompleter().getId();
        // remove from reservation map
        reservationMap.remove(volumeId.toString());
        dbClient.persistObject(pool);
      }

      String opId = getTaskCompleter().getOpId();
      StringBuilder logMsgBuilder =
          new StringBuilder(
              String.format(
                  "Updating status of job %s to %s, task: %s",
                  this.getJobName(), jobStatus.name(), opId));

      if (jobStatus == JobStatus.SUCCESS) {
        VolumeExpandCompleter taskCompleter = (VolumeExpandCompleter) getTaskCompleter();
        Volume volume = dbClient.queryObject(Volume.class, taskCompleter.getId());
        // set requested capacity
        volume.setCapacity(taskCompleter.getSize());
        // set meta related properties
        volume.setTotalMetaMemberCapacity(taskCompleter.getTotalMetaMembersSize());
        volume.setMetaMemberCount(taskCompleter.getMetaMemberCount());
        volume.setMetaMemberSize(taskCompleter.getMetaMemberSize());
        volume.setIsComposite(taskCompleter.isComposite());
        volume.setCompositionType(taskCompleter.getMetaVolumeType());

        // set provisioned capacity
        associatorIterator =
            client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
        if (associatorIterator.hasNext()) {
          CIMObjectPath volumePath = associatorIterator.next();
          CIMInstance volumeInstance = client.getInstance(volumePath, true, false, null);
          if (volumeInstance != null) {
            CIMProperty consumableBlocks =
                volumeInstance.getProperty(SmisConstants.CP_CONSUMABLE_BLOCKS);
            CIMProperty blockSize = volumeInstance.getProperty(SmisConstants.CP_BLOCK_SIZE);
            // calculate provisionedCapacity = consumableBlocks * block size
            Long provisionedCapacity =
                Long.valueOf(consumableBlocks.getValue().toString())
                    * Long.valueOf(blockSize.getValue().toString());
            volume.setProvisionedCapacity(provisionedCapacity);
          }

          // set allocated capacity
          instanceIterator =
              client.referenceInstances(
                  volumePath,
                  SmisConstants.CIM_ALLOCATED_FROM_STORAGEPOOL,
                  null,
                  false,
                  SmisConstants.PS_SPACE_CONSUMED);
          if (instanceIterator.hasNext()) {
            CIMInstance allocatedFromStoragePoolPath = instanceIterator.next();
            CIMProperty spaceConsumed =
                allocatedFromStoragePoolPath.getProperty(SmisConstants.CP_SPACE_CONSUMED);
            if (null != spaceConsumed) {
              volume.setAllocatedCapacity(Long.valueOf(spaceConsumed.getValue().toString()));
            }
          }
        }
        logMsgBuilder.append(
            String.format(
                "%n   Capacity: %s, Provisioned capacity: %s, Allocated Capacity: %s",
                volume.getCapacity(),
                volume.getProvisionedCapacity(),
                volume.getAllocatedCapacity()));
        if (volume.getIsComposite()) {
          logMsgBuilder.append(
              String.format(
                  "%n   Is Meta: %s, Total meta member capacity: %s, Meta member count %s, Meta member size: %s",
                  volume.getIsComposite(),
                  volume.getTotalMetaMemberCapacity(),
                  volume.getMetaMemberCount(),
                  volume.getMetaMemberSize()));
        }

        _log.info(logMsgBuilder.toString());

        // Reset list of meta member volumes in the volume
        if (volume.getMetaVolumeMembers() != null) {
          volume.getMetaVolumeMembers().clear();
        }

        StorageSystem storageSystem =
            dbClient.queryObject(StorageSystem.class, volume.getStorageController());
        // set the RP tag on the volume if the volume is RP protected
        if (volume.checkForRp()
            && storageSystem.getSystemType() != null
            && storageSystem
                .getSystemType()
                .equalsIgnoreCase(DiscoveredDataObject.Type.vmax.toString())) {
          SmisCommandHelper helper = jobContext.getSmisCommandHelper();
          List<CIMObjectPath> volumePathList = new ArrayList<CIMObjectPath>();
          volumePathList.add(helper.getVolumeMember(storageSystem, volume));
          helper.setRecoverPointTag(storageSystem, volumePathList, true);
        }

        dbClient.persistObject(volume);
        // Reset list of meta members native ids in WF data (when meta is created meta members are
        // removed from array)
        WorkflowService.getInstance().storeStepData(opId, new ArrayList<String>());
      }
    } catch (Exception e) {
      _log.error("Caught an exception while trying to updateStatus for SmisVolumeExpandJob", e);
      setPostProcessingErrorStatus(
          "Encountered an internal error during volume expand job status processing : "
              + e.getMessage());
    } finally {
      _metaVolumeTaskCompleter.setLastStepStatus(jobStatus);
      if (associatorIterator != null) {
        associatorIterator.close();
      }
      if (instanceIterator != null) {
        instanceIterator.close();
      }
      super.updateStatus(jobContext);
    }
  }
  private void processVolumes(
      CloseableIterator<CIMInstance> volumeInstances, Map<String, Object> keyMap)
      throws IOException {

    List<CIMObjectPath> metaVolumes = new ArrayList<>();
    while (volumeInstances.hasNext()) {
      CIMInstance volumeViewInstance = volumeInstances.next();
      String nativeGuid = getVolumeViewNativeGuid(volumeViewInstance.getObjectPath(), keyMap);

      if (isSnapShot(volumeViewInstance)) {
        BlockSnapshot snapShot = checkSnapShotExistsInDB(nativeGuid, _dbClient);
        if (null == snapShot || snapShot.getInactive()) {
          _logger.debug("Skipping Snapshot, as its not being managed in Bourne");
          continue;
        }
        updateBlockSnapShot(volumeViewInstance, snapShot, keyMap);
        if (_updateSnapShots.size() > BATCH_SIZE) {
          _partitionManager.updateInBatches(
              _updateSnapShots, getPartitionSize(keyMap), _dbClient, BLOCK_SNAPSHOT);
          _updateSnapShots.clear();
        }
      } else if (isMirror(volumeViewInstance)) {
        BlockMirror mirror = checkBlockMirrorExistsInDB(nativeGuid, _dbClient);
        if (null == mirror || mirror.getInactive()) {
          _logger.debug("Skipping Mirror, as its not being managed in Bourne");
          continue;
        }
        updateBlockMirror(volumeViewInstance, mirror, keyMap);
        if (_updateMirrors.size() > BATCH_SIZE) {
          _partitionManager.updateInBatches(
              _updateMirrors, getPartitionSize(keyMap), _dbClient, BLOCK_MIRROR);
          _updateMirrors.clear();
        }
      } else {
        Volume storageVolume = checkStorageVolumeExistsInDB(nativeGuid, _dbClient);
        if (null == storageVolume || storageVolume.getInactive()) {
          continue;
        }
        _logger.debug("Volume managed by Bourne :" + storageVolume.getNativeGuid());
        updateStorageVolume(volumeViewInstance, storageVolume, keyMap);

        // Check if this is a meta volume and if we need to set missing meta volume related
        // properties.
        // This is applicable for meta volumes discovered as unmanaged volumes and ingested prior to
        // vipr controller 2.2 .
        if (storageVolume.getIsComposite()
            && (storageVolume.getCompositionType() == null
                || storageVolume.getCompositionType().isEmpty())) {
          // meta volume is missing meta related data. Need to discover this data and set in the
          // volume.
          metaVolumes.add(volumeViewInstance.getObjectPath());
          _logger.info(
              "Found meta volume in vipr with missing data: {}, name: {}",
              volumeViewInstance.getObjectPath(),
              storageVolume.getLabel());
        }
      }
      if (_updateVolumes.size() > BATCH_SIZE) {
        _partitionManager.updateInBatches(
            _updateVolumes, getPartitionSize(keyMap), _dbClient, VOLUME);
        _updateVolumes.clear();
      }
    }

    // Add meta volumes to the keyMap
    try {
      if (metaVolumes != null && !metaVolumes.isEmpty()) {
        _metaVolumeViewPaths.addAll(metaVolumes);
        _logger.info("Added  {} meta volumes.", metaVolumes.size());
      }
    } catch (Exception ex) {
      _logger.error("Processing meta volumes.", ex);
    }
  }