Search in sources :

Example 31 with DataObject

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

the class BlockRPCGIngestDecorator method getAssociatedObjects.

@Override
protected List<BlockObject> getAssociatedObjects(BlockConsistencyGroup cg, Collection<BlockObject> allCGBlockObjects, IngestionRequestContext requestContext) throws Exception {
    // Get all of the block objects that are in the protection set
    RecoverPointVolumeIngestionContext rpContext = (RecoverPointVolumeIngestionContext) requestContext.getVolumeContext();
    ProtectionSet pset = rpContext.getManagedProtectionSet();
    if (pset == null) {
        return null;
    }
    // All of the volumes in the CG are in the "objects to be updated" map in the RP context.
    List<BlockObject> boList = new ArrayList<BlockObject>();
    for (String volumeIdStr : pset.getVolumes()) {
        for (DataObject dataObj : allCGBlockObjects) {
            if (URIUtil.identical(dataObj.getId(), URI.create(volumeIdStr))) {
                boList.add((BlockObject) dataObj);
            }
        }
    }
    return boList;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) RecoverPointVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RecoverPointVolumeIngestionContext) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) ArrayList(java.util.ArrayList) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 32 with DataObject

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

the class BaseIngestionRequestContext method findDataObjectByType.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.IngestionRequestContext#findObjectAnywhere(java.lang.
     * Class, java.net.URI)
     */
@Override
public <T extends DataObject> T findDataObjectByType(Class<T> clazz, URI id, boolean fallbackToDatabase) {
    _logger.info("looking for {} object with id {}", clazz.toString(), id);
    // check for DataObjects in already-loaded Updated Objects first
    DataObject dob = this.findInUpdatedObjects(id);
    if (clazz.isInstance(dob)) {
        _logger.info("\tfound in updated objects: " + dob.forDisplay());
        return clazz.cast(dob);
    }
    // check for Mirrors/Snapshots/Volumes that have been created
    if (clazz.equals(BlockMirror.class) || clazz.equals(Volume.class) || clazz.equals(BlockSnapshot.class)) {
        BlockObject bo = this.findCreatedBlockObject(id);
        if (clazz.isInstance(bo)) {
            _logger.info("\tfound in created objects: " + bo.forDisplay());
            return clazz.cast(bo);
        }
    }
    // search for any already-loaded UnManagedVolume instances
    if (clazz.equals(UnManagedVolume.class)) {
        for (UnManagedVolume umv : this.findAllUnManagedVolumesToBeDeleted()) {
            if (umv != null && umv.getId().equals(id)) {
                _logger.info("\tfound in volumes to be deleted: " + umv.forDisplay());
                return clazz.cast(umv);
            }
        }
        VolumeIngestionContext currentVolumeContext = getVolumeContext();
        if (currentVolumeContext != null && currentVolumeContext instanceof IngestionRequestContext) {
            UnManagedVolume umv = currentVolumeContext.getUnmanagedVolume();
            if (umv != null && umv.getId().equals(id)) {
                _logger.info("\tfound in current volume context: " + umv.forDisplay());
                return clazz.cast(umv);
            }
        }
        for (VolumeIngestionContext volumeContext : this.getProcessedUnManagedVolumeMap().values()) {
            if (volumeContext instanceof IngestionRequestContext) {
                UnManagedVolume umv = volumeContext.getUnmanagedVolume();
                if (umv != null && umv.getId().equals(id)) {
                    _logger.info("\tfound in already-processed volume context: " + umv.forDisplay());
                    return clazz.cast(umv);
                }
            }
        }
    }
    // search for any already-loaded UnManagedProtectionSet instances
    if (clazz.equals(UnManagedProtectionSet.class)) {
        VolumeIngestionContext currentVolumeContext = getVolumeContext();
        if (currentVolumeContext != null && currentVolumeContext instanceof RecoverPointVolumeIngestionContext) {
            UnManagedProtectionSet umpset = ((RecoverPointVolumeIngestionContext) currentVolumeContext).getUnManagedProtectionSetLocal();
            if (umpset != null && umpset.getId().equals(id)) {
                _logger.info("\tfound in current volume context: " + umpset.forDisplay());
                return clazz.cast(umpset);
            }
        }
        for (VolumeIngestionContext volumeContext : this.getProcessedUnManagedVolumeMap().values()) {
            if (volumeContext != null && volumeContext instanceof RecoverPointVolumeIngestionContext) {
                UnManagedProtectionSet umpset = ((RecoverPointVolumeIngestionContext) volumeContext).getUnManagedProtectionSetLocal();
                if (umpset != null && umpset.getId().equals(id)) {
                    _logger.info("\tfound in already-processed volume context: " + umpset.forDisplay());
                    return clazz.cast(umpset);
                }
            }
        }
    }
    if (fallbackToDatabase) {
        // if we still haven't found it, load it from the database
        T dataObject = _dbClient.queryObject(clazz, id);
        if (dataObject != null) {
            _logger.info("\tloaded object from database: " + dataObject.forDisplay());
            return clazz.cast(dataObject);
        }
    }
    return null;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) IngestionRequestContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.IngestionRequestContext) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 33 with DataObject

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

