Search in sources :

Example 11 with DataDomainClient

use of com.emc.storageos.datadomain.restapi.DataDomainClient in project coprhd-controller by CoprHD.

the class DataDomainFileStorageDevice method updateExportRules.

@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    // Requested Export Rules
    List<ExportRule> exportAdd = args.getExportRulesToAdd();
    List<ExportRule> exportDelete = args.getExportRulesToDelete();
    List<ExportRule> exportModify = args.getExportRulesToModify();
    // Export path
    String exportPath;
    String subDir = args.getSubDirectory();
    StringBuilder path = new StringBuilder();
    if (!args.getFileOperation()) {
        path.append(args.getSnapshotPath());
    } else {
        path.append(args.getFs().getPath());
    }
    if ((subDir != null) && (subDir.length() > 0)) {
        path.append("/");
        path.append(subDir);
    }
    exportPath = path.toString();
    // Data Domain attaches a prefix to every file system path
    path = new StringBuilder();
    if (!exportPath.startsWith(DataDomainApiConstants.FS_PATH_BASE)) {
        path.append(DataDomainApiConstants.FS_PATH_BASE);
    }
    path.append(exportPath);
    _log.info("exportPath : {}", path);
    args.setExportPath(path.toString());
    // Check to ensure clients are not repeated
    if (repeatedClientsInRequest(exportAdd, exportDelete, exportModify)) {
        ServiceError serviceError = DeviceControllerErrors.datadomain.exportUpdateFailedRepeatedClients();
        return BiosCommandResult.createErrorResult(serviceError);
    }
    // Ensure that the clients being added don't already exist in
    // another export rule
    List<ExportRule> existingExports = args.getExistingDBExportRules();
    if (addingExistingClient(existingExports, path.toString(), exportAdd)) {
        ServiceError serviceError = DeviceControllerErrors.datadomain.exportUpdateFailedAddingExistingClient();
        return BiosCommandResult.createErrorResult(serviceError);
    }
    // To be processed export rules
    List<ExportRule> exportsToRemove = new ArrayList<>();
    List<ExportRule> exportsToAdd = new ArrayList<>();
    if (existingExports != null && !existingExports.isEmpty()) {
        args.setObjIdOnDevice(existingExports.get(0).getDeviceExportId());
        _log.info("Number of existng Rules found {}", existingExports.size());
    }
    // Create/Modify/Delete exports on the array
    DataDomainClient ddClient = getDataDomainClient(storage);
    if (ddClient == null) {
        _log.error("updateExportRules failed, provider unreachable");
        String op = "Update export rules";
        return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
    }
    URI storagePoolId = args.getFs().getPool();
    StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
    // may be deleted selectively without deleting the export.
    if ((exportModify != null) && (!exportModify.isEmpty())) {
        // Are all existing rules being modified?
        int existingRulesToModify = 0;
        int numExistingRules = 0;
        for (ExportRule modifyRule : exportModify) {
            String securityFlavor = modifyRule.getSecFlavor();
            for (ExportRule existingRule : existingExports) {
                if (existingRule.getExportPath().equals(path.toString())) {
                    if (existingRule.getSecFlavor().equals(securityFlavor)) {
                        existingRulesToModify++;
                    }
                    numExistingRules++;
                }
            }
        }
        if (existingRulesToModify == numExistingRules) {
            // All rules are being modified, delete the existing export on the array
            String deviceExportId = null;
            for (ExportRule existingRule : existingExports) {
                if (existingRule.getExportPath().equals(path.toString())) {
                    deviceExportId = existingRule.getDeviceExportId();
                    break;
                }
            }
            try {
                doDeleteFsExport(ddClient, storagePool.getNativeId(), deviceExportId);
            } catch (DataDomainApiException dde) {
                _log.error("Export update failed, device error.", dde);
                return BiosCommandResult.createErrorResult(dde);
            }
            // Export rules to create
            for (ExportRule modifyRule : exportModify) {
                exportsToAdd.add(modifyRule);
            }
            doCreateExports(ddClient, storagePool.getNativeId(), path.toString(), exportsToAdd);
            exportsToAdd.clear();
        } else {
            // end points selectively
            for (ExportRule modifyRule : exportModify) {
                String securityFlavor = modifyRule.getSecFlavor();
                ExportRule matchingRule = null;
                for (ExportRule existingRule : existingExports) {
                    if (existingRule.getSecFlavor().equals(securityFlavor)) {
                        matchingRule = existingRule;
                        break;
                    }
                }
                // Since the list has been validated already, we can safely assume we will
                // always find a matching existing rule.
                modifyRule.setExportPath(args.getExportPath());
                modifyRule.setFsID(args.getFsId());
                exportsToRemove.add(matchingRule);
                exportsToAdd.add(modifyRule);
            }
        }
    }
    // Process add list
    if ((exportAdd != null) && (!exportAdd.isEmpty())) {
        for (ExportRule newExport : exportAdd) {
            _log.info("Adding Export Rule {}", newExport);
            if (args.getFileObjExports() != null) {
                Collection<FileExport> expList = args.getFileObjExports().values();
                Iterator<FileExport> it = expList.iterator();
                FileExport exp = null;
                while (it.hasNext()) {
                    FileExport export = it.next();
                    if (export.getPath().equalsIgnoreCase(path.toString())) {
                        exp = export;
                    }
                }
                // set the device export id with export id.
                if (exp != null) {
                    if (exp.getIsilonId() != null) {
                        newExport.setDeviceExportId(exp.getIsilonId());
                    }
                    if (exp.getNativeId() != null) {
                        newExport.setDeviceExportId(exp.getNativeId());
                    }
                }
            }
            newExport.setExportPath(args.getExportPath());
            newExport.setFsID(args.getFsId());
            exportsToAdd.add(newExport);
        }
        // otherwise, update the exports.
        if (existingExports == null || existingExports.isEmpty()) {
            doCreateExports(ddClient, storagePool.getNativeId(), path.toString(), exportsToAdd);
            exportsToAdd.clear();
        }
    }
    // selectively, without disrupting unaffected end points.
    if ((exportDelete != null) && (!exportDelete.isEmpty())) {
        // Are all existing rules being deleted?
        int existingRulesToDelete = 0;
        for (ExportRule deleteRule : exportDelete) {
            String securityFlavor = deleteRule.getSecFlavor();
            for (ExportRule existingRule : existingExports) {
                if (existingRule.getSecFlavor().equals(securityFlavor)) {
                    existingRulesToDelete++;
                }
            }
        }
        if (existingRulesToDelete == existingExports.size()) {
            // All rules are being deleted, delete the existing export on the array
            String deviceExportId = existingExports.get(0).getDeviceExportId();
            try {
                doDeleteFsExport(ddClient, storagePool.getNativeId(), deviceExportId);
            } catch (DataDomainApiException dde) {
                _log.error("Export update failed, device error.", dde);
                return BiosCommandResult.createErrorResult(dde);
            }
        } else {
            // end points selectively
            for (ExportRule deleteRule : exportDelete) {
                String securityFlavor = deleteRule.getSecFlavor();
                ExportRule matchingRule = null;
                for (ExportRule existingRule : existingExports) {
                    if (existingRule.getSecFlavor().equals(securityFlavor)) {
                        matchingRule = existingRule;
                        break;
                    }
                }
                // Since the list has been validated already, we can safely assume we will
                // always find a matching existing rule.
                exportsToRemove.add(matchingRule);
            }
        }
    }
    _log.info("No of exports to be removed from the existing list {}", exportsToRemove.size());
    _log.info("No of exports to be added to the existing list {}", exportsToAdd.size());
    // Delete clients selectively
    try {
        String deviceExportId = null;
        for (ExportRule existingRule : existingExports) {
            if (existingRule.getExportPath().equals(path.toString())) {
                deviceExportId = existingRule.getDeviceExportId();
                break;
            }
        }
        boolean deleteClients = true;
        doAddDeleteClients(ddClient, storagePool.getNativeId(), deviceExportId, exportsToRemove, deleteClients);
    } catch (DataDomainApiException dde) {
        _log.error("Export update failed, device error.", dde);
        return BiosCommandResult.createErrorResult(dde);
    }
    // Create exports
    try {
        String deviceExportId = null;
        for (ExportRule existingRule : existingExports) {
            if (existingRule.getExportPath().equals(path.toString())) {
                deviceExportId = existingRule.getDeviceExportId();
                break;
            }
        }
        boolean deleteClients = false;
        doAddDeleteClients(ddClient, storagePool.getNativeId(), deviceExportId, exportsToAdd, deleteClients);
    } catch (DataDomainApiException dde) {
        _log.error("Export update failed, device error.", dde);
        return BiosCommandResult.createErrorResult(dde);
    }
    _log.info("DataDomainFileStorageDevice updateFSExportRules {} - complete", args.getFsId());
    return BiosCommandResult.createSuccessfulResult();
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) URI(java.net.URI) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) FileExport(com.emc.storageos.db.client.model.FileExport) ExportRule(com.emc.storageos.model.file.ExportRule)

