Search in sources :

Example 21 with RelatedResourceRep

use of com.emc.storageos.model.RelatedResourceRep in project coprhd-controller by CoprHD.

the class BlockMapper method map.

public static BlockConsistencyGroupRestRep map(BlockConsistencyGroup from, Set<URI> volumes, DbClient dbClient) {
    if (from == null) {
        return null;
    }
    BlockConsistencyGroupRestRep to = new BlockConsistencyGroupRestRep();
    mapDataObjectFields(from, to);
    to.setVirtualArray(toRelatedResource(ResourceTypeEnum.VARRAY, from.getVirtualArray()));
    to.setProject(toRelatedResource(ResourceTypeEnum.PROJECT, from.getProject().getURI()));
    if (!NullColumnValueGetter.isNullURI(from.getStorageController())) {
        to.setStorageController(toRelatedResource(ResourceTypeEnum.STORAGE_SYSTEM, from.getStorageController()));
    }
    to.setArrayConsistency(from.getArrayConsistency());
    // Default snapshot session support to false
    to.setSupportsSnapshotSessions(Boolean.FALSE);
    if (dbClient != null && from.getSystemConsistencyGroups() != null) {
        for (String systemId : from.getSystemConsistencyGroups().keySet()) {
            StorageSystem system = dbClient.queryObject(StorageSystem.class, URI.create(systemId));
            if (system != null && system.checkIfVmax3()) {
                to.setSupportsSnapshotSessions(Boolean.TRUE);
            }
        }
    }
    try {
        if (from.getSystemConsistencyGroups() != null) {
            to.setSystemConsistencyGroups(new StringSetMapAdapter().marshal(from.getSystemConsistencyGroups()));
            if (!to.getSupportsSnapshotSessions()) {
                // we can flag this as true.
                if (dbClient != null && to.getSystemConsistencyGroups() != null) {
                    for (StringSetMapAdapter.Entry entry : to.getSystemConsistencyGroups()) {
                        String storageSystemId = entry.getKey();
                        if (storageSystemId != null) {
                            StorageSystem system = dbClient.queryObject(StorageSystem.class, URI.create(storageSystemId));
                            if (system != null && system.checkIfVmax3()) {
                                to.setSupportsSnapshotSessions(Boolean.TRUE);
                                break;
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        // internally ignored
        logger.debug(e.getMessage(), e);
    }
    if (from.getTypes() != null) {
        to.setTypes(from.getTypes());
    }
    if (dbClient != null) {
        List<RelatedResourceRep> volumesResourceRep = new ArrayList<RelatedResourceRep>();
        final URIQueryResultList cgVolumesResults = new URIQueryResultList();
        dbClient.queryByConstraint(getVolumesByConsistencyGroup(from.getId()), cgVolumesResults);
        Iterator<Volume> volumeIterator = dbClient.queryIterativeObjects(Volume.class, cgVolumesResults);
        boolean first = true;
        while (volumeIterator.hasNext()) {
            // Get the first RP or SRDF volume. From this we are able to obtain the
            // link status and protection set (RP) information for all volumes in the
            // CG.
            Volume volume = volumeIterator.next();
            if (first) {
                if (from.getTypes().contains(BlockConsistencyGroup.Types.RP.toString()) && !NullColumnValueGetter.isNullNamedURI(volume.getProtectionSet())) {
                    // Get the protection set from the first volume and set the appropriate fields
                    ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
                    to.setRpConsistenyGroupId(protectionSet.getProtectionId());
                    to.setLinkStatus(protectionSet.getProtectionStatus());
                    to.setRpProtectionSystem(protectionSet.getProtectionSystem());
                } else if (from.getTypes().contains(BlockConsistencyGroup.Types.SRDF.toString())) {
                    // Operations cannot be performed individually on volumes within an SRDF CG, hence
                    // we can take any one of the volume's link status and update the CG link status.
                    to.setLinkStatus(volume.getLinkStatus());
                }
            }
            // Only display CG volumes that are non-RP or RP source volumes. Exclude RP+VPlex backing volumes.
            if ((!volume.checkForRp() && !RPHelper.isAssociatedToAnyRpVplexTypes(volume, dbClient)) || (volume.checkForRp() && PersonalityTypes.SOURCE.name().equals(volume.getPersonality()))) {
                volumesResourceRep.add(toRelatedResource(ResourceTypeEnum.VOLUME, volume.getId()));
            }
            first = false;
        }
        to.setVolumes(volumesResourceRep);
    }
    return to;
}
Also used : BlockConsistencyGroupRestRep(com.emc.storageos.model.block.BlockConsistencyGroupRestRep) RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) VirtualArrayRelatedResourceRep(com.emc.storageos.model.VirtualArrayRelatedResourceRep) ArrayList(java.util.ArrayList) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StringSetMapAdapter(com.emc.storageos.model.adapters.StringSetMapAdapter) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 22 with RelatedResourceRep

use of com.emc.storageos.model.RelatedResourceRep in project coprhd-controller by CoprHD.

the class BlockMapper method map.

/**
 * Maps a BlockSnapshotSession instance to its Rest representation.
 *
 * @param dbClient A reference to a database client.
 * @param from An instance of BlockSnapshotSession.
 *
 * @return An instance of BlockSnapshotSessionRestRep
 */
public static BlockSnapshotSessionRestRep map(DbClient dbClient, BlockSnapshotSession from) {
    if (from == null) {
        return null;
    }
    BlockSnapshotSessionRestRep to = new BlockSnapshotSessionRestRep();
    // Map base class fields.
    mapDataObjectFields(from, to);
    // Map snapshot session consistency group.
    URI consistencyGroup = from.getConsistencyGroup();
    if (consistencyGroup != null) {
        to.setConsistencyGroup(toRelatedResource(ResourceTypeEnum.BLOCK_CONSISTENCY_GROUP, consistencyGroup));
    }
    // Map snapshot session parent i.e., the snapshot session source.
    NamedURI parentNamedURI = from.getParent();
    if (parentNamedURI != null) {
        URI parentURI = parentNamedURI.getURI();
        // It may be possible that the source for the snapshot
        // session is a backend source volume for a VPLEX volume
        // if we support creating snapshot sessions for VPLEX
        // volumes backed by storage that supports snapshot sessions.
        // In this case, the parent we want to reflect in the response
        // is the VPLEX volume.
        URIQueryResultList results = new URIQueryResultList();
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeByAssociatedVolumesConstraint(parentURI.toString()), results);
        Iterator<URI> resultsIter = results.iterator();
        if (resultsIter.hasNext()) {
            parentURI = resultsIter.next();
        }
        // volume for an array snapshot, which is a BlockSnapshot.
        if (URIUtil.isType(parentURI, Volume.class)) {
            to.setParent(toRelatedResource(ResourceTypeEnum.VOLUME, parentURI));
        } else {
            to.setParent(toRelatedResource(ResourceTypeEnum.BLOCK_SNAPSHOT, parentURI));
        }
    }
    // Map project
    NamedURI projectURI = from.getProject();
    if (projectURI != null) {
        to.setProject(toRelatedResource(ResourceTypeEnum.PROJECT, projectURI.getURI()));
    }
    // Map storage controller
    URI storageURI = from.getStorageController();
    if (storageURI != null) {
        to.setStorageController(storageURI);
    }
    // Map linked targets.
    StringSet linkedTargetIds = from.getLinkedTargets();
    if ((linkedTargetIds != null) && (!linkedTargetIds.isEmpty())) {
        List<RelatedResourceRep> linkedTargetReps = new ArrayList<RelatedResourceRep>();
        for (String linkedTargetId : linkedTargetIds) {
            URI linkedTargetURI = URI.create(linkedTargetId);
            // Linked targets are instances of BlockSnapshot.
            linkedTargetReps.add(toRelatedResource(ResourceTypeEnum.BLOCK_SNAPSHOT, linkedTargetURI));
        }
        to.setLinkedTargets(linkedTargetReps);
    }
    // Map session label.
    to.setSessionLabel(from.getSessionLabel());
    // Map replication group name.
    to.setReplicationGroupInstance(from.getReplicationGroupInstance());
    // Map session set name.
    to.setSessionSetName(from.getSessionSetName());
    return to;
}
Also used : BlockSnapshotSessionRestRep(com.emc.storageos.model.block.BlockSnapshotSessionRestRep) RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) VirtualArrayRelatedResourceRep(com.emc.storageos.model.VirtualArrayRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 23 with RelatedResourceRep

use of com.emc.storageos.model.RelatedResourceRep in project coprhd-controller by CoprHD.

the class ComputeVirtualPoolMapper method getAvailableComputeElements.

private static Set<RelatedResourceRep> getAvailableComputeElements(DbClient dbClient, StringSet matchedComputeElements) {
    Set<RelatedResourceRep> returnSet = new HashSet<RelatedResourceRep>();
    Collection<ComputeElement> computeElements = dbClient.queryObject(ComputeElement.class, toUriList(matchedComputeElements));
    for (ComputeElement computeElement : computeElements) {
        if (computeElement.getAvailable()) {
            returnSet.add(toRelatedResource(ResourceTypeEnum.COMPUTE_ELEMENT, computeElement.getId()));
        }
    }
    return returnSet;
}
Also used : RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) HashSet(java.util.HashSet)

Example 24 with RelatedResourceRep

use of com.emc.storageos.model.RelatedResourceRep in project coprhd-controller by CoprHD.

the class EventMapper method map.

public static EventRestRep map(ActionableEvent from) {
    if (from == null) {
        return null;
    }
    EventRestRep to = new EventRestRep();
    mapDataObjectFields(from, to);
    to.setTenant(toRelatedResource(ResourceTypeEnum.TENANT, from.getTenant()));
    to.setResource(toNamedRelatedResource(from.getResource()));
    to.setEventStatus(from.getEventStatus());
    to.setDescription(from.getDescription());
    to.setWarning(from.getWarning());
    to.setEventCode(from.getEventCode());
    to.setEventExecutionTime(from.getEventExecutionTime());
    if ((from.getTaskIds() != null) && (!from.getTaskIds().isEmpty())) {
        List<RelatedResourceRep> taskIds = new ArrayList<RelatedResourceRep>();
        for (String task : from.getTaskIds()) {
            taskIds.add(toRelatedResource(ResourceTypeEnum.TASK, URI.create(task)));
        }
        to.setTaskIds(taskIds);
    }
    if ((from.getApproveDetails() != null) && (!from.getApproveDetails().isEmpty())) {
        List<String> approveDetails = new ArrayList<String>();
        for (String details : from.getApproveDetails()) {
            approveDetails.add(details);
        }
        to.setApproveDetails(approveDetails);
    }
    if ((from.getDeclineDetails() != null) && (!from.getDeclineDetails().isEmpty())) {
        List<String> declineDetails = new ArrayList<String>();
        for (String details : from.getDeclineDetails()) {
            declineDetails.add(details);
        }
        to.setDeclineDetails(declineDetails);
    }
    return to;
}
Also used : RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) EventRestRep(com.emc.storageos.model.event.EventRestRep) ArrayList(java.util.ArrayList)

Example 25 with RelatedResourceRep

use of com.emc.storageos.model.RelatedResourceRep in project coprhd-controller by CoprHD.

the class WFDirectoryService method map.

private WFDirectoryRestRep map(WFDirectory from) {
    WFDirectoryRestRep to = new WFDirectoryRestRep();
    mapDataObjectFields(from, to);
    if (null != from.getParent()) {
        if (from.getParent().equals(getRootLevelParentId())) {
            // Removing the dummy parent Id that was set during create
            to.setParent(null);
        } else {
            to.setParent(new RelatedResourceRep(from.getParent(), new RestLinkRep("self", RestLinkFactory.newLink(ResourceTypeEnum.WF_DIRECTORY, from.getParent()))));
        }
    }
    if (null != from.getWorkflows()) {
        to.setWorkflows(StringSetUtil.stringSetToUriList(from.getWorkflows()));
    }
    return to;
}
Also used : NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) RestLinkRep(com.emc.storageos.model.RestLinkRep) WFDirectoryRestRep(com.emc.vipr.model.catalog.WFDirectoryRestRep)

Aggregations

RelatedResourceRep (com.emc.storageos.model.RelatedResourceRep)41 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)25 ArrayList (java.util.ArrayList)19 VirtualArrayRelatedResourceRep (com.emc.storageos.model.VirtualArrayRelatedResourceRep)14 URI (java.net.URI)12 Asset (com.emc.sa.asset.annotation.Asset)8 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)8 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)7 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)7 BlockSnapshotRestRep (com.emc.storageos.model.block.BlockSnapshotRestRep)5 BlockSnapshotSessionRestRep (com.emc.storageos.model.block.BlockSnapshotSessionRestRep)5 ClusterRestRep (com.emc.storageos.model.host.cluster.ClusterRestRep)5 BlockSnapshotSessionList (com.emc.storageos.model.block.BlockSnapshotSessionList)4 StoragePortList (com.emc.storageos.model.ports.StoragePortList)4 VirtualArrayRestRep (com.emc.storageos.model.varray.VirtualArrayRestRep)4 AssetOption (com.emc.vipr.model.catalog.AssetOption)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 VolumeGroupList (com.emc.storageos.model.application.VolumeGroupList)3