Search in sources :

Example 6 with SchedulePolicy

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

the class IsilonFileStorageDevice method isiDeleteSnapshotSchedules.

/**
 * Deleting snapshots: - deletes snapshots of a file system
 *
 * @param isi
 *            IsilonApi object
 * @param args
 *            FileDeviceInputOutput
 * @throws IsilonException
 */
private void isiDeleteSnapshotSchedules(IsilonApi isi, FileDeviceInputOutput args) throws IsilonException {
    StringSet policies = args.getFs().getFilePolicies();
    for (String policy : policies) {
        SchedulePolicy fp = _dbClient.queryObject(SchedulePolicy.class, URI.create(policy));
        String snapshotScheduleName = fp.getPolicyName() + "_" + args.getFsName();
        isi.deleteSnapshotSchedule(snapshotScheduleName);
    }
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy)

Example 7 with SchedulePolicy

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

the class IsilonFileStorageDevice method unassignFilePolicy.

@Deprecated
@Override
public BiosCommandResult unassignFilePolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
    SchedulePolicy fp = args.getFilePolicy();
    String snapshotScheduleName = fp.getPolicyName() + "_" + args.getFsName();
    IsilonApi isi = getIsilonDevice(storageObj);
    try {
        isi.deleteSnapshotSchedule(snapshotScheduleName);
    } catch (IsilonException e) {
        _log.error("unassign file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
    return BiosCommandResult.createSuccessfulResult();
}
Also used : IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 8 with SchedulePolicy

use of com.emc.storageos.db.client.model.SchedulePolicy 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 9 with SchedulePolicy

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

the class SchedulePolicyService method getPolicyById.

/**
 * Get schedule policy object from id
 *
 * @param id the URN of a CoprHD Schedule Policy
 * @return
 */
private SchedulePolicy getPolicyById(URI id, boolean checkInactive) {
    if (id == null) {
        return null;
    }
    SchedulePolicy schedulePolicy = _permissionsHelper.getObjectById(id, SchedulePolicy.class);
    ArgValidator.checkEntity(schedulePolicy, id, isIdEmbeddedInURL(id));
    return schedulePolicy;
}
Also used : MapSchedulePolicy(com.emc.storageos.api.mapper.functions.MapSchedulePolicy) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy)

Example 10 with SchedulePolicy

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

the class SchedulePolicyService method getSchedulePolicy.

/**
 * Get the details of a schedule policy.
 *
 * @param policyId the URN of a schedule policy.
 *
 * @brief Show schedule policy
 * @return A SchedulePolicyRestRep reference specifying the data for the
 *         schedule policy with the passed policyId.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public SchedulePolicyRestRep getSchedulePolicy(@PathParam("id") URI policyId) {
    ArgValidator.checkFieldUriType(policyId, SchedulePolicy.class, "policyId");
    SchedulePolicy schedulePolicy = queryResource(policyId);
    return map(schedulePolicy);
}
Also used : MapSchedulePolicy(com.emc.storageos.api.mapper.functions.MapSchedulePolicy) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

SchedulePolicy (com.emc.storageos.db.client.model.SchedulePolicy)14 StringSet (com.emc.storageos.db.client.model.StringSet)8 FileShare (com.emc.storageos.db.client.model.FileShare)5 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 Path (javax.ws.rs.Path)5 MapSchedulePolicy (com.emc.storageos.api.mapper.functions.MapSchedulePolicy)4 NamedURI (com.emc.storageos.db.client.model.NamedURI)4 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)4 URI (java.net.URI)4 Produces (javax.ws.rs.Produces)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 SchedulePolicyType (com.emc.storageos.db.client.model.SchedulePolicy.SchedulePolicyType)2 SnapshotExpireType (com.emc.storageos.db.client.model.SchedulePolicy.SnapshotExpireType)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)2