Search in sources :

Example 1 with VVSetVolumeClone

use of com.emc.storageos.hp3par.command.VVSetCloneList.VVSetVolumeClone in project coprhd-controller by CoprHD.

the class HP3PARApi method createVVsetPhysicalCopy.

public VVSetVolumeClone[] createVVsetPhysicalCopy(String nativeId, String vVsetNameForClone, List<VolumeClone> clones, Boolean saveSnapshot) throws Exception {
    _log.info("3PARDriver:createVVsetPhysicalCopy enter");
    _log.info(" 3PARDriver:createVVsetPhysicalCopy CG name {} for cloning , corresponding CG clone name {} ", nativeId, vVsetNameForClone);
    ClientResponse clientResp = null;
    String vvSetClones = "";
    // for snapshot creation
    String payload = "{\"action\":\"createPhysicalCopy\", \"parameters\": { \"destVolume\": \"" + vVsetNameForClone + "\" , \"saveSnapshot\": " + saveSnapshot + "} }";
    final String path = MessageFormat.format(URI_CLONE_CG, nativeId);
    _log.info(" 3PARDriver: createVVsetPhysicalCopy uri = {} payload {} ", path, payload);
    try {
        // get Vipr generated clone name and create corresponding volumes
        for (VolumeClone clone : clones) {
            _log.info("3PARDriver: createVVsetPhysicalCopy generated clone native id {}, display name {} - start", clone.getParentId(), clone.getDisplayName());
            String generatedCloneName = clone.getDisplayName();
            String baseVolumeName = clone.getParentId();
            // create new volume , CG clone will fail if already exists
            VolumeDetailsCommandResult volResult = null;
            volResult = getVolumeDetails(baseVolumeName);
            if (volResult != null) {
                // UserCPG will be absent for clones, hence using snapCPG here. We might need to re-look CPG selection later
                String baseVolumeUserCPG = volResult.getUserCPG();
                String baseVolumeSnapCPG = volResult.getSnapCPG();
                Boolean tpvv = true;
                Boolean tdvv = false;
                if (volResult.getProvisioningType() == 6) {
                    tdvv = true;
                    tpvv = false;
                }
                _log.info("3PARDriver: createVolumeClone base volume exists, id {}, baseVolumeSnapCPG {} , baseVolumeUserCPG {} , copyOf {}, copyType {} , name {}, volume type {} - ", baseVolumeName, baseVolumeSnapCPG, baseVolumeUserCPG, volResult.getCopyOf(), volResult.getCopyType(), volResult.getName(), volResult.getProvisioningType());
                createVolume(generatedCloneName, baseVolumeSnapCPG, tpvv, tdvv, volResult.getSizeMiB());
                vvSetClones = vvSetClones + "\"" + generatedCloneName + "\",";
            }
        }
        if (vvSetClones != "") {
            vvSetClones = vvSetClones.substring(0, vvSetClones.lastIndexOf(","));
            // for VV set addition {"action":1,"setmembers":["vol-name","vol-name2"]}
            String vvsetPayload = "{\"name\": \"" + vVsetNameForClone + "\", \"setmembers\": [ \"" + vvSetClones + "\" ] }";
            // final String path = MessageFormat.format(URI_CREATE_CG);
            _log.info(" 3PARDriver: createVVsetPhysicalCopy uri = {} vvsetPayload {} ", URI_CREATE_CG.toString(), vvsetPayload);
            // Create and update Clone CG object and volumes
            try {
                clientResp = post(URI_CREATE_CG, vvsetPayload);
                if (clientResp == null) {
                    _log.error("3PARDriver: createVVsetPhysicalCopy There is no response from 3PAR");
                    throw new HP3PARException("There is no response from 3PAR");
                } else if (clientResp.getStatus() != 201) {
                    String errResp = getResponseDetails(clientResp);
                    _log.error("3PARDriver: createVVsetPhysicalCopy There is error response from 3PAR = {}", errResp);
                    throw new HP3PARException(errResp);
                } else {
                    _log.info("3PARDriver: createVVsetPhysicalCopy vvset created");
                }
            } catch (Exception e) {
                throw e;
            } finally {
                if (clientResp != null) {
                    clientResp.close();
                }
                _log.info("3PARDriver: createVVsetPhysicalCopy execute vvset");
            }
            // Executing CG clone
            try {
                clientResp = post(path, payload);
                if (clientResp == null) {
                    _log.error("3PARDriver:There is no response from 3PAR");
                    throw new HP3PARException("There is no response from 3PAR");
                } else if (clientResp.getStatus() != 201) {
                    String errResp = getResponseDetails(clientResp);
                    throw new HP3PARException(errResp);
                } else {
                    String responseString = clientResp.getEntity(String.class);
                    // String customerResponseString = "{\"Altered\":"+responseString+"}";
                    _log.info("3PARDriver:createVVsetVirtualCopy success , response ", responseString);
                    VVSetVolumeClone[] output = new Gson().fromJson(sanitize(responseString), VVSetVolumeClone[].class);
                    return output;
                }
            } catch (Exception e) {
                throw e;
            } finally {
                if (clientResp != null) {
                    clientResp.close();
                }
                _log.info("3PARDriver:createVVsetVirtualCopy leave");
            }
        // end try/catch/finally
        }
    } catch (Exception e) {
        _log.info("3PARDriver:createVVsetVirtualCopy ERROR ");
        throw e;
    }
    return null;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Gson(com.google.gson.Gson) VVSetVolumeClone(com.emc.storageos.hp3par.command.VVSetCloneList.VVSetVolumeClone) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) VolumeDetailsCommandResult(com.emc.storageos.hp3par.command.VolumeDetailsCommandResult)

Example 2 with VVSetVolumeClone

use of com.emc.storageos.hp3par.command.VVSetCloneList.VVSetVolumeClone in project coprhd-controller by CoprHD.

the class HP3PARCGHelper method createConsistencyGroupClone.

/**
 * 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
 */
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;
        // get Api client
        HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(consistencyGroup.getStorageSystemId(), driverRegistry);
        // get Vipr generated clone name
        for (VolumeClone clone : clones) {
            // native id = null ,
            _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());
        // Create vvset clone
        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());
            // snap.setAccessStatus(volResult.getAccessStatus());
            clone.setDisplayName(volResult.getName());
            clone.setReplicationState(VolumeClone.ReplicationState.SYNCHRONIZED);
            clone.setProvisionedCapacity(clone.getRequestedCapacity());
            // Allocated capacity is the sum of user, snapshot and admin reserved space
            Long allocatedCapacity = volResult.getUserSpace().getReservedMiB();
            allocatedCapacity += volResult.getSnapshotSpace().getReservedMiB();
            allocatedCapacity += volResult.getAdminSpace().getReservedMiB();
            clone.setAllocatedCapacity(allocatedCapacity * HP3PARConstants.MEGA_BYTE);
        }
        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;
}
Also used : HashMap(java.util.HashMap) VVSetVolumeClone(com.emc.storageos.hp3par.command.VVSetCloneList.VVSetVolumeClone) VolumeDetailsCommandResult(com.emc.storageos.hp3par.command.VolumeDetailsCommandResult) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) VVSetVolumeClone(com.emc.storageos.hp3par.command.VVSetCloneList.VVSetVolumeClone)

Aggregations

VVSetVolumeClone (com.emc.storageos.hp3par.command.VVSetCloneList.VVSetVolumeClone)2 VolumeDetailsCommandResult (com.emc.storageos.hp3par.command.VolumeDetailsCommandResult)2 VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)2 Gson (com.google.gson.Gson)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 HashMap (java.util.HashMap)1