/**
   * Creates the consistency group used by the BlockObjects.
   *
   * @param name
   * @return
   */
  private BlockConsistencyGroup createBlockConsistencyGroup(
      String name, URI storageSystem, String type, boolean setType) {
    BlockConsistencyGroup cg = new BlockConsistencyGroup();
    URI cgURI = URIUtil.createId(BlockConsistencyGroup.class);
    cg.setId(cgURI);
    cg.setLabel(name);
    cg.setStorageController(storageSystem);

    if (type.equals(Types.LOCAL.name())) {
      // Set the 'old' field value so it can be migrated
      cg.setDeviceName("localArrayDeviceName");
    } else if (type.equals(Types.VPLEX.name())) {
      // Set the 'old' field value so it can be migrated
      cg.setDeviceName("vplexDeviceName");
    } else if (type.equals(Types.RP.name())) {
      // Set the 'old' field value so it can be migrated.
      cg.setDeviceName("rpDeviceName");
    } else if (type.equals(Types.SRDF.name())) {
      // Set the 'old' field value so it can be migrated
      cg.setDeviceName("srdfDeviceName");
    }

    if (setType) {
      cg.setType(type);
    }

    // Set the 'old' field value so it can be migrated
    _dbClient.createObject(cg);
    return cg;
  }
  /**
   * Creates the BlockObject BlockSnapshot data.
   *
   * @param name
   * @param numSnapshots
   * @throws Exception
   */
  private void prepareBlockSnapshotData(String name, int numSnapshots) throws Exception {
    // Create the volume for the snapshots
    Volume volume = new Volume();
    URI volumeURI = URIUtil.createId(Volume.class);

    StorageSystem storageSystem = createStorageSystem(false);
    volume.setId(volumeURI);
    volume.setStorageController(storageSystem.getId());
    String volName = "blockSnapshotVolume";
    volume.setLabel(volName);
    BlockConsistencyGroup cg =
        createBlockConsistencyGroup(
            "blockSnapshotConsistencyGroup", storageSystem.getId(), Types.LOCAL.name(), true);
    volume.setConsistencyGroup(cg.getId());
    _dbClient.createObject(volume);

    for (int i = 1; i <= numSnapshots; i++) {
      BlockSnapshot blockSnapshot = new BlockSnapshot();
      URI blockSnapshotURI = URIUtil.createId(BlockSnapshot.class);
      blockSnapshotURIs.add(blockSnapshotURI);
      blockSnapshot.setId(blockSnapshotURI);
      blockSnapshot.setLabel(name + i);
      blockSnapshot.setSnapsetLabel(name + i);
      blockSnapshot.setParent(new NamedURI(volume.getId(), name + i));
      blockSnapshot.addConsistencyGroup(cg.getId().toString());
      _dbClient.createObject(blockSnapshot);
    }
  }
 /**
  * Create block volumes and associated local array consistency group.
  *
  * @throws Exception
  */
 private void prepareLocalArrayConsistencyGroupData() throws Exception {
   // Create a non-VPlex storage system
   StorageSystem storageSystem = createStorageSystem(false);
   // Create the block volumes that will be part of the cg
   List<Volume> blockVolumes = createBlockVolumes("blockVolume", 3, storageSystem.getId());
   // Create the consistency group and add the block volumes
   BlockConsistencyGroup localArrayCg =
       createBlockConsistencyGroup(
           "localArrayCg", storageSystem.getId(), Types.LOCAL.name(), true);
   localArrayConsistencyGroupURI = localArrayCg.getId();
   addVolumesToBlockConsistencyGroup(localArrayCg.getId(), blockVolumes);
 }
  /**
   * Creates the BlockObject BlockMirror data.
   *
   * @param name
   * @param numBlockMirrors
   * @throws Exception
   */
  private void prepareBlockMirrorData(String name, int numBlockMirrors) throws Exception {
    BlockConsistencyGroup cg =
        createBlockConsistencyGroup("blockMirrorConsistencyGroup", null, Types.LOCAL.name(), true);

    for (int i = 1; i <= numBlockMirrors; i++) {
      BlockMirror blockMirror = new BlockMirror();
      URI blockMirrorURI = URIUtil.createId(BlockMirror.class);
      blockMirrorURIs.add(blockMirrorURI);
      blockMirror.setId(blockMirrorURI);
      blockMirror.setLabel(name + i);
      // Set the 'old' field value so it can be migrated
      blockMirror.addConsistencyGroup(cg.getId().toString());
      _dbClient.createObject(blockMirror);
    }
  }
  /**
   * Verify the local array consistency group and its volumes have been properly migrated.
   *
   * @throws Exception
   */
  private void verifyLocalArrayConsistencyGroupMigration() throws Exception {
    log.info("Verifying local array BlockConsistencyGroup and associated volume migration.");

    BlockConsistencyGroup localArrayCg =
        _dbClient.queryObject(BlockConsistencyGroup.class, localArrayConsistencyGroupURI);
    Iterator<Volume> blockVolumeItr =
        _dbClient.queryIterativeObjects(Volume.class, blockVolumeURIs);

    // Verify the LOCAL consistency group was properly migrated
    verifyConsistencyGroupMigration(localArrayCg, Types.LOCAL.name());

    // Verify the volume migration took place correctly
    List<BlockObject> blockObjects = new ArrayList<BlockObject>();
    while (blockVolumeItr.hasNext()) {
      blockObjects.add(blockVolumeItr.next());
    }

    verifyBlockObjects(blockObjects);
  }