use of com.emc.storageos.volumecontroller.FileSMBShare 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();
}
use of com.emc.storageos.volumecontroller.FileSMBShare in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDevice 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 = getVnxUnityClient(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();
}
use of com.emc.storageos.volumecontroller.FileSMBShare in project coprhd-controller by CoprHD.
the class FileService method deleteShare.
/**
* Delete specified SMB share.
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR File system
* @param shareName
* file system share name
* @brief Delete file system SMB share
* @return Task resource representation
* @throws InternalException
*/
@DELETE
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares/{shareName}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep deleteShare(@PathParam("id") URI id, @PathParam("shareName") String shareName) throws InternalException {
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
ArgValidator.checkFieldNotNull(shareName, "shareName");
ArgValidator.checkFieldNotNull(fs, "filesystem");
String task = UUID.randomUUID().toString();
SMBFileShare smbShare = null;
if (!CifsShareUtility.doesShareExist(fs, shareName)) {
_log.error("CIFS share does not exist {}", shareName);
throw APIException.notFound.invalidParameterObjectHasNoSuchShare(id, shareName);
}
smbShare = fs.getSMBFileShares().get(shareName);
_log.info("Deleteing SMBShare {}", shareName);
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.DELETE_FILE_SYSTEM_SHARE);
FileSMBShare fileSMBShare = new FileSMBShare(shareName, smbShare.getDescription(), smbShare.getPermissionType(), smbShare.getPermission(), Integer.toString(smbShare.getMaxUsers()), smbShare.getNativeId(), smbShare.getPath());
fileSMBShare.setStoragePortGroup(smbShare.getPortGroup());
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
fileServiceApi.deleteShare(device.getId(), fs.getId(), fileSMBShare, task);
auditOp(OperationTypeEnum.DELETE_FILE_SYSTEM_SHARE, true, AuditLogManager.AUDITOP_BEGIN, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), fs.getId().toString());
return toTask(fs, task, op);
}
use of com.emc.storageos.volumecontroller.FileSMBShare in project coprhd-controller by CoprHD.
the class FileService method share.
/**
* Create SMB file share
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR File system
* @param param
* File system share parameters
* @brief Create file system 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.OWN, ACL.ALL })
public TaskResourceRep share(@PathParam("id") URI id, FileSystemShareParam param) throws InternalException {
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
ArgValidator.checkFieldNotNull(param.getShareName(), "name");
ArgValidator.checkFieldNotEmpty(param.getShareName(), "name");
FileShare fs = queryResource(id);
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
String task = UUID.randomUUID().toString();
// Check for VirtualPool whether it has CIFS enabled
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
if (!vpool.getProtocols().contains(StorageProtocol.File.CIFS.name())) {
// Throw an error
throw APIException.methodNotAllowed.vPoolDoesntSupportProtocol("Vpool Doesnt support " + StorageProtocol.File.CIFS.name() + " protocol");
}
// locate storage port for sharing file System
// Select IP port of the storage array, owning the file system, which belongs to the same varray as the 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(UNLIMITED_USERS)) {
param.setMaxUsers("-1");
}
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
// If value of permission is not provided, set the value to change
if (param.getPermission() == null || param.getPermission().isEmpty()) {
param.setPermission(FileSMBShare.Permission.change.name());
}
// Let us make sure that a share with the same name does not already exist.
String shareName = param.getShareName();
if (CifsShareUtility.doesShareExist(fs, shareName)) {
_log.error("CIFS share: {}, already exists", shareName);
throw APIException.badRequests.duplicateEntityWithField("CIFS share", "name");
}
String path = fs.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(shareName, 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 file system share --- File system 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(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_SHARE);
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
fileServiceApi.share(device.getId(), fs.getId(), smbShare, task);
auditOp(OperationTypeEnum.CREATE_FILE_SYSTEM_SHARE, true, AuditLogManager.AUDITOP_BEGIN, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), fs.getId().toString());
return toTask(fs, task, op);
}
use of com.emc.storageos.volumecontroller.FileSMBShare in project coprhd-controller by CoprHD.
the class FileSnapshotService method deleteShare.
/**
* Deletes SMB share.
* <p>
* Note: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR Snapshot
* @param shareName
* SMB share name
* @brief Delete file snapshot SMB share
* @return Task resource representation
* @throws InternalException
*/
@DELETE
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares/{shareName}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteShare(@PathParam("id") URI id, @PathParam("shareName") String shareName) throws InternalException {
ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
Snapshot snap = queryResource(id);
FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
ArgValidator.checkFieldNotNull(shareName, "shareName");
ArgValidator.checkEntity(snap, id, isIdEmbeddedInURL(id));
String task = UUID.randomUUID().toString();
if (!CifsShareUtility.doesShareExist(snap, shareName)) {
_log.error("CIFS share does not exist", shareName);
throw APIException.notFound.invalidParameterObjectHasNoSuchShare(id, shareName);
}
SMBFileShare smbShare = snap.getSMBFileShares().get(shareName);
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE);
FileSMBShare fileSMBShare = new FileSMBShare(shareName, smbShare.getDescription(), smbShare.getPermissionType(), smbShare.getPermission(), Integer.toString(smbShare.getMaxUsers()), smbShare.getNativeId(), smbShare.getPath());
FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
fileServiceApi.deleteShare(device.getId(), snap.getId(), fileSMBShare, task);
auditOp(OperationTypeEnum.DELETE_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);
}
Aggregations