use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.
the class FileService method prepareFileSystem.
/**
* Allocate, initialize and persist state of the fileSystem being created.
*
* @param param
* @param project
* @param tenantOrg
* @param neighborhood
* @param vpool
* @param flags
* @param placement
* @param token
* @return
*/
private FileShare prepareFileSystem(FileSystemParam param, Project project, TenantOrg tenantOrg, VirtualArray neighborhood, VirtualPool vpool, DataObject.Flag[] flags, FileRecommendation placement, String token) {
_log.info("prepareFile System");
StoragePool pool = null;
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel(param.getLabel());
// No need to generate any name -- Since the requirement is to use the customizing label we should use the same.
// Stripping out the special characters like ; /-+!@#$%^&())";:[]{}\ | but allow underscore character _
String convertedName = param.getLabel().replaceAll("[^\\dA-Za-z\\_]", "");
_log.info("Original name {} and converted name {}", param.getLabel(), convertedName);
fs.setName(convertedName);
Long fsSize = SizeUtil.translateSize(param.getSize());
fs.setCapacity(fsSize);
fs.setVirtualPool(param.getVpool());
if (project != null) {
fs.setProject(new NamedURI(project.getId(), fs.getLabel()));
}
fs.setTenant(new NamedURI(tenantOrg.getId(), param.getLabel()));
fs.setVirtualArray(neighborhood.getId());
if (null != placement.getSourceStoragePool()) {
pool = _dbClient.queryObject(StoragePool.class, placement.getSourceStoragePool());
if (null != pool) {
fs.setProtocol(new StringSet());
fs.getProtocol().addAll(VirtualPoolUtil.getMatchingProtocols(vpool.getProtocols(), pool.getProtocols()));
}
}
fs.setStorageDevice(placement.getSourceStorageSystem());
fs.setPool(placement.getSourceStoragePool());
if (param.getSoftLimit() != 0) {
fs.setSoftLimit(new Long(param.getSoftLimit()));
}
if (param.getNotificationLimit() != 0) {
fs.setNotificationLimit(new Long(param.getNotificationLimit()));
}
if (param.getSoftGrace() > 0) {
fs.setSoftGracePeriod(new Integer(param.getSoftGrace()));
}
if (placement.getStoragePorts() != null && !placement.getStoragePorts().isEmpty()) {
fs.setStoragePort(placement.getStoragePorts().get(0));
}
// When a VPool supports "thin" provisioning
if (VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType())) {
fs.setThinlyProvisioned(Boolean.TRUE);
}
if (placement.getvNAS() != null) {
fs.setVirtualNAS(placement.getvNAS());
}
fs.setOpStatus(new OpStatusMap());
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM);
fs.getOpStatus().createTaskStatus(token, op);
if (flags != null) {
fs.addInternalFlags(flags);
}
_dbClient.createObject(fs);
return fs;
}
use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.
the class FileService method getFileSystemShare.
/**
* Get the SMB share for the specified file system.
*
* @param id
* the URN of a ViPR File system
* @param shareName
* file system share name
* @brief Show specified share
* @return List of file system shares.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares/{shareName}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SmbShareResponse getFileSystemShare(@PathParam("id") URI id, @PathParam("shareName") String shareName) throws InternalException {
_log.info(String.format("Get SMB file share %s for file system: %s", shareName, id.toString()));
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
ArgValidator.checkFieldNotNull(shareName, "shareName");
FileShare fileShare = queryResource(id);
SMBFileShare smbShare = null;
FileSystemShareList fileShareListResponse = new FileSystemShareList();
SmbShareResponse shareParam = null;
if (fileShare.getSMBFileShares() != null) {
_log.info("Number of SMBShares found {} and looking for share to read {} ", fileShare.getSMBFileShares().size(), shareName);
_log.info(String.format("Get file system share: file system id: %1$s, share name %2$s", id, shareName));
smbShare = fileShare.getSMBFileShares().get(shareName);
if (smbShare == null) {
_log.info("CIFS share does not exist {}", shareName);
} else {
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(UNLIMITED_USERS);
}
shareParam.setPermissionType(smbShare.getPermissionType());
shareParam.setPermission(smbShare.getPermission());
shareParam.setMountPoint(smbShare.getMountPoint());
shareParam.setPath(smbShare.getPath());
}
}
return shareParam;
}
use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.
the class FileService method doMirrorOperationValidation.
private void doMirrorOperationValidation(URI id, String op) {
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare sourceFileShare = queryResource(id);
ArgValidator.checkEntity(sourceFileShare, id, true);
// Make sure that we don't have some pending
// operation against the file share
checkForPendingTasks(Arrays.asList(sourceFileShare.getTenant().getURI()), Arrays.asList(sourceFileShare));
StringBuffer notSuppReasonBuff = new StringBuffer();
// Verify the file system is capable of replication..
if (!FileSystemReplicationUtils.validateMirrorOperationSupported(sourceFileShare, notSuppReasonBuff, op.toLowerCase())) {
_log.error("Mirror Operation {} is not supported for the file system {} as : {}", op, sourceFileShare.getLabel(), notSuppReasonBuff.toString());
throw APIException.badRequests.unableToPerformMirrorOperation(op, sourceFileShare.getId(), notSuppReasonBuff.toString());
}
// Check for replication policy existence on file system..
if (FileSystemReplicationUtils.getReplicationPolicyAppliedOnFS(sourceFileShare, _dbClient) == null) {
notSuppReasonBuff.append(String.format("Mirror Operation {} is not supported for the file system {} as file system doesn't have any replication policy assigned/applied", op, sourceFileShare.getLabel()));
_log.error(notSuppReasonBuff.toString());
throw APIException.badRequests.unableToPerformMirrorOperation(op, sourceFileShare.getId(), notSuppReasonBuff.toString());
}
}
use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.
the class FileService method startContinuousCopies.
/**
* @Deprecated use @Path("/{id}/assign-file-policy/{filePolicyUri}") instead
* Assign file policy API will enable the policy and policy will run
* based on the schedule.
*
* Start continuous copies.
*
* @prereq none
* @param id the URN of a ViPR Source file share
* @brief Start the replication session between source and target file system.
* @return TaskList
* @throws ControllerException
*/
@Deprecated
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/start")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList startContinuousCopies(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
doMirrorOperationValidation(id, ProtectionOp.START.toString());
String task = UUID.randomUUID().toString();
FileShare sourceFileShare = queryResource(id);
Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_START);
op.setDescription("start the replication link between source and target");
StorageSystem system = _dbClient.queryObject(StorageSystem.class, sourceFileShare.getStorageDevice());
FileController controller = getController(FileController.class, system.getSystemType());
controller.performFileReplicationOperation(system.getId(), id, ProtectionOp.START.toString().toLowerCase(), task);
TaskList taskList = new TaskList();
TaskResourceRep taskResp = toTask(sourceFileShare, task, op);
taskList.getTaskList().add(taskResp);
return taskList;
}
use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.
the class FileService method changeFileSystemVirtualPool.
/**
* Change File System Virtual Pool
*
* @param id
* the URN of a ViPR fileSystem
* @param param
* File System Virtual Pool Change parameter
* @brief Change a file systems virtual pool
* @desc Add the file system to a different virtual pool.
* @return TaskResponse
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/vpool-change")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep changeFileSystemVirtualPool(@PathParam("id") URI id, FileSystemVirtualPoolChangeParam param) {
_log.info("Request to change VirtualPool for filesystem {}", id);
StringBuilder errorMsg = new StringBuilder();
// Validate the FS id.
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
String task = UUID.randomUUID().toString();
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
// Make sure that we don't have some pending
// operation against the file system!!!
checkForPendingTasks(Arrays.asList(fs.getTenant().getURI()), Arrays.asList(fs));
// Get the project.
URI projectURI = fs.getProject().getURI();
Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
ArgValidator.checkEntity(project, projectURI, false);
_log.info("Found filesystem project {}", projectURI);
// Get the VirtualPool for the request and verify that the
// project's tenant has access to the VirtualPool.
VirtualPool newVpool = getVirtualPoolForRequest(project, param.getVirtualPool(), _dbClient, _permissionsHelper);
_log.info("Found new VirtualPool {}", newVpool.getId());
VirtualPool currentVpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
StringBuffer notSuppReasonBuff = new StringBuffer();
// Verify the vPool change is supported!!!
if (!VirtualPoolChangeAnalyzer.isSupportedFileReplicationChange(currentVpool, newVpool, notSuppReasonBuff)) {
_log.error("Virtual Pool change is not supported due to {}", notSuppReasonBuff.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), notSuppReasonBuff.toString());
}
ArgValidator.checkFieldUriType(param.getFilePolicy(), FilePolicy.class, "file_policy");
FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, param.getFilePolicy());
ArgValidator.checkEntity(filePolicy, param.getFilePolicy(), true);
StringSet existingFSPolicies = fs.getFilePolicies();
if (existingFSPolicies != null && existingFSPolicies.contains(param.getFilePolicy().toString())) {
errorMsg.append("Provided file policy:" + filePolicy.getId() + " is already is applied to the file system:" + fs.getId());
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), errorMsg.toString());
}
// check if same TYPE of policy already applied to file system
if (filePolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name()) && existingFSPolicies != null && !existingFSPolicies.isEmpty()) {
checkForDuplicatePolicyApplied(filePolicy, existingFSPolicies);
}
// Check if the target vpool supports provided policy type..
FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, newVpool);
// Check if the vpool supports policy at file system level..
if (!newVpool.getAllowFilePolicyAtFSLevel()) {
errorMsg.append("Provided vpool :" + newVpool.getLabel() + " doesn't support policy at file system level");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), errorMsg.toString());
}
// only single replication policy per vpool/project/fs.
if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && FilePolicyServiceUtils.fsHasReplicationPolicy(_dbClient, newVpool.getId(), fs.getProject().getURI(), fs.getId())) {
errorMsg.append("Provided vpool/project/fs has already assigned with replication policy.");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), errorMsg.toString());
}
if (FilePolicyServiceUtils.fsHasSnapshotPolicyWithSameSchedule(_dbClient, fs.getId(), filePolicy)) {
errorMsg.append("Snapshot policy with similar schedule is already present on fs " + fs.getLabel());
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), errorMsg.toString());
}
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CHANGE_FILE_SYSTEM_VPOOL);
op.setDescription("Change vpool operation");
op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, op);
TaskResourceRep fileSystemTask = toTask(fs, task, op);
try {
// Change the virtual pool of source file system!!
fs.setVirtualPool(newVpool.getId());
_dbClient.updateObject(fs);
FilePolicyFileSystemAssignParam policyAssignParam = new FilePolicyFileSystemAssignParam();
policyAssignParam.setTargetVArrays(param.getTargetVArrays());
if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
return assignFileReplicationPolicyToFS(fs, filePolicy, policyAssignParam, task);
} else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
return assignFilePolicyToFS(fs, filePolicy, task);
}
} catch (BadRequestException e) {
op = _dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Change vpool operation failed {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Change vpool operation failed {}, {}", e.getMessage(), e);
// revert the virtual pool of source file system!!
fs.setVirtualPool(currentVpool.getId());
_dbClient.updateObject(fs);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return fileSystemTask;
}
Aggregations