Search in sources :

Example 1 with FileSMBShare

use of com.emc.storageos.volumecontroller.FileSMBShare in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method createCIFSShareOnTarget.

private static void createCIFSShareOnTarget(Workflow workflow, URI systemTarget, List<SMBFileShare> smbShares, StoragePort cifsPort, FileShare targetFileShare, FileShare sourceFileShare) {
    for (SMBFileShare smbShare : smbShares) {
        FileSMBShare fileSMBShare = new FileSMBShare(smbShare);
        fileSMBShare.setStoragePortName(cifsPort.getPortName());
        fileSMBShare.setStoragePortNetworkId(cifsPort.getPortNetworkId());
        if (fileSMBShare.isSubDirPath()) {
            fileSMBShare.setPath(targetFileShare.getPath() + fileSMBShare.getPath().split(sourceFileShare.getPath())[1]);
        } else {
            fileSMBShare.setPath(targetFileShare.getPath());
        }
        String shareCreationStep = workflow.createStepId();
        String stepDescription = String.format("creating CIFS Share : %s, path : %s", fileSMBShare.getName(), fileSMBShare.getPath());
        Object[] args = new Object[] { systemTarget, targetFileShare.getId(), fileSMBShare };
        _fileDeviceController.createMethod(workflow, null, CREATE_FILESYSTEM_SHARE_METHOD, shareCreationStep, stepDescription, systemTarget, args);
    }
}
Also used : FileObject(com.emc.storageos.db.client.model.FileObject) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare)

Example 2 with FileSMBShare

use of com.emc.storageos.volumecontroller.FileSMBShare in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method deleteCIFSShareFromTarget.

private static void deleteCIFSShareFromTarget(Workflow workflow, URI systemTarget, List<SMBFileShare> smbShares, FileShare targetFileShare) {
    for (SMBFileShare smbShare : smbShares) {
        FileSMBShare fileSMBShare = new FileSMBShare(smbShare);
        String stepDescription = String.format("deleting CIFS share : %s, path : %s", fileSMBShare.getName(), fileSMBShare.getPath());
        String sharedeleteStep = workflow.createStepId();
        Object[] args = new Object[] { systemTarget, targetFileShare.getId(), fileSMBShare };
        _fileDeviceController.createMethod(workflow, null, DELETE_FILESYSTEM_SHARE_METHOD, sharedeleteStep, stepDescription, systemTarget, args);
    }
}
Also used : FileObject(com.emc.storageos.db.client.model.FileObject) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare)

Example 3 with FileSMBShare

use of com.emc.storageos.volumecontroller.FileSMBShare in project coprhd-controller by CoprHD.

the class FileSnapshotService method share.

