public DriverTask createConsistencyGroupClone(VolumeConsistencyGroup consistencyGroup,List<VolumeClone> clones,List<CapabilityInstance> capabilities,DriverTask task,Registry driverRegistry){
  _log.info("3PARDriver: createConsistencyGroupClone for storage system  id {}, Base CG name {} , Base CG native id {} - start",consistencyGroup.getStorageSystemId(),consistencyGroup.getDisplayName(),consistencyGroup.getNativeId());
  String VVsetNameForClone=consistencyGroup.getDisplayName();
  VolumeDetailsCommandResult volResult=null;
  HashMap<String,VolumeClone> clonesMap=new HashMap<String,VolumeClone>();
  try {
    Boolean saveSnapshot=true;
    HP3PARApi hp3parApi=hp3parUtil.getHP3PARDeviceFromNativeId(consistencyGroup.getStorageSystemId(),driverRegistry);
    for (    VolumeClone clone : clones) {
      _log.info("3PARDriver: createConsistencyGroupClone generated clone parent id {}, display name {} ",clone.getParentId(),clone.getDisplayName());
      String generatedCloneName=clone.getDisplayName();
      VVsetNameForClone=generatedCloneName.substring(0,generatedCloneName.lastIndexOf("-"));
      _log.info("3PARDriver: createConsistencyGroupClone CG name {} to be used in cloning ",VVsetNameForClone);
      clonesMap.put(clone.getParentId(),clone);
    }
    _log.info("3PARDriver: createConsistencyGroupClone  clonesMap {}",clonesMap.toString());
    VVSetVolumeClone[] result=hp3parApi.createVVsetPhysicalCopy(consistencyGroup.getNativeId(),VVsetNameForClone,clones,saveSnapshot);
    _log.info("3PARDriver: createConsistencyGroupClone outPut of CG clone result  {} ",result.toString());
    for (    VVSetVolumeClone cloneCreated : result) {
      VolumeClone clone=clonesMap.get(cloneCreated.getParent());
      _log.info("createConsistencyGroupClone cloneCreated {} and local clone obj nativeid = {} , parent id = {}",cloneCreated.getValues(),clone.getNativeId(),clone.getParentId());
      volResult=hp3parApi.getVolumeDetails(cloneCreated.getChild());
      _log.info("createConsistencyGroupClone cloneCreated All values {} ",volResult.getAllValues());
      clone.setWwn(volResult.getWwn());
      clone.setNativeId(volResult.getId());
      clone.setDeviceLabel(volResult.getName());
      clone.setDisplayName(volResult.getName());
      clone.setReplicationState(VolumeClone.ReplicationState.SYNCHRONIZED);
      clone.setProvisionedCapacity(clone.getRequestedCapacity());
      clone.setAllocatedCapacity(clone.getRequestedCapacity());
    }
    task.setStatus(DriverTask.TaskStatus.READY);
    _log.info("createConsistencyGroupClone for storage system native id {}, CG display Name {}, CG native id {} - end",consistencyGroup.getStorageSystemId(),consistencyGroup.getDisplayName(),consistencyGroup.getNativeId());
  }
 catch (  Exception e) {
    String msg=String.format("3PARDriver: createConsistencyGroupClone Unable to create vv set snap name %s and its native id %s whose storage system  id is %s; Error: %s.\n",VVsetNameForClone,consistencyGroup.getNativeId(),consistencyGroup.getStorageSystemId(),e.getMessage());
    _log.error(msg);
    task.setMessage(msg);
    task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
    e.printStackTrace();
  }
  return task;
}

