Search in sources :

Example 86 with DataObject

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

the class FieldValueTimeUUIDPair method rebuildIndex.

private void rebuildIndex(DataObjectType doType, ColumnField columnField, Object value, String rowKey, Column<CompositeColumnName> column, RowMutator rowMutator) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    rowMutator.getRecordColumnList(doType.getCF(), rowKey).deleteColumn(column.getName());
    rowMutator.resetTimeUUIDStartTime(TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID()));
    DataObject dataObject = DataObject.createInstance(doType.getDataObjectClass(), URI.create(rowKey));
    dataObject.trackChanges();
    columnField.getPropertyDescriptor().getWriteMethod().invoke(dataObject, value);
    columnField.serialize(dataObject, rowMutator);
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject)

Example 87 with DataObject

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

the class Joiner method joinBid2A.

/**
 * Join A to B where B's id is in A's joinToField
 * Here the assumption is that we have already computed the necessary A's,
 * either by previous joins or selections on A columns, as the normal case.
 * If the number of potential As is less than the number of potential Bs,
 * we will just find all the Bs in the As by iterating.
 * Otherwise if the number of potential Bs ls less than the number of potential As,
 * we use a containment constraint to find the A's containing each B and eliminate
 * any A's found that are not in the A result set.
 *
 * @param jc
 */
