Search in sources :

Example 1 with PrefixConstraint

use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.

the class DbIndexTest method testPrefixIndex.

@Test
public void testPrefixIndex() {
    URI id = URIUtil.createId(Volume.class);
    String lbl0 = "abcd1234";
    String lbl1 = "efgh5678";
    PrefixConstraint constraint0 = PrefixConstraint.Factory.getFullMatchConstraint(Volume.class, "label", lbl0);
    PrefixConstraint constraint1 = PrefixConstraint.Factory.getFullMatchConstraint(Volume.class, "label", lbl1);
    {
        Volume obj = new Volume();
        obj.setId(id);
        obj.setLabel(lbl0);
        _dbClient.createObject(obj);
    }
    verifyContain(constraint0, id, 1);
    verifyContain(constraint1, null, 0);
    {
        Volume obj = _dbClient.queryObject(Volume.class, id);
        obj.setLabel(lbl1);
        _dbClient.persistObject(obj);
    }
    verifyContain(constraint1, id, 1);
    verifyContain(constraint0, null, 0);
}
Also used : PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) URI(java.net.URI) Test(org.junit.Test)

Example 2 with PrefixConstraint

use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.

the class DbIndexTest method testScopedLabelIndex.

@Test
public void testScopedLabelIndex() {
    URI id = URIUtil.createId(Volume.class);
    URI pid0 = URIUtil.createId(TenantOrg.class);
    URI pid1 = URIUtil.createId(TenantOrg.class);
    String lbl0 = "abcd1234";
    String lbl1 = "efgh5678";
    PrefixConstraint constraint0 = new LabelConstraintImpl(pid0, lbl0, TypeMap.getDoType(Volume.class).getColumnField("tags"));
    PrefixConstraint constraint1 = new LabelConstraintImpl(pid1, lbl1, TypeMap.getDoType(Volume.class).getColumnField("tags"));
    {
        Volume obj = new Volume();
        obj.setId(id);
        obj.setTag(new ScopedLabelSet());
        obj.getTag().add(new ScopedLabel(pid0.toString(), lbl0));
        _dbClient.createObject(obj);
    }
    verifyContain(constraint0, id, 1);
    verifyContain(constraint1, null, 0);
    {
        Volume obj = _dbClient.queryObject(Volume.class, id);
        obj.getTag().add(new ScopedLabel(pid1.toString(), lbl1));
        _dbClient.persistObject(obj);
    }
    verifyContain(constraint0, id, 1);
    verifyContain(constraint1, id, 1);
    {
        Volume obj = _dbClient.queryObject(Volume.class, id);
        obj.getTag().remove(new ScopedLabel(pid0.toString(), lbl0));
        _dbClient.persistObject(obj);
    }
    verifyContain(constraint1, id, 1);
    verifyContain(constraint0, null, 0);
}
Also used : PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) LabelConstraintImpl(com.emc.storageos.db.client.constraint.impl.LabelConstraintImpl) ContainmentLabelConstraintImpl(com.emc.storageos.db.client.constraint.impl.ContainmentLabelConstraintImpl) URI(java.net.URI) Test(org.junit.Test)

Example 3 with PrefixConstraint

use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.

the class VPlexUtil method lookupVplexProject.

/**
 * Lookup the Project assigned to this VPlex for its artifact, using the Vplex nativeGuid
 * as the project name. If one is found thatbelongs to the root tenant, it is returned.
 * Otherwise the project from the protoVolume is returned.
 *
 * @protoVolume A volume from the backend array.
 *              If no Vplex project is found, the proto volume's project is returned.
 * @param vplexSystem A StorageSystem instance representing a VPlex.
 * @param dbClient A reference to a database client.
 *
 * @return Project instance (vplex project if created, otherwise protoVolume's project).
 */
public static Project lookupVplexProject(Volume protoVolume, StorageSystem vplexSystem, DbClient dbClient) {
    BasePermissionsHelper helper = new BasePermissionsHelper(dbClient);
    TenantOrg rootTenant = helper.getRootTenant();
    PrefixConstraint constraint = PrefixConstraint.Factory.getLabelPrefixConstraint(Project.class, vplexSystem.getNativeGuid());
    URIQueryResultList result = new URIQueryResultList();
    dbClient.queryByConstraint(constraint, result);
    Iterator<URI> iter = result.iterator();
    while (iter.hasNext()) {
        Project project = dbClient.queryObject(Project.class, iter.next());
        if (project == null || project.getInactive() == true) {
            continue;
        }
        if (project.getLabel().equals(vplexSystem.getNativeGuid()) && project.getTenantOrg().getURI().toString().equals(rootTenant.getId().toString())) {
            return project;
        }
    }
    // VPlex project not found. Return on from proto volume.
    return dbClient.queryObject(Project.class, protoVolume.getProject().getURI());
}
Also used : Project(com.emc.storageos.db.client.model.Project) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) URI(java.net.URI) BasePermissionsHelper(com.emc.storageos.security.authorization.BasePermissionsHelper) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 4 with PrefixConstraint

use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.

the class ModelClientImpl method findByPrefix.

@Override
public <T extends DataObject> List<NamedElement> findByPrefix(Class<T> clazz, String columnField, String prefix) throws DatabaseException {
    LOG.debug("findByPrefix({}, {}, {})", new Object[] { clazz, columnField, prefix });
    DataObjectType doType = TypeMap.getDoType(clazz);
    PrefixConstraint constraint = new PrefixConstraintImpl(prefix, doType.getColumnField(columnField));
    return queryNamedElementsByConstraint(constraint);
}
Also used : PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentPrefixConstraintImpl(com.emc.storageos.db.client.constraint.impl.ContainmentPrefixConstraintImpl) PrefixConstraintImpl(com.emc.storageos.db.client.constraint.impl.PrefixConstraintImpl)

Example 5 with PrefixConstraint

use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.

the class BourneDbClient method findByPrefix.

public <T extends DataObject> List<NamedElement> findByPrefix(Class<T> clazz, String prefixColumnField, String prefix) throws DataAccessException {
    LOG.debug("findByPrefix({}, {}, {})", new Object[] { clazz, prefixColumnField, prefix });
    DataObjectType doType = TypeMap.getDoType(clazz);
    PrefixConstraint constraint = new PrefixConstraintImpl(prefix, doType.getColumnField(prefixColumnField));
    return queryNamedElementsByConstraint(constraint);
}
Also used : PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Aggregations

PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)6 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)5 URI (java.net.URI)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 Project (com.emc.storageos.db.client.model.Project)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 BasePermissionsHelper (com.emc.storageos.security.authorization.BasePermissionsHelper)2 Test (org.junit.Test)2 ContainmentLabelConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentLabelConstraintImpl)1 ContainmentPrefixConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentPrefixConstraintImpl)1 LabelConstraintImpl (com.emc.storageos.db.client.constraint.impl.LabelConstraintImpl)1 PrefixConstraintImpl (com.emc.storageos.db.client.constraint.impl.PrefixConstraintImpl)1 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 FCTN_STRING_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI)1 FCTN_VPLEX_MIRROR_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI)1 ProjectElement (com.emc.storageos.model.project.ProjectElement)1 ProjectParam (com.emc.storageos.model.project.ProjectParam)1