use of com.emc.storageos.db.client.model.AbstractChangeTrackingSet in project coprhd-controller by CoprHD.
the class VolumeIngestionUtil method isRpExportMask.
/**
* Returns true if the given UnManagedExportMask is for a RecoverPoint Export.
*
* @param uem the UnManagedExportMask to check
* @param dbClient a reference to the database client
* @return true if the given UnManagedExportMask is for a RecoverPoint Export
*/
public static boolean isRpExportMask(UnManagedExportMask uem, DbClient dbClient) {
for (String wwn : uem.getKnownInitiatorNetworkIds()) {
List<URI> protectionSystemUris = dbClient.queryByType(ProtectionSystem.class, true);
List<ProtectionSystem> protectionSystems = dbClient.queryObject(ProtectionSystem.class, protectionSystemUris);
for (ProtectionSystem protectionSystem : protectionSystems) {
for (Entry<String, AbstractChangeTrackingSet<String>> siteInitEntry : protectionSystem.getSiteInitiators().entrySet()) {
if (siteInitEntry.getValue().contains(wwn)) {
_logger.info("this is a RecoverPoint related UnManagedExportMask: " + uem.getMaskName());
return true;
}
}
}
}
return false;
}
use of com.emc.storageos.db.client.model.AbstractChangeTrackingSet in project coprhd-controller by CoprHD.
the class RPCommunicationInterface method discoverAssociatedStorageSystems.
/**
* Discovers the Storage Systems associated to the Protection System.
*
* @param protectionSystem A reference to the Protection System
*/
private void discoverAssociatedStorageSystems(ProtectionSystem protectionSystem) {
// Find all the RPSiteArrays that are associated to this protection system
List<RPSiteArray> siteArrays = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, RPSiteArray.class, AlternateIdConstraint.Factory.getConstraint(RPSiteArray.class, "rpProtectionSystem", protectionSystem.getId().toString()));
// For each RPSiteArray, if there is a Storage System, add it to the list of
// associated Storage Systems for this Protection System
// TODO: May not be the most efficient way to do this; suggested that we have a way to determine
// which objects in the StringSet are new, modified, or old and go from there. It could be that
// nothing really changed.
// But for now, force the associatedStorageSystems StringSet to be cleared and
// use the setter so that setChanged(true) is invoked for Cassandra.
StringSet associatedStorageSystems = protectionSystem.getAssociatedStorageSystems();
associatedStorageSystems.clear();
protectionSystem.setAssociatedStorageSystems(associatedStorageSystems);
for (RPSiteArray siteArray : siteArrays) {
if (siteArray != null && siteArray.getStorageSystem() != null) {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, siteArray.getStorageSystem());
String serialNumber = storageSystem.getSerialNumber();
// serial number from the storage system.
if (protectionSystem.getSiteVisibleStorageArrays() != null) {
for (Map.Entry<String, AbstractChangeTrackingSet<String>> clusterStorageSystemSerialNumberEntry : protectionSystem.getSiteVisibleStorageArrays().entrySet()) {
if (siteArray.getRpInternalSiteName().equals(clusterStorageSystemSerialNumberEntry.getKey())) {
for (String clusterSerialNumber : clusterStorageSystemSerialNumberEntry.getValue()) {
// Helper method to load the storage system by serial number
URI foundStorageSystemURI = ConnectivityUtil.findStorageSystemBySerialNumber(clusterSerialNumber, _dbClient, StorageSystemType.BLOCK);
if (storageSystem.getId().equals(foundStorageSystemURI)) {
serialNumber = clusterSerialNumber;
break;
}
}
}
}
}
// the VPLEX.
if (ConnectivityUtil.isAVPlex(storageSystem) && serialNumber.contains(":")) {
String[] splitSerialNumber = serialNumber.split(":");
String firstHalf = splitSerialNumber[0];
String secondHalf = splitSerialNumber[1];
// Check the network connectivity between the RP site and the storage array
if (isNetworkConnected(firstHalf, siteArray)) {
// Add first half
protectionSystem.getAssociatedStorageSystems().add(ProtectionSystem.generateAssociatedStorageSystem(siteArray.getRpInternalSiteName(), String.valueOf(firstHalf)));
}
// Second half to be added next
serialNumber = secondHalf;
}
// Check the network connectivity between the RP site and the storage array
if (isNetworkConnected(serialNumber, siteArray)) {
protectionSystem.getAssociatedStorageSystems().add(ProtectionSystem.generateAssociatedStorageSystem(siteArray.getRpInternalSiteName(), String.valueOf(serialNumber)));
}
}
}
_dbClient.updateObject(protectionSystem);
}
use of com.emc.storageos.db.client.model.AbstractChangeTrackingSet in project coprhd-controller by CoprHD.
the class DbDependencyPurger method purge.
private <T extends DataObject> void purge(T dataObj, Set<URI> visited) throws DatabaseException {
if (dataObj == null || visited.contains(dataObj.getId())) {
return;
}
visited.add(dataObj.getId());
Class<? extends DataObject> type = dataObj.getClass();
List<DependencyTracker.Dependency> dependencyList = _dependencyTracker.getDependencies(type);
try {
for (DependencyTracker.Dependency dependence : dependencyList) {
// Query relational index to see if any dependents exist
Class<? extends DataObject> childType = dependence.getType();
ColumnField childField = dependence.getColumnField();
ContainmentConstraint constraint = new ContainmentConstraintImpl(dataObj.getId(), childType, childField);
URIQueryResultList list = new URIQueryResultList();
_dbClient.queryByConstraint(constraint, list);
if (!list.iterator().hasNext()) {
continue;
}
// used to remove efficiently identical URIs from the list.
HashSet<URI> childSet = new HashSet();
while (list.iterator().hasNext()) {
childSet.clear();
while (list.iterator().hasNext()) {
childSet.add(list.iterator().next());
if (childSet.size() >= MAX_PERSISTENCE_LIMIT) {
break;
}
}
List<URI> childUriList = new ArrayList(childSet);
List<? extends DataObject> children = _dbClient.queryObjectField(childType, childField.getName(), childUriList);
List<DataObject> decommissionedChildren = new ArrayList();
for (DataObject childObj : children) {
switch(childField.getType()) {
case TrackingSet:
case TrackingMap:
// assume @indexByKey is set
java.beans.PropertyDescriptor pd = childField.getPropertyDescriptor();
Object fieldValue = pd.getReadMethod().invoke(childObj);
boolean deactivateChildObj = false;
if (fieldValue != null) {
// should be always true.
if (AbstractChangeTrackingMap.class.isAssignableFrom(pd.getPropertyType())) {
AbstractChangeTrackingMap<?> trackingMap = (AbstractChangeTrackingMap<?>) fieldValue;
trackingMap.remove(dataObj.getId().toString());
if (trackingMap.isEmpty() && childField.deactivateIfEmpty()) {
deactivateChildObj = true;
}
} else if (AbstractChangeTrackingSet.class.isAssignableFrom(pd.getPropertyType())) {
AbstractChangeTrackingSet trackingSet = (AbstractChangeTrackingSet) fieldValue;
trackingSet.remove(dataObj.getId().toString());
if (trackingSet.isEmpty() && childField.deactivateIfEmpty()) {
deactivateChildObj = true;
}
}
if (deactivateChildObj) {
purge(childObj, visited);
childObj.setInactive(true);
_log.info("Deactivated db_object: type = {}, id = {}", childType.toString(), childObj.getId());
}
}
break;
default:
{
purge(childObj, visited);
childObj.setInactive(true);
_log.info("Deactivated db_object: type = {}, id = {}", childType.toString(), childObj.getId());
}
}
decommissionedChildren.add(childObj);
}
_dbClient.persistObject(decommissionedChildren);
}
}
}// should never get here....
catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
_log.error("Unexpected purge error", e);
throw DatabaseException.fatals.purgeFailed(e);
}
}
use of com.emc.storageos.db.client.model.AbstractChangeTrackingSet in project coprhd-controller by CoprHD.
the class ColumnField method serialize.
/**
* Serializes object field into database updates
*
* @param obj data object to serialize
* @param mutator row mutator to hold insertion queries
* @return boolean
* @throws DatabaseException
*/
public boolean serialize(DataObject obj, RowMutator mutator) {
try {
String id = obj.getId().toString();
if (isLazyLoaded() || _property.getReadMethod() == null) {
return false;
}
Object val = _property.getReadMethod().invoke(obj);
if (val == null) {
return false;
}
boolean changed = false;
switch(_colType) {
case NamedURI:
case Primitive:
{
if (!obj.isChanged(_name)) {
return false;
}
changed = addColumn(id, getColumnName(null, mutator), val, mutator, obj);
break;
}
case TrackingSet:
{
AbstractChangeTrackingSet valueSet = (AbstractChangeTrackingSet) val;
Set<?> addedSet = valueSet.getAddedSet();
if (addedSet != null) {
Iterator<?> it = valueSet.getAddedSet().iterator();
while (it.hasNext()) {
Object itVal = it.next();
String targetVal = valueSet.valToString(itVal);
changed |= addColumn(id, getColumnName(targetVal, mutator), itVal, mutator);
}
}
Set<?> removedVal = valueSet.getRemovedSet();
if (removedVal != null) {
Iterator<?> removedIt = removedVal.iterator();
while (removedIt.hasNext()) {
String targetVal = valueSet.valToString(removedIt.next());
if (_index == null) {
changed |= removeColumn(id, new ColumnWrapper(getColumnName(targetVal, mutator), targetVal), mutator);
} else {
addDeletionMark(id, getColumnName(targetVal, mutator), mutator);
changed = true;
}
}
}
break;
}
case TrackingMap:
{
AbstractChangeTrackingMap valueMap = (AbstractChangeTrackingMap) val;
Set<String> changedSet = valueMap.getChangedKeySet();
if (changedSet != null) {
Iterator<String> it = valueMap.getChangedKeySet().iterator();
while (it.hasNext()) {
String key = it.next();
Object entryVal = valueMap.get(key);
CompositeColumnName colName = getColumnName(key, mutator);
if (clockIndValue != null) {
int ordinal = ((ClockIndependentValue) entryVal).ordinal();
colName = getColumnName(key, String.format("%08d", ordinal), mutator);
}
changed |= addColumn(id, colName, valueMap.valToByte(entryVal), mutator);
}
}
Set<String> removedKey = valueMap.getRemovedKeySet();
if (removedKey != null) {
Iterator<String> removedIt = removedKey.iterator();
while (removedIt.hasNext()) {
String key = removedIt.next();
CompositeColumnName colName = getColumnName(key, mutator);
if (clockIndValue != null) {
Object removedVal = valueMap.getRemovedValue(key);
if (removedVal != null) {
colName = getColumnName(key, String.format("%08d", ((ClockIndependentValue) removedVal).ordinal()), mutator);
}
}
if (_index == null) {
changed |= removeColumn(id, new ColumnWrapper(colName, null), mutator);
} else {
addDeletionMark(id, colName, mutator);
changed = true;
}
}
}
break;
}
case TrackingSetMap:
{
AbstractChangeTrackingSetMap valueMap = (AbstractChangeTrackingSetMap) val;
Set<String> keys = valueMap.keySet();
if (keys != null) {
Iterator<String> it = keys.iterator();
while (it.hasNext()) {
String key = it.next();
AbstractChangeTrackingSet valueSet = valueMap.get(key);
Set<?> addedSet = valueSet.getAddedSet();
if (addedSet != null) {
Iterator<?> itSet = valueSet.getAddedSet().iterator();
while (itSet.hasNext()) {
String value = valueSet.valToString(itSet.next());
changed |= addColumn(id, getColumnName(key, value, mutator), value, mutator);
}
}
Set<?> removedVal = valueSet.getRemovedSet();
if (removedVal != null) {
Iterator<?> removedIt = removedVal.iterator();
while (removedIt.hasNext()) {
String targetVal = valueSet.valToString(removedIt.next());
if (_index == null) {
changed |= removeColumn(id, new ColumnWrapper(getColumnName(key, targetVal, mutator), targetVal), mutator);
} else {
addDeletionMark(id, getColumnName(key, targetVal, mutator), mutator);
changed = true;
}
}
}
}
}
break;
}
case NestedObject:
{
if (!obj.isChanged(_name)) {
break;
}
AbstractSerializableNestedObject nestedObject = (AbstractSerializableNestedObject) val;
changed |= addColumn(id, getColumnName(null, mutator), nestedObject.toBytes(), mutator);
}
}
return changed;
} catch (final InvocationTargetException e) {
throw DatabaseException.fatals.serializationFailedId(obj.getId(), e);
} catch (final IllegalAccessException e) {
throw DatabaseException.fatals.serializationFailedId(obj.getId(), e);
}
}
use of com.emc.storageos.db.client.model.AbstractChangeTrackingSet in project coprhd-controller by CoprHD.
the class ColumnValue method setField.
public static void setField(Column<CompositeColumnName> column, PropertyDescriptor pd, Object obj) {
try {
Class type = pd.getPropertyType();
Object objValue = null;
if (AbstractChangeTrackingSetMap.class.isAssignableFrom(type)) {
objValue = pd.getReadMethod().invoke(obj);
if (objValue == null) {
objValue = type.newInstance();
}
AbstractChangeTrackingSetMap<?> trackingMap = (AbstractChangeTrackingSetMap<?>) objValue;
String entryValue = column.getStringValue();
if (entryValue == null || entryValue.isEmpty()) {
trackingMap.removeNoTrack(column.getName().getTwo(), column.getName().getThree());
} else {
trackingMap.putNoTrack(column.getName().getTwo(), entryValue);
}
} else if (AbstractChangeTrackingMap.class.isAssignableFrom(type)) {
objValue = pd.getReadMethod().invoke(obj);
if (objValue == null) {
objValue = type.newInstance();
}
AbstractChangeTrackingMap<?> trackingMap = (AbstractChangeTrackingMap<?>) objValue;
byte[] entryValue = column.getByteArrayValue();
if (entryValue == null || entryValue.length == 0) {
trackingMap.removeNoTrack(column.getName().getTwo());
} else {
trackingMap.putNoTrack(column.getName().getTwo(), column.getByteArrayValue());
}
} else if (AbstractChangeTrackingSet.class.isAssignableFrom(type)) {
objValue = pd.getReadMethod().invoke(obj);
if (objValue == null) {
objValue = type.newInstance();
}
AbstractChangeTrackingSet trackingSet = (AbstractChangeTrackingSet) objValue;
String entryValue = column.getStringValue();
if (entryValue == null || entryValue.isEmpty()) {
trackingSet.removeNoTrack(column.getName().getTwo());
} else {
trackingSet.addNoTrack(entryValue);
}
} else {
objValue = getPrimitiveColumnValue(column, pd);
}
pd.getWriteMethod().invoke(obj, objValue);
} catch (IllegalAccessException e) {
// should never get here
throw DatabaseException.fatals.deserializationFailedProperty(pd.getName(), e);
} catch (InvocationTargetException e) {
throw DatabaseException.fatals.deserializationFailedProperty(pd.getName(), e);
} catch (InstantiationException e) {
throw DatabaseException.fatals.deserializationFailedProperty(pd.getName(), e);
}
}
Aggregations