Search in sources :

Example 11 with FileReplicationTopology

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

FileReplicationTopology (com.emc.storageos.db.client.model.FileReplicationTopology)11 URI (java.net.URI)5 StringSet (com.emc.storageos.db.client.model.StringSet)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)3 DbClient (com.emc.storageos.db.client.DbClient)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)2 VpoolRemoteCopyProtectionSettings (com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)2 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)2 TaskMapper.toTask (com.emc.storageos.api.mapper.TaskMapper.toTask)1 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)1 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1