Search in sources :

Example 41 with FilePolicy

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

the class IsilonFileStorageDevice method listSanpshotByPolicy.

@Override
public BiosCommandResult listSanpshotByPolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
    FilePolicy sp = args.getFileProtectionPolicy();
    FileShare fs = args.getFs();
    String snapshotScheduleName = sp.getFilePolicyName() + "_" + args.getFsName();
    if (sp.getPolicyStorageResources() != null && !sp.getPolicyStorageResources().isEmpty()) {
        for (String uriResource : sp.getPolicyStorageResources()) {
            PolicyStorageResource policyRes = _dbClient.queryObject(PolicyStorageResource.class, URI.create(uriResource));
            if (policyRes != null && policyRes.getStorageSystem().equals(storageObj.getId())) {
                snapshotScheduleName = policyRes.getPolicyNativeId();
                break;
            }
        }
    }
    IsilonApi isi = getIsilonDevice(storageObj);
    String resumeToken = null;
    try {
        do {
            IsilonList<IsilonSnapshot> snapshots = isi.listSnapshotsCreatedByPolicy(resumeToken, snapshotScheduleName);
            if (snapshots != null) {
                for (IsilonSnapshot islon_snap : snapshots.getList()) {
                    _log.info("file policy snapshot is  : " + islon_snap.getName());
                    Snapshot snap = new Snapshot();
                    snap.setLabel(islon_snap.getName());
                    snap.setMountPath(islon_snap.getPath());
                    snap.setName(islon_snap.getName());
                    snap.setId(URIUtil.createId(Snapshot.class));
                    snap.setOpStatus(new OpStatusMap());
                    snap.setProject(new NamedURI(fs.getProject().getURI(), islon_snap.getName()));
                    snap.setMountPath(getSnapshotPath(islon_snap.getPath(), islon_snap.getName()));
                    snap.setParent(new NamedURI(fs.getId(), islon_snap.getName()));
                    StringMap map = new StringMap();
                    Long createdTime = Long.parseLong(islon_snap.getCreated()) * SEC_IN_MILLI;
                    String expiresTime = "Never";
                    if (islon_snap.getExpires() != null && !islon_snap.getExpires().isEmpty()) {
                        Long expTime = Long.parseLong(islon_snap.getExpires()) * SEC_IN_MILLI;
                        expiresTime = expTime.toString();
                    }
                    map.put("created", createdTime.toString());
                    map.put("expires", expiresTime);
                    map.put("schedule", sp.getFilePolicyName());
                    snap.setExtensions(map);
                    _dbClient.updateObject(snap);
                }
                resumeToken = snapshots.getToken();
            }
        } while (resumeToken != null && !resumeToken.equalsIgnoreCase("null"));
    } catch (IsilonException e) {
        _log.error("listing snapshot by file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
    Task task = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), args.getOpId());
    // set task to completed and progress to 100 and store in DB, so waiting thread in apisvc can read it.
    task.ready();
    task.setProgress(100);
    _dbClient.updateObject(task);
    return BiosCommandResult.createSuccessfulResult();
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) NamedURI(com.emc.storageos.db.client.model.NamedURI) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 42 with FilePolicy

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

the class IsilonFileStorageDevice method getEquivalentPolicyStorageResource.

public static PolicyStorageResource getEquivalentPolicyStorageResource(FileShare fs, DbClient dbClient) {
    FilePolicy fp = getReplicationPolicyAppliedOnFS(fs, dbClient);
    if (fp != null) {
        StringSet policyStrResources = fp.getPolicyStorageResources();
        List<URI> policyStrURIs = new ArrayList<>();
        for (String policyStrResource : policyStrResources) {
            policyStrURIs.add(URI.create(policyStrResource));
        }
        Iterator<PolicyStorageResource> iterator = dbClient.queryIterativeObjects(PolicyStorageResource.class, policyStrURIs, true);
        while (iterator.hasNext()) {
            PolicyStorageResource policyRes = iterator.next();
            if (policyRes.getAppliedAt().equals(fs.getId()) && policyRes.getStorageSystem().equals(fs.getStorageDevice())) {
                _log.info("Found replication policy:{} corresponding storage resource: {}  applied to the file system: {}.", fp.getLabel(), policyRes.toString(), fs.getId());
                return policyRes;
            }
        }
    }
    return null;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource)

Example 43 with FilePolicy

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

the class IsilonFileStorageDevice method updateLocalTargetFileSystemPath.

/**
 * @param dbClient
 * @param project
 * @param storageSystem
 * @return
 */
