Search in sources :

Example 11 with VNXeApiClient

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

the class VNXeStorageDevice method extraExportRuleFromArray.

/**
 * Get the export rule which are present in array but not in CoprHD Database.
 *
 * @param storage
 * @param args
 * @return map with security flavor and export rule
 */
private Map<String, ExportRule> extraExportRuleFromArray(StorageSystem storage, FileDeviceInputOutput args) {
    // map to store the export rule grouped by sec flavor
    Map<String, ExportRule> exportRuleMap = new HashMap<>();
    List<VNXeNfsShare> exportsList = new ArrayList<VNXeNfsShare>();
    Set<String> arrayReadOnlyHost = new HashSet<>();
    Set<String> arrayReadWriteHost = new HashSet<>();
    Set<String> arrayRootHost = new HashSet<>();
    Set<String> dbReadOnlyHost = new HashSet<>();
    Set<String> dbReadWriteHost = new HashSet<>();
    Set<String> dbRootHost = new HashSet<>();
    // get all export rule from CoprHD data base
    List<ExportRule> existingDBExportRules = args.getExistingDBExportRules();
    // get the all the export from the storage system.
    VNXeApiClient apiClient = getVnxeClient(storage);
    for (ExportRule exportRule : existingDBExportRules) {
        if (exportRule.getReadOnlyHosts() != null) {
            dbReadOnlyHost.addAll(exportRule.getReadOnlyHosts());
        }
        if (exportRule.getReadWriteHosts() != null) {
            dbReadWriteHost.addAll(exportRule.getReadWriteHosts());
        }
        if (exportRule.getRootHosts() != null) {
            dbRootHost.addAll(exportRule.getRootHosts());
        }
        String vnxeExportId = exportRule.getDeviceExportId();
        if (vnxeExportId != null) {
            List<VNXeNfsShare> vnxeExports = null;
            vnxeExports = apiClient.getNfsSharesForFileSystem(args.getFs().getNativeId());
            exportsList.addAll(vnxeExports);
            for (VNXeNfsShare vnXeNfsShare : vnxeExports) {
                List<VNXeBase> hostIdReadOnly = vnXeNfsShare.getReadOnlyHosts();
                for (VNXeBase vnXeBase : hostIdReadOnly) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayReadOnlyHost.add(host.getName());
                }
                List<VNXeBase> hostIdReadWrite = vnXeNfsShare.getReadWriteHosts();
                for (VNXeBase vnXeBase : hostIdReadWrite) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayReadWriteHost.add(host.getName());
                }
                List<VNXeBase> hostIdRootHost = vnXeNfsShare.getRootAccessHosts();
                for (VNXeBase vnXeBase : hostIdRootHost) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayRootHost.add(host.getName());
                }
            }
        }
        // find out the change between array and CoprHD database.
        Set<String> arrayExtraReadOnlyHost = Sets.difference(arrayReadOnlyHost, dbReadOnlyHost);
        Set<String> arrayExtraReadWriteHost = Sets.difference(arrayReadWriteHost, dbReadWriteHost);
        Set<String> arrayExtraRootHost = Sets.difference(arrayRootHost, dbRootHost);
        // if change found update the exportRuleMap
        if (!arrayExtraReadOnlyHost.isEmpty() || !arrayExtraReadWriteHost.isEmpty() || !arrayExtraRootHost.isEmpty()) {
            ExportRule extraRuleFromArray = new ExportRule();
            extraRuleFromArray.setDeviceExportId(exportRule.getDeviceExportId());
            extraRuleFromArray.setAnon(exportRule.getAnon());
            extraRuleFromArray.setSecFlavor(exportRule.getSecFlavor());
            extraRuleFromArray.setExportPath(exportRule.getExportPath());
            extraRuleFromArray.setReadOnlyHosts(arrayExtraReadOnlyHost);
            extraRuleFromArray.setReadWriteHosts(arrayExtraReadWriteHost);
            extraRuleFromArray.setRootHosts(arrayExtraRootHost);
            exportRuleMap.put(exportRule.getSecFlavor(), extraRuleFromArray);
        }
    }
    return exportRuleMap;
}
Also used : HashMap(java.util.HashMap) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ArrayList(java.util.ArrayList) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) ExportRule(com.emc.storageos.model.file.ExportRule) HashSet(java.util.HashSet)

