Search in sources :

Example 46 with FilePolicy

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

the class FileOrchestrationDeviceController method unassignFilePolicy.

@Override
public void unassignFilePolicy(URI policy, Set<URI> unassignFrom, String taskId) throws InternalException {
    FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, policy);
    FilePolicyUnAssignWorkflowCompleter completer = new FilePolicyUnAssignWorkflowCompleter(policy, unassignFrom, taskId);
    try {
        Workflow workflow = _workflowService.getNewWorkflow(this, UNASSIGN_FILE_POLICY_WF_NAME, false, taskId, completer);
        completer.setWorkFlowId(workflow.getWorkflowURI());
        s_logger.info("Generating steps for unassigning file policy {} from resources", policy);
        Set<String> policyResources = filePolicy.getPolicyStorageResources();
        if (policyResources != null && !policyResources.isEmpty()) {
            for (URI uri : unassignFrom) {
                for (String policyResource : policyResources) {
                    PolicyStorageResource policyStorage = s_dbClient.queryObject(PolicyStorageResource.class, URI.create(policyResource));
                    if (policyStorage.getAppliedAt().toString().equals(uri.toString())) {
                        StorageSystem storageSystem = s_dbClient.queryObject(StorageSystem.class, policyStorage.getStorageSystem());
                        String stepId = workflow.createStepId();
                        String stepDes = String.format("unassigning file policy : %s,  from resource: %s,", filePolicy.getId(), uri);
                        Object[] args = new Object[] { storageSystem.getId(), policy, policyStorage.getId() };
                        _fileDeviceController.createMethod(workflow, null, UNASSIGN_FILE_POLICY_METHOD, stepId, stepDes, storageSystem.getId(), args);
                    }
                }
            }
        } else {
            s_logger.info("file policy {} is not applied to any storage system", policy);
            for (URI uri : unassignFrom) {
                filePolicy.removeAssignedResources(uri);
                FileOrchestrationUtils.updateUnAssignedResource(filePolicy, uri, s_dbClient);
            }
            // If no other resources are assigned to replication policy
            // Remove the replication topology from the policy
            FileOrchestrationUtils.removeTopologyInfo(filePolicy, s_dbClient);
            s_dbClient.updateObject(filePolicy);
            s_logger.info("Unassigning file policy: {} from resources: {} finished successfully", policy.toString(), unassignFrom.toString());
        }
        String successMessage = String.format("unassigning file policy : %s,  from resources: %s finsihed successfully,", filePolicy.getId(), unassignFrom);
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error(String.format("unassigning file policy : %s,  from resource: %s failed,", filePolicy.getId(), unassignFrom), ex);
        ServiceError serviceError = DeviceControllerException.errors.unassignFilePolicyFailed(policy.toString(), ex);
        completer.error(s_dbClient, _locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FilePolicyUnAssignWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FilePolicyUnAssignWorkflowCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) URI(java.net.URI) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 47 with FilePolicy

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

the class FileOrchestrationDeviceController method getVpoolLevelPolices.

/**
 * Get the valid policy templates which are applied at vpool level
 *
 * @param vpool
 * @return List of policies at the given vpool level
 */
private static List<FilePolicy> getVpoolLevelPolices(VirtualPool vpool) {
    StringSet vPoolFilePolicies = vpool.getFilePolicies();
    List<FilePolicy> filePoliciesToCreate = new ArrayList<FilePolicy>();
    if (!CollectionUtils.isEmpty(vPoolFilePolicies)) {
        for (String fileVpoolPolicy : vPoolFilePolicies) {
            FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, URIUtil.uri(fileVpoolPolicy));
            if (filePolicy != null && !filePolicy.getInactive()) {
                filePoliciesToCreate.add(filePolicy);
            }
        }
    }
    return filePoliciesToCreate;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList)

Example 48 with FilePolicy

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

the class FileOrchestrationUtils method getFilePolicyStorageResources.

/**
 * Get the set of file policy storage resource for given policy
 *
 * @param dbClient
 * @param policy
 * @return
 */
