Search in sources :

Example 11 with ScopedLabel

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

the class XIVSmisCommandHelper method removeLabel.

private void removeLabel(ScopedLabelSet tagSet, String scope) {
    ScopedLabel oldScopedLabel = null;
    Iterator<ScopedLabel> itr = tagSet.iterator();
    while (itr.hasNext()) {
        ScopedLabel scopedLabel = itr.next();
        if (scope.equals(scopedLabel.getScope())) {
            oldScopedLabel = scopedLabel;
            break;
        }
    }
    if (oldScopedLabel != null) {
        tagSet.remove(oldScopedLabel);
    }
}
Also used : ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel)

Example 12 with ScopedLabel

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

the class DbClientTest method testTagIndex.

@Test
public void testTagIndex() throws Exception {
    _logger.info("Starting testTagIndex");
    final int objCount = 1000;
    final String prefix = "55";
    Set<URI> expectedResult = new HashSet<URI>();
    URI tenant = URIUtil.createId(TenantOrg.class);
    DbClient dbClient = _dbClient;
    for (int index = 0; index < objCount; index++) {
        FileShare fs = new FileShare();
        fs.setId(URIUtil.createId(FileShare.class));
        fs.setLabel("foobar");
        String tag = String.format("%1$d - test label", index);
        if (tag.startsWith(prefix)) {
            expectedResult.add(fs.getId());
        }
        ScopedLabelSet tagSet = new ScopedLabelSet();
        tagSet.add(new ScopedLabel(tenant.toString(), tag));
        fs.setTag(tagSet);
        dbClient.persistObject(fs);
    }
    List<URI> hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, prefix, null));
    Assert.assertEquals(hits.size(), expectedResult.size());
    for (int i = 0; i < hits.size(); i++) {
        Assert.assertTrue(expectedResult.contains(hits.get(i)));
    }
    hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, prefix, tenant));
    Assert.assertEquals(hits.size(), expectedResult.size());
    for (int i = 0; i < hits.size(); i++) {
        Assert.assertTrue(expectedResult.contains(hits.get(i)));
    }
    hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, "foobar", tenant));
    Assert.assertEquals(hits.size(), 0);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) 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) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with ScopedLabel

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

the class DbConsistencyCheckerHelper method getIndexColumns.

public static Object[] getIndexColumns(ColumnField field, Column<CompositeColumnName> column, String rowKey) {
    Object[] indexColumns = null;
    DbIndex dbIndex = field.getIndex();
    if (dbIndex instanceof AggregateDbIndex) {
        // Not support this index type yet.
        return indexColumns;
    }
    if (dbIndex instanceof NamedRelationDbIndex) {
        indexColumns = new String[4];
        indexColumns[0] = field.getDataObjectType().getSimpleName();
        NamedURI namedURI = NamedURI.fromString(column.getStringValue());
        String name = namedURI.getName();
        indexColumns[1] = name.toLowerCase();
        indexColumns[2] = name;
        indexColumns[3] = rowKey;
    } else if (dbIndex instanceof PrefixDbIndex) {
        indexColumns = new String[4];
        indexColumns[0] = field.getDataObjectType().getSimpleName();
        indexColumns[1] = column.getStringValue().toLowerCase();
        indexColumns[2] = column.getStringValue();
        indexColumns[3] = rowKey;
    } else if (dbIndex instanceof ScopedLabelDbIndex) {
        indexColumns = new String[4];
        indexColumns[0] = field.getDataObjectType().getSimpleName();
        ScopedLabel label = ScopedLabel.fromString(column.getStringValue());
        indexColumns[1] = label.getLabel().toLowerCase();
        indexColumns[2] = label.getLabel();
        indexColumns[3] = rowKey;
    } else if (dbIndex instanceof DecommissionedDbIndex) {
        indexColumns = new String[2];
        Boolean val = column.getBooleanValue();
        indexColumns[0] = val.toString();
        indexColumns[1] = rowKey;
    } else if (dbIndex instanceof ClassNameTimeSeriesDBIndex || dbIndex instanceof TimeSeriesDbIndex) {
        indexColumns = new Object[3];
        indexColumns[0] = field.getDataObjectType().getSimpleName();
        indexColumns[1] = TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID());
        indexColumns[2] = rowKey;
    } else {
        // For AltIdDbIndex, RelationDbIndex, PermissionsDbIndex
        indexColumns = new String[2];
        indexColumns[0] = field.getDataObjectType().getSimpleName();
        indexColumns[1] = rowKey;
    }
    return indexColumns;
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) DataObject(com.emc.storageos.db.client.model.DataObject)

Example 14 with ScopedLabel

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

the class VolumeBootVolumeMigrationTest method verifyVolumeResults.

/**
 * Verifies the results for migrating volumes
 *
 * @throws Exception When an error occurs verifying the Volume
 *             migration results.
 */
