Search in sources :

Example 1 with StorageResource

use of com.emc.storageos.vnxe.models.StorageResource in project coprhd-controller by CoprHD.

the class VNXUnityBlockStorageDevice method doDeleteVolumes.

@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter completer) throws DeviceControllerException {
    logger.info("deleting volumes, array: {}", storageSystem.getSerialNumber());
    VNXeApiClient apiClient = getVnxUnityClient(storageSystem);
    Map<String, List<String>> cgNameMap = new HashMap<String, List<String>>();
    try {
        Set<URI> updateStoragePools = new HashSet<URI>();
        // Invoke a test failure if testing
        for (Volume volume : volumes) {
            String lunId = volume.getNativeId();
            if (NullColumnValueGetter.isNullValue(lunId)) {
                logger.info(String.format("The volume %s does not have native id, do nothing", volume.getLabel()));
                continue;
            }
            updateStoragePools.add(volume.getPool());
            if (!apiClient.checkLunExists(lunId)) {
                logger.info(String.format("The volume %s does not exist in the array, do nothing", volume.getLabel()));
                continue;
            }
            String cgName = volume.getReplicationGroupInstance();
            if (NullColumnValueGetter.isNotNullValue(cgName)) {
                List<String> lunIds = cgNameMap.get(cgName);
                if (lunIds == null) {
                    lunIds = new ArrayList<String>();
                    cgNameMap.put(cgName, lunIds);
                }
                lunIds.add(volume.getNativeId());
            } else {
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_035);
                apiClient.deleteLunSync(volume.getNativeId(), false);
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_036);
            }
        }
        for (Map.Entry<String, List<String>> entry : cgNameMap.entrySet()) {
            String cgName = entry.getKey();
            List<String> lunIDs = entry.getValue();
            String cgId = apiClient.getConsistencyGroupIdByName(cgName);
            boolean isRP = false;
            if (cgId != null && !cgId.isEmpty()) {
                // Check if the CG has blockHostAccess to a RP host. if the CG is exported to a RP, we could not delete the lun
                // directly, we have to remove the volume from the CG first, then delete it.
                StorageResource cg = apiClient.getStorageResource(cgId);
                List<BlockHostAccess> hosts = cg.getBlockHostAccess();
                if (hosts != null && !hosts.isEmpty()) {
                    for (BlockHostAccess hostAccess : hosts) {
                        VNXeBase hostId = hostAccess.getHost();
                        if (hostId != null) {
                            VNXeHost host = apiClient.getHostById(hostId.getId());
                            if (host != null) {
                                if (host.getType() == HostTypeEnum.RPA.getValue()) {
                                    // Remove the luns from the CG
                                    isRP = true;
                                    logger.info(String.format("Removing volumes from CG because the CG %sis exported to RP", cgName));
                                    VNXeUtils.getCGLock(workflowService, storageSystem, cgName, opId);
                                    InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_034);
                                    apiClient.removeLunsFromConsistencyGroup(cgId, lunIDs);
                                    for (String lunId : lunIDs) {
                                        logger.info(String.format("Deleting the volume %s", lunId));
                                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_035);
                                        apiClient.deleteLunSync(lunId, false);
                                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_036);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (!isRP) {
                VNXeUtils.getCGLock(workflowService, storageSystem, cgName, opId);
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_034);
                apiClient.deleteLunsFromConsistencyGroup(cgId, lunIDs);
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_037);
            }
        }
        for (URI pool : updateStoragePools) {
            VNXeJob.updateStoragePoolCapacity(dbClient, apiClient, pool, null);
        }
        completer.ready(dbClient);
    } catch (VNXeException e) {
        logger.error("Delete volumes got the exception", e);
        completer.error(dbClient, e);
    } catch (Exception ex) {
        logger.error("Delete volumes got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteVolumes", ex.getMessage());
        completer.error(dbClient, error);
    }
}
Also used : StorageResource(com.emc.storageos.vnxe.models.StorageResource) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) URI(java.net.URI) 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) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Volume(com.emc.storageos.db.client.model.Volume) VNXeException(com.emc.storageos.vnxe.VNXeException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashSet(java.util.HashSet)

Example 2 with StorageResource

use of com.emc.storageos.vnxe.models.StorageResource in project coprhd-controller by CoprHD.

the class VNXUnityUnManagedObjectDiscoverer method addObjectToUnManagedConsistencyGroup.

/**
 * Adds the passed in unmanaged volume to an unmanaged consistency group object
 *
 * @param apiClient
 *            - connection to Unity REST interface
 * @param unManagedVolume
 *            - unmanaged volume associated with a consistency group
 * @param cgNameToProcess
 *            - consistency group being processed
 * @param storageSystem
 *            - storage system the objects are on
 * @param dbClient
 *            - dbclient
 * @throws Exception
 */
private void addObjectToUnManagedConsistencyGroup(VNXeApiClient apiClient, UnManagedVolume unManagedVolume, String cgNameToProcess, StorageSystem storageSystem, DbClient dbClient) throws Exception {
    log.info("Unmanaged volume {} belongs to consistency group {} on the array", unManagedVolume.getLabel(), cgNameToProcess);
    // Update the unManagedVolume object with CG information
    unManagedVolume.getVolumeCharacterstics().put(SupportedVolumeCharacterstics.IS_VOLUME_ADDED_TO_CONSISTENCYGROUP.toString(), Boolean.TRUE.toString());
    String unManagedCGNativeGuid = NativeGUIDGenerator.generateNativeGuidForCG(storageSystem.getNativeGuid(), cgNameToProcess);
    // determine if the unmanaged CG already exists in the unManagedCGToUpdateMap or in the database
    // if the the unmanaged CG is not in either create a new one
    UnManagedConsistencyGroup unManagedCG = null;
    if (unManagedCGToUpdateMap.containsKey(unManagedCGNativeGuid)) {
        unManagedCG = unManagedCGToUpdateMap.get(unManagedCGNativeGuid);
        log.info("Unmanaged consistency group {} was previously added to the unManagedCGToUpdateMap", unManagedCG.getLabel());
    } else {
        unManagedCG = DiscoveryUtils.checkUnManagedCGExistsInDB(dbClient, unManagedCGNativeGuid);
        if (null == unManagedCG) {
            // unmanaged CG does not exist in the database, create it
            StorageResource res = apiClient.getStorageResource(cgNameToProcess);
            unManagedCG = createUnManagedCG(unManagedCGNativeGuid, res, storageSystem.getId(), dbClient);
            log.info("Created unmanaged consistency group: {}", unManagedCG.getId().toString());
        } else {
            log.info("Unmanaged consistency group {} was previously added to the database", unManagedCG.getLabel());
            // clean out the list of unmanaged volumes if this unmanaged cg was already
            // in the database and its first time being used in this discovery operation
            // the list should be re-populated by the current discovery operation
            log.info("Cleaning out unmanaged volume map from unmanaged consistency group: {}", unManagedCG.getLabel());
            unManagedCG.getUnManagedVolumesMap().clear();
        }
    }
    log.info("Adding unmanaged volume {} to unmanaged consistency group {}", unManagedVolume.getLabel(), unManagedCG.getLabel());
    // set the uri of the unmanaged CG in the unmanaged volume object
    unManagedVolume.getVolumeInformation().put(SupportedVolumeInformation.UNMANAGED_CONSISTENCY_GROUP_URI.toString(), unManagedCG.getId().toString());
    // add the unmanaged volume object to the unmanaged CG
    unManagedCG.getUnManagedVolumesMap().put(unManagedVolume.getNativeGuid(), unManagedVolume.getId().toString());
    // add the unmanaged CG to the map of unmanaged CGs to be updated in the database once all volumes have been
    // processed
    unManagedCGToUpdateMap.put(unManagedCGNativeGuid, unManagedCG);
    // add the unmanaged CG to the current set of CGs being discovered on the array. This is for book keeping later.
    allCurrentUnManagedCgURIs.add(unManagedCG.getId());
}
Also used : StorageResource(com.emc.storageos.vnxe.models.StorageResource) UnManagedConsistencyGroup(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedConsistencyGroup)

Example 3 with StorageResource

use of com.emc.storageos.vnxe.models.StorageResource in project coprhd-controller by CoprHD.

the class VNXeApiClient method createLunsInConsistencyGroup.

/**
 * Create multiple volumes in a lun group
 *
 * @param names
 * @param poolId
 * @param size
 * @param isThin
 * @param tieringPolicy
 * @param cgId
 * @return
 */
public VNXeCommandJob createLunsInConsistencyGroup(List<String> names, String poolId, Long size, boolean isThin, String tieringPolicy, String cgId) {
    _logger.info("creating luns in the consistencyGroup group: {}", cgId);
    LunGroupModifyParam param = new LunGroupModifyParam();
    List<LunCreateParam> lunCreates = new ArrayList<LunCreateParam>();
    boolean isPolicyOn = false;
    FastVPParam fastVP = new FastVPParam();
    if (tieringPolicy != null && !tieringPolicy.isEmpty()) {
        TieringPolicyEnum tierValue = TieringPolicyEnum.valueOf(tieringPolicy);
        if (tierValue != null) {
            fastVP.setTieringPolicy(tierValue.getValue());
            isPolicyOn = true;
        }
    }
    StorageResourceRequest cgRequest = new StorageResourceRequest(_khClient);
    StorageResource cg = cgRequest.get(cgId);
    for (String lunName : names) {
        LunParam lunParam = new LunParam();
        lunParam.setIsThinEnabled(isThin);
        lunParam.setSize(size);
        lunParam.setPool(new VNXeBase(poolId));
        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(lunName);
        createParam.setLunParameters(lunParam);
        if (isPolicyOn) {
            lunParam.setFastVPParameters(fastVP);
        }
        lunCreates.add(createParam);
    }
    param.setLunCreate(lunCreates);
    ConsistencyGroupRequests req = new ConsistencyGroupRequests(_khClient);
    return req.modifyConsistencyGroupAsync(cgId, param);
}
Also used : StorageResource(com.emc.storageos.vnxe.models.StorageResource) FastVPParam(com.emc.storageos.vnxe.models.FastVPParam) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ArrayList(java.util.ArrayList) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) TieringPolicyEnum(com.emc.storageos.vnxe.models.StorageResource.TieringPolicyEnum) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunParam(com.emc.storageos.vnxe.models.LunParam) StorageResourceRequest(com.emc.storageos.vnxe.requests.StorageResourceRequest) DeleteStorageResourceRequest(com.emc.storageos.vnxe.requests.DeleteStorageResourceRequest) LunCreateParam(com.emc.storageos.vnxe.models.LunCreateParam)

