use of com.emc.storageos.model.file.policy.FilePolicyFileSystemAssignParam in project coprhd-controller by CoprHD.
the class FileSystems method associateFilePolicy.
/**
* Associate a file policy to a given file system
* <p>
* API Call: <tt>PUT /file/filesystems/{id}/assign-file-policy/{file_policy_uri}</tt>
*
* @param fileSystemId
* the ID of the file system.
* @param filePolicyId
* the ID of the file policy.
* @return a task for monitoring the progress of the operation.
*/
public Task<FileShareRestRep> associateFilePolicy(URI fileSystemId, URI filePolicyId, URI targetVarray) {
UriBuilder builder = client.uriBuilder(getIdUrl() + "/assign-file-policy/{file_policy_uri}");
URI targetUri = builder.build(fileSystemId, filePolicyId);
FilePolicyFileSystemAssignParam param = new FilePolicyFileSystemAssignParam();
Set<URI> targetArrays = new HashSet<URI>();
targetArrays.add(targetVarray);
param.setTargetVArrays(targetArrays);
return putTaskURI(param, targetUri);
}
use of com.emc.storageos.model.file.policy.FilePolicyFileSystemAssignParam 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