public static List<PolicyStorageResource> getFilePolicyStorageResources(DbClient dbClient, VirtualPool vpool, Project project, FileShare fs) {
    // Get the replication policies for vpool/project/fs!!
    List<PolicyStorageResource> policyStorageResources = new ArrayList<PolicyStorageResource>();
    List<FilePolicy> replicationPolicies = getReplicationPolices(dbClient, vpool, project, fs);
    if (replicationPolicies != null && !replicationPolicies.isEmpty()) {
        if (replicationPolicies.size() > 1) {
            _log.error("More than one replication policy could not be applied accross vpool/project/fs");
            throw APIException.badRequests.moreThanOneReplicationPolicySpecified();
        } else {
            FilePolicy policy = replicationPolicies.get(0);
            for (PolicyStorageResource strRes : getFilePolicyStorageResources(dbClient, policy)) {
                if (strRes != null) {
                    if (FilePolicyApplyLevel.project.name().equalsIgnoreCase(policy.getApplyAt()) && strRes.getAppliedAt().toString().equals(project.getId().toString())) {
                        policyStorageResources.add(strRes);
                    } else if (FilePolicyApplyLevel.vpool.name().equalsIgnoreCase(policy.getApplyAt()) && strRes.getAppliedAt().toString().equals(vpool.getId().toString())) {
                        policyStorageResources.add(strRes);
                    }
                }
            }
        }
    }
    return policyStorageResources;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource)

Example 49 with FilePolicy

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

the class FileOrchestrationUtils method isReplicationPolicyExistsOnTarget.

/**
 * Verify the replication policy was applied at given level
 *
 * @param dbClient
 * @param system
 * @param nasServer
 * @param vpool
 * @param project
 * @param fs
 * @return
 */
public static Boolean isReplicationPolicyExistsOnTarget(DbClient dbClient, StorageSystem system, VirtualPool vpool, Project project, FileShare fs) {
    if (fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.TARGET.name())) {
        List<FilePolicy> replicationPolicies = getReplicationPolices(dbClient, vpool, project, fs);
        if (replicationPolicies != null && !replicationPolicies.isEmpty()) {
            if (replicationPolicies.size() > 1) {
                _log.warn("More than one replication policy found {}", replicationPolicies.size());
            } else {
                FilePolicy replPolicy = replicationPolicies.get(0);
                FileShare sourceFS = dbClient.queryObject(FileShare.class, fs.getParentFileShare().getURI());
                StorageSystem sourceStorage = dbClient.queryObject(StorageSystem.class, sourceFS.getStorageDevice());
                NASServer nasServer = null;
                if (sourceFS != null && sourceFS.getVirtualNAS() != null) {
                    nasServer = dbClient.queryObject(VirtualNAS.class, sourceFS.getVirtualNAS());
                } else {
                    // Get the physical NAS for the storage system!!
                    nasServer = FileOrchestrationUtils.getSystemPhysicalNAS(dbClient, sourceStorage);
                }
                if (replPolicy.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.vpool.name())) {
                    return isvPoolPolicyAppliedOnStorageSystem(dbClient, sourceStorage, nasServer, vpool, replPolicy);
                } else if (replPolicy.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.project.name())) {
                    return isProjectPolicyAppliedOnStorageSystem(dbClient, sourceStorage, nasServer, project, replPolicy);
                } else if (replPolicy.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.file_system.name())) {
                    FileShare fsParent = dbClient.queryObject(FileShare.class, fs.getParentFileShare());
                    return isFSPolicyAppliedOnStorageSystem(dbClient, sourceStorage, nasServer, fsParent, replPolicy);
                }
            }
        }
    }
    return false;
}
Also used : NASServer(com.emc.storageos.db.client.model.NASServer) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) FileShare(com.emc.storageos.db.client.model.FileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 50 with FilePolicy

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

the class FileOrchestrationUtils method getAllVpoolLevelPolices.

/**
 * Return list of policies to be applied at vpool
 *
 * @param dbClient
 * @param vpool
 * @param storageSystem
 * @return
 */
public static List<FilePolicy> getAllVpoolLevelPolices(DbClient dbClient, VirtualPool vpool, URI storageSystem, URI nasServer) {
    List<FilePolicy> filePoliciesToCreate = new ArrayList<FilePolicy>();
    StringSet fileVpoolPolicies = vpool.getFilePolicies();
    if (fileVpoolPolicies != null && !fileVpoolPolicies.isEmpty()) {
        for (String fileVpoolPolicy : fileVpoolPolicies) {
            FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, URIUtil.uri(fileVpoolPolicy));
            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.getAppliedAt().toString().equals(vpool.getId().toString()) && strRes.getStorageSystem().toString().equals(storageSystem.toString()) && strRes.getNasServer().toString().equalsIgnoreCase(nasServer.toString())) {
                        _log.info("File Policy {} is already exists for vpool {} , storage system {} and nas server {}", filePolicy.getFilePolicyName(), vpool.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)

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