private void verifyVolumeResults() throws Exception {
    log.info("Verifying updated Volume boot volume tag for VolumeBootVolumeMigration handler");
    for (Entry<URI, URI> volumeToHostId : volumeToHostIds.entrySet()) {
        Volume volume = _dbClient.queryObject(Volume.class, volumeToHostId.getKey());
        if (volume.getLabel().equals("VOL1-ABOOTVOLUME")) {
            // Make sure volume1 has the new tag
            Assert.assertNotNull("Tag Set of volume 1 must be non-null", volume.getTag());
            Assert.assertTrue("Tag set of volume 1 must be non-empty", !volume.getTag().isEmpty());
            ScopedLabel sl = volume.getTag().iterator().next();
            Assert.assertEquals(sl.getScope(), volume.getTenant().getURI().toASCIIString());
            Assert.assertEquals(sl.getLabel(), "vipr:bootVolume=" + volumeToHostId.getValue().toASCIIString());
        }
        if (volume.getLabel().equals("VOL2-ABOOTVOLUME")) {
            // Make sure volume1 has the new tag
            Assert.assertNotNull("Tag Set of volume 1 must be non-null", volume.getTag());
            Assert.assertTrue("Tag set of volume 2 must be non-empty", !volume.getTag().isEmpty());
            boolean found = false;
            Iterator<ScopedLabel> slIter = volume.getTag().iterator();
            while (slIter.hasNext()) {
                ScopedLabel sl = slIter.next();
                if (sl.getScope().equals(volume.getTenant().getURI().toASCIIString()) && (sl.getLabel().equals("vipr:bootVolume=" + volumeToHostId.getValue().toASCIIString()))) {
                    found = true;
                }
            }
            Assert.assertTrue("Tag not found in tag set", found);
        }
        if (volume.getLabel().equals("VOL3-NOTABOOTVOLUME")) {
            // Make sure volume1 has no tags
            Assert.assertNull("Tag Set of volume 3 must be null", volume.getTag());
        }
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 15 with ScopedLabel

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

the class VolumeBootVolumeMigrationTest method prepareVolumeData.

/**
 * Prepares the data for RP volume tests.
 *
 * @throws Exception When an error occurs preparing the RP volume data.
 */
private void prepareVolumeData() throws Exception {
    log.info("Preparing Volumes for VolumeAccessStateLinkStatusMigration");
    TenantOrg tenantOrg = new TenantOrg();
    URI tenantOrgURI = URIUtil.createId(TenantOrg.class);
    tenantOrg.setId(tenantOrgURI);
    _dbClient.createObject(tenantOrg);
    Project proj = new Project();
    URI projectURI = URIUtil.createId(Project.class);
    String projectLabel = "project";
    proj.setId(projectURI);
    proj.setLabel(projectLabel);
    proj.setTenantOrg(new NamedURI(tenantOrgURI, projectLabel));
    _dbClient.createObject(proj);
    // Create a boot volume for a host with no tags
    Volume vol1 = new Volume();
    URI vol1URI = URIUtil.createId(Volume.class);
    vol1.setId(vol1URI);
    vol1.setLabel("VOL1-ABOOTVOLUME");
    vol1.setTenant(new NamedURI(tenantOrgURI, "provider"));
    _dbClient.createObject(vol1);
    // Create a host object with a boot volume
    Host host1 = new Host();
    URI host1URI = URIUtil.createId(Host.class);
    host1.setId(host1URI);
    host1.setHostName("Host1WithBootVol");
    host1.setBootVolumeId(vol1URI);
    volumeToHostIds.put(vol1URI, host1URI);
    _dbClient.createObject(host1);
    // Create a boot volume for a host with existing tags
    Volume vol2 = new Volume();
    URI vol2URI = URIUtil.createId(Volume.class);
    vol2.setId(vol2URI);
    vol2.setLabel("VOL2-ABOOTVOLUME");
    vol2.setTenant(new NamedURI(tenantOrgURI, "provider"));
    ScopedLabel label = new ScopedLabel();
    label.setScope(tenantOrg.getId().toASCIIString());
    label.setLabel("vipr:someothertag=" + vol2URI.toASCIIString());
    ScopedLabelSet labelSet = new ScopedLabelSet();
    labelSet.add(label);
    vol2.setTag(labelSet);
    _dbClient.createObject(vol2);
    // Create a host object with a boot volume
    Host host2 = new Host();
    URI host2URI = URIUtil.createId(Host.class);
    host2.setId(host2URI);
    host2.setHostName("Host2WithBootVol");
    host2.setBootVolumeId(vol2URI);
    volumeToHostIds.put(vol2URI, host2URI);
    _dbClient.createObject(host2);
    // Create a volume with no host association
    Volume vol3 = new Volume();
    URI vol3URI = URIUtil.createId(Volume.class);
    vol3.setId(vol3URI);
    vol3.setLabel("VOL3-NOTABOOTVOLUME");
    vol3.setTenant(new NamedURI(tenantOrgURI, "provider"));
    volumeToHostIds.put(vol3URI, null);
    _dbClient.createObject(vol3);
}
Also used : Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) Volume(com.emc.storageos.db.client.model.Volume) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Host(com.emc.storageos.db.client.model.Host) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet)

Aggregations

ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)23 ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)14 URI (java.net.URI)9 Volume (com.emc.storageos.db.client.model.Volume)7 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 ArrayList (java.util.ArrayList)5 Host (com.emc.storageos.db.client.model.Host)4 Project (com.emc.storageos.db.client.model.Project)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Produces (javax.ws.rs.Produces)4 BlockServiceApi (com.emc.storageos.api.service.impl.resource.BlockServiceApi)3 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)3 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 StringMap (com.emc.storageos.db.client.model.StringMap)3 TaskList (com.emc.storageos.model.TaskList)3 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)3 BlockFullCopyManager (com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager)2 DbClient (com.emc.storageos.db.client.DbClient)2