use of com.emc.storageos.db.client.model.SMBShareMap 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.SMBShareMap 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.SMBShareMap in project coprhd-controller by CoprHD.
the class CifsShareUtility method doesShareExist.
/**
* Checks whether share exists in the file object
*
* @param fileObject fileshare or snapshot object
* @param shareName name of the share
* @return true if share exists in the SMBShareMap, false otherwise
*/
public static boolean doesShareExist(FileObject fileObject, String shareName) {
SMBShareMap existingShares = fileObject.getSMBFileShares();
if (existingShares != null && !existingShares.isEmpty()) {
SMBFileShare existingShare = existingShares.get(shareName);
if (existingShare != null) {
_log.info("CIFS share: {}, exists in ", shareName, fileObject.getId());
return true;
}
}
_log.info("CIFS share: {}, does not exist in {}", shareName, fileObject.getId());
return false;
}
use of com.emc.storageos.db.client.model.SMBShareMap in project coprhd-controller by CoprHD.
the class FileDeviceController method deleteQDExportsAndShares.
/**
* Delete NFS exports and shares file system quota directory
*
* @param storage
* @param fs
* @param quotaDirObj
* @param task
*/
private void deleteQDExportsAndShares(URI storage, FileShare fs, QuotaDirectory quotaDirObj, String task) {
FSExportMap fsExportMap = fs.getFsExports();
String quotaName = quotaDirObj.getName();
boolean isExported = false;
// delete export
if (fsExportMap != null && !fsExportMap.isEmpty()) {
// check the quota directory is exported
for (FileExport fileExport : fsExportMap.values()) {
if (quotaName.equals(fileExport.getSubDirectory()) && fileExport.getPath().endsWith(quotaName)) {
isExported = true;
_log.info("Delete the nfs sub directory export path {} and key {}", fileExport.getPath(), fileExport.getFileExportKey());
}
}
if (true == isExported) {
// delete the export of quota directory
this.deleteExportRules(storage, fs.getId(), false, quotaName, task);
}
}
// delete fileshare of quota directory
SMBShareMap smbShareMap = fs.getSMBFileShares();
if (smbShareMap != null && !smbShareMap.isEmpty()) {
FileSMBShare fileSMBShare = null;
List<FileSMBShare> fileSMBShares = new ArrayList<FileSMBShare>();
for (SMBFileShare smbFileShare : smbShareMap.values()) {
// check for quotaname in native fs path
if (true == (smbFileShare.getPath().endsWith(quotaName))) {
fileSMBShare = new FileSMBShare(smbFileShare);
_log.info("Delete the cifs sub directory path of quota directory {}", smbFileShare.getPath());
fileSMBShares.add(fileSMBShare);
}
}
if (fileSMBShares != null && !fileSMBShares.isEmpty()) {
// delete shares
for (FileSMBShare tempFileSMBShare : fileSMBShares) {
this.deleteShare(storage, fs.getId(), tempFileSMBShare, task);
_log.info("Delete SMB Share Name{} for quota ", tempFileSMBShare.getName());
}
}
}
}
Aggregations