Search in sources :

Example 36 with FilePolicy

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

the class FileSystemAssignPolicyWorkflowCompleter method updateFilePolicyResource.

private void updateFilePolicyResource(DbClient dbClient) {
    FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, filePolicyURI);
    if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
        filePolicy.addAssignedResources(getIds().get(0));
        FileShare fileSystem = dbClient.queryObject(FileShare.class, getIds().get(0));
        fileSystem.addFilePolicy(filePolicyURI);
        dbClient.updateObject(filePolicy);
        dbClient.updateObject(fileSystem);
    } else {
        FileShare fileSystem = getSourceFileSystem(dbClient);
        if (fileSystem != null) {
            filePolicy.addAssignedResources(fileSystem.getId());
            fileSystem.addFilePolicy(filePolicyURI);
            dbClient.updateObject(filePolicy);
            dbClient.updateObject(fileSystem);
        }
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileShare(com.emc.storageos.db.client.model.FileShare)

Example 37 with FilePolicy

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

the class FileSnapshotPolicyMigration method process.

@Override
public void process() throws MigrationCallbackException {
    logger.info("File snapshot schedule policy to file policy migration START");
    DbClient dbClient = getDbClient();
    try {
        List<URI> schedulePolicyURIs = dbClient.queryByType(SchedulePolicy.class, true);
        Iterator<SchedulePolicy> schedulePolicies = dbClient.queryIterativeObjects(SchedulePolicy.class, schedulePolicyURIs, true);
        List<FilePolicy> filePolicies = new ArrayList<FilePolicy>();
        List<VirtualPool> modifiedVpools = new ArrayList<VirtualPool>();
        while (schedulePolicies.hasNext()) {
            SchedulePolicy schedulePolicy = schedulePolicies.next();
            FilePolicy fileSnapshotPolicy = new FilePolicy();
            VirtualPool associatedVP = new VirtualPool();
            fileSnapshotPolicy.setId(URIUtil.createId(FilePolicy.class));
            if (schedulePolicy.getAssignedResources() != null && !schedulePolicy.getAssignedResources().isEmpty()) {
                for (String assignedResource : schedulePolicy.getAssignedResources()) {
                    logger.info("assigning resource to fileSnapshotPolicy from schedulePolicy : {}", schedulePolicy.getAssignedResources());
                    fileSnapshotPolicy.addAssignedResources(resourceURI(assignedResource));
                    logger.info("Assigned resources from fileSnapshotPolicy : {}", fileSnapshotPolicy.getAssignedResources());
                }
            }
            fileSnapshotPolicy.setFilePolicyDescription("Policy created from Schedule Policy " + schedulePolicy.getLabel() + " while system upgrade");
            String polName = schedulePolicy.getLabel() + "_File_Snapshot_Policy";
            fileSnapshotPolicy.setLabel(polName);
            fileSnapshotPolicy.setFilePolicyName(schedulePolicy.getLabel());
            fileSnapshotPolicy.setFilePolicyType(FilePolicyType.file_snapshot.name());
            fileSnapshotPolicy.setScheduleFrequency(schedulePolicy.getScheduleFrequency());
            fileSnapshotPolicy.setScheduleRepeat(schedulePolicy.getScheduleRepeat());
            fileSnapshotPolicy.setScheduleTime(schedulePolicy.getScheduleTime());
            fileSnapshotPolicy.setScheduleDayOfWeek(schedulePolicy.getScheduleDayOfWeek());
            fileSnapshotPolicy.setScheduleDayOfMonth(schedulePolicy.getScheduleDayOfMonth());
            fileSnapshotPolicy.setSnapshotExpireTime(schedulePolicy.getSnapshotExpireTime());
            fileSnapshotPolicy.setSnapshotExpireType(schedulePolicy.getSnapshotExpireType());
            // snapshot policy apply at file system level
            fileSnapshotPolicy.setApplyAt(FilePolicyApplyLevel.file_system.name());
            if (schedulePolicy.getAssignedResources() != null && !schedulePolicy.getAssignedResources().isEmpty()) {
                List<URI> fileShareURIs = getAssignedResourcesURIs(schedulePolicy.getAssignedResources());
                for (URI fsURI : fileShareURIs) {
                    FileShare fs = dbClient.queryObject(FileShare.class, fsURI);
                    if (!fs.getInactive()) {
                        StorageSystem system = dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
                        updatePolicyStorageResouce(system, fileSnapshotPolicy, fs);
                        // Remove the existing schedule policy from fs
                        // add new file policy to fs!!
                        StringSet fsExistingPolicies = fs.getFilePolicies();
                        if (fsExistingPolicies != null && !fsExistingPolicies.isEmpty()) {
                            Set<String> snapSchedulesToRemove = new HashSet<String>();
                            for (String existingSnapPolicyId : fsExistingPolicies) {
                                if (URIUtil.isType(URI.create(existingSnapPolicyId), SchedulePolicy.class)) {
                                    snapSchedulesToRemove.add(existingSnapPolicyId);
                                }
                            }
                            if (!snapSchedulesToRemove.isEmpty()) {
                                /*
                                     * StringSet.removeAll() does not work if the set has only one entry.
                                     * Hence the logic below
                                     */
                                if (fsExistingPolicies.size() == 1 && snapSchedulesToRemove.size() == 1) {
                                    fsExistingPolicies.clear();
                                } else {
                                    fsExistingPolicies.removeAll(snapSchedulesToRemove);
                                }
                            }
                        } else {
                            fsExistingPolicies = new StringSet();
                        }
                        fsExistingPolicies.add(fileSnapshotPolicy.getId().toString());
                        fs.setFilePolicies(fsExistingPolicies);
                        dbClient.updateObject(fs);
                        URI associatedVPId = fs.getVirtualPool();
                        associatedVP = dbClient.queryObject(VirtualPool.class, associatedVPId);
                        associatedVP.setAllowFilePolicyAtFSLevel(true);
                        modifiedVpools.add(associatedVP);
                    }
                }
            }
            filePolicies.add(fileSnapshotPolicy);
        }
        // Update DB
        if (!filePolicies.isEmpty()) {
            logger.info("Created {} file snapshot policies", filePolicies.size());
            dbClient.createObject(filePolicies);
        }
        if (!modifiedVpools.isEmpty()) {
            logger.info("Modified {} vpools ", modifiedVpools.size());
            dbClient.updateObject(modifiedVpools);
        }
    } catch (Exception ex) {
        logger.error("Exception occured while migrating file replication policy for Virtual pools");
        logger.error(ex.getMessage(), ex);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) StringSet(com.emc.storageos.db.client.model.StringSet) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

Example 38 with FilePolicy

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

the class VirtualPoolFileReplicationPolicyMigration method process.

@Override
public void process() throws MigrationCallbackException {
    logger.info("File Virtual pool to file replication policy migration START");
    DbClient dbClient = getDbClient();
    try {
        List<URI> virtualPoolURIs = dbClient.queryByType(VirtualPool.class, true);
        Iterator<VirtualPool> virtualPools = dbClient.queryIterativeObjects(VirtualPool.class, virtualPoolURIs, true);
        List<VirtualPool> modifiedVpools = new ArrayList<VirtualPool>();
        List<FilePolicy> replPolicies = new ArrayList<FilePolicy>();
        // Establish relation from policy to FilePolicyResource
        while (virtualPools.hasNext()) {
            VirtualPool virtualPool = virtualPools.next();
            if (VirtualPool.Type.file.name().equals(virtualPool.getType()) && virtualPool.getFileReplicationType() != null && !FileReplicationType.NONE.name().equalsIgnoreCase(virtualPool.getFileReplicationType())) {
                logger.info("vpool {} has enabled with replication, Creating appropriate file policy.....", virtualPool.getLabel());
                // Create replication policy
                FilePolicy replPolicy = new FilePolicy();
                replPolicy.setId(URIUtil.createId(FilePolicy.class));
                replPolicy.setFilePolicyDescription("Policy created from virtual pool " + virtualPool.getLabel() + " while system upgrade");
                String polName = virtualPool.getLabel() + "_Replication_Policy";
                replPolicy.setLabel(polName);
                replPolicy.setFilePolicyName(polName);
                replPolicy.setLabel(polName);
                replPolicy.setFilePolicyType(FilePolicyType.file_replication.name());
                replPolicy.setFilePolicyVpool(virtualPool.getId());
                // Replication policy was created always at file system level!!
                replPolicy.setApplyAt(FilePolicyApplyLevel.file_system.name());
                if (virtualPool.getFileReplicationCopyMode().equals(VirtualPool.RPCopyMode.ASYNCHRONOUS.name())) {
                    replPolicy.setFileReplicationCopyMode(FilePolicy.FileReplicationCopyMode.ASYNC.name());
                } else {
                    replPolicy.setFileReplicationCopyMode(FilePolicy.FileReplicationCopyMode.SYNC.name());
                }
                replPolicy.setFileReplicationType(virtualPool.getFileReplicationType());
                replPolicy.setPriority(FilePolicyPriority.Normal.toString());
                // Set the policy schedule based on vPool RPO
                if (virtualPool.getFrRpoValue() != null && virtualPool.getFrRpoType() != null) {
                    replPolicy.setScheduleRepeat((long) virtualPool.getFrRpoValue());
                    replPolicy.setScheduleTime("00:00AM");
                    replPolicy.setScheduleFrequency(virtualPool.getFrRpoType().toLowerCase());
                    // Virtual pool was supporting only Minutes/Hours/Days for RPO type
                    // Day of the week and month is not applicable!!
                    replPolicy.setScheduleDayOfWeek(NullColumnValueGetter.getNullStr());
                    replPolicy.setScheduleDayOfMonth(0L);
                }
                // set topology reference to policy
                if (FileReplicationType.REMOTE.name().equalsIgnoreCase(virtualPool.getFileReplicationType())) {
                    logger.info("Creating replication topology for remote replication vpool {} .....", virtualPool.getLabel());
                    StringSet replicationTopologies = new StringSet();
                    StringSet targetVarrays = new StringSet();
                    String targetVarray = null;
                    String targetVPool = null;
                    Map<URI, VpoolRemoteCopyProtectionSettings> remoteSettings = virtualPool.getFileRemoteProtectionSettings(virtualPool, dbClient);
                    if (remoteSettings != null && !remoteSettings.isEmpty()) {
                        for (Map.Entry<URI, VpoolRemoteCopyProtectionSettings> entry : remoteSettings.entrySet()) {
                            if (entry != null) {
                                targetVarray = entry.getKey().toString();
                                if (entry.getValue() != null && entry.getValue().getVirtualPool() != null) {
                                    targetVPool = entry.getValue().getVirtualPool().toString();
                                }
                                break;
                            }
                        }
                        if (targetVarray != null) {
                            targetVarrays.add(targetVarray);
                        }
                    }
                    if (virtualPool.getVirtualArrays() != null && !virtualPool.getVirtualArrays().isEmpty()) {
                        for (String srcvArray : virtualPool.getVirtualArrays()) {
                            FileReplicationTopology dbReplTopology = new FileReplicationTopology();
                            dbReplTopology.setId(URIUtil.createId(FileReplicationTopology.class));
                            dbReplTopology.setPolicy(replPolicy.getId());
                            dbReplTopology.setSourceVArray(URI.create(srcvArray));
                            dbReplTopology.setTargetVArrays(targetVarrays);
                            if (targetVarray != null && targetVPool != null) {
                                dbReplTopology.setTargetVAVPool(targetVarray + SEPARATOR + targetVPool);
                            }
                            dbClient.createObject(dbReplTopology);
                            replicationTopologies.add(dbReplTopology.getId().toString());
                        }
                        replPolicy.setReplicationTopologies(replicationTopologies);
                        logger.info("Created {} replication topologies from vpool {}", replicationTopologies.size(), virtualPool.getLabel().toString());
                    }
                }
                // Fetch if there are any file system were provisioned with the vpool
                // if present, link them to replication policy!!
                URIQueryResultList resultList = new URIQueryResultList();
                dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolFileshareConstraint(virtualPool.getId()), resultList);
                for (Iterator<URI> fileShareItr = resultList.iterator(); fileShareItr.hasNext(); ) {
                    FileShare fs = dbClient.queryObject(FileShare.class, fileShareItr.next());
                    if (!fs.getInactive() && fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.SOURCE.name())) {
                        StorageSystem system = dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
                        updatePolicyStorageResouce(system, replPolicy, fs);
                        fs.addFilePolicy(replPolicy.getId());
                        dbClient.updateObject(fs);
                    }
                }
                replPolicies.add(replPolicy);
                virtualPool.setAllowFilePolicyAtFSLevel(true);
                virtualPool.setFileReplicationSupported(true);
                modifiedVpools.add(virtualPool);
            }
        }
        // Udate DB
        if (!replPolicies.isEmpty()) {
            logger.info("Created {} replication policies ", replPolicies.size());
            dbClient.createObject(replPolicies);
        }
        if (!modifiedVpools.isEmpty()) {
            logger.info("Modified {} vpools ", modifiedVpools.size());
            dbClient.updateObject(modifiedVpools);
        }
    } catch (Exception ex) {
        logger.error("Exception occured while migrating file replication policy for Virtual pools");
        logger.error(ex.getMessage(), ex);
    }
    logger.info("Virtual pool file replication policy migration END");
}
Also used : VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) DbClient(com.emc.storageos.db.client.DbClient) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) StringSet(com.emc.storageos.db.client.model.StringSet) Map(java.util.Map) FileReplicaPolicyTargetMap(com.emc.storageos.db.client.model.FileReplicaPolicyTargetMap) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 39 with FilePolicy

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

