Search in sources :

Example 1 with LabelConstraintImpl

use of com.emc.storageos.db.client.constraint.impl.LabelConstraintImpl 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 2 with LabelConstraintImpl

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

the class DbIndexTest method verifyScopedLabelDbIndex.

private void verifyScopedLabelDbIndex(DataObject obj, ColumnField field, Object val, boolean indexByKey, DbClient client) {
    switch(field.getType()) {
        case TrackingSet:
            for (ScopedLabel scopedLabel : (AbstractChangeTrackingSet<ScopedLabel>) val) {
                LabelConstraintImpl constraint = new LabelConstraintImpl(URI.create(scopedLabel.getScope()), scopedLabel.getLabel(), field);
                verifyContain(constraint, obj.getId(), -1, client);
            }
            break;
        case Id:
        case NamedURI:
        case NestedObject:
        case Primitive:
        case TrackingMap:
        case TrackingSetMap:
        default:
            throw new IllegalArgumentException(String.format("Field type %s is not supported by ScopedLabelDbIndex", field.getType().toString()));
    }
}
Also used : LabelConstraintImpl(com.emc.storageos.db.client.constraint.impl.LabelConstraintImpl) ContainmentLabelConstraintImpl(com.emc.storageos.db.client.constraint.impl.ContainmentLabelConstraintImpl)

Aggregations

ContainmentLabelConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentLabelConstraintImpl)2 LabelConstraintImpl (com.emc.storageos.db.client.constraint.impl.LabelConstraintImpl)2 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 URI (java.net.URI)1 Test (org.junit.Test)1