Search in sources :

Example 51 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class TaskMapper method toTask.

public static TaskResourceRep toTask(DataObject resource, List<? extends DataObject> assocResources, String taskId, Operation operation) {
    TaskResourceRep task = toTask(resource, taskId, operation);
    List<NamedRelatedResourceRep> associatedReps = new ArrayList<NamedRelatedResourceRep>();
    for (DataObject assoc : assocResources) {
        associatedReps.add(toNamedRelatedResource(assoc));
    }
    task.setAssociatedResources(associatedReps);
    return task;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep)

Example 52 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class InternalDbClient method resetFields.

public void resetFields(Class<? extends DataObject> clazz, Map<String, ColumnField> setFields, boolean ignore) throws Exception {
    DataObjectType doType = TypeMap.getDoType(clazz);
    if (doType == null) {
        throw new IllegalArgumentException();
    }
    try {
        Keyspace ks = getKeyspace(clazz);
        OperationResult<Rows<String, CompositeColumnName>> result = ks.prepareQuery(doType.getCF()).getAllRows().setRowLimit(DEFAULT_PAGE_SIZE).execute();
        Iterator<Row<String, CompositeColumnName>> it = result.getResult().iterator();
        RemovedColumnsList removedList = new RemovedColumnsList();
        List<DataObject> objects = new ArrayList<>(DEFAULT_PAGE_SIZE);
        String key = null;
        Exception lastEx = null;
        while (it.hasNext()) {
            try {
                Row<String, CompositeColumnName> row = it.next();
                if (row.getColumns().size() == 0) {
                    continue;
                }
                key = row.getKey();
                DataObject obj = DataObject.createInstance(clazz, URI.create(key));
                obj.trackChanges();
                objects.add(obj);
                Iterator<Column<CompositeColumnName>> columnIterator = row.getColumns().iterator();
                while (columnIterator.hasNext()) {
                    Column<CompositeColumnName> column = columnIterator.next();
                    ColumnField columnField = setFields.get(column.getName().getOne());
                    if (columnField != null) {
                        columnField.deserialize(column, obj);
                        removedList.add(key, column);
                    }
                }
                if (objects.size() == DEFAULT_PAGE_SIZE) {
                    boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
                    RowMutator mutator = new RowMutator(ks, retryFailedWriteWithLocalQuorum);
                    _indexCleaner.removeColumnAndIndex(mutator, doType, removedList);
                    persistObject(objects);
                    objects.clear();
                    removedList.clear();
                }
            } catch (Exception e) {
                String message = String.format("DB migration failed reason: reset data key='%s'", key);
                log.error(message);
                log.error("e=", e);
                if (ignore) {
                    lastEx = e;
                    continue;
                }
                throw e;
            }
        }
        if (lastEx != null) {
            throw lastEx;
        }
        if (!objects.isEmpty()) {
            boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
            RowMutator mutator = new RowMutator(ks, retryFailedWriteWithLocalQuorum);
            _indexCleaner.removeColumnAndIndex(mutator, doType, removedList);
            persistObject(objects);
        }
    } catch (ConnectionException e) {
        throw DatabaseException.retryables.connectionFailed(e);
    } catch (final InstantiationException e) {
        throw DatabaseException.fatals.queryFailed(e);
    } catch (final IllegalAccessException e) {
        throw DatabaseException.fatals.queryFailed(e);
    }
}
Also used : DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) DataObject(com.emc.storageos.db.client.model.DataObject) Column(com.netflix.astyanax.model.Column) Keyspace(com.netflix.astyanax.Keyspace) Row(com.netflix.astyanax.model.Row) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) Rows(com.netflix.astyanax.model.Rows)

Example 53 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class InternalDbClient method migrateToGeoDb.