the class RecoverPointVolumeIngestionContext method commit.

/*
     * (non-Javadoc)
     *
     * @see com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext#commit()
     */
@Override
public void commit() {
    _logger.info("persisting RecoverPoint backend for volume " + getUnmanagedVolume().forDisplay());
    // commit the basic IngestionRequestContext collections
    for (BlockObject bo : getObjectsIngestedByExportProcessing()) {
        _logger.info("Creating BlockObject {} (hash {})", bo.forDisplay(), bo.hashCode());
        _dbClient.createObject(bo);
    }
    for (BlockObject bo : getBlockObjectsToBeCreatedMap().values()) {
        _logger.info("Creating BlockObject {} (hash {})", bo.forDisplay(), bo.hashCode());
        _dbClient.createObject(bo);
    }
    for (Set<DataObject> createdObjects : getDataObjectsToBeCreatedMap().values()) {
        if (createdObjects != null && !createdObjects.isEmpty()) {
            for (DataObject dob : createdObjects) {
                _logger.info("Creating DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
                _dbClient.createObject(dob);
            }
        }
    }
    for (Set<DataObject> updatedObjects : getDataObjectsToBeUpdatedMap().values()) {
        if (updatedObjects != null && !updatedObjects.isEmpty()) {
            for (DataObject dob : updatedObjects) {
                if (dob.getInactive()) {
                    _logger.info("Deleting DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
                } else {
                    _logger.info("Updating DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
                }
                _dbClient.updateObject(dob);
            }
        }
    }
    for (UnManagedVolume umv : getUnManagedVolumesToBeDeleted()) {
        _logger.info("Deleting UnManagedVolume {} (hash {})", umv.forDisplay(), umv.hashCode());
        _dbClient.updateObject(umv);
    }
    // now commit the RecoverPoint specific data
    if (_managedSourceVolumesToUpdate != null) {
        _logger.info("Updating RP Source Volumes: " + _managedSourceVolumesToUpdate);
        _dbClient.updateObject(_managedSourceVolumesToUpdate);
    }
    if (_unmanagedSourceVolumesToUpdate != null) {
        _logger.info("Updating RP Source UnManagedVolumes: " + _unmanagedSourceVolumesToUpdate);
        _dbClient.updateObject(_unmanagedSourceVolumesToUpdate);
    }
    if (_unmanagedTargetVolumesToUpdate != null) {
        _logger.info("Updating RP Target UnManagedVolumes: " + _unmanagedTargetVolumesToUpdate);
        _dbClient.updateObject(_unmanagedTargetVolumesToUpdate);
    }
    // commit the ProtectionSet, if created, and remove the UnManagedProtectionSet
    ProtectionSet managedProtectionSet = getManagedProtectionSet();
    if (null != managedProtectionSet) {
        if (getManagedBlockObject() != null) {
            managedProtectionSet.getVolumes().add(_managedBlockObject.getId().toString());
        }
        _logger.info("Creating ProtectionSet {} (hash {})", managedProtectionSet.forDisplay(), managedProtectionSet.hashCode());
        _dbClient.createObject(managedProtectionSet);
        // the protection set was created, so delete the unmanaged one
        _logger.info("Deleting UnManagedProtectionSet {} (hash {})", _unManagedProtectionSet.forDisplay(), _unManagedProtectionSet.hashCode());
        _dbClient.removeObject(_unManagedProtectionSet);
    }
    // commit the BlockConsistencyGroup, if created
    if (null != getManagedBlockConsistencyGroup()) {
        _logger.info("Creating BlockConsistencyGroup {} (hash {})", _managedBlockConsistencyGroup.forDisplay(), _managedBlockConsistencyGroup.hashCode());
        _dbClient.createObject(_managedBlockConsistencyGroup);
    }
    for (Entry<ExportGroup, Boolean> entry : getRpExportGroupMap().entrySet()) {
        ExportGroup exportGroup = entry.getKey();
        boolean exportGroupIsCreated = entry.getValue();
        if (exportGroupIsCreated) {
            _logger.info("Creating ExportGroup {} (hash {})", exportGroup.forDisplay(), exportGroup.hashCode());
            _dbClient.createObject(exportGroup);
        } else {
            _logger.info("Updating ExportGroup {} (hash {})", exportGroup.forDisplay(), exportGroup.hashCode());
            _dbClient.updateObject(exportGroup);
        }
    }
    super.commit();
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) DataObject(com.emc.storageos.db.client.model.DataObject) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 34 with DataObject

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

the class VplexVolumeIngestionContext method createVplexMirrorObjects.

/**
 * Create a VplexMirror database object if a VPLEX native mirror is present.
 * This should be called after the parent virtual volume has already been ingested.
 *
 * @param context the VplexBackendIngestionContext
 * @param virtualVolume the ingested virtual volume's Volume object.
 */
private void createVplexMirrorObjects() {
    if (!getUnmanagedVplexMirrors().isEmpty()) {
        Volume virtualVolume = (Volume) _parentRequestContext.getProcessedBlockObject(getUnmanagedVirtualVolume().getNativeGuid());
        _logger.info("creating VplexMirror object for virtual volume " + virtualVolume.getLabel());
        for (Entry<UnManagedVolume, String> entry : getUnmanagedVplexMirrors().entrySet()) {
            // find mirror and create a VplexMirror object
            BlockObject mirror = getBlockObjectsToBeCreatedMap().get(entry.getKey().getNativeGuid().replace(VolumeIngestionUtil.UNMANAGEDVOLUME, VolumeIngestionUtil.VOLUME));
            if (null != mirror) {
                _logger.info("processing mirror " + mirror.getLabel());
                if (mirror instanceof Volume) {
                    Volume mirrorVolume = (Volume) mirror;
                    // create VplexMirror set all the basic properties
                    VplexMirror vplexMirror = new VplexMirror();
                    vplexMirror.setId(URIUtil.createId(VplexMirror.class));
                    vplexMirror.setCapacity(mirrorVolume.getCapacity());
                    vplexMirror.setLabel(mirrorVolume.getLabel());
                    vplexMirror.setNativeId(entry.getValue());
                    // For Vplex virtual volumes set allocated capacity to 0 (cop-18608)
                    vplexMirror.setAllocatedCapacity(0L);
                    vplexMirror.setProvisionedCapacity(mirrorVolume.getProvisionedCapacity());
                    vplexMirror.setSource(new NamedURI(virtualVolume.getId(), virtualVolume.getLabel()));
                    vplexMirror.setStorageController(virtualVolume.getStorageController());
                    vplexMirror.setTenant(mirrorVolume.getTenant());
                    vplexMirror.setThinPreAllocationSize(mirrorVolume.getThinVolumePreAllocationSize());
                    vplexMirror.setThinlyProvisioned(mirrorVolume.getThinlyProvisioned());
                    vplexMirror.setVirtualArray(mirrorVolume.getVirtualArray());
                    vplexMirror.setVirtualPool(mirrorVolume.getVirtualPool());
                    // set the associated volume for this VplexMirror
                    StringSet associatedVolumes = new StringSet();
                    associatedVolumes.add(mirrorVolume.getId().toString());
                    vplexMirror.setAssociatedVolumes(associatedVolumes);
                    // VplexMirror will have the same project
                    // as the virtual volume (i.e., the front-end project)
                    // but the mirror backend will have the backend project
                    vplexMirror.setProject(new NamedURI(getFrontendProject().getId(), mirrorVolume.getLabel()));
                    mirrorVolume.setProject(new NamedURI(getBackendProject().getId(), mirrorVolume.getLabel()));
                    // update flags on mirror volume
                    Set<DataObject> updatedObjects = getDataObjectsToBeUpdatedMap().get(mirrorVolume.getNativeGuid());
                    if (updatedObjects == null) {
                        updatedObjects = new HashSet<DataObject>();
                        getDataObjectsToBeUpdatedMap().put(mirrorVolume.getNativeGuid(), updatedObjects);
                    }
                    VolumeIngestionUtil.clearInternalFlags(this, mirrorVolume, updatedObjects, _dbClient);
                    // VPLEX backend volumes should still have the INTERNAL_OBJECT flag
                    mirrorVolume.addInternalFlags(Flag.INTERNAL_OBJECT);
                    // deviceLabel will be the very last part of the native guid
                    String[] devicePathParts = entry.getValue().split("/");
                    String deviceName = devicePathParts[devicePathParts.length - 1];
                    vplexMirror.setDeviceLabel(deviceName);
                    // save the new VplexMirror & persist backend & updated objects
                    getCreatedVplexMirrors().add(vplexMirror);
                    // set mirrors property on the parent virtual volume
                    StringSet mirrors = virtualVolume.getMirrors();
                    if (mirrors == null) {
                        mirrors = new StringSet();
                    }
                    mirrors.add(vplexMirror.getId().toString());
                    virtualVolume.setMirrors(mirrors);
                }
            }
        }
    }
}
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) NamedURI(com.emc.storageos.db.client.model.NamedURI) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 35 with DataObject

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

the class DataObjectChangeAnalyzer method lookForChanges.

/**
 * Scans the methods looking for ones annotated with the Name annotation.
 * When found (if not excluded), invokes the method on each of the DataObjects
 * and then compares the results.
 *
 * @param left
 * @param right
 * @param changes
 * @param included -- If not null, only fields in included are checked.
 * @param excluded -- Fields that are excluded are not checked. Must not be null.
 * @param contained -- If not null, values for fields in contained are checked.
 */
private static void lookForChanges(DataObject left, DataObject right, HashMap<String, Change> changes, Set<String> included, Set<String> excluded, Set<String> contained) {
    Class refClass = left.getClass();
    Method[] methods = refClass.getMethods();
    for (Method method : methods) {
        boolean contain = false;
        // We only analyze methods that have the "Name" annotation
        Name nameAnn = method.getAnnotation(Name.class);
        if (nameAnn == null) {
            continue;
        }
        String key = nameAnn.value();
        // If contained is not null and it contains the key set contain flag to true
        if (contained != null && contained.contains(key)) {
            contain = true;
        } else // If included is not null, and does not contain the name, exclude it.
        if (included != null && !included.contains(key)) {
            continue;
        }
        // Skip any excluded annotation names
        if (excluded.contains(key)) {
            continue;
        }
        Class type = method.getReturnType();
        try {
            Object obja = method.invoke(left);
            Object objb = method.invoke(right);
            if (type == StringSet.class) {
                if (contain) {
                    analyzeNewStringSetContainsOldStringSetValues((StringSet) obja, (StringSet) objb, key, changes);
                } else {
                    analyzeStringSets((StringSet) obja, (StringSet) objb, key, changes);
                }
            } else if (type == StringMap.class) {
                analyzeStringMaps((StringMap) obja, (StringMap) objb, key, changes);
            } else if (type == StringSetMap.class) {
                analyzeStringSetMaps((StringSetMap) obja, (StringSetMap) objb, key, changes);
            } else {
                if (!isEqual(obja, objb)) {
                    Change change = new Change(key, obja, objb, nameAnn.value());
                    changes.put(key, change);
                }
            }
        } catch (IllegalAccessException ex) {
            throw new ServiceCodeException(ServiceCode.UNFORSEEN_ERROR, ex, ex.getMessage(), new String[] {});
        } catch (InvocationTargetException ex) {
            throw new ServiceCodeException(ServiceCode.UNFORSEEN_ERROR, ex, ex.getMessage(), new String[] {});
        }
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) DataObject(com.emc.storageos.db.client.model.DataObject) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Name(com.emc.storageos.db.client.model.Name)

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