Search in sources :

Example 6 with FilePolicy

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

the class FileOrchestrationDeviceController method assignFileReplicationPolicyToVirtualPools.

@Override
public void assignFileReplicationPolicyToVirtualPools(List<FileStorageSystemAssociation> associations, List<URI> vpoolURIs, URI filePolicyToAssign, String taskId) {
    FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
    FilePolicyAssignWorkflowCompleter completer = new FilePolicyAssignWorkflowCompleter(filePolicyToAssign, vpoolURIs, null, taskId);
    try {
        String waitFor = null;
        String stepId = null;
        String stepDes = null;
        Workflow workflow = _workflowService.getNewWorkflow(this, ASSIGN_FILE_POLICY_WF_NAME, false, taskId, completer);
        completer.setWorkFlowId(workflow.getWorkflowURI());
        String usePhysicalNASForProvisioning = customConfigHandler.getComputedCustomConfigValue(CustomConfigConstants.USE_PHYSICAL_NAS_FOR_PROVISIONING, "isilon", null);
        Boolean usePhysicalNAS = Boolean.valueOf(usePhysicalNASForProvisioning);
        // Verify the associations have many to one storage system relation.
        // If so, inform the user to configure cluster name in provisioning path!!
        verifyClusterNameInPathForManyToOneRecommendations(associations, filePolicy);
        s_logger.info("Generating steps for assigning file replication policy to vpool: {}.", filePolicyToAssign);
        for (FileStorageSystemAssociation association : associations) {
            StorageSystem sourceStoragesystem = s_dbClient.queryObject(StorageSystem.class, association.getSourceSystem());
            URI vpoolURI = association.getAppliedAtResource();
            List<TargetAssociation> targetAssociations = association.getTargets();
            if (targetAssociations != null && !targetAssociations.isEmpty()) {
                for (Iterator<TargetAssociation> iterator = targetAssociations.iterator(); iterator.hasNext(); ) {
                    TargetAssociation targetAssociation = iterator.next();
                    URI targetVNASURI = targetAssociation.getvNASURI();
                    URI targetStorage = targetAssociation.getStorageSystemURI();
                    URI targetVArray = targetAssociation.getvArrayURI();
                    if (targetVNASURI != null && association.getSourceVNAS() != null) {
                        stepId = workflow.createStepId();
                        stepDes = String.format("Assigning file policy: %s, to vpool: %s on storage system: %s with source vnas %s and target vnas %s", filePolicy.getId(), vpoolURI, association.getSourceSystem(), association.getSourceVNAS(), targetVNASURI);
                        Object[] args = new Object[] { association.getSourceSystem(), targetStorage, association.getSourceVNAS(), targetVArray, targetVNASURI, filePolicyToAssign, vpoolURI };
                        _fileDeviceController.createMethod(workflow, waitFor, ASSIGN_FILE_REPLICATION_POLICY_TO_VIRTUAL_POOLS_METHOD, stepId, stepDes, association.getSourceSystem(), args);
                    } else {
                        if (sourceStoragesystem.getSystemType().equals(Type.isilon.toString())) {
                            if (usePhysicalNAS) {
                                stepId = workflow.createStepId();
                                stepDes = String.format("Assigning file policy: %s, to vpool: %s on storage system: %s", filePolicy.getId(), vpoolURI, association.getSourceSystem());
                                // Let the all workflow steps be executed
                                // workflow completer should handle the unsuccessful steps
                                Object[] args = new Object[] { association.getSourceSystem(), targetStorage, association.getSourceVNAS(), targetVArray, null, filePolicyToAssign, vpoolURI };
                                _fileDeviceController.createMethod(workflow, waitFor, ASSIGN_FILE_REPLICATION_POLICY_TO_VIRTUAL_POOLS_METHOD, stepId, stepDes, association.getSourceSystem(), args);
                            }
                        }
                    }
                }
            }
        }
        String successMessage = String.format("Assigning file policy : %s, to vpool(s) successful.", filePolicy.getId());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        // If no other resources are assigned to replication policy
        // Remove the replication topology from the policy
        FileOrchestrationUtils.removeTopologyInfo(filePolicy, s_dbClient);
        s_logger.error(String.format("Assigning file policy : %s to vpool(s) failed", filePolicy.getId()), ex);
        ServiceError serviceError = DeviceControllerException.errors.assignFilePolicyFailed(filePolicyToAssign.toString(), filePolicy.getApplyAt(), ex);
        completer.error(s_dbClient, _locker, serviceError);
    }
}
Also used : FilePolicyAssignWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FilePolicyAssignWorkflowCompleter) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) TargetAssociation(com.emc.storageos.fileorchestrationcontroller.FileStorageSystemAssociation.TargetAssociation) Workflow(com.emc.storageos.workflow.Workflow) URI(java.net.URI) 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) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 7 with FilePolicy

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

