Search in sources :

Example 1 with DbClientImpl

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);
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) PrintStream(java.io.PrintStream) TimeSeriesConstraint(com.emc.storageos.db.client.constraint.TimeSeriesConstraint) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) URI(java.net.URI) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) InvalidParameterException(java.security.InvalidParameterException) WebApplicationException(javax.ws.rs.WebApplicationException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 2 with DbClientImpl

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);
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ColumnList(com.netflix.astyanax.model.ColumnList) List(java.util.List) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) URI(java.net.URI)

Example 3 with DbClientImpl

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);
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 4 with DbClientImpl

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();
    }
}
Also used : DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 5 with DbClientImpl

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);
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ColumnField(com.emc.storageos.db.client.impl.ColumnField) RangeBuilder(com.netflix.astyanax.util.RangeBuilder) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) ClassNameTimeSeries(com.emc.storageos.db.client.model.ClassNameTimeSeries) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) MutationBatch(com.netflix.astyanax.MutationBatch) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) Rows(com.netflix.astyanax.model.Rows)

Aggregations

DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)27 Test (org.junit.Test)11 URI (java.net.URI)9 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)6 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)5 Order (com.emc.storageos.db.client.model.uimodels.Order)5 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)4 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)4 Volume (com.emc.storageos.db.client.model.Volume)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)4 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)4 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)3 DbClientContext (com.emc.storageos.db.client.impl.DbClientContext)3 DbConsistencyCheckerHelper (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper)3 GlobalLockImpl (com.emc.storageos.db.client.impl.GlobalLockImpl)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)3 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2