Search in sources :

Example 56 with VNXeApiClient

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

the class VNXeExportOperations method addInitiators.

@Override
public void addInitiators(StorageSystem storage, URI exportMaskUri, List<URI> volumeURIs, List<Initiator> initiatorList, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
    _logger.info("{} addInitiator START...", storage.getSerialNumber());
    List<Initiator> createdInitiators = new ArrayList<Initiator>();
    ExportMask exportMask = null;
    try {
        ExportOperationContext context = new VNXeExportOperationContext();
        taskCompleter.updateWorkflowStepContext(context);
        exportMask = _dbClient.queryObject(ExportMask.class, exportMaskUri);
        if (exportMask == null || exportMask.getInactive()) {
            throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskUri);
        }
        VNXeApiClient apiClient = getVnxeClient(storage);
        List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
        // Finding existing host from the array
        Collection<VNXeHostInitiator> vnxeInitiators = prepareInitiators(initiators).values();
        String hostId = null;
        for (VNXeHostInitiator init : vnxeInitiators) {
            VNXeHostInitiator foundInit = apiClient.getInitiatorByWWN(init.getInitiatorId());
            if (foundInit != null) {
                VNXeBase host = foundInit.getParentHost();
                if (host != null) {
                    hostId = host.getId();
                    break;
                }
            }
        }
        if (hostId == null) {
            String msg = String.format("No existing host found in the array for the existing exportMask %s", exportMask.getMaskName());
            _logger.error(msg);
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addiniator", msg);
            taskCompleter.error(_dbClient, error);
            return;
        }
        validateInitiators(_dbClient, initiatorList, apiClient, hostId);
        Map<Initiator, VNXeHostInitiator> initiatorMap = prepareInitiators(initiatorList);
        for (Entry<Initiator, VNXeHostInitiator> entry : initiatorMap.entrySet()) {
            VNXeHostInitiator newInit = entry.getValue();
            VNXeHostInitiator init = apiClient.getInitiatorByWWN(newInit.getInitiatorId());
            // COP-27752 - fresh deleted initiator may not be deleted completely
            int retry = 0;
            while (retry <= MAX_REMOVE_INITIATOR_RETRIES && init != null && init.getParentHost() == null) {
                try {
                    Thread.sleep(WAIT_FOR_RETRY);
                } catch (InterruptedException e1) {
                    Thread.currentThread().interrupt();
                }
                init = apiClient.getInitiatorByWWN(newInit.getInitiatorId());
            }
            if (init != null) {
                // found it
                VNXeBase host = init.getParentHost();
                if (host != null && host.getId().equals(hostId)) {
                    // do nothing. it is already in the array
                    _logger.info("The initiator exist in the host in the array");
                } else if (host == null) {
                    // initiator without parent host, add parent host
                    apiClient.setInitiatorHost(init.getId(), hostId);
                } else {
                    String msg = String.format("Initiator %s belongs to %s, but other initiator belongs to %s. Please move initiator to the correct host", init.getInitiatorId(), host.getId(), hostId);
                    _logger.error(msg);
                    if (!createdInitiators.isEmpty()) {
                        for (Initiator initiator : createdInitiators) {
                            exportMask.getInitiators().add(initiator.getId().toString());
                        }
                        _dbClient.updateObject(exportMask);
                        ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_INITIATORS_TO_HOST, createdInitiators);
                    }
                    ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addiniator", msg);
                    taskCompleter.error(_dbClient, error);
                    return;
                }
            } else {
                apiClient.createInitiator(newInit, hostId);
                createdInitiators.add(entry.getKey());
            }
        }
        for (Initiator initiator : initiatorList) {
            exportMask.getInitiators().add(initiator.getId().toString());
        }
        _dbClient.updateObject(exportMask);
        ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_INITIATORS_TO_HOST, createdInitiators);
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_003);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _logger.error("Add initiators error: ", e);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addInitiator", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 57 with VNXeApiClient

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

the class VNXeJob method getVNXeClient.

/**
 * Get VNXe API client
 *
 * @param jobContext
 * @return
 */