Example 12 with DataDomainClient

use of com.emc.storageos.datadomain.restapi.DataDomainClient in project coprhd-controller by CoprHD.

the class DataDomainFileStorageDevice method doCreateFS.

@Override
public BiosCommandResult doCreateFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    _log.info("DataDomainFileStorageDevice doCreateFS {} with name {} - start", args.getFsId(), args.getFsName());
    // TODO
    try {
        _log.info("DataDomainFileStorageDevice doCreateFS {} with name {} - start", args.getFsId(), args.getFsName());
        DataDomainClient ddclient = getDataDomainClient(storage);
        if (ddclient == null) {
            _log.error("doCreateFS failed, provider unreachable");
            String op = "FS create";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        // Update path and mountPath
        // TODO: try to mount export
        String path = args.getFsName();
        String mountPath;
        if (!path.startsWith(DataDomainApiConstants.FS_PATH_BASE)) {
            mountPath = DataDomainApiConstants.FS_PATH_BASE + path;
        } else {
            mountPath = path;
        }
        _log.info("Mount path to mount the DataDomain File System {}", mountPath);
        args.setFsMountPath(mountPath);
        args.setFsPath(mountPath);
        // Create MTree
        // Data Domain expects capacity in Bytes
        Long mtreeCapacity = args.getFsCapacity();
        // TODO: Following two values are hard-coded for now, until they are implemented in UI
        Boolean enableRetention = false;
        String retentionMode = "compliance";
        DDMTreeInfo ddMtreeInfo = ddclient.createMTree(args.getStoragePool().getNativeId(), mountPath, mtreeCapacity, enableRetention, retentionMode);
        args.setFsNativeId(ddMtreeInfo.getId());
        String serialNumber = storage.getSerialNumber();
        if (serialNumber == null) {
            serialNumber = storage.getModel();
        }
        String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(storage.getSystemType(), serialNumber.toUpperCase(), ddMtreeInfo.getId());
        args.setFsNativeGuid(fsNativeGuid);
        args.setNewFSCapacity(args.getFsCapacity());
        if (args.getFsExtensions() == null) {
            args.initFsExtensions();
        }
        args.getFsExtensions().put(DataDomainApiConstants.TOTAL_PHYSICAL_CAPACITY, String.valueOf(args.getFsCapacity()));
        _log.info("DataDomainFileStorageDevice doCreateFS {} - complete", args.getFsId());
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doCreateFS failed, device error...attempting to delete FS to rollback.", e);
        // rollback this operation to prevent partial result of file share create
        BiosCommandResult rollbackResult = doDeleteFS(storage, args);
        if (rollbackResult.isCommandSuccess()) {
            _log.info("DataDomainFileStorageDevice doCreateFS {} - rollback completed.", args.getFsId());
        } else {
            _log.error("DataDomainFileStorageDevice doCreateFS {} - rollback failed,  message: {} .", args.getFsId(), rollbackResult.getMessage());
        }
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) DDMTreeInfo(com.emc.storageos.datadomain.restapi.model.DDMTreeInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient)

Example 13 with DataDomainClient

use of com.emc.storageos.datadomain.restapi.DataDomainClient in project coprhd-controller by CoprHD.

the class DataDomainFileStorageDevice method doDeleteFS.

@Override
public BiosCommandResult doDeleteFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    try {
        _log.info("DataDomainFileStorageDevice doDeleteFS {} - start", args.getFsId());
        DataDomainClient ddClient = getDataDomainClient(storage);
        if (ddClient == null) {
            _log.error("doDeleteFS failed, provider unreachable");
            String op = "FS delete";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        URI storagePoolId = args.getFs().getPool();
        StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
        // Delete the exports for this file system
        FSExportMap exportMap = args.getFsExports();
        List<FileExport> exportMapvalues = null;
        if (exportMap != null) {
            exportMapvalues = new ArrayList<>(exportMap.values());
        }
        if ((exportMap != null) && (exportMapvalues != null)) {
            try {
                ddDeleteExports(ddClient, storagePool.getNativeId(), exportMap, exportMapvalues);
            } catch (DataDomainApiException dde) {
                _log.error("Unable to delete exports for the FS: ", dde);
            }
        }
        // Delete the SMB shares for this file system
        SMBShareMap shareMap = args.getFsShares();
        List<SMBFileShare> shareMapValues = null;
        if (shareMap != null) {
            shareMapValues = new ArrayList<>(shareMap.values());
        }
        if ((shareMap != null) && (shareMapValues != null)) {
            try {
                ddDeleteShares(ddClient, storagePool.getNativeId(), shareMap, shareMapValues);
            } catch (DataDomainApiException dde) {
                _log.error("Unable to delete cifs shares for the FS: ", dde);
            }
        }
        // Delete mtree on the DD array
        DDServiceStatus ddSvcStatus = ddClient.deleteMTree(storagePool.getNativeId(), args.getFs().getNativeId());
        _log.info("DataDomainFileStorageDevice doDeleteFS {} - complete", args.getFsId());
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doDeleteFS failed, device error", e);
        return BiosCommandResult.createErrorResult(e);
    } catch (DataDomainResourceNotFoundException e) {
        _log.error("doDeleteFS failed, Mtree not found.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) DDServiceStatus(com.emc.storageos.datadomain.restapi.model.DDServiceStatus) DataDomainResourceNotFoundException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) URI(java.net.URI) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) FileExport(com.emc.storageos.db.client.model.FileExport) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 14 with DataDomainClient

use of com.emc.storageos.datadomain.restapi.DataDomainClient in project coprhd-controller by CoprHD.

the class DataDomainFileStorageDevice method doDeleteShares.

@Override
public BiosCommandResult doDeleteShares(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    try {
        _log.info("DataDomainFileStorageDevice doDeleteShares: {} - start");
        DataDomainClient ddClient = getDataDomainClient(storage);
        if (ddClient == null) {
            _log.error("doDeleteShares failed, provider unreachable");
            String op = "FS shares delete";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        URI storagePoolId = args.getFs().getPool();
        StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
        SMBShareMap currentShares = args.getFileObjShares();
        List<SMBFileShare> sharesToDelete = new ArrayList<SMBFileShare>();
        sharesToDelete.addAll(currentShares.values());
        ddDeleteShares(ddClient, storagePool.getNativeId(), currentShares, sharesToDelete);
        _log.info("DataDomainFileStorageDevice doDeleteShare {} - complete");
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doDeleteShare failed, device error.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) StoragePool(com.emc.storageos.db.client.model.StoragePool) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) ArrayList(java.util.ArrayList) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) URI(java.net.URI)

Example 15 with DataDomainClient

use of com.emc.storageos.datadomain.restapi.DataDomainClient in project coprhd-controller by CoprHD.

the class DataDomainFileStorageDevice method doExport.

@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    _log.info("DataDomainFileStorageDevice doExport {} - start", args.getFileObjId());
    // Snapshot Export operation is not supported by Data Domain.
    if (args.getFileOperation() == false) {
        return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.doCreateSnapshotExportFailed());
    }
    if ((exportList == null) || (exportList.isEmpty())) {
        return BiosCommandResult.createSuccessfulResult();
    }
    try {
        DataDomainClient ddClient = getDataDomainClient(storage);
        if (ddClient == null) {
            _log.error("doExport failed, provider unreachable");
            String op = "FS export";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        if ((args.getFsExports() == null) || (args.getFsExports().isEmpty())) {
            // Initialize exports map
            args.initFileObjExports();
        }
        // Go through the list of new exports and add each to create list
        // if not in the list of existing exports or to the modify list if
        // contained in the existing list
        FSExportMap currExpMap = args.getFsExports();
        List<FileExport> modifyFileExports = new ArrayList<>();
        List<FileExport> createFileExports = new ArrayList<>();
        ddInitCreateModifyFileExportLists(currExpMap, exportList, modifyFileExports, createFileExports);
        // Create new exports and add to file export map
        ddCreateExports(ddClient, args.getStoragePool().getNativeId(), args.getFsExports(), createFileExports);
        // Modify existing exports
        ddModifyExports(ddClient, args.getStoragePool().getNativeId(), args.getFsExports(), modifyFileExports);
        _log.info("DataDomainFileStorageDevice doExport {} - complete", args.getFileObjId());
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doExport failed, device error.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient)

Aggregations

DataDomainClient (com.emc.storageos.datadomain.restapi.DataDomainClient)17 DataDomainApiException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException)14 URI (java.net.URI)12 StoragePool (com.emc.storageos.db.client.model.StoragePool)8 ArrayList (java.util.ArrayList)7 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)5 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)5 DataDomainResourceNotFoundException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException)4 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)4 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)3 FileExport (com.emc.storageos.db.client.model.FileExport)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 DDMCInfoDetail (com.emc.storageos.datadomain.restapi.model.DDMCInfoDetail)2 DDMTreeInfo (com.emc.storageos.datadomain.restapi.model.DDMTreeInfo)2 DDServiceStatus (com.emc.storageos.datadomain.restapi.model.DDServiceStatus)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 ExportRule (com.emc.storageos.model.file.ExportRule)2 DDMTreeInfoDetail (com.emc.storageos.datadomain.restapi.model.DDMTreeInfoDetail)1 DDMtreeCapacityInfos (com.emc.storageos.datadomain.restapi.model.DDMtreeCapacityInfos)1