use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class StatsCleanupMigration method process.
@Override
public void process() throws MigrationCallbackException {
log.info("begin to cleanup stats CF and change it compaction strategy");
DbClientImpl dbClient = (DbClientImpl) getDbClient();
TimeSeriesType<Stat> doType = TypeMap.getTimeSeriesType(StatTimeSeries.class);
try {
dbClient.getLocalContext().getKeyspace().prepareQuery(doType.getCf()).setConsistencyLevel(ConsistencyLevel.CL_ALL).withCql(String.format("TRUNCATE TABLE \"%s\"", doType.getCf().getName())).execute();
dbClient.getLocalContext().getKeyspace().prepareQuery(doType.getCf()).withCql(String.format("ALTER TABLE \"%s\" WITH compaction = {'class': 'SizeTieredCompactionStrategy'}", doType.getCf().getName())).execute();
} catch (Exception e) {
log.error("Failed to cleanup stats CF {}", e);
throw new MigrationCallbackException("Failed to cleanup stats CF", e);
}
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class PersistingChangesTest method testPersistingChanges.
/**
* Tests the changes tracking and the logic of persisting only diffs is working as expected
*/
@Test
public void testPersistingChanges() throws Exception {
VirtualPool vpool = new VirtualPool();
vpool.setId(URIUtil.createId(VirtualPool.class));
vpool.setLabel("GOLD");
vpool.setType("file");
vpool.setProtocols(new StringSet());
this.dbClient.persistObject(vpool);
TenantOrg tenant = new TenantOrg();
tenant.setId(URIUtil.createId(TenantOrg.class));
tenant.setLabel("test tenant");
tenant.setRoleAssignments(new StringSetMap());
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel("fileshare");
fs.setCapacity(102400L);
fs.setVirtualPool(vpool.getId());
fs.setOpStatus(new OpStatusMap());
fs.setTenant(new NamedURI(tenant.getId(), fs.getLabel()));
Operation op = new Operation();
op.setStatus(Operation.Status.pending.name());
fs.getOpStatus().put("filesharereq", op);
dbClient.persistObject(fs);
fs.getOpStatus().put("filesharereq", op);
this.dbClient.persistObject(fs);
FileShare fsQ = this.dbClient.queryObject(FileShare.class, fs.getId());
FileShare fsE = this.dbClient.queryObject(FileShare.class, fs.getId());
// file share creation
Assert.assertEquals(fsQ.getId(), fs.getId());
Assert.assertEquals(fsQ.getLabel(), "fileshare");
Assert.assertEquals((long) fsQ.getCapacity(), 102400L);
Assert.assertEquals(fsQ.getVirtualPool(), vpool.getId());
Assert.assertEquals(fsQ.getOpStatus().get("filesharereq").getStatus(), Operation.Status.pending.name());
fsQ.setMountPath("test/mount/path");
fsQ.setNativeGuid("nativeguid");
fsQ.setFsExports(new FSExportMap());
FileExport fsExport = new FileExport(Arrays.asList("client"), "storageport", "sys", "rw", "root", "nfs");
fsQ.getFsExports().put("fsexport1", fsExport);
op = new Operation();
op.setStatus(Operation.Status.ready.name());
fsQ.getOpStatus().put("filesharereq", op);
// request to add exports
Assert.assertEquals(fsE.getId(), fs.getId());
Assert.assertEquals(fsE.getLabel(), "fileshare");
Assert.assertEquals((long) fsE.getCapacity(), 102400L);
Assert.assertEquals(fsE.getVirtualPool(), vpool.getId());
Assert.assertEquals(fsE.getOpStatus().get("filesharereq").getStatus(), Operation.Status.pending.name());
fsE.setLabel("changed label");
op = new Operation();
op.setStatus(Operation.Status.pending.name());
fsE.getOpStatus().put("adding export", op);
// persist - in reverse order
this.dbClient.persistObject(fsQ);
this.dbClient.persistObject(fsE);
// test create and update status objects
FileShare fs_tasks = new FileShare();
fs_tasks.setId(URIUtil.createId(FileShare.class));
fs_tasks.setLabel("fileshare1");
fs_tasks.setCapacity(102400L);
fs_tasks.setVirtualPool(vpool.getId());
fs_tasks.setOpStatus(new OpStatusMap());
Operation op1 = new Operation();
op1.setStatus(Operation.Status.pending.name());
op1.setDescription("sample description");
fs_tasks.getOpStatus().createTaskStatus("filesharereq2", op1);
fs_tasks.setTenant(new NamedURI(tenant.getId(), fs.getLabel()));
this.dbClient.persistObject(fs_tasks);
FileShare fsBeforeUpdate = this.dbClient.queryObject(FileShare.class, fs_tasks.getId());
Operation opActual = fsBeforeUpdate.getOpStatus().get("filesharereq2");
Assert.assertNotNull(opActual.getStartTime());
Assert.assertNull(opActual.getEndTime());
this.dbClient.updateTaskOpStatus(FileShare.class, fs_tasks.getId(), "filesharereq2", new Operation(Operation.Status.ready.name()));
FileShare fsAfterUpdate = this.dbClient.queryObject(FileShare.class, fs_tasks.getId());
opActual = fsAfterUpdate.getOpStatus().get("filesharereq2");
Assert.assertNotNull(opActual.getStartTime());
Assert.assertNotNull(opActual.getEndTime());
// make sure both changes exist
FileShare fsV = this.dbClient.queryObject(FileShare.class, fs.getId());
Assert.assertEquals(fsV.getId(), fs.getId());
Assert.assertEquals(fsV.getLabel(), "changed label");
Assert.assertEquals((long) fsV.getCapacity(), 102400L);
Assert.assertEquals(fsV.getVirtualPool(), vpool.getId());
Assert.assertEquals(fsV.getOpStatus().get("filesharereq").getStatus(), Operation.Status.ready.name());
Assert.assertEquals(fsV.getOpStatus().get("adding export").getStatus(), Operation.Status.pending.name());
Assert.assertEquals(fsV.getNativeGuid(), "nativeguid");
Assert.assertEquals(fsV.getFsExports().get("fsexport1"), fsExport);
Assert.assertEquals(fsV.getMountPath(), "test/mount/path");
// update from StringMap
op = new Operation();
op.setStatus(Operation.Status.error.name());
fsV.getOpStatus().put("filesharereq", op);
this.dbClient.persistObject(fsV);
FileShare fs1 = this.dbClient.queryObject(FileShare.class, fs.getId());
Assert.assertEquals(Operation.Status.error.name(), fs1.getOpStatus().get("filesharereq").getStatus());
Assert.assertEquals(Operation.Status.pending.name(), fs1.getOpStatus().get("adding export").getStatus());
// SetMap tests
StringSetMap expected = new StringSetMap();
String indexkey1 = "indexkey1";
expected.put(indexkey1, "role1");
tenant.addRole(indexkey1, "role1");
expected.put(indexkey1, "role2");
tenant.addRole(indexkey1, "role2");
expected.put("indexkey2", "role3");
tenant.addRole("indexkey2", "role3");
this.dbClient.persistObject(tenant);
TenantOrg read = this.dbClient.queryObject(TenantOrg.class, tenant.getId());
Assert.assertEquals(expected, read.getRoleAssignments());
read.removeRole("indexkey2", "role3");
this.dbClient.persistObject(read);
class PermResults extends QueryResultList<URI> {
StringSetMap permissionsMap = new StringSetMap();
@Override
public URI createQueryHit(URI uri) {
// none
return uri;
}
@Override
public URI createQueryHit(URI uri, String permission, UUID timestamp) {
permissionsMap.put(uri.toString(), permission);
return uri;
}
@Override
public URI createQueryHit(URI uri, Object entry) {
return createQueryHit(uri);
}
public StringSetMap getPermissionsMap() {
return permissionsMap;
}
}
PermResults results = new PermResults();
this.dbClient.queryByConstraint(ContainmentPermissionsConstraint.Factory.getTenantsWithPermissionsConstraint(indexkey1), results);
expected = new StringSetMap();
expected.put(tenant.getId().toString(), "role1");
expected.put(tenant.getId().toString(), "role2");
for (Iterator<URI> iterator = results.iterator(); iterator.hasNext(); iterator.next()) {
;
}
Assert.assertEquals(expected, results.getPermissionsMap());
// just remove
expected = new StringSetMap();
expected.put(indexkey1, "role1");
expected.put(indexkey1, "role2");
read = this.dbClient.queryObject(TenantOrg.class, tenant.getId());
Assert.assertEquals(expected, read.getRoleAssignments());
read.removeRole(indexkey1, "role2");
this.dbClient.updateAndReindexObject(read);
PermResults newResults = new PermResults();
this.dbClient.queryByConstraint(ContainmentPermissionsConstraint.Factory.getTenantsWithPermissionsConstraint(indexkey1), newResults);
for (Iterator<URI> iterator = newResults.iterator(); iterator.hasNext(); iterator.next()) {
;
}
expected = new StringSetMap();
expected.put(tenant.getId().toString(), "role1");
Assert.assertEquals(expected, newResults.getPermissionsMap());
// query
TenantOrg tenant2 = new TenantOrg();
tenant2.setId(URIUtil.createId(TenantOrg.class));
tenant2.setLabel("test tenant2");
this.dbClient.updateAndReindexObject(tenant2);
List<URI> uris = new ArrayList<URI>();
uris.add(tenant.getId());
uris.add(tenant2.getId());
List<TenantOrg> tenantOrgs = this.dbClient.queryObjectField(TenantOrg.class, "label", uris);
Assert.assertTrue(tenantOrgs.size() == 2);
for (TenantOrg each : tenantOrgs) {
Assert.assertTrue((each.getId().equals(tenant.getId()) && each.getLabel().equals("test tenant")) || (each.getId().equals(tenant2.getId()) && each.getLabel().equals("test tenant2")));
}
final int count = 1000;
final int indexCount = 10;
String key = "scale-test-index-key ";
String val = "scale-test-index-value ";
String key2 = "scale-test-index-key2 ";
String val2 = "scale-test-index-value2 ";
List<URI> uriList = new ArrayList<URI>(count);
long createTime = 0;
long updateTime = 0;
long updateTime2 = 0;
long updateTime3 = 0;
for (int i = 0; i < count; i++) {
long startTime = System.currentTimeMillis();
TenantOrg t = new TenantOrg();
t.setId(URIUtil.createId(TenantOrg.class));
t.setLabel("test tenant " + i);
t.setRoleAssignments(new StringSetMap());
for (int j = 0; j < indexCount; j++) {
t.addRole(key + j, val + j);
}
this.dbClient.persistObject(t);
createTime += System.currentTimeMillis() - startTime;
uriList.add(t.getId());
// update 1 - index modifications
startTime = System.currentTimeMillis();
TenantOrg t2 = new TenantOrg();
t2.setId(t.getId());
for (int j = 0; j < indexCount; j++) {
t2.removeRole(key + j, val + j);
t2.addRole(key2 + j, val2 + j);
}
this.dbClient.updateAndReindexObject(t2);
updateTime += System.currentTimeMillis() - startTime;
// update 2 - label modification
startTime = System.currentTimeMillis();
t2 = new TenantOrg();
t2.setId(t.getId());
t2.setLabel(t.getLabel() + " modified");
this.dbClient.updateAndReindexObject(t2);
updateTime2 += System.currentTimeMillis() - startTime;
// update 3 - non-indexed field modification
startTime = System.currentTimeMillis();
t2 = new TenantOrg();
t2.setId(t.getId());
t2.setDescription("test tenant description");
this.dbClient.updateAndReindexObject(t2);
updateTime3 += System.currentTimeMillis() - startTime;
}
_log.info("Total objects created: " + count);
_log.info("Total create time: " + createTime + "msec");
_log.info("Total update time (multiple index fields): " + updateTime + "msec");
_log.info("Total update time (label only): " + updateTime2 + "msec");
_log.info("Total update time (non indexed field): " + updateTime3 + "msec");
class CountResults extends QueryResultList<URI> {
public int got = 0;
@Override
public URI createQueryHit(URI uri) {
// none
return uri;
}
@Override
public URI createQueryHit(URI uri, String permission, UUID timestamp) {
got++;
return uri;
}
@Override
public URI createQueryHit(URI uri, Object entry) {
return createQueryHit(uri);
}
public void verify() {
Assert.assertEquals(count, got);
}
}
for (int i = 0; i < indexCount; i++) {
CountResults countResults = new CountResults();
this.dbClient.queryByConstraint(ContainmentPermissionsConstraint.Factory.getTenantsWithPermissionsConstraint(key2 + i), countResults);
for (Iterator<URI> iterator = countResults.iterator(); iterator.hasNext(); iterator.next()) {
;
}
countResults.verify();
}
// test decommissioned index
tenant = this.dbClient.queryObject(TenantOrg.class, tenant.getId());
tenant.setInactive(true);
tenant2 = this.dbClient.queryObject(TenantOrg.class, tenant2.getId());
tenant2.setInactive(true);
this.dbClient.persistObject(tenant, tenant2);
URIQueryResultList list = new URIQueryResultList();
this.dbClient.queryByConstraint(DecommissionedConstraint.Factory.getDecommissionedObjectsConstraint(TenantOrg.class, 0), list);
List<URI> gotUris = new ArrayList<URI>();
for (Iterator<URI> iterator = list.iterator(); iterator.hasNext(); ) {
gotUris.add(iterator.next());
}
Assert.assertTrue(gotUris.size() >= 2);
Assert.assertTrue(gotUris.contains(tenant.getId()));
Assert.assertTrue(gotUris.contains(tenant2.getId()));
// test time slicing - 1
long nowTimeUsec = TimeUUIDUtils.getMicrosTimeFromUUID(TimeUUIDUtils.getUniqueTimeUUIDinMicros());
list = new URIQueryResultList();
this.dbClient.queryByConstraint(DecommissionedConstraint.Factory.getDecommissionedObjectsConstraint(TenantOrg.class, nowTimeUsec), list);
gotUris = new ArrayList<URI>();
for (Iterator<URI> iterator = list.iterator(); iterator.hasNext(); ) {
gotUris.add(iterator.next());
}
Assert.assertTrue(gotUris.size() >= 2);
Assert.assertTrue(gotUris.contains(tenant.getId()));
Assert.assertTrue(gotUris.contains(tenant2.getId()));
// test time slicing - 2
list = new URIQueryResultList();
this.dbClient.queryByConstraint(DecommissionedConstraint.Factory.getDecommissionedObjectsConstraint(TenantOrg.class, nowTimeUsec - (60 * 1000 * 1000)), list);
gotUris = new ArrayList<URI>();
for (Iterator<URI> iterator = list.iterator(); iterator.hasNext(); ) {
gotUris.add(iterator.next());
}
Assert.assertEquals(0, gotUris.size());
// test remove object
((DbClientImpl) dbClient).internalRemoveObjects(tenant, tenant2);
read = this.dbClient.queryObject(TenantOrg.class, tenant.getId());
Assert.assertNull(read);
read = this.dbClient.queryObject(TenantOrg.class, tenant2.getId());
Assert.assertNull(read);
newResults = new PermResults();
this.dbClient.queryByConstraint(ContainmentPermissionsConstraint.Factory.getTenantsWithPermissionsConstraint(indexkey1), newResults);
for (Iterator<URI> iterator = newResults.iterator(); iterator.hasNext(); iterator.next()) {
;
}
Assert.assertTrue(newResults.getPermissionsMap().isEmpty());
newResults = new PermResults();
this.dbClient.queryByConstraint(ContainmentPermissionsConstraint.Factory.getTenantsWithPermissionsConstraint(indexkey1), newResults);
for (Iterator<URI> iterator = newResults.iterator(); iterator.hasNext(); iterator.next()) {
;
}
expected = new StringSetMap();
Assert.assertEquals(expected, newResults.getPermissionsMap());
for (int i = 0; i < indexCount; i++) {
CountResults countResults = new CountResults();
this.dbClient.queryByConstraint(ContainmentPermissionsConstraint.Factory.getTenantsWithPermissionsConstraint(key2 + i), countResults);
for (Iterator<URI> iterator = countResults.iterator(); iterator.hasNext(); iterator.next()) {
;
}
countResults.verify();
}
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class RowMutationTest method insertDataObject.
@Test
public void insertDataObject() throws ConnectionException {
String prefix = "AA";
Volume volume = new Volume();
URI id = URIUtil.createId(Volume.class);
URI pool = URIUtil.createId(StoragePool.class);
volume.setId(id);
volume.setLabel(prefix + "volume");
volume.setPool(pool);
volume.setNativeGuid(prefix + "native_guid-2");
volume.setNativeId(prefix + "native_id-2");
volume.setCompositionType(prefix + "compositionType");
volume.setInactive(false);
volume.setAllocatedCapacity(1000L);
volume.setProvisionedCapacity(2000L);
this.getDbClient().updateObject(volume);
Volume target = (Volume) this.getDbClient().queryObject(id);
Assert.assertNotNull(target);
Assert.assertEquals(target.getLabel(), volume.getLabel());
Assert.assertEquals(target.getPool(), volume.getPool());
Assert.assertEquals(target.getNativeGuid(), volume.getNativeGuid());
Assert.assertEquals(target.getNativeId(), volume.getNativeId());
Assert.assertEquals(target.getCompositionType(), volume.getCompositionType());
Assert.assertEquals(target.getAllocatedCapacity(), volume.getAllocatedCapacity());
Assert.assertEquals(target.getProvisionedCapacity(), volume.getProvisionedCapacity());
CqlStatement statement = ((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace().prepareCqlStatement();
String cql = String.format("select * from \"LabelPrefixIndex\" where key='%s' and column1='Volume' and column2='%s' and column3='%s' and column4='%s'", prefix.toLowerCase(), volume.getLabel().toLowerCase(), volume.getLabel(), volume.getId().toString());
CqlStatementResult result = statement.withCql(cql).execute().getResult();
Rows<String, IndexColumnName> rows = result.getRows(indexCF);
Assert.assertEquals(rows.size(), 1);
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class RowMutationTest method testTimeUUID.
@Test
public void testTimeUUID() throws Exception {
Volume volume = new Volume();
URI id1 = URIUtil.createId(Volume.class);
URI pool1 = URIUtil.createId(StoragePool.class);
volume.setId(id1);
volume.setLabel("volume1");
volume.setPool(pool1);
volume.setInactive(false);
volume.setAllocatedCapacity(1000L);
volume.setProvisionedCapacity(2000L);
volume.setAssociatedSourceVolume(URI.create("test"));
volume.setVolumeGroupIds(new StringSet(Sets.newHashSet("v1", "v2")));
getDbClient().updateObject(volume);
DataObjectType doType = TypeMap.getDoType(Volume.class);
OperationResult<ColumnList<CompositeColumnName>> result = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace().prepareQuery(doType.getCF()).getKey(volume.getId().toString()).execute();
List<Long> columnTimeUUIDStamps = new ArrayList<Long>();
for (Column<CompositeColumnName> column : result.getResult()) {
if (column.getName().getTimeUUID() != null) {
columnTimeUUIDStamps.add(TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID()));
}
}
Collections.sort(columnTimeUUIDStamps);
for (int i = 1; i < columnTimeUUIDStamps.size(); i++) {
Assert.assertEquals(1, columnTimeUUIDStamps.get(i) - columnTimeUUIDStamps.get(i - 1));
}
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class RowMutationTest method insertRecordAndIndexColumn.
@Test
public void insertRecordAndIndexColumn() throws ConnectionException {
String rowKey = URIUtil.createId(Volume.class).toString();
String volumeLabel = "volume label";
// insert data object
ColumnListMutation<CompositeColumnName> columnList = rowMutator.getRecordColumnList(volumeCF, rowKey);
columnList.putColumn(new CompositeColumnName("allocatedCapacity"), 20);
columnList.putColumn(new CompositeColumnName("label"), volumeLabel);
// insert related index
rowMutator.getIndexColumnList(indexCF, "vo").putColumn(new IndexColumnName("Volume", volumeLabel, volumeLabel, rowKey, rowMutator.getTimeUUID()), "");
rowMutator.execute();
// verify data object information
Volume volume = (Volume) this.getDbClient().queryObject(URI.create(rowKey));
Assert.assertNotNull(volume);
Assert.assertEquals(volume.getAllocatedCapacity().longValue(), 20L);
Assert.assertEquals(volume.getLabel(), volumeLabel);
// verify index information
CqlStatement statement = ((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace().prepareCqlStatement();
String cql = String.format("select * from \"LabelPrefixIndex\" where key='%s' and column1='Volume' and column2='%s' and column3='%s' and column4='%s'", "vo", volumeLabel, volumeLabel, rowKey);
CqlStatementResult result = statement.withCql(cql).execute().getResult();
Rows<String, IndexColumnName> rows = result.getRows(indexCF);
Assert.assertEquals(rows.size(), 1);
}
Aggregations