public DriverTask createConsistencyGroupClone ( VolumeConsistencyGroup consistencyGroup , List < VolumeClone > clones , List < CapabilityInstance > capabilities , DriverTask task , Registry driverRegistry ) { _log . info ( "3PARDriver: createConsistencyGroupClone for storage system  id {}, Base CG name {} , Base CG native id {} - start" , consistencyGroup . getStorageSystemId ( ) , consistencyGroup . getDisplayName ( ) , consistencyGroup . getNativeId ( ) ) ; String VVsetNameForClone = consistencyGroup . getDisplayName ( ) ; VolumeDetailsCommandResult volResult = null ; HashMap < String , VolumeClone > clonesMap = new HashMap < String , VolumeClone > ( ) ; try { Boolean saveSnapshot = true ; HP3PARApi hp3parApi = hp3parUtil . getHP3PARDeviceFromNativeId ( consistencyGroup . getStorageSystemId ( ) , driverRegistry ) ; for ( VolumeClone clone : clones ) { _log . info ( "3PARDriver: createConsistencyGroupClone generated clone parent id {}, display name {} " , clone . getParentId ( ) , clone . getDisplayName ( ) ) ; String generatedCloneName = clone . getDisplayName ( ) ; VVsetNameForClone = generatedCloneName . substring ( 0 , generatedCloneName . lastIndexOf ( "-" ) ) ; _log . info ( "3PARDriver: createConsistencyGroupClone CG name {} to be used in cloning " , VVsetNameForClone ) ; clonesMap . put ( clone . getParentId ( ) , clone ) ; } _log . info ( "3PARDriver: createConsistencyGroupClone  clonesMap {}" , clonesMap . toString ( ) ) ; VVSetVolumeClone [ ] result = hp3parApi . createVVsetPhysicalCopy ( consistencyGroup . getNativeId ( ) , VVsetNameForClone , clones , saveSnapshot ) ; _log . info ( "3PARDriver: createConsistencyGroupClone outPut of CG clone result  {} " , result . toString ( ) ) ; for ( VVSetVolumeClone cloneCreated : result ) { VolumeClone clone = clonesMap . get ( cloneCreated . getParent ( ) ) ; _log . info ( "createConsistencyGroupClone cloneCreated {} and local clone obj nativeid = {} , parent id = {}" , cloneCreated . getValues ( ) , clone . getNativeId ( ) , clone . getParentId ( ) ) ; volResult = hp3parApi . getVolumeDetails ( cloneCreated . getChild ( ) ) ; _log . info ( "createConsistencyGroupClone cloneCreated All values {} " , volResult . getAllValues ( ) ) ; clone . setWwn ( volResult . getWwn ( ) ) ; clone . setNativeId ( volResult . getId ( ) ) ; clone . setDeviceLabel ( volResult . getName ( ) ) ; clone . setDisplayName ( volResult . getName ( ) ) ; clone . setReplicationState ( VolumeClone . ReplicationState . SYNCHRONIZED ) ; clone . setProvisionedCapacity ( clone . getRequestedCapacity ( ) ) ; clone . setAllocatedCapacity ( clone . getRequestedCapacity ( ) ) ; } task . setStatus ( DriverTask . TaskStatus . READY ) ; _log . info ( "createConsistencyGroupClone for storage system native id {}, CG display Name {}, CG native id {} - end" , consistencyGroup . getStorageSystemId ( ) , consistencyGroup . getDisplayName ( ) , consistencyGroup . getNativeId ( ) ) ; } catch ( Exception e ) { String msg = String . format ( "3PARDriver: createConsistencyGroupClone Unable to create vv set snap name %s and its native id %s whose storage system  id is %s; Error: %s.\n" , VVsetNameForClone , consistencyGroup . getNativeId ( ) , consistencyGroup . getStorageSystemId ( ) , e . getMessage ( ) ) ; _log . error ( msg ) ; task . setMessage ( msg ) ; task . setStatus ( DriverTask . TaskStatus . PARTIALLY_FAILED ) ; e . printStackTrace ( ) ; } return task ; }
creating physical copy for vvset or cg clone rest api expects created vvset with its corresponding volumes types for clone destination so , there are many ways for implementation 1 . customer will provide the vvset name which already exist in array with its corresponding similar volumes for cloning 2 . customer will not provide any existing and matching vv set with corresponding volumes for cg clone 3 . customer will provide vvset name which is created but volumes are not matching for clone creation . create new vv set / cg . create new volumes similar to parent vvset volumes use this newly created vv set for cg clone option 2 is implemented , need to handle negative / error cases of option 3
