Search in sources :

Example 1 with FilePolicyFileSystemAssignParam

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);
}
Also used : FilePolicyFileSystemAssignParam(com.emc.storageos.model.file.policy.FilePolicyFileSystemAssignParam) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) HashSet(java.util.HashSet)

Example 2 with FilePolicyFileSystemAssignParam

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;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Project(com.emc.storageos.db.client.model.Project) StringSet(com.emc.storageos.db.client.model.StringSet) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) FilePolicyFileSystemAssignParam(com.emc.storageos.model.file.policy.FilePolicyFileSystemAssignParam) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

FilePolicyFileSystemAssignParam (com.emc.storageos.model.file.policy.FilePolicyFileSystemAssignParam)2 URI (java.net.URI)2 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Operation (com.emc.storageos.db.client.model.Operation)1 Project (com.emc.storageos.db.client.model.Project)1 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1