Example 4 with StorageResource

use of com.emc.storageos.vnxe.models.StorageResource in project coprhd-controller by CoprHD.

the class DeleteStorageResourceRequest method deleteLunGroup.

/**
 * Delete lun group
 *
 * @param groupId
 * @param isForceSnapDeletion
 * @return
 * @throws VNXeException
 */
public VNXeCommandResult deleteLunGroup(String groupId, boolean isForceSnapDeletion) throws VNXeException {
    StorageResourceRequest req = new StorageResourceRequest(_client);
    StorageResource group = req.get(groupId);
    if (group == null) {
        String error = "Could not find lun group: " + groupId;
        _logger.error(error);
        throw VNXeException.exceptions.vnxeCommandFailed(error);
    }
    return deleteResourceSync(groupId, isForceSnapDeletion);
}
Also used : StorageResource(com.emc.storageos.vnxe.models.StorageResource)

Example 5 with StorageResource

use of com.emc.storageos.vnxe.models.StorageResource in project coprhd-controller by CoprHD.

the class ApiClientTest method getCG.

// @Test
public void getCG() {
    StorageResourceRequest req = new StorageResourceRequest(_client);
    StorageResource res = req.get("res_1");
    System.out.println(res.getName());
    System.out.println(res.getLuns().size());
}
Also used : StorageResource(com.emc.storageos.vnxe.models.StorageResource)

Aggregations

StorageResource (com.emc.storageos.vnxe.models.StorageResource)5 BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)2 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)2 ArrayList (java.util.ArrayList)2 StringMap (com.emc.storageos.db.client.model.StringMap)1 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)1 UnManagedConsistencyGroup (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedConsistencyGroup)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 FastVPParam (com.emc.storageos.vnxe.models.FastVPParam)1 LunCreateParam (com.emc.storageos.vnxe.models.LunCreateParam)1 LunGroupModifyParam (com.emc.storageos.vnxe.models.LunGroupModifyParam)1 LunParam (com.emc.storageos.vnxe.models.LunParam)1 TieringPolicyEnum (com.emc.storageos.vnxe.models.StorageResource.TieringPolicyEnum)1 VNXeHost (com.emc.storageos.vnxe.models.VNXeHost)1 ConsistencyGroupRequests (com.emc.storageos.vnxe.requests.ConsistencyGroupRequests)1