use of com.emc.storageos.db.client.model.FSExportMap 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.db.client.model.FSExportMap in project coprhd-controller by CoprHD.
the class FileService method getFileSystemExportList.
/**
* @Deprecated use @Path("/{id}/export") instead.
* Get list of file system exports
* @param id
* the URN of a ViPR File system
* @brief List file system exports.
* <p>
* Use /file/filesystems/{id}/export instead
* @return File system exports list.
*/
@Deprecated
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FileSystemExportList getFileSystemExportList(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fileShare = queryResource(id);
FileSystemExportList fileExportListResponse = new FileSystemExportList();
if (fileShare.getInactive()) {
return fileExportListResponse;
}
// Get export map from fileSystem
FSExportMap exportMap = fileShare.getFsExports();
Collection<FileExport> fileExports = new ArrayList<FileExport>();
if (exportMap != null) {
fileExports = exportMap.values();
}
// Process each export from the map and its data to exports in response list.
for (FileExport fileExport : fileExports) {
FileSystemExportParam fileExportParam = new FileSystemExportParam();
fileExportParam.setEndpoints(fileExport.getClients());
fileExportParam.setSecurityType(fileExport.getSecurityType());
fileExportParam.setPermissions(fileExport.getPermissions());
fileExportParam.setRootUserMapping(fileExport.getRootUserMapping());
fileExportParam.setProtocol(fileExport.getProtocol());
fileExportParam.setMountPoint(fileExport.getMountPoint());
fileExportParam.setSubDirectory(fileExport.getSubDirectory());
fileExportListResponse.getExportList().add(fileExportParam);
}
return fileExportListResponse;
}
use of com.emc.storageos.db.client.model.FSExportMap in project coprhd-controller by CoprHD.
the class FileSnapshotService method export.
/**
* Add file share snapshot export.
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR Snapshot
* @param param
* File system export parameters
* @brief Create file snapshot export
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep export(@PathParam("id") URI id, FileSystemExportParam param) throws InternalException {
_log.info("Snapshot Export request recieved {}", id);
String task = UUID.randomUUID().toString();
ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
Snapshot snap = queryResource(id);
ArgValidator.checkEntity(snap, id, true);
if (!param.getPermissions().equals(FileShareExport.Permissions.ro.name())) {
throw APIException.badRequests.snapshotExportPermissionReadOnly();
}
ArgValidator.checkFieldValueFromEnum(param.getSecurityType(), "type", EnumSet.allOf(FileShareExport.SecurityTypes.class));
ArgValidator.checkFieldValueFromEnum(param.getProtocol(), "protocol", EnumSet.allOf(StorageProtocol.File.class));
ArgValidator.checkSubDirName("sub_directory", param.getSubDirectory());
FileService.validateIpInterfacesRegistered(param.getEndpoints(), _dbClient);
FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
// Locate storage port for exporting file snap
// We use file system in the call since file snap belongs to the same neighbourhood as its parent file system
StoragePort sport = _fileScheduler.placeFileShareExport(fs, param.getProtocol(), param.getEndpoints());
String path = snap.getPath();
String mountPath = snap.getMountPath();
_log.info("Check whether there is a NFS Export already for the path {}", path);
FSExportMap exportMap = snap.getFsExports();
if (exportMap != null) {
Iterator it = snap.getFsExports().keySet().iterator();
boolean exportExists = false;
while (it.hasNext()) {
String fsExpKey = (String) it.next();
FileExport fileExport = snap.getFsExports().get(fsExpKey);
_log.info("Snap export key {} does it exist ? {}", fsExpKey + ":" + fileExport.getPath(), exportExists);
if (fileExport.getPath().equalsIgnoreCase(path)) {
exportExists = true;
_log.info("Snap export key {} exist {}", fsExpKey + ":" + fileExport.getPath(), exportExists);
break;
}
}
if (exportExists) {
throw APIException.badRequests.snapshotHasExistingExport();
}
}
verifyFileSnapshotExports(snap, param, path);
FileShareExport export = new FileShareExport(param.getEndpoints(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol(), sport.getPortGroup(), sport.getPortNetworkId(), path, mountPath, param.getSubDirectory(), param.getComments());
_log.info("FileSnapExport --- FileSnap id: " + id + ", Clients: " + export.getClients() + ", StoragePort:" + sport.getPortName() + ", StoragePort :" + export.getStoragePort() + ", SecurityType: " + export.getSecurityType() + ", Permissions: " + export.getPermissions() + ", Root user mapping: " + export.getRootUserMapping() + ",Protocol: " + export.getProtocol() + ",path:" + export.getPath() + ",mountPath:" + export.getMountPath());
Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.EXPORT_FILE_SNAPSHOT);
FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
fileServiceApi.export(device.getId(), snap.getId(), Arrays.asList(export), task);
auditOp(OperationTypeEnum.EXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), device.getId().toString(), export.getClients(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol());
return toTask(snap, task, op);
}
use of com.emc.storageos.db.client.model.FSExportMap in project coprhd-controller by CoprHD.
the class FileSnapshotService method verifyFileSnapshotExports.
private void verifyFileSnapshotExports(Snapshot snap, FileSystemExportParam param, String path) {
FSExportMap snapExports = snap.getFsExports();
URI id = snap.getId();
if (null != snapExports) {
Iterator<FileExport> it = snapExports.values().iterator();
while (it.hasNext()) {
FileExport fileExport = it.next();
// If no key found then it should process as it is.
boolean isAlreadyExportedToSameEndpoint = false;
if (fileExport.getPath().equals(path)) {
List<String> availableEndpoints = fileExport.getClients();
List<String> providedEndpoints = param.getEndpoints();
for (String providedEndpoint : providedEndpoints) {
if (availableEndpoints.contains(providedEndpoint)) {
isAlreadyExportedToSameEndpoint = true;
break;
}
}
if (isAlreadyExportedToSameEndpoint) {
_log.info(String.format("Existing Export params for Snapshot id: %1$s, SecurityType: %2$s, " + "Permissions: %3$s, Root user mapping: %4$s, ", id, fileExport.getSecurityType(), fileExport.getPermissions(), fileExport.getRootUserMapping()));
_log.info(String.format("Recieved Export params for Snapshot id: %1$s, SecurityType: %2$s, " + "Permissions: %3$s, Root user mapping: %4$s, ", id, param.getSecurityType(), param.getPermissions(), param.getRootUserMapping()));
if (!fileExport.getPermissions().equals(param.getPermissions())) {
throw APIException.badRequests.updatingSnapshotExportNotAllowed("permissions");
}
if (!fileExport.getSecurityType().equals(param.getSecurityType())) {
throw APIException.badRequests.updatingSnapshotExportNotAllowed("type");
}
if (!fileExport.getRootUserMapping().equals(param.getRootUserMapping())) {
throw APIException.badRequests.updatingSnapshotExportNotAllowed("root_user");
}
}
}
}
}
}
use of com.emc.storageos.db.client.model.FSExportMap in project coprhd-controller by CoprHD.
the class PropertySetterUtil method convertUnManagedExportMapToManaged.
/**
* extract value from a String Set
* This method is used, to get value from a StringSet of size 1.
*
* @param key
* @param volumeInformation
* @return String
*/
public static FSExportMap convertUnManagedExportMapToManaged(UnManagedFSExportMap unManagedFSExportMap, StoragePort storagePort, StorageHADomain dataMover) {
FSExportMap fsExportMap = new FSExportMap();
if (unManagedFSExportMap == null) {
return fsExportMap;
}
for (UnManagedFSExport export : unManagedFSExportMap.values()) {
FileExport fsExport = new FileExport();
if (null != export.getIsilonId()) {
fsExport.setIsilonId(export.getIsilonId());
}
if (null != export.getNativeId()) {
fsExport.setNativeId(export.getNativeId());
}
if (null != storagePort) {
fsExport.setStoragePort(storagePort.getPortName());
if ((export.getMountPath() != null) && (export.getMountPath().length() > 0)) {
fsExport.setMountPoint(ExportUtils.getFileMountPoint(storagePort.getPortNetworkId(), export.getMountPath()));
} else {
fsExport.setMountPoint(ExportUtils.getFileMountPoint(storagePort.getPortNetworkId(), export.getPath()));
}
} else if (null != export.getStoragePort()) {
fsExport.setStoragePort(export.getStoragePort());
if (null != export.getMountPoint()) {
fsExport.setMountPoint(export.getMountPoint());
}
}
if (null != dataMover) {
fsExport.setStoragePortName(dataMover.getName());
} else if (null != storagePort) {
fsExport.setStoragePortName(storagePort.getPortName());
} else if (null != export.getStoragePortName()) {
fsExport.setStoragePortName(export.getStoragePortName());
}
if (null != export.getMountPath()) {
fsExport.setMountPath(export.getMountPath());
}
fsExport.setPath(export.getPath());
fsExport.setPermissions(export.getPermissions());
fsExport.setProtocol(export.getProtocol());
fsExport.setRootUserMapping(export.getRootUserMapping());
fsExport.setSecurityType(export.getSecurityType());
fsExport.setClients(export.getClients());
fsExportMap.put(fsExport.getFileExportKey(), fsExport);
}
return fsExportMap;
}
Aggregations