use of com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method failoverFileSystem.
@Override
public void failoverFileSystem(URI fsURI, StoragePort nfsPort, StoragePort cifsPort, boolean replicateConfiguration, String taskId) throws ControllerException {
FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
Workflow workflow = null;
String stepDescription = null;
MirrorFileFailoverTaskCompleter failoverCompleter = null;
try {
FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
FileShare targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
StorageSystem systemTarget = s_dbClient.queryObject(StorageSystem.class, targetFileShare.getStorageDevice());
workflow = this._workflowService.getNewWorkflow(this, FAILOVER_FILESYSTEMS_WF_NAME, false, taskId, completer);
// Failover File System to Target
s_logger.info("Generating steps for Failover File System to Target");
String failoverStep = workflow.createStepId();
List<URI> combined = Arrays.asList(sourceFileShare.getId(), targetFileShare.getId());
failoverCompleter = new MirrorFileFailoverTaskCompleter(FileShare.class, combined, failoverStep);
stepDescription = String.format("Failover Source File System %s to Target System.", sourceFileShare.getLabel());
Object[] args = new Object[] { systemTarget.getId(), targetFileShare.getId(), failoverCompleter };
String waitForFailover = _fileDeviceController.createMethod(workflow, null, FAILOVER_FILE_SYSTEM_METHOD, failoverStep, stepDescription, systemTarget.getId(), args);
// Replicate quota setting
stepDescription = String.format("Replicating directory quota settings from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
Workflow.Method replicateDirQuotaSettingsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_DIRECTORY_QUOTA_SETTINGS_METHOD, systemTarget.getId(), fsURI);
String replicateDirQuotaSettingsStep = workflow.createStepId();
workflow.createStep(null, stepDescription, waitForFailover, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateDirQuotaSettingsMethod, null, replicateDirQuotaSettingsStep);
if (replicateConfiguration) {
Map<String, List<NfsACE>> sourceNFSACL = FileOrchestrationUtils.queryNFSACL(sourceFileShare, s_dbClient);
Map<String, List<NfsACE>> targetNFSACL = FileOrchestrationUtils.queryNFSACL(targetFileShare, s_dbClient);
if (!sourceNFSACL.isEmpty() || !targetNFSACL.isEmpty()) {
stepDescription = String.format("Replicating NFS ACL from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
Workflow.Method replicateNFSACLsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_ACLS_METHOD, systemTarget.getId(), fsURI);
String replicateNFSACLsStep = workflow.createStepId();
workflow.createStep(null, stepDescription, waitForFailover, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateNFSACLsMethod, null, replicateNFSACLsStep);
}
SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
SMBShareMap targetSMBShareMap = targetFileShare.getSMBFileShares();
if (sourceSMBShareMap != null || targetSMBShareMap != null) {
// Both source and target share map shouldn't be null
stepDescription = String.format("Replicating CIFS shares from source file system : %s to target file system : %s", sourceFileShare.getId(), targetFileShare.getId());
Workflow.Method replicateCIFSShareMethod = new Workflow.Method(REPLICATE_FILESYSTEM_CIFS_SHARES_METHOD, systemTarget.getId(), fsURI, cifsPort);
String replicateCIFSShareStep = workflow.createStepId();
String waitForShare = workflow.createStep(null, stepDescription, waitForFailover, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateCIFSShareMethod, null, replicateCIFSShareStep);
stepDescription = String.format("Replicating CIFS share ACLs from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
Workflow.Method replicateCIFSShareACLsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_CIFS_SHARE_ACLS_METHOD, systemTarget.getId(), fsURI);
String replicateCIFSShareACLsStep = workflow.createStepId();
workflow.createStep(null, stepDescription, waitForShare, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateCIFSShareACLsMethod, null, replicateCIFSShareACLsStep);
}
// Replicate NFS export and rules to Target Cluster.
FSExportMap sourceNFSExportMap = sourceFileShare.getFsExports();
FSExportMap targetNFSExportMap = targetFileShare.getFsExports();
if (sourceNFSExportMap != null || targetNFSExportMap != null) {
// Both source and target export map shouldn't be null
stepDescription = String.format("Replicating NFS exports from source file system : %s to target file system : %s", sourceFileShare.getId(), targetFileShare.getId());
Workflow.Method replicateNFSExportMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_EXPORT_METHOD, systemTarget.getId(), fsURI, nfsPort);
String replicateNFSExportStep = workflow.createStepId();
String waitForExport = workflow.createStep(null, stepDescription, waitForFailover, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateNFSExportMethod, null, replicateNFSExportStep);
stepDescription = String.format("Replicating NFS export rules from source file system : %s to target file system : %s", sourceFileShare.getId(), targetFileShare.getId());
Workflow.Method replicateNFSExportRulesMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_EXPORT_RULE_METHOD, systemTarget.getId(), fsURI);
String replicateNFSExportRulesStep = workflow.createStepId();
workflow.createStep(null, stepDescription, waitForExport, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateNFSExportRulesMethod, null, replicateNFSExportRulesStep);
}
}
String successMessage = "Failover FileSystem successful for: " + sourceFileShare.getLabel();
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error("Could not failover filesystems: " + 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.volumecontroller.impl.file.FileWorkflowCompleter in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method deleteShare.
@Override
public void deleteShare(URI storage, URI uri, FileSMBShare fileSMBShare, String opId) throws ControllerException {
FileObject fileObj = null;
String stepDescription = null;
String successMessage = null;
String opName = null;
TaskCompleter completer = null;
if (URIUtil.isType(uri, FileShare.class)) {
completer = new FileWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(FileShare.class, uri);
stepDescription = String.format("Deleting file system: %s CIFS share: %s ", uri, fileSMBShare.getName());
successMessage = String.format("Deleting file system: %s CIFS share: %s finished succesfully.", uri, fileSMBShare.getName());
opName = ResourceOperationTypeEnum.DELETE_FILE_SYSTEM_SHARE.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Deleting file system snapshot: %s CIFS share: %s ", uri, fileSMBShare.getName());
successMessage = String.format("Deleting file system snapshot: %s CIFS share: %s finished succesfully.", uri, fileSMBShare.getName());
opName = ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, DELETE_FILESYSTEM_CIFS_SHARE_WF_NAME, false, opId, completer);
String sharedeleteStep = workflow.createStepId();
Object[] args = new Object[] { storage, uri, fileSMBShare };
_fileDeviceController.createMethod(workflow, null, DELETE_FILESYSTEM_SHARE_METHOD, sharedeleteStep, stepDescription, storage, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Deleting file system snapshot: %s CIFS share: %s failed.", uri, fileSMBShare.getName()), ex);
ServiceError serviceError = DeviceControllerException.errors.deleteCIFSShareFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method updateExportRules.
@Override
public void updateExportRules(URI storage, URI uri, FileExportUpdateParams param, boolean unmountExport, String opId) throws ControllerException {
FileObject fileObj = null;
String stepDescription = null;
String successMessage = null;
String opName = null;
TaskCompleter completer = null;
if (URIUtil.isType(uri, FileShare.class)) {
completer = new FileWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(FileShare.class, uri);
stepDescription = String.format("Updating file system : %s export rules: %s", uri, param.toString());
successMessage = String.format("Updating file system : %s export rules: %s finished successfully.", uri, param.toString());
opName = ResourceOperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SYSTEM.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Updating file system : %s export rules: %s", uri, param.toString());
successMessage = String.format("Updating file system : %s export rules: %s finished successfully.", uri, param.toString());
opName = ResourceOperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SNAPSHOT.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, UPDATE_FILESYSTEM_EXPORT_RULES_WF_NAME, false, opId, completer);
String waitFor = null;
// Check if the export should be unmounted before deleting
if (unmountExport) {
// get all the mounts and generate steps for unmounting them
List<MountInfo> mountList = _fileDeviceController.getMountedExports(uri, param.getSubDir(), param);
for (MountInfo mount : mountList) {
Object[] args = new Object[] { mount.getHostId(), mount.getFsId(), mount.getMountPath() };
waitFor = _fileDeviceController.createMethod(workflow, waitFor, UNMOUNT_FILESYSTEM_EXPORT_METHOD, null, "Unmounting path:" + mount.getMountPath(), storage, args);
}
} else if (URIUtil.isType(uri, FileShare.class)) {
// Check if the export rule is mounted and throw an error if mounted
Object[] args = new Object[] { uri, param };
waitFor = _fileDeviceController.createMethod(workflow, waitFor, VERIFY_MOUNT_DEPENDENCIES_METHOD, null, "Verifying mount dependencies", storage, args);
}
Object[] args = new Object[] { storage, uri, param };
_fileDeviceController.createMethod(workflow, waitFor, UPDATE_FILESYSTEM_EXPORT_RULES_METHOD, null, stepDescription, storage, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Updating file system : %s export rules: %s failed.", uri, param.toString()), ex);
ServiceError serviceError = DeviceControllerException.errors.updateFileShareExportRulesFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter 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.volumecontroller.impl.file.FileWorkflowCompleter 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);
}
}
Aggregations