Search in sources :

Example 1 with FilePolicyApplyLevel

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

the class FileOrchestrationUtils method updateUnAssignedResource.

public static void updateUnAssignedResource(FilePolicy filePolicy, URI unassignRes, DbClient dbClient) {
    FilePolicyApplyLevel applyLevel = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
    switch(applyLevel) {
        case vpool:
            VirtualPool vpool = dbClient.queryObject(VirtualPool.class, unassignRes);
            vpool.removeFilePolicy(filePolicy.getId());
            dbClient.updateObject(vpool);
            break;
        case project:
            Project project = dbClient.queryObject(Project.class, unassignRes);
            project.removeFilePolicy(project, filePolicy.getId());
            dbClient.updateObject(project);
            break;
        case file_system:
            FileShare fs = dbClient.queryObject(FileShare.class, unassignRes);
            fs.removeFilePolicy(filePolicy.getId());
            dbClient.updateObject(fs);
            break;
        default:
            _log.error("Not a valid policy apply level: " + applyLevel);
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FilePolicyApplyLevel(com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel) FileShare(com.emc.storageos.db.client.model.FileShare)

Example 2 with FilePolicyApplyLevel

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

the class FilePolicyService method assignFilePolicy.

/**
 * Assign File Policy
 *
 * @param id
 *            of the file policy.
 * @param param
 *            FilePolicyAssignParam
 * @brief Assign file policy to vpool, project, file system
 * @return FilePolicyAssignResp
 */
@POST
@Path("/{id}/assign-policy")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.TENANT_ADMIN })
public TaskResourceRep assignFilePolicy(@PathParam("id") URI id, FilePolicyAssignParam param) {
    ArgValidator.checkFieldUriType(id, FilePolicy.class, "id");
    FilePolicy filepolicy = this._dbClient.queryObject(FilePolicy.class, id);
    ArgValidator.checkEntity(filepolicy, id, true);
    // Verify user has permission to assign policy
    canUserAssignPolicyAtGivenLevel(filepolicy);
    String applyAt = filepolicy.getApplyAt();
    FilePolicyApplyLevel appliedAt = FilePolicyApplyLevel.valueOf(applyAt);
    switch(appliedAt) {
        case vpool:
            return assignFilePolicyToVpools(param, filepolicy);
        case project:
            return assignFilePolicyToProjects(param, filepolicy);
        default:
            throw APIException.badRequests.invalidFilePolicyApplyLevel(appliedAt.name());
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) FilePolicyApplyLevel(com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with FilePolicyApplyLevel

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

the class FilePolicyAssignWorkflowCompleter method updatePolicyAssignedResources.

private void updatePolicyAssignedResources(DbClient dbClient, FilePolicy filePolicy, Status status, ServiceCoded coded) {
    for (URI resourceURI : assignToResource) {
        filePolicy.addAssignedResources(resourceURI);
        FilePolicyApplyLevel applyAt = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
        switch(applyAt) {
            case project:
                Project project = dbClient.queryObject(Project.class, resourceURI);
                project.addFilePolicy(filePolicy.getId());
                dbClient.updateObject(project);
                if (projectVPool != null) {
                    filePolicy.setFilePolicyVpool(projectVPool);
                }
                break;
            case vpool:
                VirtualPool vpool = dbClient.queryObject(VirtualPool.class, resourceURI);
                vpool.addFilePolicy(filePolicy.getId());
                dbClient.updateObject(vpool);
                break;
            default:
                break;
        }
    }
    dbClient.updateObject(filePolicy);
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) FilePolicyApplyLevel(com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel)

Example 4 with FilePolicyApplyLevel

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

the class FilePolicyUnAssignWorkflowCompleter method updatePolicyUnAssignedResources.

protected void updatePolicyUnAssignedResources(DbClient dbClient, FilePolicy filePolicy, Status status, ServiceCoded coded) {
    for (URI resourceURI : unassignFromResource) {
        filePolicy.removeAssignedResources(resourceURI);
        FilePolicyApplyLevel applyLevel = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
        switch(applyLevel) {
            case vpool:
                VirtualPool vpool = dbClient.queryObject(VirtualPool.class, resourceURI);
                vpool.removeFilePolicy(filePolicy.getId());
                dbClient.updateObject(vpool);
                break;
            case project:
                Project project = dbClient.queryObject(Project.class, resourceURI);
                project.removeFilePolicy(project, filePolicy.getId());
                dbClient.updateObject(project);
                break;
            case file_system:
                FileShare fs = dbClient.queryObject(FileShare.class, resourceURI);
                fs.removeFilePolicy(filePolicy.getId());
                dbClient.updateObject(fs);
                break;
            default:
                _log.error("Not a valid policy apply level: " + applyLevel);
        }
    }
    if (filePolicy.getAssignedResources() == null || filePolicy.getAssignedResources().isEmpty()) {
        // remove the file policy vpool
        if (!NullColumnValueGetter.isNullURI(filePolicy.getFilePolicyVpool())) {
            filePolicy.setFilePolicyVpool(NullColumnValueGetter.getNullURI());
        }
        // If no other resources are assigned to replication policy
        // Remove the replication topology from the policy
        FileOrchestrationUtils.removeTopologyInfo(filePolicy, dbClient);
    }
    dbClient.updateObject(filePolicy);
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) FilePolicyApplyLevel(com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel) FileShare(com.emc.storageos.db.client.model.FileShare)

Example 5 with FilePolicyApplyLevel

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

the class IsilonFileStorageDevice method generatePathForPolicy.

private String generatePathForPolicy(FilePolicy filePolicy, FileShare fileShare, FileDeviceInputOutput args) {
    String policyPath = "";
    FilePolicyApplyLevel applyLevel = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
    switch(applyLevel) {
        case vpool:
            String vpool = getNameWithNoSpecialCharacters(args.getVPool().getLabel(), args);
            if (fileShare.getNativeId().contains(vpool)) {
                policyPath = fileShare.getNativeId().split(vpool)[0] + vpool;
            } else {
                _log.info("File system path {} does not contain vpool name {}", fileShare.getNativeId(), vpool);
            }
            break;
        case project:
            String project = getNameWithNoSpecialCharacters(args.getProject().getLabel(), args);
            if (fileShare.getNativeId().contains(project)) {
                policyPath = fileShare.getNativeId().split(project)[0] + project;
            } else {
                _log.info("File system path {} does not contain project name {}", fileShare.getNativeId(), project);
            }
            break;
        case file_system:
            policyPath = fileShare.getNativeId();
            break;
        default:
            _log.error("Not a valid policy applied at level {} ", applyLevel);
    }
    return policyPath;
}
Also used : FilePolicyApplyLevel(com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel)

Aggregations

FilePolicyApplyLevel (com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel)8 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 Project (com.emc.storageos.db.client.model.Project)3 URI (java.net.URI)3 FileShare (com.emc.storageos.db.client.model.FileShare)2 MapFilePolicy (com.emc.storageos.api.mapper.functions.MapFilePolicy)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 FileReplicationTopology (com.emc.storageos.db.client.model.FileReplicationTopology)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)1 FilePolicyRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep)1 ReplicationSettingsRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep.ReplicationSettingsRestRep)1 ScheduleRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep.ScheduleRestRep)1 SnapshotSettingsRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep.SnapshotSettingsRestRep)1 FileReplicationTopologyRestRep (com.emc.storageos.model.file.policy.FileReplicationTopologyRestRep)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1