public void updateLocalTargetFileSystemPath(StorageSystem system, FileDeviceInputOutput args) {
    VirtualPool vpool = args.getVPool();
    Project project = args.getProject();
    FileShare fs = args.getFs();
    if (fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.TARGET.name())) {
        List<FilePolicy> replicationPolicies = FileOrchestrationUtils.getReplicationPolices(_dbClient, vpool, project, null);
        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);
                if (replPolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.LOCAL.name())) {
                    // For local replication, the path should be different
                    // add localTaget to file path at directory level where the policy is applied!!!
                    String mountPath = generatePathForLocalTarget(replPolicy, fs, args);
                    // replace extra forward slash with single one
                    mountPath = mountPath.replaceAll("/+", "/");
                    _log.info("Mount path to mount the Isilon File System {}", mountPath);
                    args.setFsMountPath(mountPath);
                    args.setFsNativeGuid(args.getFsMountPath());
                    args.setFsNativeId(args.getFsMountPath());
                    args.setFsPath(args.getFsMountPath());
                }
            }
        } else if (fs.getLabel().contains("-localTarget")) {
            String mountPath = fs.getNativeId() + "_localTarget";
            // replace extra forward slash with single one
            mountPath = mountPath.replaceAll("/+", "/");
            _log.info("Mount path to mount the Isilon File System {}", mountPath);
            args.setFsMountPath(mountPath);
            args.setFsNativeGuid(args.getFsMountPath());
            args.setFsNativeId(args.getFsMountPath());
            args.setFsPath(args.getFsMountPath());
        }
    }
    return;
}
Also used : Project(com.emc.storageos.db.client.model.Project) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 44 with FilePolicy

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

the class FileOrchestrationDeviceController method assignFileSnapshotPolicyToProjects.