Example 12 with VNXeApiClient

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

the class VNXeStorageDevice method doConnect.

@Override
public void doConnect(StorageSystem storage) throws ControllerException {
    try {
        _logger.info("doConnect {} - start", storage.getId());
        VNXeApiClient client = getVnxeClient(storage);
        client.getStorageSystem();
        String msg = String.format("doConnect %1$s - complete", storage.getId());
        _logger.info(msg);
    } catch (VNXeException e) {
        _logger.error("doConnect failed.", e);
        throw DeviceControllerException.exceptions.connectStorageFailed(e);
    }
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException)

Example 13 with VNXeApiClient

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

the class VNXeStorageDevice method doRestoreFS.

@Override
public BiosCommandResult doRestoreFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    _logger.info("restoring file system {} snap {} ", args.getFsName(), args.getSnapshotLabel());
    VNXeApiClient apiClient = getVnxeClient(storage);
    VNXeCommandJob job = null;
    VNXeFSSnapshotTaskCompleter completer = null;
    try {
        job = apiClient.restoreFileSystemSnap(args.getSnapNativeId());
        if (job != null) {
            completer = new VNXeFSSnapshotTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
            VNXeRestoreFileSystemSnapshotJob snapJob = new VNXeRestoreFileSystemSnapshotJob(job.getId(), storage.getId(), completer);
            ControllerServiceImpl.enqueueJob(new QueueJob(snapJob));
        } else {
            _logger.error("No job returned from restoreFileSystemSnap");
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("restoreSnapshotFileSystem", "No Job returned from restoreFileSystemSnap");
            return BiosCommandResult.createErrorResult(error);
        }
    } catch (VNXeException e) {
        _logger.error("Restore file system snapshot got the exception", e);
        if (completer != null) {
            completer.error(_dbClient, e);
        }
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception ex) {
        _logger.error("Restore file system snpashot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreFileSystemSnapshot", ex.getMessage());
        if (completer != null) {
            completer.error(_dbClient, error);
        }
        return BiosCommandResult.createErrorResult(error);
    }
    StringBuilder logMsgBuilder = new StringBuilder(String.format("Restore filesystem snapshot job submitted - Array:%s, fileSystem: %s, snapshot: %s", storage.getSerialNumber(), args.getFsName(), args.getSnapshotLabel()));
    _logger.info(logMsgBuilder.toString());
    return BiosCommandResult.createPendingResult();
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeFSSnapshotTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFSSnapshotTaskCompleter) VNXeRestoreFileSystemSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeRestoreFileSystemSnapshotJob) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException) 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 14 with VNXeApiClient

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

the class VNXeStorageDevice method doShare.