/**
 * Creates SMB file share.
 * <p>
 * Note: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @param param
 *            File system share parameters
 * @brief Create file snapshot SMB share
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep share(@PathParam("id") URI id, FileSystemShareParam param) throws InternalException {
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    ArgValidator.checkFieldNotNull(param.getShareName(), "name");
    ArgValidator.checkFieldNotEmpty(param.getShareName(), "name");
    Snapshot snap = queryResource(id);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    ArgValidator.checkEntity(snap, id, isIdEmbeddedInURL(id));
    // Let us make sure that a share with the same name does not already exist.
    String shareName = param.getShareName();
    if (CifsShareUtility.doesShareExist(snap, shareName)) {
        _log.error("CIFS share: {}, already exists", shareName);
        throw APIException.badRequests.duplicateEntityWithField("CIFS share", "name");
    }
    // If value of permission is not provided, set the value to read-only
    if (param.getPermission() == null || param.getPermission().isEmpty()) {
        param.setPermission(FileSMBShare.Permission.read.name());
    }
    if (!param.getPermission().equals(FileSMBShare.Permission.read.name())) {
        throw APIException.badRequests.snapshotSMBSharePermissionReadOnly();
    }
    // Locate storage port for sharing snapshot
    // Select IP port of the storage array, owning the parent file system, which belongs to the same varray as the
    // file system.
    // We use file system in the call since file snap belongs to the same neighbourhood as its parent file system
    StoragePort sport = _fileScheduler.placeFileShareExport(fs, StorageProtocol.File.CIFS.name(), null);
    // Check if maxUsers is "unlimited" and set it to -1 in this case.
    if (param.getMaxUsers().equalsIgnoreCase(FileService.UNLIMITED_USERS)) {
        param.setMaxUsers("-1");
    }
    String path = snap.getPath();
    _log.info("Path {}", path);
    _log.info("Param Share Name : {} SubDirectory : {}", param.getShareName(), param.getSubDirectory());
    boolean isSubDirPath = false;
    if (ArgValidator.checkSubDirName("subDirectory", param.getSubDirectory())) {
        path += "/" + param.getSubDirectory();
        isSubDirPath = true;
        _log.info("Sub-directory path {}", path);
    }
    FileSMBShare smbShare = new FileSMBShare(param.getShareName(), param.getDescription(), param.getPermissionType(), param.getPermission(), param.getMaxUsers(), null, path);
    smbShare.setStoragePortName(sport.getPortName());
    smbShare.setStoragePortNetworkId(sport.getPortNetworkId());
    smbShare.setStoragePortGroup(sport.getPortGroup());
    smbShare.setSubDirPath(isSubDirPath);
    _log.info(String.format("Create snapshot share --- Snap id: %1$s, Share name: %2$s, StoragePort: %3$s, PermissionType: %4$s, " + "Permissions: %5$s, Description: %6$s, maxUsers: %7$s", id, smbShare.getName(), sport.getPortName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getDescription(), smbShare.getMaxUsers()));
    _log.info("SMB share path: {}", smbShare.getPath());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE);
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.share(device.getId(), snap.getId(), smbShare, task);
    auditOp(OperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE, true, AuditLogManager.AUDITOP_BEGIN, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), snap.getId().toString());
    return toTask(snap, task, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileController(com.emc.storageos.volumecontroller.FileController) StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with FileSMBShare

use of com.emc.storageos.volumecontroller.FileSMBShare 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 5 with FileSMBShare

use of com.emc.storageos.volumecontroller.FileSMBShare in project coprhd-controller by CoprHD.

the class VNXeStorageDevice method doDeleteShare.

@Override
public BiosCommandResult doDeleteShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    _logger.info(String.format(String.format("Deleting smbShare: %s, nativeId: %s", smbFileShare.getName(), smbFileShare.getNativeId())));
    VNXeApiClient apiClient = getVnxeClient(storage);
    String shareId = smbFileShare.getNativeId();
    VNXeCommandJob job = null;
    VNXeFileTaskCompleter completer = null;
    boolean isFile = args.getFileOperation();
    FileSMBShare newShare = new FileSMBShare(smbFileShare);
    try {
        if (isFile) {
            String fsId = args.getFs().getNativeId();
            job = apiClient.removeCifsShare(shareId, fsId);
        } else {
            job = apiClient.deleteCifsShareForSnapshot(shareId);
        }
        if (job != null) {
            if (isFile) {
                completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
            } else {
                completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
            }
            VNXeDeleteShareJob deleteShareJob = new VNXeDeleteShareJob(job.getId(), storage.getId(), completer, newShare, isFile);
            ControllerServiceImpl.enqueueJob(new QueueJob(deleteShareJob));
        } else {
            _logger.error("No job returned from deleteCifsShare");
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("deleteShare", "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("delete 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("Delete 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) VNXeDeleteShareJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeDeleteShareJob) 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) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Aggregations

SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 FileSMBShare (com.emc.storageos.volumecontroller.FileSMBShare)12 FileShare (com.emc.storageos.db.client.model.FileShare)9 Snapshot (com.emc.storageos.db.client.model.Snapshot)7 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 Operation (com.emc.storageos.db.client.model.Operation)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)4 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)4 VNXeException (com.emc.storageos.vnxe.VNXeException)4 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)4 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)4 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)2 MapFileSnapshot (com.emc.storageos.api.mapper.functions.MapFileSnapshot)2