Search in sources :

Example 11 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileOrchestrationUtils method getAllProjectLevelPolices.

/**
 * Return list of policies to be applied at project
 *
 * @param dbClient
 * @param project
 * @param storageSystem
 * @return
 */
public static List<FilePolicy> getAllProjectLevelPolices(DbClient dbClient, Project project, VirtualPool vpool, URI storageSystem, URI nasServer) {
    List<FilePolicy> filePoliciesToCreate = new ArrayList<FilePolicy>();
    StringSet fileProjectPolicies = project.getFilePolicies();
    if (fileProjectPolicies != null && !fileProjectPolicies.isEmpty()) {
        for (String fileProjectPolicy : fileProjectPolicies) {
            FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, URIUtil.uri(fileProjectPolicy));
            if (NullColumnValueGetter.isNullURI(filePolicy.getFilePolicyVpool()) || !filePolicy.getFilePolicyVpool().toString().equals(vpool.getId().toString())) {
                continue;
            }
            filePoliciesToCreate.add(filePolicy);
            StringSet policyStrRes = filePolicy.getPolicyStorageResources();
            if (policyStrRes != null && !policyStrRes.isEmpty()) {
                for (String policyStrRe : policyStrRes) {
                    PolicyStorageResource strRes = dbClient.queryObject(PolicyStorageResource.class, URIUtil.uri(policyStrRe));
                    if (strRes != null && strRes.getAppliedAt().toString().equals(project.getId().toString()) && strRes.getStorageSystem().toString().equals(storageSystem.toString()) && strRes.getNasServer().toString().equalsIgnoreCase(nasServer.toString())) {
                        _log.info("File Policy {} is already exists for project {} , storage system {} and nas server {}", filePolicy.getFilePolicyName(), project.getLabel(), storageSystem.toString(), strRes);
                        filePoliciesToCreate.remove(filePolicy);
                        break;
                    }
                }
            }
        }
    }
    return filePoliciesToCreate;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource)

Example 12 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileService method checkForDuplicatePolicyApplied.

