Search in sources :

Example 1 with SmisCreateListReplicaJob

use of com.emc.storageos.volumecontroller.impl.smis.job.SmisCreateListReplicaJob in project coprhd-controller by CoprHD.

the class AbstractReplicaOperations method createListReplica.

@Override
public void createListReplica(StorageSystem storage, List<URI> replicaList, Boolean createInactive, TaskCompleter taskCompleter) {
    _log.info("createListReplica operation START");
    List<String> targetDeviceIds = new ArrayList<String>();
    try {
        List<String> sourceIds = new ArrayList<String>();
        List<String> labels = new ArrayList<String>();
        Map<String, URI> srcNativeIdToReplicaUriMap = new HashMap<String, URI>();
        Map<String, String> tgtToSrcMap = new HashMap<String, String>();
        String replicaGroupName = null;
        String sessionName = null;
        Volume source = null;
        boolean isThinlyProvisioned = false;
        for (URI replicaURI : replicaList) {
            BlockObject replica = BlockObject.fetch(_dbClient, replicaURI);
            source = (Volume) _helper.getSource(replica);
            // Use the existing replica group instance name for the new snaps to add.
            TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, source.getTenant().getURI());
            int maxLength = SmisConstants.MAX_VOLUME_NAME_LENGTH;
            if (storage.getUsingSmis80() && URIUtil.isType(replicaURI, BlockSnapshot.class)) {
                maxLength = SmisConstants.MAX_SMI80_SNAPSHOT_NAME_LENGTH;
            }
            String label = _nameGenerator.generate(tenant.getLabel(), replica.getLabel(), replicaURI.toString(), '-', maxLength);
            labels.add(label);
            replicaGroupName = replica.getReplicationGroupInstance();
            if (sessionName == null) {
                sessionName = getSnapshotSessionNameFromReplicaGroupName(replicaGroupName, storage.getId());
            }
            String sourceNativeId = source.getNativeId();
            isThinlyProvisioned = source.getThinlyProvisioned();
            sourceIds.add(sourceNativeId);
            srcNativeIdToReplicaUriMap.put(sourceNativeId, replica.getId());
            if (storage.deviceIsType(Type.vnxblock)) {
                // need to create target devices first
                final URI poolId = source.getPool();
                final List<String> newDeviceIds = ReplicationUtils.createTargetDevices(storage, replicaGroupName, label, createInactive, 1, poolId, source.getCapacity(), isThinlyProvisioned, null, taskCompleter, _dbClient, _helper, _cimPath);
                targetDeviceIds.addAll(newDeviceIds);
                tgtToSrcMap.put(newDeviceIds.get(0), source.getNativeId());
            }
        }
        int syncType = getSyncType(replicaList.get(0));
        CIMObjectPath[] sourceVolumePaths = _cimPath.getVolumePaths(storage, sourceIds.toArray(new String[sourceIds.size()]));
        CIMObjectPath[] targetDevicePaths = _cimPath.getVolumePaths(storage, targetDeviceIds.toArray(new String[targetDeviceIds.size()]));
        CIMObjectPath targetVPSnapPoolPath = null;
        if (syncType == SmisConstants.SNAPSHOT_VALUE && !volumeHasSnapshot(source)) {
            targetVPSnapPoolPath = ReplicationUtils.getTargetPoolForVPSnapCreation(storage, null, replicaGroupName, isThinlyProvisioned, _dbClient, _helper, _cimPath);
        }
        CIMArgument[] inArgs = _helper.getCreateListReplicaInputArguments(storage, sourceVolumePaths, targetDevicePaths, labels, syncType, replicaGroupName, sessionName, createInactive, targetVPSnapPoolPath);
        CIMArgument[] outArgs = new CIMArgument[5];
        CIMObjectPath replicationSvc = _cimPath.getControllerReplicationSvcPath(storage);
        _helper.invokeMethod(storage, replicationSvc, CREATE_LIST_REPLICA, inArgs, outArgs);
        CIMObjectPath job = _cimPath.getCimObjectPathFromOutputArgs(outArgs, JOB);
        ControllerServiceImpl.enqueueJob(new QueueJob(new SmisCreateListReplicaJob(job, storage.getId(), srcNativeIdToReplicaUriMap, tgtToSrcMap, syncType, !createInactive, taskCompleter)));
    } catch (Exception e) {
        final String errMsg = format("An exception occurred when trying to create list replica on storage system {0}", storage.getId());
        _log.error(errMsg, e);
        // Roll back changes
        ReplicationUtils.rollbackCreateReplica(storage, null, targetDeviceIds, taskCompleter, _dbClient, _helper, _cimPath);
        List<? extends BlockObject> replicas = BlockObject.fetch(_dbClient, replicaList);
        for (BlockObject replica : replicas) {
            replica.setInactive(true);
        }
        _dbClient.updateObject(replicas);
        ServiceError error = DeviceControllerErrors.smis.methodFailed("createListReplica", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _log.info("createListReplica operation END");
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CIMObjectPath(javax.cim.CIMObjectPath) URI(java.net.URI) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Volume(com.emc.storageos.db.client.model.Volume) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) SmisCreateListReplicaJob(com.emc.storageos.volumecontroller.impl.smis.job.SmisCreateListReplicaJob) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockObject(com.emc.storageos.db.client.model.BlockObject) CIMArgument(javax.cim.CIMArgument)

Aggregations

ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 BlockObject (com.emc.storageos.db.client.model.BlockObject)1 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 Volume (com.emc.storageos.db.client.model.Volume)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 SmisCreateListReplicaJob (com.emc.storageos.volumecontroller.impl.smis.job.SmisCreateListReplicaJob)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CIMArgument (javax.cim.CIMArgument)1 CIMObjectPath (javax.cim.CIMObjectPath)1