Search in sources :

Example 1 with DataObject

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

the class ResourceService method getNamedElementsWithNoAcls.

/**
 * Filters the data objects with no configured acls from the given list of objects.
 * From the filtered list, creates the name and id pair elements.
 *
 * @param clazz class objects to be filtered.
 * @param nameField name field of the objects.
 * @param dataObjects list of data objects to be filtered with no acls.
 * @return a name and id list of a given class with no acls.
 */
protected <T extends DiscoveredComputeSystemWithAcls> List<NamedElementQueryResultList.NamedElement> getNamedElementsWithNoAcls(Class<T> clazz, String nameField, List<T> dataObjects) {
    List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(dataObjects.size());
    for (T dataObject : dataObjects) {
        if (CollectionUtils.isEmpty(dataObject.getAcls())) {
            Object name = DataObjectUtils.getPropertyValue(clazz, dataObject, nameField);
            elements.add(NamedElementQueryResultList.NamedElement.createElement(dataObject.getId(), name == null ? "" : name.toString()));
        }
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) DataObject(com.emc.storageos.db.client.model.DataObject) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 2 with DataObject

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

the class ResourceService method listChildrenWithAcls.

/**
 * Retrieves the list of NamedElements of the data objects with acls
 * and the list is filtered based on the tenant information.
 *
 * @param tenantId the URN of parent
 * @param clzz the child class
 * @param nameField the name of the field of the child class that will be displayed as
 *            name in {@link NamedRelatedResourceRep}. Note this field should be a required
 *            field because, objects for which this field is null will not be returned by
 *            this function.
 * @return a list of NamedElements filtered by tenant.
 */
protected <T extends DiscoveredComputeSystemWithAcls> List<NamedElementQueryResultList.NamedElement> listChildrenWithAcls(URI tenantId, Class<T> clzz, String nameField) {
    Iterator<T> dataObjects = getDiscoveredComputeObjects(tenantId, clzz);
    List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>();
    while (dataObjects.hasNext()) {
        T dataObject = dataObjects.next();
        Object name = DataObjectUtils.getPropertyValue(Vcenter.class, dataObject, nameField);
        elements.add(NamedElementQueryResultList.NamedElement.createElement(dataObject.getId(), name == null ? "" : name.toString()));
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) DataObject(com.emc.storageos.db.client.model.DataObject) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 3 with DataObject

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

the class ResourceService method listChildren.

/**
 * This function is to retrieve the children of a given class.
 *
 * @param id the URN of parent
 * @param clzz the child class
 * @param nameField the name of the field of the child class that will be displayed as
 *            name in {@link NamedRelatedResourceRep}. Note this field should be a required
 *            field because, objects for which this field is null will not be returned by
 *            this function.
 * @param linkField the name of the field in the child class that stored the parent id
 * @return a list of children of tenant for the given class
 */
protected <T extends DataObject> List<NamedElementQueryResultList.NamedElement> listChildren(URI id, Class<T> clzz, String nameField, String linkField) {
    @SuppressWarnings("deprecation") List<URI> uris = _dbClient.queryByConstraint(ContainmentConstraint.Factory.getContainedObjectsConstraint(id, clzz, linkField));
    if (uris != null && !uris.isEmpty()) {
        Iterator<T> dataObjects = _dbClient.queryIterativeObjectField(clzz, nameField, uris);
        List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>();
        while (dataObjects.hasNext()) {
            T dataObject = dataObjects.next();
            Object name = DataObjectUtils.getPropertyValue(clzz, dataObject, nameField);
            elements.add(NamedElementQueryResultList.NamedElement.createElement(dataObject.getId(), name == null ? "" : name.toString()));
        }
        return elements;
    } else {
        return new ArrayList<NamedElementQueryResultList.NamedElement>();
    }
}
Also used : ArrayList(java.util.ArrayList) DataObject(com.emc.storageos.db.client.model.DataObject) URI(java.net.URI) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 4 with DataObject

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

the class BlockIngestOrchestrator method decorateCGInfoInVolumes.

/**
 * Decorates the BlockConsistencyGroup information in all other volumes ingested in the UnManagedConsistencyGroup
 * managed objects.
 *
 * For each unmanaged volume in unmanaged cg,
 * 1. We verify whether the BlockObject is available in the current createdBlockObjects in context or not.
 * If it is available, then set the CG properties
 * Else, verify in the current updatedBlockObjects in context.
 * 2. If the blockObject is available in updateBlockObjects, then update CG properties.
 * Else, blockObject might have ingested in previous requests, so, we should check from DB.
 * If blockObject is in DB, update CG properties else log a warning message.
 *
 * @param cg - cg object
 * @param blockObject - BlockObject to decorate
 * @param requestContext - current context of unmanagedVolume
 * @param unManagedVolume - current unmanagedVolume to ingest
 */
protected void decorateCGInfoInVolumes(BlockConsistencyGroup cg, BlockObject blockObject, IngestionRequestContext requestContext, UnManagedVolume unManagedVolume) {
    UnManagedConsistencyGroup umcg = requestContext.findUnManagedConsistencyGroup(cg.getLabel());
    Set<DataObject> blockObjectsToUpdate = new HashSet<DataObject>();
    if (null != umcg && null != umcg.getManagedVolumesMap() && !umcg.getManagedVolumesMap().isEmpty()) {
        for (Entry<String, String> managedVolumeEntry : umcg.getManagedVolumesMap().entrySet()) {
            BlockObject bo = requestContext.getRootIngestionRequestContext().findCreatedBlockObject(managedVolumeEntry.getKey());
            if (bo == null) {
                // Next look in the updated objects.
                bo = (BlockObject) requestContext.findInUpdatedObjects(URI.create(managedVolumeEntry.getKey()));
            }
            if (bo == null) {
                // Finally look in the DB itself. It may be from a previous ingestion operation.
                bo = BlockObject.fetch(_dbClient, URI.create(managedVolumeEntry.getValue()));
                // If blockObject is still not exists
                if (null == bo) {
                    _logger.warn("Volume {} is not yet ingested. Hence skipping", managedVolumeEntry.getKey());
                    continue;
                }
                blockObjectsToUpdate.add(bo);
            }
            bo.setConsistencyGroup(cg.getId());
            // Set the replication group instance only if it is not already populated during the block object's ingestion.
            if (bo.getReplicationGroupInstance() == null || bo.getReplicationGroupInstance().isEmpty()) {
                bo.setReplicationGroupInstance(cg.getLabel());
            }
        }
        if (!blockObjectsToUpdate.isEmpty()) {
            requestContext.getDataObjectsToBeUpdatedMap().put(unManagedVolume.getNativeGuid(), blockObjectsToUpdate);
        }
    }
    blockObject.setConsistencyGroup(cg.getId());
    blockObject.setReplicationGroupInstance(cg.getLabel());
    if (blockObject instanceof BlockSnapshot) {
        // Check if the unmanaged volume has SNAPSHOT_CONSISTENCY_GROUP_NAME property populated. If yes,
        // use that for replicationGroupInstance
        String snapsetName = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.SNAPSHOT_CONSISTENCY_GROUP_NAME.toString(), unManagedVolume.getVolumeInformation());
        if (snapsetName != null && !snapsetName.isEmpty()) {
            blockObject.setReplicationGroupInstance(snapsetName);
        }
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) UnManagedConsistencyGroup(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedConsistencyGroup) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet)

Example 5 with DataObject

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

the class BlockRecoverPointIngestOrchestrator method decorateVolumeInformationFinalIngest.

/**
 * This method will perform all of the final decorations (attribute setting) on the Volume
 * object after creating the required BlockConsistencyGroup and ProtectionSet objects.
 *
 * Fields such as rpCopyName and rSetName were already filled in when we did the ingest of
 * the volume itself. In this method, we worry about stitching together all of the object
 * references within the Volume object so it will act like a native CoprHD-created RP volume.
 *
 * @param volumeContext the RecoverPointVolumeIngestionContext for the volume currently being ingested
 * @param unManagedVolume the currently ingesting UnManagedVolume
 */
private void decorateVolumeInformationFinalIngest(IngestionRequestContext requestContext, UnManagedVolume unManagedVolume) {
    RecoverPointVolumeIngestionContext volumeContext = (RecoverPointVolumeIngestionContext) requestContext.getVolumeContext();
    ProtectionSet pset = volumeContext.getManagedProtectionSet();
    BlockConsistencyGroup cg = volumeContext.getManagedBlockConsistencyGroup();
    if (pset.getVolumes() == null) {
        _logger.error("No volumes found in protection set: " + pset.getLabel() + ", cannot process ingestion");
        throw IngestionException.exceptions.noVolumesFoundInProtectionSet(pset.getLabel());
    }
    List<Volume> volumes = new ArrayList<Volume>();
    for (String volId : pset.getVolumes()) {
        BlockObject volume = requestContext.getRootIngestionRequestContext().findCreatedBlockObject(URI.create(volId));
        if (volume != null && volume instanceof Volume) {
            volumes.add((Volume) volume);
        }
    }
    // Make sure all of the changed managed block objects get updated
    volumes.add((Volume) volumeContext.getManagedBlockObject());
    Set<DataObject> updatedObjects = new HashSet<DataObject>();
    VolumeIngestionUtil.decorateRPVolumesCGInfo(volumes, pset, cg, updatedObjects, _dbClient, requestContext);
    VolumeIngestionUtil.clearPersistedReplicaFlags(requestContext, volumes, updatedObjects, _dbClient);
    clearReplicaFlagsInIngestionContext(volumeContext, volumes);
    for (DataObject volume : updatedObjects) {
        if (volumeContext.getManagedBlockObject().getId().equals(volume.getId()) && (null == _dbClient.queryObject(Volume.class, volume.getId()))) {
            // this is the managed block object and it hasn't been saved to the db yet
            continue;
        } else {
            // add all volumes except the newly ingested one to the update list
            volumeContext.addDataObjectToUpdate(volume, unManagedVolume);
        }
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) RecoverPointVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RecoverPointVolumeIngestionContext) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) ArrayList(java.util.ArrayList) BlockObject(com.emc.storageos.db.client.model.BlockObject) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) HashSet(java.util.HashSet)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)154 URI (java.net.URI)62 ArrayList (java.util.ArrayList)53 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)44 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)30 Volume (com.emc.storageos.db.client.model.Volume)26 NamedURI (com.emc.storageos.db.client.model.NamedURI)24 StringSet (com.emc.storageos.db.client.model.StringSet)23 HashMap (java.util.HashMap)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)17 HashSet (java.util.HashSet)17 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)16 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)14 Operation (com.emc.storageos.db.client.model.Operation)13 List (java.util.List)10 Set (java.util.Set)10 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)9 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8