public VNXeApiClient getVNXeClient(JobContext jobContext) {
    VNXeApiClient vnxeApiClient = null;
    StorageSystem storageSystem = jobContext.getDbClient().queryObject(StorageSystem.class, _storageSystemUri);
    if (Type.unity.name().equalsIgnoreCase(storageSystem.getSystemType())) {
        vnxeApiClient = jobContext.getVNXeApiClientFactory().getUnityClient(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword());
    } else {
        vnxeApiClient = jobContext.getVNXeApiClientFactory().getClient(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword());
    }
    return vnxeApiClient;
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 58 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient 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 59 with VNXeApiClient

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

the class VNXUnityBlockStorageDevice method doExpandVolume.

@Override
public void doExpandVolume(StorageSystem storage, StoragePool pool, Volume volume, Long size, TaskCompleter taskCompleter) throws DeviceControllerException {
    logger.info(String.format("Expand Volume Start - Array: %s, Pool: %s, Volume: %s, New size: %d", storage.getSerialNumber(), pool.getNativeGuid(), volume.getLabel(), size));
    String cgName = volume.getReplicationGroupInstance();
    String consistencyGroupId = null;
    try {
        VNXeApiClient apiClient = getVnxUnityClient(storage);
        if (NullColumnValueGetter.isNotNullValue(cgName)) {
            consistencyGroupId = apiClient.getConsistencyGroupIdByName(cgName);
            VNXeUtils.getCGLock(workflowService, storage, cgName, taskCompleter.getOpId());
        }
        VNXeCommandJob commandJob = apiClient.expandLun(volume.getNativeId(), size, consistencyGroupId);
        VNXeExpandVolumeJob expandVolumeJob = new VNXeExpandVolumeJob(commandJob.getId(), storage.getId(), taskCompleter);
        ControllerServiceImpl.enqueueJob(new QueueJob(expandVolumeJob));
    } catch (VNXeException e) {
        logger.error("Expand volume got the exception", e);
        taskCompleter.error(dbClient, e);
    } catch (Exception ex) {
        logger.error("Expand volume got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("ExpandVolume", ex.getMessage());
        taskCompleter.error(dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException) VNXeExpandVolumeJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeExpandVolumeJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) 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)

Example 60 with VNXeApiClient

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

the class VNXUnityBlockStorageDevice method doAddToConsistencyGroup.

@Override
public void doAddToConsistencyGroup(StorageSystem storage, URI consistencyGroupId, String replicationGroupName, List<URI> blockObjects, TaskCompleter taskCompleter) throws DeviceControllerException {
    BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
    VNXeApiClient apiClient = getVnxUnityClient(storage);
    try {
        List<String> luns = new ArrayList<String>();
        for (URI volume : blockObjects) {
            BlockObject blockObject = BlockObject.fetch(dbClient, volume);
            if (blockObject instanceof Volume) {
                Volume lun = (Volume) blockObject;
                luns.add(lun.getNativeId());
            } else {
                String errorStr = String.format("The blockObject %s is not a volume. it is not supported.", volume.toString());
                logger.error(errorStr);
                handleAddToCGError(blockObjects, taskCompleter, consistencyGroup.getLabel(), replicationGroupName, errorStr);
                return;
            }
        }
        String cgNativeId = apiClient.getConsistencyGroupIdByName(replicationGroupName);
        if (cgNativeId == null || cgNativeId.isEmpty()) {
            String errorStr = String.format("Could not find the consistency group %s in the error", replicationGroupName);
            logger.error(errorStr);
            handleAddToCGError(blockObjects, taskCompleter, consistencyGroup.getLabel(), replicationGroupName, errorStr);
            return;
        }
        apiClient.addLunsToConsistencyGroup(cgNativeId, luns);
        for (URI blockObjectURI : blockObjects) {
            BlockObject blockObject = BlockObject.fetch(dbClient, blockObjectURI);
            if (blockObject != null) {
                blockObject.setConsistencyGroup(consistencyGroupId);
            }
            dbClient.updateObject(blockObject);
        }
        taskCompleter.ready(dbClient);
        logger.info("Added volumes to the consistency group successfully");
    } catch (Exception e) {
        logger.error("Exception caught when adding volumes to the consistency group ", e);
        handleAddToCGError(blockObjects, taskCompleter, consistencyGroup.getLabel(), replicationGroupName, e.getMessage());
    }
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) 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) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Aggregations

VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)123 VNXeException (com.emc.storageos.vnxe.VNXeException)79 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)66 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)55 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)48 ControllerException (com.emc.storageos.volumecontroller.ControllerException)44 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)40 URI (java.net.URI)37 ArrayList (java.util.ArrayList)34 FileShare (com.emc.storageos.db.client.model.FileShare)33 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)33 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)30 Snapshot (com.emc.storageos.db.client.model.Snapshot)27 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)24 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)23 DbClient (com.emc.storageos.db.client.DbClient)21 Volume (com.emc.storageos.db.client.model.Volume)18 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)18 FileExport (com.emc.storageos.db.client.model.FileExport)14 HashMap (java.util.HashMap)14