// only used during migration stage in single thread, so it's safe to suppress
@SuppressWarnings("findbugs:IS2_INCONSISTENT_SYNC")
public <T extends DataObject> void migrateToGeoDb(Class<T> clazz) {
    DataObjectType doType = TypeMap.getDoType(clazz);
    if (doType == null) {
        throw new IllegalArgumentException();
    }
    if (!KeyspaceUtil.isGlobal(clazz)) {
        throw new IllegalArgumentException(String.format("CF %s is not a global resource", clazz.getName()));
    }
    // this CF ensured to be a global resource
    doType.setEncryptionProvider(_geoEncryptionProvider);
    // find all the records of CF <T> in local db, similar to queryByType(clazz, false)
    URIQueryResultList result = new URIQueryResultList();
    DecommissionedConstraint constraint = DecommissionedConstraint.Factory.getAllObjectsConstraint(clazz, null);
    constraint.setKeyspace(localContext.getKeyspace());
    constraint.execute(result);
    Iterator<URI> recIt = result.iterator();
    List<URI> batch = getNextBatch(recIt);
    while (!batch.isEmpty()) {
        Rows<String, CompositeColumnName> rows = queryRowsWithAllColumns(localContext.getKeyspace(), batch, doType.getCF());
        Iterator<Row<String, CompositeColumnName>> it = rows.iterator();
        while (it.hasNext()) {
            Row<String, CompositeColumnName> row = it.next();
            try {
                if (row.getColumns().size() == 0) {
                    continue;
                }
                // can't simply use doType.deserialize(clazz, row, cleanList) below
                // since the DataObject instance retrieved in this way doesn't have
                // change tracking information within and nothing gets persisted into
                // db in the end.
                log.info("Migrating record {} to geo db", row.getKey());
                DataObject obj = DataObject.createInstance(clazz, URI.create(row.getKey()));
                obj.trackChanges();
                Iterator<Column<CompositeColumnName>> columnIterator = row.getColumns().iterator();
                while (columnIterator.hasNext()) {
                    Column<CompositeColumnName> column = columnIterator.next();
                    ColumnField columnField = doType.getColumnField(column.getName().getOne());
                    if (columnField.isEncrypted()) {
                        // Decrypt using the local encryption provider and later
                        // encrypt it again using the geo encryption provider
                        columnField.deserializeEncryptedColumn(column, obj, _encryptionProvider);
                    } else {
                        columnField.deserialize(column, obj);
                    }
                    // set changed for ChangeTracking structures
                    columnField.setChanged(obj);
                }
                // persist the object into geo db, similar to createObject(objects)
                // only that we need to specify the keyspace explicitly here
                // also we shouldn't overwrite the creation time
                boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
                RowMutator mutator = new RowMutator(geoContext.getKeyspace(), retryFailedWriteWithLocalQuorum);
                doType.serialize(mutator, obj);
                mutator.execute();
            } catch (final InstantiationException e) {
                throw DatabaseException.fatals.queryFailed(e);
            } catch (final IllegalAccessException e) {
                throw DatabaseException.fatals.queryFailed(e);
            }
        }
        batch = getNextBatch(recIt);
    }
}
Also used : URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DataObject(com.emc.storageos.db.client.model.DataObject) Column(com.netflix.astyanax.model.Column) DecommissionedConstraint(com.emc.storageos.db.client.constraint.DecommissionedConstraint) Row(com.netflix.astyanax.model.Row)

Example 54 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class InternalDbClient method generateFieldIndex.

// TODO geo : migration only works for local keyspace; need to expand to use local or global
public <T extends DataObject> void generateFieldIndex(Class<T> clazz, String fieldName) {
    DataObjectType doType = TypeMap.getDoType(clazz);
    if (doType == null) {
        throw new IllegalArgumentException();
    }
    ColumnField columnField = doType.getColumnField(fieldName);
    if (columnField == null) {
        throw new IllegalArgumentException();
    }
    List<URI> allrecs = queryByType(clazz, false);
    Keyspace ks = getKeyspace(clazz);
    Iterator<URI> recIt = allrecs.iterator();
    List<URI> batch = getNextBatch(recIt);
    while (!batch.isEmpty()) {
        Rows<String, CompositeColumnName> rows = queryRowsWithAColumn(ks, batch, doType.getCF(), columnField);
        List<T> objects = new ArrayList<T>(rows.size());
        Iterator<Row<String, CompositeColumnName>> it = rows.iterator();
        while (it.hasNext()) {
            Row<String, CompositeColumnName> row = it.next();
            try {
                if (row.getColumns().size() == 0) {
                    continue;
                }
                DataObject obj = DataObject.createInstance(clazz, URI.create(row.getKey()));
                obj.trackChanges();
                Iterator<Column<CompositeColumnName>> columnIterator = row.getColumns().iterator();
                while (columnIterator.hasNext()) {
                    Column<CompositeColumnName> column = columnIterator.next();
                    columnField.deserialize(column, obj);
                }
                // set changed for ChangeTracking structures
                columnField.setChanged(obj);
                objects.add(clazz.cast(obj));
            } catch (final InstantiationException e) {
                throw DatabaseException.fatals.queryFailed(e);
            } catch (final IllegalAccessException e) {
                throw DatabaseException.fatals.queryFailed(e);
            }
        }
        updateAndReindexObject(objects);
        batch = getNextBatch(recIt);
    }
}
Also used : URI(java.net.URI) DataObject(com.emc.storageos.db.client.model.DataObject) Column(com.netflix.astyanax.model.Column) Keyspace(com.netflix.astyanax.Keyspace) Row(com.netflix.astyanax.model.Row)

Example 55 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class DbClientTest method checkAggregatedQuery.

private void checkAggregatedQuery(Iterator<AggregationQueryResultList.AggregatedEntry> it, Class<? extends DataObject> clazz, String field, Map<URI, ? extends DataObject> validatedObj) {
    int count = 0;
    while (it.hasNext()) {
        AggregationQueryResultList.AggregatedEntry entry = it.next();
        _logger.info("         " + entry.getId() + ";  capacity = " + entry.getValue().toString());
        DataObject obj = validatedObj.get(entry.getId());
        DataObjectType doType = TypeMap.getDoType(clazz);
        Object value = ColumnField.getFieldValue(doType.getColumnField(field), obj);
        Assert.assertEquals(value, entry.getValue());
        count++;
    }
    Assert.assertEquals(count, validatedObj.size());
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) DataObject(com.emc.storageos.db.client.model.DataObject) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)154 URI (java.net.URI)62 ArrayList (java.util.ArrayList)53 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)44 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)30 Volume (com.emc.storageos.db.client.model.Volume)26 NamedURI (com.emc.storageos.db.client.model.NamedURI)24 StringSet (com.emc.storageos.db.client.model.StringSet)23 HashMap (java.util.HashMap)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)17 HashSet (java.util.HashSet)17 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)16 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)14 Operation (com.emc.storageos.db.client.model.Operation)13 List (java.util.List)10 Set (java.util.Set)10 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)9 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8