use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class OrderService method exportOrders.
private void exportOrders(List<URI> tids, long startTime, long endTime, OutputStream outputStream, OrderJobStatus status) {
PrintStream out = new PrintStream(outputStream);
out.println("ORDER DETAILS");
out.println("-------------");
List<URI> orderIDs = status.getOrderIDs();
if (!orderIDs.isEmpty()) {
dumpOrders(out, orderIDs, status);
} else {
long completed = 0;
long failed = 0;
for (URI tid : tids) {
TimeSeriesConstraint constraint = TimeSeriesConstraint.Factory.getOrders(tid, startTime, endTime);
DbClientImpl dbclient = (DbClientImpl) _dbClient;
constraint.setKeyspace(dbclient.getKeyspace(Order.class));
NamedElementQueryResultList ids = new NamedElementQueryResultList();
_dbClient.queryByConstraint(constraint, ids);
for (NamedElementQueryResultList.NamedElement namedID : ids) {
URI id = namedID.getId();
try {
dumpOrder(out, id, status);
completed++;
} catch (Exception e) {
failed++;
}
}
}
status.setTotal(completed + failed);
}
try {
saveJobInfo(status);
} catch (Exception e) {
log.error("Failed to save job info status={} e=", status, e);
}
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class StaleRelationURICleanupMigration method process.
@Override
public void process() throws MigrationCallbackException {
initRelationFields();
DbClientImpl dbClient = (DbClientImpl) getDbClient();
for (Entry<Class<? extends DataObject>, List<String>> entry : relationFields.entrySet()) {
DataObjectType doType = TypeMap.getDoType(entry.getKey());
// for each class, query out all objects iteratively
List<URI> uriList = dbClient.queryByType(entry.getKey(), true);
Iterator<DataObject> resultIterator = (Iterator<DataObject>) dbClient.queryIterativeObjects(entry.getKey(), uriList, true);
while (resultIterator.hasNext()) {
DataObject dataObject = resultIterator.next();
boolean isChanged = false;
for (String relationField : entry.getValue()) {
isChanged |= doRelationURICleanup(doType, dataObject, relationField);
}
if (isChanged) {
totalModifiedObject++;
dbClient.updateObject(dataObject);
}
}
}
log.info("Totally found {} stale/invalid URI keys", totalStaleURICount);
log.info("Totally {} data objects have been modifed to remove stale/invalid URI", totalModifiedObject);
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class VDCRoleMigrationCallback method buildDbClient.
public static DbClient buildDbClient() {
try {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/dbclient-conf.xml");
DbClientImpl dbClient = (DbClientImpl) ctx.getBean("dbclient");
dbClient.start();
return dbClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class StaleIndexCleanerMigration method process.
@Override
public void process() throws MigrationCallbackException {
checkHelper = new DbConsistencyCheckerHelper((DbClientImpl) getDbClient());
checkHelper.setDoubleConfirmed(false);
Map<String, IndexAndCf> allIdxCfs = getAllIndexCFs();
CheckResult checkResult = new CheckResult();
try {
for (IndexAndCf indexAndCf : allIdxCfs.values()) {
try {
checkHelper.checkIndexingCF(indexAndCf, false, checkResult, true);
} catch (ConnectionException e) {
log.error("Failed to check stale index CF {}", indexAndCf, e);
}
}
ThreadPoolExecutor executor = checkHelper.getExecutor();
executor.shutdown();
try {
if (!executor.awaitTermination(120, TimeUnit.SECONDS)) {
executor.shutdownNow();
}
} catch (Exception e) {
executor.shutdownNow();
}
log.info("Totally find {} stale index", checkResult.getTotal());
if (checkResult.getTotal() > 0) {
executeCleanupScripts();
}
} catch (Exception e) {
log.error("failed to cleanup stale/invalid index:", e);
} finally {
DbCheckerFileWriter.close();
}
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class UserToOrdersMigration method process.
@Override
public void process() throws MigrationCallbackException {
log.info("Adding new index records for class: {} field: {} annotation: {} name={}", new Object[] { Order.class, Order.SUBMITTED_BY_USER_ID, ClassNameTimeSeries.class.getName(), name });
DataObjectType doType = TypeMap.getDoType(Order.class);
ColumnField field = doType.getColumnField(Order.SUBMITTED_BY_USER_ID);
newIndexCF = field.getIndexCF();
ColumnFamily<String, IndexColumnName> userToOrders = new ColumnFamily<>(SOURCE_INDEX_CF_NAME, StringSerializer.get(), IndexColumnNameSerializer.get());
DbClientImpl client = (DbClientImpl) dbClient;
ks = client.getKeyspace(Order.class);
MutationBatch mutationBatch = ks.prepareMutationBatch();
long m = 0;
try {
OperationResult<Rows<String, IndexColumnName>> result = ks.prepareQuery(userToOrders).getAllRows().setRowLimit(1000).withColumnRange(new RangeBuilder().setLimit(0).build()).execute();
ColumnList<IndexColumnName> cols;
for (Row<String, IndexColumnName> row : result.getResult()) {
RowQuery<String, IndexColumnName> rowQuery = ks.prepareQuery(userToOrders).getKey(row.getKey()).autoPaginate(true).withColumnRange(new RangeBuilder().setLimit(5).build());
while (!(cols = rowQuery.execute().getResult()).isEmpty()) {
m++;
for (Column<IndexColumnName> col : cols) {
String indexKey = row.getKey();
String orderId = col.getName().getTwo();
ClassNameTimeSeriesIndexColumnName newCol = new ClassNameTimeSeriesIndexColumnName(col.getName().getOne(), orderId, col.getName().getTimeUUID());
mutationBatch.withRow(newIndexCF, indexKey).putEmptyColumn(newCol, null);
if (m % 10000 == 0) {
mutationBatch.execute();
}
}
}
}
mutationBatch.execute();
} catch (Exception e) {
log.error("Migration to {} failed e=", newIndexCF.getName(), e);
}
}
Aggregations