Search in sources :

Example 1 with SnapshotSettingsRestRep

use of com.emc.storageos.model.file.policy.FilePolicyRestRep.SnapshotSettingsRestRep in project coprhd-controller by CoprHD.

the class FilePolicyMapper method map.

public static FilePolicyRestRep map(FilePolicy from, DbClient dbClient) {
    FilePolicyRestRep resp = new FilePolicyRestRep();
    DbObjectMapper.mapDataObjectFields(from, resp);
    resp.setName(from.getFilePolicyName());
    resp.setDescription(from.getFilePolicyDescription());
    ScheduleRestRep schedule = new ScheduleRestRep();
    String dayOfWeek = from.getScheduleDayOfWeek();
    if (NullColumnValueGetter.isNotNullValue(dayOfWeek)) {
        schedule.setDayOfWeek(dayOfWeek);
    }
    schedule.setDayOfMonth(from.getScheduleDayOfMonth());
    schedule.setFrequency(from.getScheduleFrequency());
    schedule.setRepeat(from.getScheduleRepeat());
    schedule.setTime(from.getScheduleTime());
    resp.setSchedule(schedule);
    URI vpoolURI = from.getFilePolicyVpool();
    if (!NullColumnValueGetter.isNullURI(vpoolURI)) {
        VirtualPool vpool = dbClient.queryObject(VirtualPool.class, vpoolURI);
        resp.setVpool(DbObjectMapper.toNamedRelatedResource(ResourceTypeEnum.FILE_VPOOL, vpoolURI, vpool.getLabel()));
    }
    String appliedAt = from.getApplyAt();
    if (NullColumnValueGetter.isNotNullValue(appliedAt)) {
        resp.setAppliedAt(appliedAt);
        StringSet assignedResources = from.getAssignedResources();
        if (assignedResources != null && !assignedResources.isEmpty()) {
            List<URI> resourceURIs = new ArrayList<>();
            for (Iterator<String> iterator = assignedResources.iterator(); iterator.hasNext(); ) {
                String resourceId = iterator.next();
                resourceURIs.add(URI.create(resourceId));
            }
            if (!resourceURIs.isEmpty()) {
                FilePolicyApplyLevel level = FilePolicyApplyLevel.valueOf(appliedAt);
                Class<? extends DataObject> clazz = null;
                switch(level) {
                    case file_system:
                        clazz = FileShare.class;
                        break;
                    case vpool:
                        clazz = VirtualPool.class;
                        break;
                    case project:
                        clazz = Project.class;
                        break;
                    default:
                        break;
                }
                if (clazz != null) {
                    Iterator<? extends DataObject> resourceIterator = dbClient.queryIterativeObjects(clazz, resourceURIs);
                    while (resourceIterator.hasNext()) {
                        DataObject dataObject = resourceIterator.next();
                        if (FilePolicyApplyLevel.vpool == level) {
                            resp.addAssignedResource(DbObjectMapper.toNamedRelatedResource(ResourceTypeEnum.FILE_VPOOL, dataObject.getId(), dataObject.getLabel()));
                        } else {
                            resp.addAssignedResource(DbObjectMapper.toNamedRelatedResource(dataObject));
                        }
                    }
                }
            }
        }
    }
    if (from.getPriority() != null) {
        resp.setPriority(from.getPriority());
    }
    if (from.getNumWorkerThreads() != null) {
        resp.setNumWorkerThreads(from.getNumWorkerThreads());
    }
    if (from.getApplyOnTargetSite() != null) {
        resp.setApplyOnTargetSite(from.getApplyOnTargetSite());
    }
    String policyType = from.getFilePolicyType();
    resp.setType(policyType);
    if (FilePolicyType.file_replication.name().equals(policyType)) {
        ReplicationSettingsRestRep replicationSettings = new ReplicationSettingsRestRep();
        replicationSettings.setMode(from.getFileReplicationCopyMode());
        replicationSettings.setType(from.getFileReplicationType());
        List<FileReplicationTopologyRestRep> replicationTopologies = new ArrayList<FileReplicationTopologyRestRep>();
        if (from.getReplicationTopologies() != null) {
            for (String topology : from.getReplicationTopologies()) {
                FileReplicationTopologyRestRep replicationTopology = new FileReplicationTopologyRestRep();
                FileReplicationTopology dbTopology = dbClient.queryObject(FileReplicationTopology.class, URI.create(topology));
                if (dbTopology != null) {
                    VirtualArray srcVArray = dbClient.queryObject(VirtualArray.class, dbTopology.getSourceVArray());
                    replicationTopology.setSourceVArray(DbObjectMapper.toNamedRelatedResource(srcVArray));
                    // Set Target varrays!!!
                    StringSet tgtVArrays = dbTopology.getTargetVArrays();
                    if (tgtVArrays != null && !tgtVArrays.isEmpty()) {
                        List<URI> resourceURIs = new ArrayList<URI>();
                        for (Iterator<String> iterator = tgtVArrays.iterator(); iterator.hasNext(); ) {
                            resourceURIs.add(URI.create(iterator.next()));
                        }
                        Iterator<? extends DataObject> resourceIterator = dbClient.queryIterativeObjects(VirtualArray.class, resourceURIs);
                        while (resourceIterator.hasNext()) {
                            DataObject dataObject = resourceIterator.next();
                            replicationTopology.addTargetVArray(DbObjectMapper.toNamedRelatedResource(dataObject));
                        }
                    }
                }
                replicationTopologies.add(replicationTopology);
            }
            replicationSettings.setReplicationTopologies(replicationTopologies);
        }
        resp.setReplicationSettings(replicationSettings);
    }
    if (FilePolicyType.file_snapshot.name().equals(policyType)) {
        SnapshotSettingsRestRep snapshotSettings = new SnapshotSettingsRestRep();
        String expiryType = from.getSnapshotExpireType();
        snapshotSettings.setExpiryType(expiryType);
        if (!SnapshotExpireType.NEVER.name().equalsIgnoreCase(expiryType)) {
            snapshotSettings.setExpiryTime(from.getSnapshotExpireTime());
        }
        if (from.getSnapshotNamePattern() != null) {
            snapshotSettings.setSnapshotNamePattern(from.getSnapshotNamePattern());
        }
        resp.setSnapshotSettings(snapshotSettings);
    }
    return resp;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) FileReplicationTopologyRestRep(com.emc.storageos.model.file.policy.FileReplicationTopologyRestRep) FilePolicyRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep) ArrayList(java.util.ArrayList) SnapshotSettingsRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep.SnapshotSettingsRestRep) ScheduleRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep.ScheduleRestRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) ReplicationSettingsRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep.ReplicationSettingsRestRep) DataObject(com.emc.storageos.db.client.model.DataObject) StringSet(com.emc.storageos.db.client.model.StringSet) FilePolicyApplyLevel(com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)1 FilePolicyApplyLevel (com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel)1 FileReplicationTopology (com.emc.storageos.db.client.model.FileReplicationTopology)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 FilePolicyRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep)1 ReplicationSettingsRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep.ReplicationSettingsRestRep)1 ScheduleRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep.ScheduleRestRep)1 SnapshotSettingsRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep.SnapshotSettingsRestRep)1 FileReplicationTopologyRestRep (com.emc.storageos.model.file.policy.FileReplicationTopologyRestRep)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1