@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    _logger.info("creating smbShare: " + smbFileShare.getName());
    VNXeApiClient apiClient = getVnxeClient(storage);
    String permission = smbFileShare.getPermission();
    String shareName = smbFileShare.getName();
    String path = "/";
    VNXeCommandJob job = null;
    VNXeFileTaskCompleter completer = null;
    FileSMBShare newShare = new FileSMBShare(smbFileShare);
    String absolutePath = smbFileShare.getPath();
    newShare.setStoragePortNetworkId(smbFileShare.getStoragePortNetworkId());
    newShare.setStoragePortName(smbFileShare.getStoragePortName());
    try {
        if (args.getFileOperation()) {
            if (newShare.isSubDirPath()) {
                String basePath = args.getFsPath();
                /*
                     * The below line will allow us to get the relative path of subdir
                     * For example: absolutePath = /vnxeShare1/subdir1
                     * Then, the below line will assign path = subdir
                     * VNXe takes the relative path of the sub-directory. Not the absolute path
                     */
                path = "/" + new File(basePath).toURI().relativize(new File(absolutePath).toURI()).getPath();
            }
            String fsNativeId = args.getFs().getNativeId();
            _logger.info("Creating CIFS share for path {}", path);
            job = apiClient.createCIFSShare(fsNativeId, shareName, permission, path);
            if (job != null) {
                newShare.setNetBIOSName(apiClient.getNetBios());
                completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                VNXeCreateShareJob createShareJob = new VNXeCreateShareJob(job.getId(), storage.getId(), completer, newShare, true);
                ControllerServiceImpl.enqueueJob(new QueueJob(createShareJob));
            } else {
                _logger.error("No job returned from creaetCifsShare");
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createShare", "No Job returned");
                return BiosCommandResult.createErrorResult(error);
            }
        } else {
            // create share for a snapshot
            if (newShare.isSubDirPath()) {
                String basePath = args.getSnapshotPath();
                /*
                     * The below line will allow us to get the relative path of subdir
                     * For example: absolutePath = /vnxeShare1/subdir1
                     * Then, the below line will assign path = subdir
                     * VNXe takes the relative path of the sub-directory. Not the absolute path
                     */
                path = "/" + new File(basePath).toURI().relativize(new File(absolutePath).toURI()).getPath();
            }
            String fsNativeId = args.getFs().getNativeId();
            String snapId = args.getSnapNativeId();
            job = apiClient.createCifsShareForSnap(snapId, shareName, permission, path, fsNativeId);
            if (job != null) {
                newShare.setNetBIOSName(apiClient.getNetBios());
                completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                VNXeCreateShareJob createShareJob = new VNXeCreateShareJob(job.getId(), storage.getId(), completer, newShare, false);
                ControllerServiceImpl.enqueueJob(new QueueJob(createShareJob));
            } else {
                _logger.error("No job returned from creaetCifsShare");
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createShare", "No Job returned");
                return BiosCommandResult.createErrorResult(error);
            }
        }
    } catch (VNXeException e) {
        _logger.error("Create share got the exception", e);
        if (completer != null) {
            completer.error(_dbClient, e);
        }
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception ex) {
        _logger.error("create share got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("create share", ex.getMessage());
        if (completer != null) {
            completer.error(_dbClient, error);
        }
        return BiosCommandResult.createErrorResult(error);
    }
    StringBuilder logMsgBuilder = new StringBuilder(String.format("Create share job submitted - Array:%s, share: %s", storage.getSerialNumber(), smbFileShare.getName()));
    _logger.info(logMsgBuilder.toString());
    return BiosCommandResult.createPendingResult();
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeFileTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) 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) Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeException(com.emc.storageos.vnxe.VNXeException) VNXeCreateShareJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeCreateShareJob) File(java.io.File) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Example 15 with VNXeApiClient

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

the class VNXeStorageDevice method doRemoveFromConsistencyGroup.

@Override
public void doRemoveFromConsistencyGroup(StorageSystem storage, URI consistencyGroupId, List<URI> blockObjects, TaskCompleter taskCompleter) throws DeviceControllerException {
    BlockConsistencyGroup consistencyGroup = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
    // check if lungroup has been created in the array
    String lunGroupId = consistencyGroup.getCgNameOnStorageSystem(storage.getId());
    if (lunGroupId == null || lunGroupId.isEmpty()) {
        // lun group has not created yet. return error
        _logger.error("The consistency group does not exist in the array: {}", storage.getSerialNumber());
        taskCompleter.error(_dbClient, DeviceControllerException.exceptions.consistencyGroupNotFound(consistencyGroup.getLabel(), consistencyGroup.getCgNameOnStorageSystem(storage.getId())));
        return;
    }
    VNXeApiClient apiClient = getVnxeClient(storage);
    try {
        List<String> luns = new ArrayList<String>();
        for (URI volume : blockObjects) {
            luns.add(volume.toString());
        }
        apiClient.removeLunsFromLunGroup(lunGroupId, luns);
        for (URI blockObjectURI : blockObjects) {
            BlockObject blockObject = BlockObject.fetch(_dbClient, blockObjectURI);
            if (blockObject != null) {
                blockObject.setConsistencyGroup(NullColumnValueGetter.getNullURI());
            }
            _dbClient.updateAndReindexObject(blockObject);
        }
        taskCompleter.ready(_dbClient);
        _logger.info("Remove volumes from the consistency group successfully");
    } catch (Exception e) {
        _logger.error("Exception caught when removing volumes from the consistency group ", e);
        taskCompleter.error(_dbClient, DeviceControllerException.exceptions.failedToRemoveMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getCgNameOnStorageSystem(storage.getId()), e.getMessage()));
    }
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) 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)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