Search in sources :

Example 41 with VNXeApiClient

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

the class VNXeExportFileSystemJob method updateStatus.

/**
 * Called to update the job status when the export file system job completes.
 *
 * @param jobContext The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
        FileShare fsObj = null;
        Snapshot snapObj = null;
        URI objId = getTaskCompleter().getId();
        StorageSystem storageObj = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS) {
            _isSuccess = true;
            FileExport newExport = exportInfo.getFileExport();
            newExport.setMountPoint(ExportUtils.getFileMountPoint(exportInfo.getStoragePort(), exportInfo.getMountPath()));
            if (isFile) {
                fsObj = dbClient.queryObject(FileShare.class, objId);
                updateFSExport(fsObj, dbClient, vnxeApiClient, newExport);
            } else {
                snapObj = updateSnapExport(dbClient, vnxeApiClient, newExport);
                fsObj = dbClient.queryObject(FileShare.class, snapObj.getParent().getURI());
            }
        } else if (_status == JobStatus.FAILED) {
            // cleanupFSExport(fsObj, dbClient);
            logMsgBuilder.append("\n");
            logMsgBuilder.append(String.format("Task %s failed to export file system: %s", opId, objId.toString()));
        }
        _logger.info(logMsgBuilder.toString());
        if (isFile) {
            fsObj = dbClient.queryObject(FileShare.class, objId);
            FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.EXPORT_FILE_SYSTEM, _isSuccess, logMsgBuilder.toString(), "", fsObj, storageObj);
        } else {
            snapObj = dbClient.queryObject(Snapshot.class, objId);
            fsObj = dbClient.queryObject(FileShare.class, snapObj.getParent().getURI());
            FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.EXPORT_FILE_SNAPSHOT, _isSuccess, logMsgBuilder.toString(), "", snapObj, fsObj, storageObj);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeExportFIleSystemJob", e);
        setErrorStatus("Encountered an internal error during file system export job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) FileExport(com.emc.storageos.db.client.model.FileExport) FileShare(com.emc.storageos.db.client.model.FileShare) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 42 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 43 with VNXeApiClient

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

the class VNXUnityBlockStorageDevice method doDeleteConsistencyGroup.

@Override
public void doDeleteConsistencyGroup(StorageSystem storage, URI consistencyGroupId, String replicationGroupName, Boolean keepRGName, Boolean markInactive, TaskCompleter taskCompleter) throws DeviceControllerException {
    logger.info("Deleting consistency group, array: {}", storage.getSerialNumber());
    BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
    StringSet cgNames = new StringSet();
    if (NullColumnValueGetter.isNullValue(replicationGroupName)) {
        StringSetMap ssm = consistencyGroup.getSystemConsistencyGroups();
        if (ssm != null) {
            cgNames = ssm.get(storage.getId().toString());
            if (cgNames == null || cgNames.isEmpty()) {
                logger.info("There is no array consistency group to be deleted.");
                // Clean up the system consistency group references
                BlockConsistencyGroupUtils.cleanUpCGAndUpdate(consistencyGroup, storage.getId(), null, markInactive, dbClient);
                taskCompleter.ready(dbClient);
                return;
            }
        }
    } else {
        cgNames.add(replicationGroupName);
    }
    VNXeApiClient apiClient = getVnxUnityClient(storage);
    try {
        for (String cgName : cgNames) {
            logger.info("Deleting the consistency group {}", cgName);
            String id = apiClient.getConsistencyGroupIdByName(cgName);
            if (id != null && !id.isEmpty()) {
                apiClient.deleteConsistencyGroup(id, false, false);
            }
            if (!keepRGName) {
                // Clean up the system consistency group references
                BlockConsistencyGroupUtils.cleanUpCGAndUpdate(consistencyGroup, storage.getId(), cgName, markInactive, dbClient);
                if (consistencyGroup.getInactive()) {
                    logger.info("CG is deleted");
                }
            }
        }
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        logger.info("Failed to delete consistency group: " + e);
        // Set task to error
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("doDeleteConsistencyGroup", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) StringSet(com.emc.storageos.db.client.model.StringSet) 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)

Example 44 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient 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 {
        boolean isCG = false;
        Volume vol = volumes.get(0);
        String cgName = vol.getReplicationGroupInstance();
        if (vol.getConsistencyGroup() != null && NullColumnValueGetter.isNotNullValue(cgName)) {
            isCG = true;
        }
        List<String> volNames = new ArrayList<String>();
        String autoTierPolicyName = null;
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_022);
        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);
            autoTierPolicyName = ControllerUtils.getAutoTieringPolicyName(volume.getId(), dbClient);
            if (autoTierPolicyName.equals(Constants.NONE)) {
                autoTierPolicyName = null;
            }
            volume.setNativeGuid(label);
            dbClient.updateObject(volume);
            if (!isCG) {
                VNXeCommandJob job = apiClient.createLun(label, storagePool.getNativeId(), volume.getCapacity(), volume.getThinlyProvisioned(), autoTierPolicyName);
                jobs.add(job.getId());
            } else {
                volNames.add(label);
            }
        }
        if (isCG) {
            logger.info(String.format("cg %s for the volume", cgName));
            String cgId = apiClient.getConsistencyGroupIdByName(cgName);
            VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
            VNXeCommandJob job = apiClient.createLunsInConsistencyGroup(volNames, storagePool.getNativeId(), vol.getCapacity(), vol.getThinlyProvisioned(), autoTierPolicyName, cgId);
            jobs.add(job.getId());
        }
        VNXeCreateVolumesJob createVolumesJob = new VNXeCreateVolumesJob(jobs, storage.getId(), taskCompleter, storagePool.getId(), isCG);
        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 : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ArrayList(java.util.ArrayList) VNXeCreateVolumesJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeCreateVolumesJob) 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) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) 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) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Example 45 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)

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)36 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)13