use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method updateShareACLs.
@Override
public void updateShareACLs(URI storage, URI uri, String shareName, CifsShareACLUpdateParams param, 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 share : %s ACLs: %s", uri, shareName, param.toString());
successMessage = String.format("Updating file system : %s share : %s ACLs: %s finished successfully.", uri, shareName, param.toString());
opName = ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM_SHARE_ACL.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Updating file system snapshot : %s share : %s ACLs: %s", uri, shareName, param.toString());
successMessage = String.format("Updating file system snapshot : %s share : %s ACLs: %s finished successfully.", uri, shareName, param.toString());
opName = ResourceOperationTypeEnum.UPDATE_FILE_SNAPSHOT_SHARE_ACL.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, UPDATE_FILESYSTEM_CIFS_SHARE_ACLS_WF_NAME, false, opId, completer);
String shareACLUpdateStep = workflow.createStepId();
Object[] args = new Object[] { storage, uri, shareName, param };
_fileDeviceController.createMethod(workflow, null, UPDATE_FILESYSTEM_SHARE_ACLS_METHOD, shareACLUpdateStep, stepDescription, storage, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Updating file system : %s share : %s ACLs: %s failed.", uri, shareName, param.toString()), ex);
ServiceError serviceError = DeviceControllerException.errors.updateFileShareCIFSACLsFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method deleteFileSystems.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController#deleteFileSystems(java.util.List,
* java.lang.String)
*/
/**
* Deletes one or more filesystem.
*
* @param fileDescriptors
* @param taskId
* @throws ControllerException
*/
@Override
public void deleteFileSystems(List<FileDescriptor> fileDescriptors, String taskId) throws ControllerException {
List<URI> fileShareUris = FileDescriptor.getFileSystemURIs(fileDescriptors);
FileDeleteWorkflowCompleter completer = new FileDeleteWorkflowCompleter(fileShareUris, taskId);
Workflow workflow = null;
try {
// Generate the Workflow.
workflow = _workflowService.getNewWorkflow(this, DELETE_FILESYSTEMS_WF_NAME, false, taskId);
// call the FileDeviceController to add its delete methods.
_fileDeviceController.addStepsForDeleteFileSystems(workflow, null, fileDescriptors, taskId);
// Finish up and execute the plan.
// The Workflow will handle the TaskCompleter
String successMessage = "Delete FileShares successful for: " + fileShareUris.toString();
Object[] callbackArgs = new Object[] { fileShareUris };
workflow.executePlan(completer, successMessage, new WorkflowCallback(), callbackArgs, null, null);
} catch (Exception ex) {
s_logger.error("Could not delete FileShares: " + fileShareUris, ex);
releaseWorkflowLocks(workflow);
String opName = ResourceOperationTypeEnum.DELETE_FILE_SYSTEM.getName();
ServiceError serviceError = DeviceControllerException.errors.deleteFileSharesFailed(fileShareUris.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method updateFileProtectionPolicy.
@Override
public void updateFileProtectionPolicy(URI policy, FilePolicyUpdateParam param, String taskId) {
FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, policy);
String opName = ResourceOperationTypeEnum.UPDATE_FILE_PROTECTION_POLICY.getName();
FileProtectionPolicyUpdateCompleter completer = new FileProtectionPolicyUpdateCompleter(policy, taskId);
try {
String waitFor = null;
Workflow workflow = _workflowService.getNewWorkflow(this, UPDATE_FILE_POLICY_WF_NAME, false, taskId, completer);
completer.setWorkFlowId(workflow.getWorkflowURI());
// Get the file policy storage resources!!!
List<PolicyStorageResource> policyStorageResources = FileOrchestrationUtils.getFilePolicyStorageResources(s_dbClient, filePolicy);
if (policyStorageResources != null && !policyStorageResources.isEmpty()) {
s_logger.info("Generating steps for updating file policy {} ", filePolicy.getFilePolicyName());
for (PolicyStorageResource policyStorageRes : policyStorageResources) {
StorageSystem system = s_dbClient.queryObject(StorageSystem.class, policyStorageRes.getStorageSystem());
String stepId = workflow.createStepId();
String stepDes = String.format("Updating policy on storage system %s, at path: %s", system.getLabel(), policyStorageRes.getResourcePath());
Object[] args = new Object[] { policyStorageRes.getStorageSystem(), policy, policyStorageRes.getId(), param };
// Try to update all storage system policies
// Dont use waitFor for next step!!!
_fileDeviceController.createMethod(workflow, waitFor, UPDATE_STORAGE_SYSTEM_FILE_PROTECTION_POLICY_METHOD, stepId, stepDes, policyStorageRes.getStorageSystem(), args);
}
String successMessage = String.format("Updating file policy {} is successful.", filePolicy.getFilePolicyName());
workflow.executePlan(completer, successMessage);
} else {
s_logger.info("No File Policy Storage resource for policy {} to update", filePolicy.getFilePolicyName());
}
} catch (Exception ex) {
s_logger.error(String.format("Updating file protection policy {} failed", filePolicy.getFilePolicyName()), ex);
ServiceError serviceError = DeviceControllerException.errors.updateFilePolicyFailed(filePolicy.toString(), ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method assignFilePolicyToFileSystem.
@Override
public void assignFilePolicyToFileSystem(FilePolicy filePolicy, List<FileDescriptor> fileDescriptors, String taskId) throws ControllerException {
FileShare sourceFS = null;
Workflow workflow = null;
List<URI> fsURIs = FileDescriptor.getFileSystemURIs(fileDescriptors);
FileSystemAssignPolicyWorkflowCompleter completer = new FileSystemAssignPolicyWorkflowCompleter(filePolicy.getId(), fsURIs, taskId);
try {
workflow = _workflowService.getNewWorkflow(this, ASSIGN_FILE_POLICY_TO_FS_WF_NAME, false, taskId);
String waitFor = null;
s_logger.info("Generating steps for creating mirror filesystems...");
for (FileDescriptor fileDescriptor : fileDescriptors) {
if (fileDescriptor.getType().toString().equals(FileDescriptor.Type.FILE_EXISTING_MIRROR_SOURCE.name()) || fileDescriptor.getType().toString().equals(FileDescriptor.Type.FILE_EXISTING_SOURCE.name())) {
sourceFS = s_dbClient.queryObject(FileShare.class, fileDescriptor.getFsURI());
break;
}
}
// then we have to create mirror file system first..
if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
waitFor = _fileDeviceController.addStepsForCreateFileSystems(workflow, waitFor, fileDescriptors, taskId);
}
// 2. Apply the file protection policy
String stepDescription = String.format("applying file policy : %s for file system : %s", filePolicy.getId(), sourceFS.getId());
String applyFilePolicyStep = workflow.createStepId();
Object[] args = new Object[] { sourceFS.getStorageDevice(), sourceFS.getId(), filePolicy.getId() };
_fileDeviceController.createMethod(workflow, waitFor, APPLY_FILE_POLICY_METHOD, applyFilePolicyStep, stepDescription, sourceFS.getStorageDevice(), args);
// Finish up and execute the plan.
String successMessage = String.format("Assigning file policy : %s, to file system: %s successful.", filePolicy.getId(), sourceFS.getId());
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Assigning file policy : %s to file system : %s failed", filePolicy.getId(), sourceFS.getId()), ex);
ServiceError serviceError = DeviceControllerException.errors.assignFilePolicyFailed(filePolicy.toString(), FilePolicyApplyLevel.file_system.name(), ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method addStepsToReplicateNFSACLs.
/**
* Child workflow for replicating source file system NFS ACL 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 addStepsToReplicateNFSACLs(URI systemTarget, URI fsURI, String taskId) {
s_logger.info("Generating steps for Replicating NFS ACLs to Target Cluster");
FileNfsACLUpdateParams params = null;
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_NFS_ACLS_TO_TARGET_WF_NAME, false, taskId, completer);
Map<String, List<NfsACE>> sourceFSACLMap = FileOrchestrationUtils.queryNFSACL(sourceFileShare, s_dbClient);
Map<String, List<NfsACE>> targetFSACLMap = FileOrchestrationUtils.queryNFSACL(targetFileShare, s_dbClient);
if (!sourceFSACLMap.isEmpty() && targetFSACLMap.isEmpty()) {
// target share doesn't have any ACLs but corresponding share on source does have ACL
s_logger.info("Target NFS doesn't have any ACL but corresponding NFS on source does have ACL.");
for (String fsPath : sourceFSACLMap.keySet()) {
List<NfsACE> aclToAdd = null;
params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(fsPath, sourceFileShare);
aclToAdd = sourceFSACLMap.get(fsPath);
params.setAcesToAdd(aclToAdd);
s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
}
} else if (!targetFSACLMap.isEmpty() && sourceFSACLMap.isEmpty()) {
s_logger.info("Source NFS doesn't have any ACL but corresponding NFS on target has ACL.");
for (String fsPath : targetFSACLMap.keySet()) {
List<NfsACE> aclToDelete = null;
params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(fsPath, targetFileShare);
aclToDelete = targetFSACLMap.get(fsPath);
// TO FIX COP-26361 DU case
// params.setAcesToDelete(aclToDelete);
s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
}
} else if (!sourceFSACLMap.isEmpty() && !targetFSACLMap.isEmpty()) {
// both source and target FS have some ACL
for (String sourceFSACLPath : sourceFSACLMap.keySet()) {
List<NfsACE> aclToAdd = new ArrayList<NfsACE>();
List<NfsACE> aclToDelete = new ArrayList<NfsACE>();
List<NfsACE> aclToModify = new ArrayList<NfsACE>();
// Segregate source and target NFS ACL
params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(sourceFSACLPath, sourceFileShare);
List<NfsACE> sourceNFSACL = sourceFSACLMap.get(sourceFSACLPath);
if (sourceNFSACL == null) {
sourceNFSACL = new ArrayList<NfsACE>();
}
String subDir = params.getSubDir();
String targetFSACLPath = targetFileShare.getPath();
if (subDir != null) {
targetFSACLPath += "/" + subDir;
}
List<NfsACE> targetNFSACL = targetFSACLMap.get(targetFSACLPath);
if (targetNFSACL == null) {
targetNFSACL = new ArrayList<NfsACE>();
}
HashMap<String, NfsACE> sourceUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(sourceNFSACL);
HashMap<String, NfsACE> targetUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(targetNFSACL);
// ACL To Add
for (String sourceACEUser : sourceUserToNFSACLMap.keySet()) {
if (targetUserToNFSACLMap.get(sourceACEUser) == null) {
NfsACE nfsACE = sourceUserToNFSACLMap.get(sourceACEUser);
aclToAdd.add(nfsACE);
}
}
// ACL To Delete
for (String targetACEUser : targetUserToNFSACLMap.keySet()) {
if (sourceUserToNFSACLMap.get(targetACEUser) == null) {
aclToDelete.add(targetUserToNFSACLMap.get(targetACEUser));
}
}
// ACL to Modify
targetNFSACL.removeAll(aclToDelete);
sourceNFSACL.removeAll(aclToAdd);
sourceUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(sourceNFSACL);
targetUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(targetNFSACL);
for (String sourceACEUser : sourceUserToNFSACLMap.keySet()) {
NfsACE targetACE = targetUserToNFSACLMap.get(sourceACEUser);
NfsACE sourceACE = sourceUserToNFSACLMap.get(sourceACEUser);
if (targetACE != null && (!targetACE.getPermissions().equals(sourceACE.getPermissions()) || !targetACE.getPermissionType().equals(sourceACE.getPermissionType()))) {
targetACE.setPermissions(sourceACE.getPermissions());
targetACE.setPermissionType(sourceACE.getPermissionType());
aclToModify.add(targetACE);
}
}
if (!aclToAdd.isEmpty()) {
params.setAcesToAdd(aclToAdd);
}
if (!aclToDelete.isEmpty()) {
// TO FIX COP-26361 DU case
// params.setAcesToDelete(aclToDelete);
}
if (!aclToModify.isEmpty()) {
params.setAcesToModify(aclToModify);
}
if (!params.retrieveAllACL().isEmpty()) {
s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
}
}
}
String successMessage = String.format("Replicating source file system : %s, NFS ACL to target file system finished successfully", sourceFileShare.getLabel());
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error("Could not replicate source filesystem NFS ACL : " + fsURI, ex);
String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
ServiceError serviceError = DeviceControllerException.errors.updateFileShareNFSACLFailed(fsURI.toString(), opName, ex);
completer.error(s_dbClient, this._locker, serviceError);
}
}
Aggregations