Search in sources :

Example 1 with VNXUnityCreateVolumesJob

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

the class VNXUnityBlockStorageDevice method doCreateVolumes.

@Override
public void doCreateVolumes(StorageSystem storage, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
    logger.info("creating volumes, array: {}, pool : {}", storage.getSerialNumber(), storagePool.getNativeId());
    VNXeApiClient apiClient = getVnxUnityClient(storage);
    List<String> jobs = new ArrayList<String>();
    boolean opFailed = false;
    try {
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_022);
        Map<String, List<Volume>> cgVolumes = new HashMap<String, List<Volume>>();
        Map<String, List<URI>> jobVolumesMap = new HashMap<String, List<URI>>();
        for (Volume volume : volumes) {
            String tenantName = "";
            try {
                TenantOrg tenant = dbClient.queryObject(TenantOrg.class, volume.getTenant().getURI());
                tenantName = tenant.getLabel();
            } catch (DatabaseException e) {
                logger.error("Error lookup TenantOrb object", e);
            }
            String label = nameGenerator.generate(tenantName, volume.getLabel(), volume.getId().toString(), '-', VNXeConstants.MAX_NAME_LENGTH);
            String cgName = volume.getReplicationGroupInstance();
            volume.setNativeGuid(label);
            dbClient.updateObject(volume);
            if (NullColumnValueGetter.isNullValue(cgName)) {
                String autoTierPolicyName = ControllerUtils.getAutoTieringPolicyName(volume.getId(), dbClient);
                if (autoTierPolicyName.equals(Constants.NONE)) {
                    autoTierPolicyName = null;
                }
                VNXeCommandJob job = apiClient.createLun(label, storagePool.getNativeId(), volume.getCapacity(), volume.getThinlyProvisioned(), autoTierPolicyName);
                jobs.add(job.getId());
                jobVolumesMap.put(job.getId(), Arrays.asList(volume.getId()));
            } else {
                logger.info(String.format("Creating the volume %s in CG %s", volume.getLabel(), cgName));
                List<Volume> vols = cgVolumes.get(cgName);
                if (vols == null) {
                    vols = new ArrayList<Volume>();
                }
                vols.add(volume);
                cgVolumes.put(cgName, vols);
            }
        }
        for (Map.Entry<String, List<Volume>> cgVol : cgVolumes.entrySet()) {
            // Creating volumes in a CG
            String cgName = cgVol.getKey();
            String cgId = apiClient.getConsistencyGroupIdByName(cgName);
            if (cgId == null) {
                String errorMsg = String.format("The CG %s could not be found in the array", cgName);
                logger.error(errorMsg);
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateVolumes", errorMsg);
                taskCompleter.error(dbClient, error);
                dbClient.markForDeletion(cgVol.getValue());
                return;
            }
            List<Volume> vols = cgVol.getValue();
            VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
            List<LunCreateParam> lunCreates = new ArrayList<LunCreateParam>();
            StorageResource cg = apiClient.getConsistencyGroup(cgId);
            List<URI> volURIs = new ArrayList<URI>();
            for (Volume volToCreate : vols) {
                volURIs.add(volToCreate.getId());
                boolean isPolicyOn = false;
                String tierPolicy = ControllerUtils.getAutoTieringPolicyName(volToCreate.getId(), dbClient);
                FastVPParam fastVP = new FastVPParam();
                if (!tierPolicy.equals(Constants.NONE)) {
                    TieringPolicyEnum tierValue = TieringPolicyEnum.valueOf(tierPolicy);
                    if (tierValue != null) {
                        fastVP.setTieringPolicy(tierValue.getValue());
                        isPolicyOn = true;
                    }
                }
                // Construct Unity API LunParam for each volume to be created.
                LunParam lunParam = new LunParam();
                lunParam.setIsThinEnabled(volToCreate.getThinlyProvisioned());
                lunParam.setSize(volToCreate.getCapacity());
                lunParam.setPool(new VNXeBase(storagePool.getNativeId()));
                List<BlockHostAccess> hostAccesses = cg.getBlockHostAccess();
                if (hostAccesses != null && !hostAccesses.isEmpty()) {
                    for (BlockHostAccess hostAccess : hostAccesses) {
                        hostAccess.setAccessMask(HostLUNAccessEnum.NOACCESS.getValue());
                    }
                    lunParam.setHostAccess(hostAccesses);
                }
                LunCreateParam createParam = new LunCreateParam();
                createParam.setName(volToCreate.getLabel());
                createParam.setLunParameters(lunParam);
                if (isPolicyOn) {
                    lunParam.setFastVPParameters(fastVP);
                }
                lunCreates.add(createParam);
            }
            VNXeCommandJob result = apiClient.createLunsInConsistencyGroup(lunCreates, cgId);
            jobs.add(result.getId());
            jobVolumesMap.put(result.getId(), volURIs);
        }
        VNXUnityCreateVolumesJob createVolumesJob = new VNXUnityCreateVolumesJob(jobVolumesMap, jobs, storage.getId(), taskCompleter, storagePool.getId());
        ControllerServiceImpl.enqueueJob(new QueueJob(createVolumesJob));
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_023);
    } catch (VNXeException e) {
        logger.error("Create volumes got the exception", e);
        opFailed = true;
        taskCompleter.error(dbClient, e);
    } catch (Exception ex) {
        logger.error("Create volumes got the exception", ex);
        opFailed = true;
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateVolumes", ex.getMessage());
        taskCompleter.error(dbClient, error);
    }
    if (opFailed) {
        for (Volume vol : volumes) {
            vol.setInactive(true);
            dbClient.updateObject(vol);
        }
    }
}
Also used : StorageResource(com.emc.storageos.vnxe.models.StorageResource) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) TieringPolicyEnum(com.emc.storageos.vnxe.models.StorageResource.TieringPolicyEnum) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) List(java.util.List) ArrayList(java.util.ArrayList) VNXUnityCreateVolumesJob(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityCreateVolumesJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FastVPParam(com.emc.storageos.vnxe.models.FastVPParam) VNXeException(com.emc.storageos.vnxe.VNXeException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) LunParam(com.emc.storageos.vnxe.models.LunParam) Volume(com.emc.storageos.db.client.model.Volume) VNXeException(com.emc.storageos.vnxe.VNXeException) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) LunCreateParam(com.emc.storageos.vnxe.models.LunCreateParam) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Aggregations

StringMap (com.emc.storageos.db.client.model.StringMap)1 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 Volume (com.emc.storageos.db.client.model.Volume)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)1 VNXeException (com.emc.storageos.vnxe.VNXeException)1 BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)1 FastVPParam (com.emc.storageos.vnxe.models.FastVPParam)1 LunCreateParam (com.emc.storageos.vnxe.models.LunCreateParam)1 LunParam (com.emc.storageos.vnxe.models.LunParam)1 StorageResource (com.emc.storageos.vnxe.models.StorageResource)1 TieringPolicyEnum (com.emc.storageos.vnxe.models.StorageResource.TieringPolicyEnum)1 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)1 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 VNXUnityCreateVolumesJob (com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityCreateVolumesJob)1