use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class DbCli method printFieldsByCf.
/**
* Print the fields' info of column family.
*
* @Param cfName
*/
public void printFieldsByCf(String cfName) {
// fill in type from cfName
final Class clazz = getClassFromCFName(cfName);
if (clazz == null) {
return;
}
if (DataObject.class.isAssignableFrom(clazz)) {
DataObjectType doType = TypeMap.getDoType(clazz);
System.out.println(String.format("Column Family: %s", doType.getCF().getName()));
Collection<ColumnField> cfs = doType.getColumnFields();
Iterator it = cfs.iterator();
while (it.hasNext()) {
ColumnField field = (ColumnField) it.next();
System.out.println(String.format("\tfield=%-30s\ttype=%s", field.getName(), field.getPropertyDescriptor().getPropertyType().toString().substring(6)));
}
}
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class DBClient method checkDB.
/**
* This db consistency check is for a specific CF,
* It could also detect the 2 paths same as {@link DBClient#checkDB()}
*
* @param cfName
*/
public void checkDB(String cfName) {
final Class clazz = getClassFromCFName(cfName);
if (clazz == null) {
return;
}
DataObjectType dataCf = TypeMap.getDoType(clazz);
DbConsistencyCheckerHelper helper = new DbConsistencyCheckerHelper(_dbClient);
int corruptedCount = 0;
try {
logMsg(DbConsistencyCheckerHelper.MSG_OBJECT_ID_START);
int illegalCount = helper.checkDataObject(dataCf, true);
logMsg(String.format(DbConsistencyCheckerHelper.MSG_OBJECT_ID_END_SPECIFIED, dataCf.getCF().getName(), illegalCount));
corruptedCount += illegalCount;
logMsg(DbConsistencyCheckerHelper.MSG_OBJECT_INDICES_START);
CheckResult checkResult = new CheckResult();
helper.checkCFIndices(dataCf, true, checkResult);
logMsg(checkResult.toString());
logMsg(String.format(DbConsistencyCheckerHelper.MSG_OBJECT_INDICES_END_SPECIFIED, dataCf.getCF().getName(), checkResult.getTotal()));
corruptedCount += checkResult.getTotal();
logMsg(DbConsistencyCheckerHelper.MSG_INDEX_OBJECTS_START);
Collection<DbConsistencyCheckerHelper.IndexAndCf> idxCfs = helper.getIndicesOfCF(dataCf).values();
checkResult = new CheckResult();
for (DbConsistencyCheckerHelper.IndexAndCf indexAndCf : idxCfs) {
helper.checkIndexingCF(indexAndCf, true, checkResult);
}
logMsg(checkResult.toString());
logMsg(String.format(DbConsistencyCheckerHelper.MSG_INDEX_OBJECTS_END_SPECIFIED, idxCfs.size(), dataCf.getCF().getName(), checkResult.getTotal()));
corruptedCount += checkResult.getTotal();
String msg = generateSummaryForDBChecker(corruptedCount != 0);
System.out.println(msg);
log.info(msg);
} catch (ConnectionException e) {
log.error("Database connection exception happens, fail to connect: ", e);
System.err.println("The checker has been stopped by database connection exception. " + "Please see the log for more information.");
} finally {
DbCheckerFileWriter.close();
}
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class MailHandler method getMailAddressOfUser.
/**
* get user's mail address from UserPreference CF
*
* @param userName
* @return
*/
private String getMailAddressOfUser(String userName) {
DataObjectType doType = TypeMap.getDoType(UserPreferences.class);
AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(UserPreferences.USER_ID), userName);
NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
this.dbClient.queryByConstraint(constraint, queryResults);
List<URI> userPrefsIds = new ArrayList<>();
for (NamedElementQueryResultList.NamedElement namedElement : queryResults) {
userPrefsIds.add(namedElement.getId());
}
if (userPrefsIds.isEmpty()) {
return null;
}
final List<UserPreferences> userPrefs = new ArrayList<>();
Iterator<UserPreferences> iter = this.dbClient.queryIterativeObjects(UserPreferences.class, userPrefsIds);
while (iter.hasNext()) {
userPrefs.add(iter.next());
}
if (userPrefs.size() > 1) {
throw new IllegalStateException("There should only be 1 user preferences object for a user");
}
if (userPrefs.isEmpty()) {
// if there isn't a user prefs object in the DB yet then we haven't saved one for this user yet.
return null;
}
return userPrefs.get(0).getEmail();
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class SchedulerConfig method getMailAddressOfUser.
/**
* get user's mail address from UserPreference CF
*
* @param userName
* @return
*/
private String getMailAddressOfUser(String userName) {
DataObjectType doType = TypeMap.getDoType(UserPreferences.class);
AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(UserPreferences.USER_ID), userName);
NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
this.dbClient.queryByConstraint(constraint, queryResults);
List<URI> userPrefsIds = new ArrayList<>();
for (NamedElementQueryResultList.NamedElement namedElement : queryResults) {
userPrefsIds.add(namedElement.getId());
}
if (userPrefsIds.isEmpty()) {
return null;
}
final List<UserPreferences> userPrefs = new ArrayList<>();
Iterator<UserPreferences> iter = this.dbClient.queryIterativeObjects(UserPreferences.class, userPrefsIds);
while (iter.hasNext()) {
userPrefs.add(iter.next());
}
if (userPrefs.size() > 1) {
throw new IllegalStateException("There should only be 1 user preferences object for a user");
}
if (userPrefs.isEmpty()) {
// if there isn't a user prefs object in the DB yet then we haven't saved one for this user yet.
return null;
}
return userPrefs.get(0).getEmail();
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class PersistingChangesTest method testCleanupSoftReference.
@Test
public void testCleanupSoftReference() throws ConnectionException {
Volume volume = new Volume();
URI id = URIUtil.createId(Volume.class);
URI pool = URIUtil.createId(StoragePool.class);
volume.setId(id);
volume.setLabel("origin");
volume.setPool(pool);
volume.setNativeGuid("native_guid");
volume.setNativeId("native_id");
volume.setCompositionType("compositionType");
volume.setInactive(false);
volume.setAllocatedCapacity(1000L);
volume.setProvisionedCapacity(2000L);
dbClient.updateObject(volume);
// Search the label index directly
String labelFieldName = "label";
int labelCount = getIndexRecordCount(labelFieldName);
// By default, label index contains one record for VirtualDataCenter
Assert.assertEquals(2, labelCount);
List<URI> volumes = dbClient.queryByType(Volume.class, true);
int size = 0;
for (URI uri : volumes) {
Volume entry = dbClient.queryObject(Volume.class, uri);
_log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
Assert.assertEquals("origin", entry.getLabel());
}
Assert.assertEquals(1, size);
_log.info("\nStart to update with new label");
// Mock warning when listToCleanRef is null in indexCleaner
this.dbClient = super.getDbClient(new DbClientTest.DbClientImplUnitTester() {
@Override
public synchronized void start() {
super.start();
_indexCleaner = new IndexCleaner() {
@Override
public void cleanIndex(RowMutator mutator, DataObjectType doType, SoftReference<IndexCleanupList> listToCleanRef) {
listToCleanRef.clear();
super.cleanIndex(mutator, doType, listToCleanRef);
}
};
}
});
volume = dbClient.queryObject(Volume.class, id);
volume.setLabel("new");
dbClient.updateObject(volume);
// Search the label index directly
labelCount = getIndexRecordCount(labelFieldName);
// We mocked indexCleaner, so that old label index couldn't be removed, still in DB
Assert.assertEquals(3, labelCount);
volumes = dbClient.queryByType(Volume.class, true);
size = 0;
for (URI uri : volumes) {
Volume entry = dbClient.queryObject(Volume.class, uri);
_log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
Assert.assertEquals("new", entry.getLabel());
}
Assert.assertEquals(1, size);
// Remove the object
_log.info("\nStart to remove volume");
this.dbClient = super.getDbClient(new DbClientTest.DbClientImplUnitTester());
volume = dbClient.queryObject(Volume.class, id);
dbClient.removeObject(volume);
// Search the label index directly
labelCount = getIndexRecordCount(labelFieldName);
// All the label index related to volume should be removed.
Assert.assertEquals(1, labelCount);
volumes = dbClient.queryByType(Volume.class, true);
size = 0;
for (URI uri : volumes) {
Volume entry = dbClient.queryObject(Volume.class, uri);
_log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
}
Assert.assertEquals(0, size);
}
Aggregations