private void checkForDuplicatePolicyApplied(FilePolicy filePolicy, StringSet existingFSPolicies) {
    List<URI> existingFSPolicyURIs = new ArrayList<>();
    for (String filePolicyURI : existingFSPolicies) {
        existingFSPolicyURIs.add(URI.create(filePolicyURI));
    }
    Iterator<FilePolicy> iterator = _dbClient.queryIterativeObjects(FilePolicy.class, existingFSPolicyURIs, true);
    while (iterator.hasNext()) {
        FilePolicy fp = iterator.next();
        if (filePolicy.getFilePolicyType().equals(fp.getFilePolicyType())) {
            _log.error("File policy of same type is already applied to the file system {}.", filePolicy.getFilePolicyType());
            throw APIException.badRequests.duplicateFilePolicyTypeAssociation(filePolicy.getFilePolicyType());
        }
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 13 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileService method stopContinuousCopies.

/**
 * Stop continuous copies.
 *
 * @prereq none
 * @param id the URN of a ViPR Source file share
 * @brief Stop the replication session between source and target file system.
 * @return TaskList
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/stop")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList stopContinuousCopies(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
    doMirrorOperationValidation(id, ProtectionOp.STOP.toString());
    String task = UUID.randomUUID().toString();
    FileShare sourceFileShare = queryResource(id);
    Set<URI> unassignFrom = new HashSet<>();
    unassignFrom.add(id);
    FilePolicy filepolicy = FileSystemReplicationUtils.getReplicationPolicyAppliedOnFS(sourceFileShare, _dbClient);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_STOP);
    op.setDescription("stop the replication link between source and target");
    FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
    controller.unassignFilePolicy(filepolicy.getId(), unassignFrom, task);
    auditOp(OperationTypeEnum.STOP_FILE_MIRROR, true, "BEGIN", sourceFileShare.getId().toString());
    TaskList taskList = new TaskList();
    TaskResourceRep taskResp = toTask(sourceFileShare, task, op);
    taskList.getTaskList().add(taskResp);
    return taskList;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) 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) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileService method unAssignFilePolicy.

/**
 * Unassign existing file system to file policy.
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param filePolicyUri
 *            the URN of a Policy
 * @brief Update file system with Policy detail
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/unassign-file-policy/{filePolicyUri}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep unAssignFilePolicy(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri) throws InternalException {
    // log input received.
    _log.info("Unassign Policy on File System : request received for {}  with {}", id, filePolicyUri);
    String task = UUID.randomUUID().toString();
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
    ArgValidator.checkUri(filePolicyUri);
    FilePolicy fp = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
    ArgValidator.checkEntityNotNull(fp, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
    // verify the schedule policy is associated with file system or not.
    if (!fs.getFilePolicies().isEmpty() && !fs.getFilePolicies().contains(filePolicyUri.toString())) {
        throw APIException.badRequests.cannotFindAssociatedPolicy(filePolicyUri);
    }
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
    Operation op = _dbClient.createTaskOpStatus(FilePolicy.class, fp.getId(), task, ResourceOperationTypeEnum.UNASSIGN_FILE_POLICY);
    op.setDescription("Filesystem unassign policy");
    // As the action done by tenant admin
    // Set current tenant as task's tenant!!!
    Task taskObj = op.getTask(fp.getId());
    FilePolicyServiceUtils.updateTaskTenant(_dbClient, fp, "unassign", taskObj, fs.getTenant().getURI());
    try {
        Set<URI> unassignFrom = new HashSet<URI>();
        unassignFrom.add(id);
        _log.info("No Errors found proceeding further {}, {}, {}", new Object[] { _dbClient, fs, fp });
        controller.unassignFilePolicy(filePolicyUri, unassignFrom, task);
        auditOp(OperationTypeEnum.UNASSIGN_FILE_POLICY, true, "BEGIN", fp.getId().toString(), fp.getFilePolicyName());
    } catch (BadRequestException e) {
        op = _dbClient.error(FilePolicy.class, fp.getId(), task, e);
        _log.error("Error Unassigning File policy {}, {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        _log.error("Error Unassigning Filesystem policy {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return toTask(fp, task, op);
}
Also used : TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) 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)

Example 15 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileService method assignFilePolicy.

/**
 * Assign existing file system to file policy.
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param filePolicyUri
 *            the URN of a Policy
 * @brief Update file system with Policy detail
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/assign-file-policy/{filePolicyUri}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep assignFilePolicy(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri, FilePolicyFileSystemAssignParam param) throws InternalException {
    TaskResourceRep resp = new TaskResourceRep();
    StringBuilder errorMsg = new StringBuilder();
    _log.info("Assigning file policy {} to file system {}", filePolicyUri, id);
    String task = UUID.randomUUID().toString();
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
    ArgValidator.checkUri(filePolicyUri);
    FilePolicy filePolicy = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
    ArgValidator.checkEntityNotNull(filePolicy, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
    StringSet existingFSPolicies = fs.getFilePolicies();
    if (existingFSPolicies != null && existingFSPolicies.contains(filePolicyUri.toString())) {
        _log.info("Provided file policy {} is already is applied to the file sytem {}", filePolicy.getId(), fs.getId());
        Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.ASSIGN_FILE_POLICY_TO_FILE_SYSTEM);
        op.setDescription("assign file policy to file system");
        _dbClient.ready(FileShare.class, fs.getId(), task);
        return toTask(fs, task, op);
    }
    // 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 vpool supports provided policy type..
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, vpool);
    // Check if the vpool supports policy at file system level..
    if (!vpool.getAllowFilePolicyAtFSLevel()) {
        errorMsg.append("Provided vpool :" + vpool.getLabel() + " doesn't support policy at file system level");
        _log.error(errorMsg.toString());
        throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    // only single replication policy per vpool/project/fs.
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && FilePolicyServiceUtils.fsHasReplicationPolicy(_dbClient, vpool.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.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_snapshot.name()) && 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.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
        return assignFileReplicationPolicyToFS(fs, filePolicy, param, task);
    } else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
        return assignFilePolicyToFS(fs, filePolicy, task);
    }
    return resp;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) 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

FilePolicy (com.emc.storageos.db.client.model.FilePolicy)70 URI (java.net.URI)25 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)21 FileShare (com.emc.storageos.db.client.model.FileShare)18 StringSet (com.emc.storageos.db.client.model.StringSet)18 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)18 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)18 ControllerException (com.emc.storageos.volumecontroller.ControllerException)18 ArrayList (java.util.ArrayList)18 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)16 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)15 WorkflowException (com.emc.storageos.workflow.WorkflowException)15 PolicyStorageResource (com.emc.storageos.db.client.model.PolicyStorageResource)14 MapFilePolicy (com.emc.storageos.api.mapper.functions.MapFilePolicy)13 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)13 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)13 Path (javax.ws.rs.Path)13 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 URISyntaxException (java.net.URISyntaxException)12