@Override
public void assignFileSnapshotPolicyToProjects(Map<URI, List<URI>> vpoolToStorageSystemMap, List<URI> projectURIs, URI filePolicyToAssign, String taskId) {
    FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
    String opName = ResourceOperationTypeEnum.ASSIGN_FILE_POLICY.getName();
    URI projectVpool = null;
    if (vpoolToStorageSystemMap != null && !vpoolToStorageSystemMap.isEmpty()) {
        Set<URI> vpoolUris = vpoolToStorageSystemMap.keySet();
        // For project assignment, there would be a single vpool!!
        projectVpool = vpoolUris.toArray(new URI[vpoolUris.size()])[0];
    }
    FilePolicyAssignWorkflowCompleter completer = new FilePolicyAssignWorkflowCompleter(filePolicyToAssign, projectURIs, projectVpool, taskId);
    try {
        String waitFor = 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);
        for (URI vpoolURI : vpoolToStorageSystemMap.keySet()) {
            s_logger.info("Generating steps for assigning file policy {} to project: {}.", filePolicyToAssign, vpoolURI);
            List<URI> storageSystemURIList = vpoolToStorageSystemMap.get(vpoolURI);
            if (storageSystemURIList != null && !storageSystemURIList.isEmpty()) {
                for (URI storageSystemURI : storageSystemURIList) {
                    if (projectURIs != null && !projectURIs.isEmpty()) {
                        for (URI projectURI : projectURIs) {
                            // Get the eligible nas server for given project from the storage system!!!
                            List<URI> vNASURIList = FileOrchestrationUtils.getVNASServersOfStorageSystemAndVarrayOfVpool(s_dbClient, storageSystemURI, vpoolURI, projectURI);
                            if (vNASURIList != null && !vNASURIList.isEmpty()) {
                                for (URI vNASURI : vNASURIList) {
                                    String stepId = workflow.createStepId();
                                    String stepDes = String.format("Assigning file policy: %s, to project: %s on storage system: %s", filePolicy.getId(), vpoolURI, storageSystemURI);
                                    Object[] args = new Object[] { storageSystemURI, vNASURI, filePolicyToAssign, vpoolURI, projectURI };
                                    // Let the all workflow steps be executed
                                    // workflow completer should handle the unsuccessful steps
                                    _fileDeviceController.createMethod(workflow, waitFor, ASSIGN_FILE_SNAPSHOT_POLICY_TO_PROJECTS_METHOD, stepId, stepDes, storageSystemURI, args);
                                }
                            }
                            StorageSystem storagesystem = s_dbClient.queryObject(StorageSystem.class, storageSystemURI);
                            // Create policy, if physical nas is eligible for provisioning!!
                            if (storagesystem.getSystemType().equals(Type.isilon.toString())) {
                                if (usePhysicalNAS) {
                                    s_logger.info("Generating step for assigning file policy {} to project on physical NAS server: {}.", filePolicyToAssign, vpoolURI);
                                    String stepId = workflow.createStepId();
                                    String stepDes = String.format("Assigning file policy: %s, to project: %s on storage system: %s", filePolicy.getId(), projectURI, storageSystemURI);
                                    Object[] args = new Object[] { storageSystemURI, null, filePolicyToAssign, vpoolURI, projectURI };
                                    // Let the all workflow steps be executed
                                    // workflow completer should handle the unsuccessful steps
                                    _fileDeviceController.createMethod(workflow, waitFor, ASSIGN_FILE_SNAPSHOT_POLICY_TO_PROJECTS_METHOD, stepId, stepDes, storageSystemURI, args);
                                }
                            }
                        }
                    }
                }
            } else {
                s_logger.info("No storage system(s) present for vpool: {}", vpoolURI);
            }
        }
        String successMessage = String.format("Assigning file policy : %s, to project(s) successful.", filePolicy.getId(), vpoolToStorageSystemMap);
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error(String.format("Assigning file policy : %s to vpool(s) failed", filePolicy.getId()), ex);
        ServiceError serviceError = DeviceControllerException.errors.assignFilePolicyFailed(filePolicyToAssign.toString(), FilePolicyApplyLevel.project.name(), 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) 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 45 with FilePolicy

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

the class FileOrchestrationDeviceController method assignFileSnapshotPolicyToVirtualPools.

@Override
public void assignFileSnapshotPolicyToVirtualPools(Map<URI, List<URI>> vpoolToStorageSystemMap, URI filePolicyToAssign, String taskId) throws InternalException {
    FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
    FilePolicyAssignWorkflowCompleter completer = new FilePolicyAssignWorkflowCompleter(filePolicyToAssign, vpoolToStorageSystemMap.keySet(), null, taskId);
    try {
        String waitFor = 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);
        for (URI vpoolURI : vpoolToStorageSystemMap.keySet()) {
            s_logger.info("Generating steps for assigning file policy {} to vpool: {}.", filePolicyToAssign, vpoolURI);
            List<URI> storageSystemURIList = vpoolToStorageSystemMap.get(vpoolURI);
            if (storageSystemURIList != null && !storageSystemURIList.isEmpty()) {
                for (URI storageSystemURI : storageSystemURIList) {
                    List<URI> vNASURIList = FileOrchestrationUtils.getVNASServersOfStorageSystemAndVarrayOfVpool(s_dbClient, storageSystemURI, vpoolURI, null);
                    if (vNASURIList != null && !vNASURIList.isEmpty()) {
                        for (URI vNASURI : vNASURIList) {
                            String stepId = workflow.createStepId();
                            String stepDes = String.format("Assigning file policy: %s, to vpool: %s on storage system: %s", filePolicy.getId(), vpoolURI, storageSystemURI);
                            Object[] args = new Object[] { storageSystemURI, vNASURI, filePolicyToAssign, vpoolURI };
                            // Let the all workflow steps be executed
                            // workflow completer should handle the unsuccessful steps
                            _fileDeviceController.createMethod(workflow, waitFor, ASSIGN_FILE_SNAPSHOT_POLICY_TO_VIRTUAL_POOLS_METHOD, stepId, stepDes, storageSystemURI, args);
                        }
                    }
                    StorageSystem storagesystem = s_dbClient.queryObject(StorageSystem.class, storageSystemURI);
                    if (storagesystem.getSystemType().equals(Type.isilon.toString())) {
                        if (usePhysicalNAS) {
                            s_logger.info("Generating step for assigning file policy {} to vpool on physical NAS server: {}.", filePolicyToAssign, vpoolURI);
                            String stepId = workflow.createStepId();
                            String stepDes = String.format("Assigning file policy: %s, to vpool: %s on storage system: %s", filePolicy.getId(), vpoolURI, storageSystemURI);
                            Object[] args = new Object[] { storageSystemURI, null, filePolicyToAssign, vpoolURI };
                            // Let the all workflow steps be executed
                            // workflow completer should handle the unsuccessful steps
                            _fileDeviceController.createMethod(workflow, waitFor, ASSIGN_FILE_SNAPSHOT_POLICY_TO_VIRTUAL_POOLS_METHOD, stepId, stepDes, storageSystemURI, args);
                        }
                    }
                }
            } else {
                s_logger.info("No storage system(s) present for vpool: {}", vpoolURI);
            }
        }
        String successMessage = String.format("Assigning file policy : %s, to vpool(s) successful.", filePolicy.getId(), vpoolToStorageSystemMap);
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error(String.format("Assigning file policy : %s to vpool(s) failed", filePolicy.getId()), ex);
        ServiceError serviceError = DeviceControllerException.errors.assignFilePolicyFailed(filePolicyToAssign.toString(), FilePolicyApplyLevel.vpool.name(), 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) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

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