the class FileOrchestrationDeviceController method assignFileReplicationPolicyToProjects.

@Override
public void assignFileReplicationPolicyToProjects(List<FileStorageSystemAssociation> associations, URI vpoolURI, List<URI> projectURIs, URI filePolicyToAssign, String taskId) {
    FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
    FilePolicyAssignWorkflowCompleter completer = new FilePolicyAssignWorkflowCompleter(filePolicyToAssign, projectURIs, vpoolURI, taskId);
    try {
        String waitFor = null;
        String stepId = null;
        String stepDes = null;
        Workflow workflow = _workflowService.getNewWorkflow(this, ASSIGN_FILE_POLICY_WF_NAME, false, taskId, completer);
        completer.setWorkFlowId(workflow.getWorkflowURI());
        String usePhysicalNASForProvisioning = customConfigHandler.getComputedCustomConfigValue(CustomConfigConstants.USE_PHYSICAL_NAS_FOR_PROVISIONING, "isilon", null);
        Boolean usePhysicalNAS = Boolean.valueOf(usePhysicalNASForProvisioning);
        // Verify the associations have many to one storage system relation.
        // If so, inform the user to configure cluster name in provisioning path!!
        verifyClusterNameInPathForManyToOneRecommendations(associations, filePolicy);
        s_logger.info("Generating steps for assigning file policy {} to project.", filePolicyToAssign);
        for (FileStorageSystemAssociation association : associations) {
            StorageSystem sourceStoragesystem = s_dbClient.queryObject(StorageSystem.class, association.getSourceSystem());
            URI projectURI = association.getAppliedAtResource();
            URI vPoolURI = association.getProjectvPool();
            List<TargetAssociation> targetAssociations = association.getTargets();
            if (targetAssociations != null && !targetAssociations.isEmpty()) {
                for (Iterator<TargetAssociation> iterator = targetAssociations.iterator(); iterator.hasNext(); ) {
                    TargetAssociation targetAssociation = iterator.next();
                    URI targetVNASURI = targetAssociation.getvNASURI();
                    URI targetStorage = targetAssociation.getStorageSystemURI();
                    URI targetVArray = targetAssociation.getvArrayURI();
                    if (targetVNASURI != null && association.getSourceVNAS() != null) {
                        stepId = workflow.createStepId();
                        stepDes = String.format("Assigning file policy: %s, to project: %s on storage system: %s", filePolicy.getId(), projectURI, association.getSourceSystem());
                        // Let the all workflow steps be executed
                        // workflow completer should handle the unsuccessful steps
                        Object[] args = new Object[] { association.getSourceSystem(), targetStorage, association.getSourceVNAS(), targetVArray, targetVNASURI, filePolicyToAssign, vPoolURI, projectURI };
                        _fileDeviceController.createMethod(workflow, waitFor, ASSIGN_FILE_REPLICATION_POLICY_TO_PROJECTS_METHOD, stepId, stepDes, association.getSourceSystem(), args);
                    } else {
                        if (sourceStoragesystem.getSystemType().equals(Type.isilon.toString())) {
                            if (usePhysicalNAS) {
                                stepId = workflow.createStepId();
                                stepDes = String.format("Assigning file policy: %s, to project: %s on storage system: %s", filePolicy.getId(), projectURI, association.getSourceSystem());
                                // Let the all workflow steps be executed
                                // workflow completer should handle the unsuccessful steps
                                Object[] args = new Object[] { association.getSourceSystem(), targetStorage, association.getSourceVNAS(), targetVArray, null, filePolicyToAssign, vPoolURI, projectURI };
                                _fileDeviceController.createMethod(workflow, waitFor, ASSIGN_FILE_REPLICATION_POLICY_TO_PROJECTS_METHOD, stepId, stepDes, association.getSourceSystem(), args);
                            }
                        }
                    }
                }
            }
        }
        String successMessage = String.format("Assigning file policy : %s, to project(s) successful.", filePolicy.getId());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        // If no other resources are assigned to replication policy
        // Remove the replication topology from the policy
        FileOrchestrationUtils.removeTopologyInfo(filePolicy, s_dbClient);
        s_logger.error(String.format("Assigning file policy : %s to project(s) failed", filePolicy.getId()), ex);
        ServiceError serviceError = DeviceControllerException.errors.assignFilePolicyFailed(filePolicyToAssign.toString(), filePolicy.getApplyAt(), ex);
        completer.error(s_dbClient, _locker, serviceError);
    }
}
Also used : FilePolicyAssignWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FilePolicyAssignWorkflowCompleter) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) TargetAssociation(com.emc.storageos.fileorchestrationcontroller.FileStorageSystemAssociation.TargetAssociation) Workflow(com.emc.storageos.workflow.Workflow) URI(java.net.URI) 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) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 8 with FilePolicy

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

