Search in sources :

Example 1 with VNXeCreateShareJob

use of com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeCreateShareJob 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 2 with VNXeCreateShareJob

use of com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeCreateShareJob in project coprhd-controller by CoprHD.

the class VNXUnityFileStorageDevice method doShare.

@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    _logger.info("creating smbShare: " + smbFileShare.getName());
    VNXeApiClient apiClient = getVnxUnityClient(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) 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) 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

FileShare (com.emc.storageos.db.client.model.FileShare)2 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)2 Snapshot (com.emc.storageos.db.client.model.Snapshot)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)2 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)2 VNXeException (com.emc.storageos.vnxe.VNXeException)2 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)2 ControllerException (com.emc.storageos.volumecontroller.ControllerException)2 FileSMBShare (com.emc.storageos.volumecontroller.FileSMBShare)2 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)2 VNXeCreateShareJob (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeCreateShareJob)2 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)2 File (java.io.File)2 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1