Search in sources :

Example 11 with SMBFileShare

use of com.emc.storageos.db.client.model.SMBFileShare in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method netAppDeleteCIFSExports.

private Boolean netAppDeleteCIFSExports(StorageSystem storage, SMBShareMap currentShares, String portGroup) throws NetAppException {
    int failedCount = 0;
    Iterator<Entry<String, SMBFileShare>> it = currentShares.entrySet().iterator();
    List<String> removedShareKeys = new ArrayList<String>();
    while (it.hasNext()) {
        Map.Entry<String, SMBFileShare> entry = it.next();
        String key = entry.getKey();
        SMBFileShare smbFileShare = entry.getValue();
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
        if (!nApi.deleteShare(smbFileShare.getName())) {
            failedCount++;
        } else {
            removedShareKeys.add(key);
        }
    }
    for (String keys : removedShareKeys) {
        currentShares.remove(keys);
    }
    if (failedCount > 0) {
        return false;
    } else {
        return true;
    }
}
Also used : Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) NetAppApi(com.emc.storageos.netapp.NetAppApi) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) HashMap(java.util.HashMap) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) Map(java.util.Map) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap)

Example 12 with SMBFileShare

use of com.emc.storageos.db.client.model.SMBFileShare in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method doDeleteShare.

/**
 * Deletes CIFS FileShare
 *
 * @param StorageSystem storage
 * @param FileDeviceInputOutput args
 * @param SMBFileShare smbFileShare
 * @return BiosCommandResult
 * @throws ControllerException
 */
@Override
public BiosCommandResult doDeleteShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppFileStorageDevice doDeleteShare - start");
        FileShare fileshare = null;
        if (args.getFileOperation() == true) {
            fileshare = args.getFs();
        } else {
            URI snapShotUID = args.getSnapshotId();
            Snapshot snapshot = _dbClient.queryObject(Snapshot.class, snapShotUID);
            fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
        }
        // Now get the VFiler from the fileShare
        String portGroup = findVfilerName(fileshare);
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
        SMBShareMap shares = args.getFileObjShares();
        if (shares == null || shares.isEmpty()) {
            _log.error("NetAppFileStorageDevice::doDeleteShare failed: FileShare(s) is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
            serviceError.setMessage("FileShare(s) is either missing or empty");
            result = BiosCommandResult.createErrorResult(serviceError);
        }
        SMBFileShare fileShare = shares.get(smbFileShare.getName());
        if (fileShare != null) {
            if (!nApi.deleteShare(smbFileShare.getName())) {
                _log.error("NetAppFileStorageDevice doDeleteShare {} - failed", args.getFileObjId());
                ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
                serviceError.setMessage("Deletion of CIFS File Share failed");
                result = BiosCommandResult.createErrorResult(serviceError);
            } else {
                _log.info("NetAppFileStorageDevice doDeleteShare {} - complete", args.getFileObjId());
                args.getFileObjShares().remove(smbFileShare.getName());
                args.getFileObjShares().remove(smbFileShare.getNativeId());
                result = BiosCommandResult.createSuccessfulResult();
            }
        }
    } catch (NetAppException e) {
        _log.error("NetAppFileStorageDevice::doDeleteShare failed with a NetAppException", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::doCreateFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppApi(com.emc.storageos.netapp.NetAppApi) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 13 with SMBFileShare

use of com.emc.storageos.db.client.model.SMBFileShare in project coprhd-controller by CoprHD.

the class NetAppClusterModeDevice method netAppDeleteCIFSExports.

private Boolean netAppDeleteCIFSExports(StorageSystem storage, SMBShareMap currentShares, String portGroup) throws NetAppCException {
    int failedCount = 0;
    Iterator<Entry<String, SMBFileShare>> it = currentShares.entrySet().iterator();
    List<String> removedShareKeys = new ArrayList<String>();
    while (it.hasNext()) {
        Map.Entry<String, SMBFileShare> entry = it.next();
        String key = entry.getKey();
        SMBFileShare smbFileShare = entry.getValue();
        NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
        if (!ncApi.deleteShare(smbFileShare.getName())) {
            failedCount++;
        } else {
            removedShareKeys.add(key);
        }
    }
    for (String keys : removedShareKeys) {
        currentShares.remove(keys);
    }
    if (failedCount > 0) {
        return false;
    } else {
        return true;
    }
}
Also used : Entry(java.util.Map.Entry) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) ArrayList(java.util.ArrayList) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) HashMap(java.util.HashMap) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) Map(java.util.Map) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap)

Example 14 with SMBFileShare

use of com.emc.storageos.db.client.model.SMBFileShare in project coprhd-controller by CoprHD.

the class NetAppClusterModeDevice method doShare.

@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    // To be in-sync with isilon implementation, currently forceGroup is
    // set to null which will set the group name as "everyone" by default.
    String forceGroup = null;
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppClusterModeDevice doShare - start");
        SMBShareMap smbShareMap = args.getFileObjShares();
        SMBFileShare existingShare = (smbShareMap == null) ? null : smbShareMap.get(smbFileShare.getName());
        Boolean modOrCreateShareSuccess = false;
        if (existingShare != null) {
            modOrCreateShareSuccess = modifyNtpShare(storage, args, smbFileShare, forceGroup, existingShare);
        } else if (existingShare == null) {
            modOrCreateShareSuccess = createNtpShare(storage, args, smbFileShare, forceGroup);
        }
        if (modOrCreateShareSuccess.booleanValue() == true) {
            _log.info("NetAppClusterModeDevice doShare {} - complete", smbFileShare.getName());
            // Update the collection.
            if (args.getFileObjShares() == null) {
                args.initFileObjShares();
            }
            // set Mount Point
            smbFileShare.setMountPoint(smbFileShare.getNetBIOSName(), smbFileShare.getStoragePortNetworkId(), smbFileShare.getStoragePortName(), smbFileShare.getName());
            args.getFileObjShares().put(smbFileShare.getName(), smbFileShare);
            result = BiosCommandResult.createSuccessfulResult();
        } else {
            _log.error("NetAppClusterModeDevice doShare {} - failed", smbFileShare.getName());
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToCreateFileShare();
            result = BiosCommandResult.createErrorResult(serviceError);
        }
    } catch (NetAppCException e) {
        _log.error("NetAppClusterModeDevice::doShare failed with a NetAppCException", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToCreateFileShare();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::doShare failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToCreateFileShare();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppCException(com.emc.storageos.netappc.NetAppCException) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetAppCException(com.emc.storageos.netappc.NetAppCException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 15 with SMBFileShare

use of com.emc.storageos.db.client.model.SMBFileShare 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)

Aggregations

SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)46 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)26 FileShare (com.emc.storageos.db.client.model.FileShare)21 Snapshot (com.emc.storageos.db.client.model.Snapshot)16 ArrayList (java.util.ArrayList)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 ControllerException (com.emc.storageos.volumecontroller.ControllerException)13 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 FileSMBShare (com.emc.storageos.volumecontroller.FileSMBShare)9 URI (java.net.URI)9 FileExport (com.emc.storageos.db.client.model.FileExport)8 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)8 VNXeException (com.emc.storageos.vnxe.VNXeException)8 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)7 FileDeviceInputOutput (com.emc.storageos.volumecontroller.FileDeviceInputOutput)7 FileObject (com.emc.storageos.db.client.model.FileObject)5 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5