private void joinBid2A(JClass jc, Set<URI> selectionUris) {
    JClass joinToClass = lookupAlias(jc.joinToAlias);
    String joinToField = jc.getJoinToField();
    Set<URI> bURIs = selectionUris;
    if (bURIs == null) {
        bURIs = engine.queryByType(jc.getClazz());
    }
    jc.setCacheValid(true);
    // Determine if A's joinToField is indexed.
    boolean aIndexed = joinToClass.getMetaData().isIndexed(joinToField);
    if (!aIndexed || joinToClass.getUris().size() < bURIs.size()) {
        // Common case; A is already bounded smaller than B universe.
        // Therefore we iterate through the As and select only the corresponding Bs.
        Iterator aIter = joinToClass.iterator(engine);
        while (aIter.hasNext()) {
            DataObject object = (DataObject) aIter.next();
            Method method = getGettr(joinToClass, joinToField);
            if (method == null) {
                throw new JoinerException("Cannot find gettr for join: " + jc.getField());
            }
            Object values = null;
            try {
                values = method.invoke(object);
            } catch (Exception ex) {
                log.warn("failed to invoke {} ", method.getName());
            }
            for (URI uri : bURIs) {
                if (uriInObject(uri, values)) {
                    DataObject bobj = engine.queryObject(jc.getClazz(), uri);
                    if (testSelections(jc, bobj) == false) {
                        continue;
                    }
                    jc.addToJoinMap(object.getId(), uri);
                    jc.getUris().add(uri);
                    jc.addToCache(bobj);
                }
            }
        }
    } else {
        // So use a constraint query.
        for (URI bURI : bURIs) {
            Constraint constraint = joinToClass.getMetaData().buildConstraint(bURI, joinToClass.getClazz(), joinToField);
            Set<URI> aURIs = engine.queryByConstraint(constraint);
            for (URI aURI : aURIs) {
                // If aURI is not in the result set of A, then skip it
                if (!joinToClass.getUris().contains(aURI)) {
                    continue;
                }
                DataObject object = (DataObject) engine.queryObject(jc.getClazz(), bURI);
                if (testSelections(jc, object) == false) {
                    continue;
                }
                jc.addToJoinMap(aURI, bURI);
                jc.addToCache(object);
                jc.getUris().add(bURI);
            }
        }
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) Constraint(com.emc.storageos.db.client.constraint.Constraint) Iterator(java.util.Iterator) DataObject(com.emc.storageos.db.client.model.DataObject) Method(java.lang.reflect.Method) URI(java.net.URI)

Example 88 with DataObject

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

the class Joiner method joinAid2B.

/**
 * Join B to A where A's ID is in B's "field"
 * B's field must be indexed.
 * Here we find only the Bs that contain A in the specified field using
 * a containment constraint (i.e. the id of A is contained in B's field).
 *
 * @param jc
 */
private void joinAid2B(JClass jc, Set<URI> selectionUris) {
    JClass joinToClass = lookupAlias(jc.joinToAlias);
    Set<URI> joinToUris = joinToClass.getUris();
    boolean manualMatch = false;
    jc.setCacheValid(true);
    for (URI aURI : joinToUris) {
        Set<URI> bURIs = null;
        if (jc.getMetaData().isIndexed(jc.getField())) {
            Constraint constraint = jc.getMetaData().buildConstraint(aURI, jc.getClazz(), jc.getField());
            bURIs = engine.queryByConstraint(constraint);
        } else {
            log.info(String.format("Joiner suboptimal query %s.%s should be indexed to join to %s", jc.getClazz().getSimpleName(), jc.getField(), joinToClass.getClazz().getSimpleName()));
            bURIs = engine.queryByType(jc.getClazz());
            manualMatch = true;
        }
        for (URI bURI : bURIs) {
            // Skip any objects that will not pass selection index
            if (selectionUris != null && !selectionUris.contains(bURI)) {
                continue;
            }
            DataObject object = (DataObject) engine.queryObject(jc.getClazz(), bURI);
            // If the join field was not indexed, manually match A's UID against the B field.
            if (manualMatch) {
                Method method = getGettr(jc, jc.getField());
                if (method == null) {
                    throw new JoinerException("Cannot find gettr for join: " + jc.getField());
                }
                Object values = null;
                try {
                    values = method.invoke(object);
                } catch (Exception ex) {
                    log.warn("failed to invoke method {}", method.getName());
                }
                if (!uriInObject(aURI, values)) {
                    continue;
                }
            }
            if (testSelections(jc, object) == false) {
                continue;
            }
            jc.addToJoinMap(aURI, bURI);
            jc.addToCache(object);
            jc.getUris().add(bURI);
        }
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) Constraint(com.emc.storageos.db.client.constraint.Constraint) DataObject(com.emc.storageos.db.client.model.DataObject) Method(java.lang.reflect.Method) URI(java.net.URI)

Example 89 with DataObject

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

the class Joiner method queryClass.

/**
 * Implements join and selection for a Class Query.
 * Algorithm:
 * 1. If indexed selection(s) are used, determine the possible URIs for the result
 * set of this Class Query from the intersection of the selection criteria.
 * 2. Execute the class query (joining with a previous class if specified).
 * 3. Do all the selctions (including those that are not indexed.)
 *
 * @param jc
 */
private void queryClass(JClass jc) {
    // Handle an indexed selections.
    // All the index selections are logically ANDed together.
    Set<URI> selectionUris = null;
    List<JSelection> selectionList = jc.getSelections();
    for (JSelection js : selectionList) {
        // id field is a special case; no need to query anything; just add the id field values to selectionURI's
        Set<URI> allValueUris = new HashSet<URI>();
        if (jc.getMetaData().isId(js.getField())) {
            for (Object value : js.getValues()) {
                if (value == null || value.equals("")) {
                    continue;
                }
                allValueUris.add(URI.create(value.toString()));
            }
            if (selectionUris == null) {
                selectionUris = new HashSet<URI>();
                selectionUris.addAll(allValueUris);
            } else {
                selectionUris = andUriSet(selectionUris, allValueUris);
            }
        } else if (jc.getMetaData().isAltIdIndex(js.getField()) || jc.getMetaData().isPrefixIndex(js.getField())) {
            // Process alternate id indexes. These are logically ANDed together.
            for (Object value : js.getValues()) {
                if (value == null || value.equals("")) {
                    continue;
                }
                Constraint constraint = jc.getMetaData().buildConstraint(js.getField(), value.toString());
                allValueUris.addAll(engine.queryByConstraint(constraint));
            }
            if (selectionUris == null) {
                selectionUris = new HashSet<URI>();
                selectionUris.addAll(allValueUris);
            } else {
                selectionUris = andUriSet(selectionUris, allValueUris);
            }
        }
    }
    if (jc.getSubJClasses() != null) {
        joinSubClasses(jc);
    } else if (jc.getJoinToField() != null) {
        // join B.id in A.field
        joinBid2A(jc, selectionUris);
    } else if (jc.getField() != null) {
        // join A.id in B.field
        joinAid2B(jc, selectionUris);
    } else if (jc.getJoinToAlias() == null) {
        // Independent query not joining to previous result
        Set<URI> uris = selectionUris;
        if (uris == null) {
            uris = engine.queryByType(jc.getClazz());
        }
        // Iterate through the URIs for result
        Iterator iter = engine.queryIterObject(jc.getClazz(), uris);
        jc.setCacheValid(true);
        while (iter.hasNext()) {
            DataObject dobj = (DataObject) iter.next();
            // If selections are specified, make sure they pass.
            if (testSelections(jc, dobj) == false) {
                continue;
            }
            jc.addToCache(dobj);
            jc.getUris().add(dobj.getId());
        }
    } else {
        throw new JoinerException("Unrecognized join");
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) DataObject(com.emc.storageos.db.client.model.DataObject) Constraint(com.emc.storageos.db.client.constraint.Constraint) Iterator(java.util.Iterator) DataObject(com.emc.storageos.db.client.model.DataObject) URI(java.net.URI) HashSet(java.util.HashSet)

Example 90 with DataObject

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

the class Joiner method join.

/**
 * @param clazz -- Class extending DataObject
 * @param alias -- String identifier
 * @param ids -- Collection<URI> start with list of ids
 * @return
 */
/**
 * Starts a new query not related to a previous class query filtering the data before joining
 *
 * @param clazz
 * @param alias
 * @param filter can be a list of URI's or a list of DataObjects
 * @return
 */
public <T extends DataObject> Joiner join(Class<? extends DataObject> clazz, String alias, Collection filter) {
    if (!jClasses.isEmpty()) {
        throw new JoinerException("Illegal use of Joiner; starting a new join in the middle of a join chain");
    }
    JClass jc = new JClass(clazz, alias, jClasses.size());
    jClasses.add(jc);
    lastJClass = jc;
    aliasMap.put(alias, jc);
    if (filter == null || filter.isEmpty()) {
        return this;
    } else if (URI.class.isAssignableFrom(filter.iterator().next().getClass())) {
        return match("Id", filter);
    } else if (DataObject.class.isAssignableFrom(filter.iterator().next().getClass())) {
        List<URI> ids = new ArrayList<URI>();
        for (DataObject obj : (Collection<DataObject>) filter) {
            ids.add(obj.getId());
        }
        return match("Id", ids);
    } else {
        // TODO : should this be an exception instead of this?
        return this;
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) Collection(java.util.Collection) URI(java.net.URI)

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