use of com.emc.storageos.db.client.model.SMBFileShare in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method addStepsToReplicateCIFSShareACLs.
/**
* Child workflow for replicating source file system CIFS ACLs to target system.
*
* @param systemTarget
* - URI of target StorageSystem where source CIFS shares has to be replicated.
* @param fsURI
* -URI of the source FileSystem
* @param taskId
*/
public void addStepsToReplicateCIFSShareACLs(URI systemTarget, URI fsURI, String taskId) {
s_logger.info("Generating steps for Replicating CIFS share ACLs to Target Cluster");
CifsShareACLUpdateParams params;
FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
FileShare targetFileShare = null;
Workflow workflow = null;
try {
FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
} else {
targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
}
workflow = this._workflowService.getNewWorkflow(this, REPLICATE_CIFS_SHARE_ACLS_TO_TARGET_WF_NAME, false, taskId, completer);
SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
if (sourceSMBShareMap != null) {
List<SMBFileShare> sourceSMBShares = new ArrayList<SMBFileShare>(sourceSMBShareMap.values());
for (SMBFileShare sourceSMBShare : sourceSMBShares) {
List<ShareACL> sourceShareACLs = FileOrchestrationUtils.queryShareACLs(sourceSMBShare.getName(), sourceFileShare.getId(), s_dbClient);
List<ShareACL> targetShareACLs = FileOrchestrationUtils.queryShareACLs(sourceSMBShare.getName(), targetFileShare.getId(), s_dbClient);
if (!sourceShareACLs.isEmpty() && targetShareACLs.isEmpty()) {
// target share doesn't have any ACLs but corresponding share on source does have ACL
params = new CifsShareACLUpdateParams();
ShareACLs shareACLs = new ShareACLs();
shareACLs.setShareACLs(sourceShareACLs);
params.setAclsToAdd(shareACLs);
updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
} else if (!targetShareACLs.isEmpty() && sourceShareACLs.isEmpty()) {
// source share doesn't have any ACLs but corresponding share on target does have ACL
params = new CifsShareACLUpdateParams();
ShareACLs shareACLs = new ShareACLs();
shareACLs.setShareACLs(targetShareACLs);
// TO FIX COP-26361 DU case
// params.setAclsToDelete(shareACLs);
updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
} else if (!targetShareACLs.isEmpty() && !sourceShareACLs.isEmpty()) {
// both source and target share have some ACL
List<ShareACL> shareACLsToAdd = new ArrayList<ShareACL>();
List<ShareACL> shareACLsToDelete = new ArrayList<ShareACL>();
List<ShareACL> shareACLsToModify = new ArrayList<ShareACL>();
HashMap<String, ShareACL> sourceShareACLMap = FileOrchestrationUtils.getShareACLMap(sourceShareACLs);
HashMap<String, ShareACL> targetShareACLMap = FileOrchestrationUtils.getShareACLMap(targetShareACLs);
// ACLs To Add
for (String sourceACLName : sourceShareACLMap.keySet()) {
if (targetShareACLMap.get(sourceACLName) == null) {
ShareACL shareACL = sourceShareACLMap.get(sourceACLName);
shareACL.setFileSystemId(targetFileShare.getId());
shareACLsToAdd.add(shareACL);
}
}
// ACLs To Delete
for (String targetACLName : targetShareACLMap.keySet()) {
if (sourceShareACLMap.get(targetACLName) == null) {
shareACLsToDelete.add(targetShareACLMap.get(targetACLName));
}
}
// ACLs to Modify
targetShareACLs.removeAll(shareACLsToDelete);
sourceShareACLs.removeAll(shareACLsToAdd);
sourceShareACLMap = FileOrchestrationUtils.getShareACLMap(sourceShareACLs);
targetShareACLMap = FileOrchestrationUtils.getShareACLMap(targetShareACLs);
for (String sourceACLName : sourceShareACLMap.keySet()) {
if (targetShareACLMap.get(sourceACLName) != null && !targetShareACLMap.get(sourceACLName).getPermission().equals(sourceShareACLMap.get(sourceACLName).getPermission())) {
ShareACL shareACL = targetShareACLMap.get(sourceACLName);
shareACL.setPermission(sourceShareACLMap.get(sourceACLName).getPermission());
shareACLsToModify.add(shareACL);
}
}
params = new CifsShareACLUpdateParams();
if (!shareACLsToAdd.isEmpty()) {
ShareACLs addShareACLs = new ShareACLs();
addShareACLs.setShareACLs(shareACLsToAdd);
params.setAclsToAdd(addShareACLs);
}
if (!shareACLsToDelete.isEmpty()) {
ShareACLs deleteShareACLs = new ShareACLs();
deleteShareACLs.setShareACLs(shareACLsToDelete);
// TO FIX COP-26361 DU case
// params.setAclsToDelete(deleteShareACLs);
}
if (!shareACLsToModify.isEmpty()) {
ShareACLs modifyShareACLs = new ShareACLs();
modifyShareACLs.setShareACLs(shareACLsToModify);
params.setAclsToModify(modifyShareACLs);
}
if (params.retrieveAllACLs() != null && !params.retrieveAllACLs().isEmpty()) {
updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
}
}
}
}
String successMessage = String.format("Replicating source File System : %s, CIFS Shares ACLs to Target System finished successfully", sourceFileShare.getLabel());
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error("Could not replicate source filesystem CIFS shares ACLs : " + fsURI, ex);
String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
ServiceError serviceError = DeviceControllerException.errors.updateFileShareCIFSACLsFailed(fsURI.toString(), opName, ex);
completer.error(s_dbClient, this._locker, serviceError);
}
}
use of com.emc.storageos.db.client.model.SMBFileShare in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method addStepsToReplicateCIFSShares.
/**
* Child workflow for replicating source file system CIFS shares to target.
*
* @param systemTarget
* - URI of target StorageSystem where source CIFS shares has to be replicated.
* @param fsURI
* -URI of the source FileSystem
* @param cifsPort
* -StoragePort, CIFS port of target File System where new shares has to be created.
* @param taskId
*/
public void addStepsToReplicateCIFSShares(URI systemTarget, URI fsURI, StoragePort cifsPort, String taskId) {
s_logger.info("Generating steps for Replicating CIFS shares to Target Cluster");
FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
Workflow workflow = null;
FileShare targetFileShare = null;
try {
FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
} else {
targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
}
workflow = this._workflowService.getNewWorkflow(this, REPLICATE_CIFS_SHARES_TO_TARGET_WF_NAME, false, taskId, completer);
SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
SMBShareMap targetSMBShareMap = targetFileShare.getSMBFileShares();
if (sourceSMBShareMap == null && targetSMBShareMap != null) {
// source file system don't have any CIFS share but target do have share.
List<SMBFileShare> targetSMBShares = new ArrayList<SMBFileShare>(targetSMBShareMap.values());
deleteCIFSShareFromTarget(workflow, systemTarget, targetSMBShares, targetFileShare);
} else if (targetSMBShareMap == null && sourceSMBShareMap != null) {
// target file system don't have any CIFS share but source do have share
List<SMBFileShare> sourceSMBShares = new ArrayList<SMBFileShare>(sourceSMBShareMap.values());
createCIFSShareOnTarget(workflow, systemTarget, sourceSMBShares, cifsPort, targetFileShare, sourceFileShare);
} else if (targetSMBShareMap != null && sourceSMBShareMap != null) {
// both source and target file system do have some shares..
List<SMBFileShare> targetSMBSharestoDelete = new ArrayList<SMBFileShare>();
List<SMBFileShare> targetSMBSharestoCreate = new ArrayList<SMBFileShare>();
for (String sourceSMBSharesName : sourceSMBShareMap.keySet()) {
if (targetSMBShareMap.get(sourceSMBSharesName) == null) {
targetSMBSharestoCreate.add(sourceSMBShareMap.get(sourceSMBSharesName));
}
}
for (String targetSMBSharesName : targetSMBShareMap.keySet()) {
if (sourceSMBShareMap.get(targetSMBSharesName) == null) {
targetSMBSharestoDelete.add(targetSMBShareMap.get(targetSMBSharesName));
}
}
if (!targetSMBSharestoCreate.isEmpty()) {
createCIFSShareOnTarget(workflow, systemTarget, targetSMBSharestoCreate, cifsPort, targetFileShare, sourceFileShare);
}
if (!targetSMBSharestoDelete.isEmpty()) {
deleteCIFSShareFromTarget(workflow, systemTarget, targetSMBSharestoDelete, targetFileShare);
}
}
String successMessage = String.format("Replicating source File System : %s, CIFS Shares to Target System finished successfully", sourceFileShare.getLabel());
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error("Could not replicate source filesystem CIFS shares: " + fsURI, ex);
String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
ServiceError serviceError = DeviceControllerException.errors.createFileSharesFailed(fsURI.toString(), opName, ex);
completer.error(s_dbClient, this._locker, serviceError);
}
}
use of com.emc.storageos.db.client.model.SMBFileShare 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.db.client.model.SMBFileShare in project coprhd-controller by CoprHD.
the class FileSnapshotService method getFileSystemShareList.
/**
* Lists all SMB shares for the specified snapshot.
*
* @param id
* the URN of a ViPR Snapshot
* @brief List file snapshot SMB shares
* @return List of SMB shares
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FileSystemShareList getFileSystemShareList(@PathParam("id") URI id) {
_log.info(String.format("Get list of SMB file shares for snapshot: %1$s", id));
ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
Snapshot snap = queryResource(id);
FileSystemShareList fileShareListResponse = new FileSystemShareList();
if (snap.getInactive()) {
return fileShareListResponse;
}
// Get SMB share map from snapshot
SMBShareMap smbShareMap = snap.getSMBFileShares();
Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
if (smbShareMap != null) {
smbShares = smbShareMap.values();
}
// Process each share from the map and add its data to shares in response list.
for (SMBFileShare smbShare : smbShares) {
SmbShareResponse shareParam = new SmbShareResponse();
shareParam.setShareName(smbShare.getName());
shareParam.setDescription(smbShare.getDescription());
shareParam.setMaxUsers(Integer.toString(smbShare.getMaxUsers()));
// Check for "unlimited"
if (shareParam.getMaxUsers().equals("-1")) {
shareParam.setMaxUsers(FileService.UNLIMITED_USERS);
}
shareParam.setPermissionType(smbShare.getPermissionType());
shareParam.setPermission(smbShare.getPermission());
shareParam.setMountPoint(smbShare.getMountPoint());
shareParam.setPath(smbShare.getPath());
fileShareListResponse.getShareList().add(shareParam);
}
return fileShareListResponse;
}
use of com.emc.storageos.db.client.model.SMBFileShare 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