the class IsilonFileStorageDevice method checkPolicyAppliedOnPath.

/**
 * This method checks these entries for existing policy
 * return true, if the policy is already applied on the path, otherwise false.
 *
 * Policy storage resource is storing all storage system paths
 * on which the policy template is applied.
 *
 * @param storageObj - The storage system on which the policy is to be checked
 * @param args
 * @param policyPath
 * @return
 */
private boolean checkPolicyAppliedOnPath(StorageSystem storageObj, FileDeviceInputOutput args, String policyPath) {
    // 
    FilePolicy filePolicy = args.getFileProtectionPolicy();
    if (filePolicy != null && !filePolicy.getInactive()) {
        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.getStorageSystem().toString().equals(storageObj.getId().toString()) && strRes.getResourcePath().equalsIgnoreCase(policyPath)) {
                    return true;
                }
            }
        }
    }
    String msg = String.format("File Policy template %s was not applied on storage system %s path %s", filePolicy.getFilePolicyName(), storageObj.getLabel(), policyPath);
    _log.info(msg);
    return false;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource)

Example 40 with FilePolicy

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

the class IsilonFileStorageDevice method checkFilePolicyPathHasResourceLabel.

@Override
public BiosCommandResult checkFilePolicyPathHasResourceLabel(StorageSystem system, FileDeviceInputOutput args) {
    _log.info("Inside checkFilePolicyPathHasResourceLabel()");
    try {
        FilePolicy filePolicy = args.getFileProtectionPolicy();
        String filePolicyBasePath = getFilePolicyPath(system, filePolicy.getApplyAt(), args);
        checkAppliedResourceNamePartOfFilePolicyPath(filePolicyBasePath, filePolicy, args);
        _log.info("checkFilePolicyPathHasResourceLabel successful.");
        return BiosCommandResult.createSuccessfulResult();
    } catch (IsilonException e) {
        _log.error("checkFilePolicyPathHasResourceLabel failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

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