the class FileOrchestrationDeviceController method getProjectLevelPolices.

/**
 * Get the valid policy templates which are applied at project level
 *
 * @param vpool
 * @param project
 * @return list of project level policies on the given vpool
 */
private static List<FilePolicy> getProjectLevelPolices(VirtualPool vpool, Project project) {
    StringSet projectPolicies = project.getFilePolicies();
    List<FilePolicy> filePoliciesToCreate = new ArrayList<FilePolicy>();
    if (!CollectionUtils.isEmpty(projectPolicies)) {
        for (String projectFilePolicy : projectPolicies) {
            FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, URIUtil.uri(projectFilePolicy));
            if (filePolicy != null && !filePolicy.getInactive()) {
                // The policy should be of for the given vpool as well.
                if (NullColumnValueGetter.isNullURI(filePolicy.getFilePolicyVpool()) || !filePolicy.getFilePolicyVpool().toString().equals(vpool.getId().toString())) {
                    continue;
                }
                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 9 with FilePolicy

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

the class FileOrchestrationDeviceController method addStepsForApplyingPolicies.

public String addStepsForApplyingPolicies(Workflow workflow, String waitFor, List<FileDescriptor> fileDescriptors) {
    FileDescriptor sourceDescriptors = FileDescriptor.filterByType(fileDescriptors, FileDescriptor.Type.FILE_DATA, FileDescriptor.Type.FILE_MIRROR_SOURCE).get(0);
    FileShare sourceFS = s_dbClient.queryObject(FileShare.class, sourceDescriptors.getFsURI());
    StorageSystem system = s_dbClient.queryObject(StorageSystem.class, sourceFS.getStorageDevice());
    // applying policy is only supported by isilon
    if (system != null && system.getSystemType().equalsIgnoreCase(Type.isilon.toString())) {
        URI nasServer = null;
        if (sourceFS.getVirtualNAS() != null) {
            nasServer = sourceFS.getVirtualNAS();
        } else {
            // Get the physical NAS for the storage system!!
            PhysicalNAS pNAS = FileOrchestrationUtils.getSystemPhysicalNAS(s_dbClient, system);
            if (pNAS != null) {
                nasServer = pNAS.getId();
            }
        }
        if (nasServer == null) {
            s_logger.error(String.format("Adding steps to apply policies failed : No Nas server found on system {}", system.getLabel()));
            throw DeviceControllerException.exceptions.noNasServerFoundToAddStepsToApplyPolicy(system.getLabel());
        }
        // Add all the vpool and project level policies to the workflow steps.
        // Verify the policy is already applied or not at device control level.
        // Create storage device policy only if the policy was not applied for policy path on storage system!!
        // Fail to create policy and/or file system, if any policy to be applied at path is invalid!!
        VirtualPool vpool = s_dbClient.queryObject(VirtualPool.class, sourceFS.getVirtualPool());
        List<FilePolicy> fileVpoolPolicies = getVpoolLevelPolices(vpool);
        if (fileVpoolPolicies != null && !fileVpoolPolicies.isEmpty()) {
            for (FilePolicy fileVpoolPolicy : fileVpoolPolicies) {
                String stepDescription = String.format("creating file policy : %s  at : %s level", fileVpoolPolicy.getId(), vpool.getLabel());
                String applyFilePolicyStep = workflow.createStepId();
                Object[] args = new Object[] { sourceFS.getStorageDevice(), sourceFS.getId(), fileVpoolPolicy.getId() };
                waitFor = _fileDeviceController.createMethod(workflow, waitFor, APPLY_FILE_POLICY_METHOD, applyFilePolicyStep, stepDescription, system.getId(), args);
            }
        }
        Project project = s_dbClient.queryObject(Project.class, sourceFS.getProject());
        List<FilePolicy> fileProjectPolicies = getProjectLevelPolices(vpool, project);
        if (fileProjectPolicies != null && !fileProjectPolicies.isEmpty()) {
            for (FilePolicy fileProjectPolicy : fileProjectPolicies) {
                String stepDescription = String.format("creating file policy : %s  at : %s level", fileProjectPolicy.getId(), project.getLabel());
                String applyFilePolicyStep = workflow.createStepId();
                Object[] args = new Object[] { sourceFS.getStorageDevice(), sourceFS.getId(), fileProjectPolicy.getId() };
                waitFor = _fileDeviceController.createMethod(workflow, waitFor, APPLY_FILE_POLICY_METHOD, applyFilePolicyStep, stepDescription, system.getId(), args);
            }
        }
    }
    return waitFor;
}
Also used : Project(com.emc.storageos.db.client.model.Project) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileObject(com.emc.storageos.db.client.model.FileObject) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) PhysicalNAS(com.emc.storageos.db.client.model.PhysicalNAS) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 10 with FilePolicy

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

the class FileOrchestrationUtils method getReplicationPolices.

/**
 * Gives list of replication policies assigned at vpool/project/fs levels
 *
 * @param dbClient
 * @param vpool
 * @param project
 * @param fs
 * @return
 */
public static List<FilePolicy> getReplicationPolices(DbClient dbClient, VirtualPool vpool, Project project, FileShare fs) {
    List<FilePolicy> replicationPolicies = new ArrayList<FilePolicy>();
    StringSet filePolicies = new StringSet();
    // vPool policies
    if (vpool.getFilePolicies() != null && !vpool.getFilePolicies().isEmpty()) {
        filePolicies.addAll(vpool.getFilePolicies());
    }
    // Project policies
    if (project.getFilePolicies() != null && !project.getFilePolicies().isEmpty()) {
        for (String strPolicy : project.getFilePolicies()) {
            FilePolicy policy = dbClient.queryObject(FilePolicy.class, URI.create(strPolicy));
            if (!NullColumnValueGetter.isNullURI(policy.getFilePolicyVpool()) && policy.getFilePolicyVpool().toString().equalsIgnoreCase(vpool.getId().toString())) {
                filePolicies.add(policy.getId().toString());
            }
        }
    }
    // fs policies
    if (fs != null && fs.getFilePolicies() != null && !fs.getFilePolicies().isEmpty()) {
        for (String strPolicy : fs.getFilePolicies()) {
            FilePolicy policy = dbClient.queryObject(FilePolicy.class, URI.create(strPolicy));
            if (!NullColumnValueGetter.isNullURI(policy.getFilePolicyVpool()) && policy.getFilePolicyVpool().toString().equalsIgnoreCase(vpool.getId().toString())) {
                filePolicies.add(policy.getId().toString());
            }
        }
    }
    if (filePolicies != null && !filePolicies.isEmpty()) {
        for (String strPolicy : filePolicies) {
            FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, URIUtil.uri(strPolicy));
            if (FilePolicyType.file_replication.name().equalsIgnoreCase(filePolicy.getFilePolicyType())) {
                replicationPolicies.add(filePolicy);
            }
        }
    } else {
        if (fs != null) {
            _log.info("No replication policy assigned to vpool {} , project {} and fs {}", vpool.getLabel(), project.getLabel(), fs.getLabel());
        } else {
            _log.info("No replication policy assigned to vpool {} and project {} ", vpool.getLabel(), project.getLabel());
        }
    }
    return replicationPolicies;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet)

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